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

Use canonicalized URIs/paths for jump to definition #982

Merged
merged 1 commit into from
May 25, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#### :bug: Bug Fix

- Fix highlighting of other languages being affected by rescript-vscode. https://github.com/rescript-lang/rescript-vscode/pull/973
- Use canonicalized URIs/paths for jump to definition. https://github.com/rescript-lang/rescript-vscode/pull/982

#### :nail_care: Polish

Expand Down
4 changes: 3 additions & 1 deletion analysis/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ let main () =
(Json.escape (CreateInterface.command ~path ~cmiFile))
| [_; "format"; path] ->
Printf.printf "\"%s\"" (Json.escape (Commands.format ~path))
| [_; "test"; path] -> Commands.test ~path
| [_; "test"; path] ->
Cfg.isTestMode := true;
Commands.test ~path
| args when List.mem "-h" args || List.mem "--help" args -> prerr_endline help
| _ ->
prerr_endline help;
Expand Down
2 changes: 2 additions & 0 deletions analysis/src/Cfg.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let debugFollowCtxPath = ref false

let isDocGenFromCompiler = ref false

let isTestMode = ref false
10 changes: 8 additions & 2 deletions analysis/src/Commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ let definition ~path ~pos ~debug =
if skipLoc then None
else
Some
{Protocol.uri = Uri.toString uri; range = Utils.cmtLocToRange loc}
{
Protocol.uri = Files.canonicalizeUri uri;
range = Utils.cmtLocToRange loc;
}
| Some _ -> None))
in
print_endline
Expand All @@ -164,7 +167,10 @@ let typeDefinition ~path ~pos ~debug =
| None -> None
| Some (uri, loc) ->
Some
{Protocol.uri = Uri.toString uri; range = Utils.cmtLocToRange loc}))
{
Protocol.uri = Files.canonicalizeUri uri;
range = Utils.cmtLocToRange loc;
}))
in
print_endline
(match maybeLocation with
Expand Down
8 changes: 7 additions & 1 deletion analysis/src/Files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let relpath base path =
let baselen = String.length base in
let rest = String.sub path baselen (String.length path - baselen) in
(if rest <> "" && rest.[0] = Filename.dir_sep.[0] then sliceToEnd rest 1
else rest)
else rest)
|> removeExtraDots
else
let rec loop bp pp =
Expand Down Expand Up @@ -102,3 +102,9 @@ let classifySourceFile path =
if Filename.check_suffix path ".res" && exists path then Res
else if Filename.check_suffix path ".resi" && exists path then Resi
else Other

let canonicalizeUri uri =
if Cfg.isTestMode.contents then uri |> Uri.toString
else
let path = Uri.toPath uri in
path |> Unix.realpath
Loading