From e59a87b39a01b65865d27e478bba39dfd9a8a6bd Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 11 Nov 2023 21:37:49 +0100 Subject: [PATCH 1/3] dont complete for illegal file module names --- analysis/src/CompletionBackEnd.ml | 4 ++-- analysis/src/Utils.ml | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index e26048a4b..22eed2b8e 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -502,7 +502,7 @@ let getComplementaryCompletionsForTypedValue ~opens ~allFiles ~scope ~env prefix Utils.checkName name ~prefix ~exact && not (* TODO complete the namespaced name too *) - (String.contains name '-') + (Utils.hasUnallowedChars name) then Some (Completion.create name ~env ~kind:(Completion.FileModule name)) @@ -528,7 +528,7 @@ let getCompletionsForPath ~debug ~package ~opens ~full ~pos ~exact ~scope Utils.checkName name ~prefix ~exact && not (* TODO complete the namespaced name too *) - (String.contains name '-') + (Utils.hasUnallowedChars name) then Some (Completion.create name ~env ~kind:(Completion.FileModule name)) diff --git a/analysis/src/Utils.ml b/analysis/src/Utils.ml index 0f0c14e9c..cd98c4aa4 100644 --- a/analysis/src/Utils.ml +++ b/analysis/src/Utils.ml @@ -221,3 +221,10 @@ let cutAfterDash s = match String.index s '-' with | n -> ( try String.sub s 0 n with Invalid_argument _ -> s) | exception Not_found -> s + +let hasUnallowedChars s = + let regexp = Str.regexp "[^A-Za-z0-9]" in + try + ignore (Str.search_forward regexp s 0); + true + with Not_found -> false From a0aba03a75b746cf4460445020ef0f6a2743271b Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 11 Nov 2023 21:40:21 +0100 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffc96d9db..a5d3e720f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ #### :bug: Bug Fix - Clean up name of namespaced module when hovering. https://github.com/rescript-lang/rescript-vscode/pull/845 +- Don't complete illegal file module names. https://github.com/rescript-lang/rescript-vscode/pull/844 - Fix issue `open` on submodules exposed via `-open` in bsconfig.json/rescript.json, that would cause the content of those `open` modules to not actually appear in autocomplete. https://github.com/rescript-lang/rescript-vscode/pull/842 - Account for namespace when filtering pipe completion items. https://github.com/rescript-lang/rescript-vscode/pull/843 From 7619c0cf76b5644863d49787e766d7f96baf46e7 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Mon, 13 Nov 2023 08:53:39 +0100 Subject: [PATCH 3/3] better name --- analysis/src/CompletionBackEnd.ml | 4 ++-- analysis/src/Utils.ml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 22eed2b8e..d82c3e2b6 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -502,7 +502,7 @@ let getComplementaryCompletionsForTypedValue ~opens ~allFiles ~scope ~env prefix Utils.checkName name ~prefix ~exact && not (* TODO complete the namespaced name too *) - (Utils.hasUnallowedChars name) + (Utils.fileNameHasUnallowedChars name) then Some (Completion.create name ~env ~kind:(Completion.FileModule name)) @@ -528,7 +528,7 @@ let getCompletionsForPath ~debug ~package ~opens ~full ~pos ~exact ~scope Utils.checkName name ~prefix ~exact && not (* TODO complete the namespaced name too *) - (Utils.hasUnallowedChars name) + (Utils.fileNameHasUnallowedChars name) then Some (Completion.create name ~env ~kind:(Completion.FileModule name)) diff --git a/analysis/src/Utils.ml b/analysis/src/Utils.ml index cd98c4aa4..17a9d258d 100644 --- a/analysis/src/Utils.ml +++ b/analysis/src/Utils.ml @@ -222,7 +222,7 @@ let cutAfterDash s = | n -> ( try String.sub s 0 n with Invalid_argument _ -> s) | exception Not_found -> s -let hasUnallowedChars s = +let fileNameHasUnallowedChars s = let regexp = Str.regexp "[^A-Za-z0-9]" in try ignore (Str.search_forward regexp s 0);