Skip to content

Commit b0b4598

Browse files
authored
More robust handling of namespaces in pipe completion (#850)
* more robust handling of namespaces in pipe completion * changelog
1 parent 8f2adcb commit b0b4598

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
## master
1414

15+
#### :bug: Bug Fix
16+
17+
- More robust handling of namespaces in pipe completions. https://github.com/rescript-lang/rescript-vscode/pull/850
18+
1519
## 1.24.0
1620

1721
#### :bug: Bug Fix

analysis/src/CompletionBackEnd.ml

+1-5
Original file line numberDiff line numberDiff line change
@@ -943,10 +943,6 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
943943
| [_], _ -> Some modulePath
944944
| s :: inner, first :: restPath when s = first ->
945945
removeRawOpen inner restPath
946-
| s :: inner, first :: restPath
947-
when String.contains first '-' && Utils.startsWith first s ->
948-
(* This handles namespaced modules, which have their namespace appended after a '-' *)
949-
removeRawOpen inner restPath
950946
| _ -> None
951947
in
952948
let rec removeRawOpens rawOpens modulePath =
@@ -959,7 +955,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
959955
| [] -> modulePath
960956
in
961957
let completionPathMinusOpens =
962-
completionPath
958+
completionPath |> Utils.flattenAnyNamespaceInPath
963959
|> removeRawOpens package.opens
964960
|> removeRawOpens rawOpens |> String.concat "."
965961
in

analysis/src/Utils.ml

+15
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,18 @@ let fileNameHasUnallowedChars s =
228228
ignore (Str.search_forward regexp s 0);
229229
true
230230
with Not_found -> false
231+
232+
(* Flattens any namespace in the provided path.
233+
Example:
234+
Globals-RescriptBun.URL.t (which is an illegal path because of the namespace) becomes:
235+
RescriptBun.Globals.URL.t
236+
*)
237+
let rec flattenAnyNamespaceInPath path =
238+
match path with
239+
| [] -> []
240+
| head :: tail ->
241+
if String.contains head '-' then
242+
let parts = String.split_on_char '-' head in
243+
(* Namespaces are in reverse order, so "URL-RescriptBun" where RescriptBun is the namespace. *)
244+
(parts |> List.rev) @ flattenAnyNamespaceInPath tail
245+
else head :: flattenAnyNamespaceInPath tail

0 commit comments

Comments
 (0)