Skip to content

Commit af5df7a

Browse files
Use canonicalized URIs/paths for jump to definition
1 parent d402233 commit af5df7a

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

analysis/bin/main.ml

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ let main () =
189189
Printf.printf "\"%s\"" (Json.escape (Commands.format ~path))
190190
| [_; "test"; path] ->
191191
Cfg.supportsSnippets := true;
192+
Cfg.isTestMode := true;
192193
Commands.test ~path
193194
| args when List.mem "-h" args || List.mem "--help" args -> prerr_endline help
194195
| _ ->

analysis/src/Cfg.ml

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ let supportsSnippets = ref false
33
let debugFollowCtxPath = ref false
44

55
let isDocGenFromCompiler = ref false
6+
7+
let isTestMode = ref false

analysis/src/Commands.ml

+8-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ let definition ~path ~pos ~debug =
112112
if skipLoc then None
113113
else
114114
Some
115-
{Protocol.uri = Uri.toString uri; range = Utils.cmtLocToRange loc}
115+
{
116+
Protocol.uri = Files.canonicalizeUri uri;
117+
range = Utils.cmtLocToRange loc;
118+
}
116119
| Some _ -> None))
117120
in
118121
print_endline
@@ -132,7 +135,10 @@ let typeDefinition ~path ~pos ~debug =
132135
| None -> None
133136
| Some (uri, loc) ->
134137
Some
135-
{Protocol.uri = Uri.toString uri; range = Utils.cmtLocToRange loc}))
138+
{
139+
Protocol.uri = Files.canonicalizeUri uri;
140+
range = Utils.cmtLocToRange loc;
141+
}))
136142
in
137143
print_endline
138144
(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)