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

More robust handling of namespaces in pipe completion #850

Merged
merged 2 commits into from
Nov 14, 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
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