Skip to content

Commit

Permalink
Dont complete for illegal file module names (#844)
Browse files Browse the repository at this point in the history
* dont complete for illegal file module names

* changelog

* better name
  • Loading branch information
zth authored Nov 13, 2023
1 parent f093f87 commit 4731805
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions analysis/src/CompletionBackEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions analysis/src/Utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4731805

Please sign in to comment.