Skip to content

Commit

Permalink
More robust handling of namespaces in pipe completion (#850)
Browse files Browse the repository at this point in the history
* more robust handling of namespaces in pipe completion

* changelog
  • Loading branch information
zth authored Nov 14, 2023
1 parent 8f2adcb commit b0b4598
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
## master

#### :bug: Bug Fix

- More robust handling of namespaces in pipe completions. https://github.com/rescript-lang/rescript-vscode/pull/850

## 1.24.0

#### :bug: Bug Fix
Expand Down
6 changes: 1 addition & 5 deletions analysis/src/CompletionBackEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -943,10 +943,6 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
| [_], _ -> Some modulePath
| s :: inner, first :: restPath when s = first ->
removeRawOpen inner restPath
| s :: inner, first :: restPath
when String.contains first '-' && Utils.startsWith first s ->
(* This handles namespaced modules, which have their namespace appended after a '-' *)
removeRawOpen inner restPath
| _ -> None
in
let rec removeRawOpens rawOpens modulePath =
Expand All @@ -959,7 +955,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
| [] -> modulePath
in
let completionPathMinusOpens =
completionPath
completionPath |> Utils.flattenAnyNamespaceInPath
|> removeRawOpens package.opens
|> removeRawOpens rawOpens |> String.concat "."
in
Expand Down
15 changes: 15 additions & 0 deletions analysis/src/Utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,18 @@ let fileNameHasUnallowedChars s =
ignore (Str.search_forward regexp s 0);
true
with Not_found -> false

(* Flattens any namespace in the provided path.
Example:
Globals-RescriptBun.URL.t (which is an illegal path because of the namespace) becomes:
RescriptBun.Globals.URL.t
*)
let rec flattenAnyNamespaceInPath path =
match path with
| [] -> []
| head :: tail ->
if String.contains head '-' then
let parts = String.split_on_char '-' head in
(* Namespaces are in reverse order, so "URL-RescriptBun" where RescriptBun is the namespace. *)
(parts |> List.rev) @ flattenAnyNamespaceInPath tail
else head :: flattenAnyNamespaceInPath tail

0 comments on commit b0b4598

Please sign in to comment.