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 diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index e26048a4b..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 *) - (String.contains 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 *) - (String.contains 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 0f0c14e9c..17a9d258d 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 fileNameHasUnallowedChars s = + let regexp = Str.regexp "[^A-Za-z0-9]" in + try + ignore (Str.search_forward regexp s 0); + true + with Not_found -> false