Skip to content

Commit 4731805

Browse files
authored
Dont complete for illegal file module names (#844)
* dont complete for illegal file module names * changelog * better name
1 parent f093f87 commit 4731805

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#### :bug: Bug Fix
1616

1717
- Clean up name of namespaced module when hovering. https://github.com/rescript-lang/rescript-vscode/pull/845
18+
- Don't complete illegal file module names. https://github.com/rescript-lang/rescript-vscode/pull/844
1819
- 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
1920
- Account for namespace when filtering pipe completion items. https://github.com/rescript-lang/rescript-vscode/pull/843
2021

Diff for: analysis/src/CompletionBackEnd.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ let getComplementaryCompletionsForTypedValue ~opens ~allFiles ~scope ~env prefix
502502
Utils.checkName name ~prefix ~exact
503503
&& not
504504
(* TODO complete the namespaced name too *)
505-
(String.contains name '-')
505+
(Utils.fileNameHasUnallowedChars name)
506506
then
507507
Some
508508
(Completion.create name ~env ~kind:(Completion.FileModule name))
@@ -528,7 +528,7 @@ let getCompletionsForPath ~debug ~package ~opens ~full ~pos ~exact ~scope
528528
Utils.checkName name ~prefix ~exact
529529
&& not
530530
(* TODO complete the namespaced name too *)
531-
(String.contains name '-')
531+
(Utils.fileNameHasUnallowedChars name)
532532
then
533533
Some
534534
(Completion.create name ~env ~kind:(Completion.FileModule name))

Diff for: analysis/src/Utils.ml

+7
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,10 @@ let cutAfterDash s =
221221
match String.index s '-' with
222222
| n -> ( try String.sub s 0 n with Invalid_argument _ -> s)
223223
| exception Not_found -> s
224+
225+
let fileNameHasUnallowedChars s =
226+
let regexp = Str.regexp "[^A-Za-z0-9]" in
227+
try
228+
ignore (Str.search_forward regexp s 0);
229+
true
230+
with Not_found -> false

0 commit comments

Comments
 (0)