Skip to content

Commit 6cd0eeb

Browse files
fhammerschmidtjfrolich
authored andcommitted
Use canonicalized URIs/paths for jump to definition (rescript-lang#982)
1 parent a63150f commit 6cd0eeb

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#### :bug: Bug Fix
1616

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

1920
#### :nail_care: Polish
2021

analysis/bin/main.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ let main () =
191191
(Json.escape (CreateInterface.command ~path ~cmiFile))
192192
| [_; "format"; path] ->
193193
Printf.printf "\"%s\"" (Json.escape (Commands.format ~path))
194-
| [_; "test"; path] -> Commands.test ~path
194+
| [_; "test"; path] ->
195+
Cfg.isTestMode := true;
196+
Commands.test ~path
195197
| args when List.mem "-h" args || List.mem "--help" args -> prerr_endline help
196198
| _ ->
197199
prerr_endline help;

analysis/src/Cfg.ml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
let debugFollowCtxPath = ref false
22

33
let isDocGenFromCompiler = ref false
4+
5+
let isTestMode = ref false

analysis/src/Commands.ml

+8-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ let definition ~path ~pos ~debug =
144144
if skipLoc then None
145145
else
146146
Some
147-
{Protocol.uri = Uri.toString uri; range = Utils.cmtLocToRange loc}
147+
{
148+
Protocol.uri = Files.canonicalizeUri uri;
149+
range = Utils.cmtLocToRange loc;
150+
}
148151
| Some _ -> None))
149152
in
150153
print_endline
@@ -164,7 +167,10 @@ let typeDefinition ~path ~pos ~debug =
164167
| None -> None
165168
| Some (uri, loc) ->
166169
Some
167-
{Protocol.uri = Uri.toString uri; range = Utils.cmtLocToRange loc}))
170+
{
171+
Protocol.uri = Files.canonicalizeUri uri;
172+
range = Utils.cmtLocToRange loc;
173+
}))
168174
in
169175
print_endline
170176
(match maybeLocation with

analysis/src/Files.ml

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let relpath base path =
2020
let baselen = String.length base in
2121
let rest = String.sub path baselen (String.length path - baselen) in
2222
(if rest <> "" && rest.[0] = Filename.dir_sep.[0] then sliceToEnd rest 1
23-
else rest)
23+
else rest)
2424
|> removeExtraDots
2525
else
2626
let rec loop bp pp =
@@ -102,3 +102,9 @@ let classifySourceFile path =
102102
if Filename.check_suffix path ".res" && exists path then Res
103103
else if Filename.check_suffix path ".resi" && exists path then Resi
104104
else Other
105+
106+
let canonicalizeUri uri =
107+
if Cfg.isTestMode.contents then uri |> Uri.toString
108+
else
109+
let path = Uri.toPath uri in
110+
path |> Unix.realpath

0 commit comments

Comments
 (0)