Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont complete for illegal file module names #844

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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