From 8918dda78ee4c4f13b125fa4868417644d6fdab4 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Tue, 14 Nov 2023 12:27:33 +0100 Subject: [PATCH 1/2] more robust handling of namespaces in pipe completion --- analysis/src/CompletionBackEnd.ml | 6 +----- analysis/src/Utils.ml | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index d82c3e2b6..690308ce2 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -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 = @@ -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 diff --git a/analysis/src/Utils.ml b/analysis/src/Utils.ml index 17a9d258d..6dce76e26 100644 --- a/analysis/src/Utils.ml +++ b/analysis/src/Utils.ml @@ -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 From 2f43fba017e2ce4c3490340cd9c8bde8fc592d3e Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Tue, 14 Nov 2023 15:16:16 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fce661349..561a89ae5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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