Skip to content

Commit 9e70e8e

Browse files
committed
Fix hover on components in interface files.
Fixes #153
1 parent d447549 commit 9e70e8e

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

analysis/src/Commands.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ let hover ~file ~line ~col ~extra ~package =
7070
match uriLocOpt with
7171
| None -> false
7272
| Some (_, loc) ->
73+
let isInterface = file.uri |> Uri2.isInterface in
7374
let posIsZero {Lexing.pos_lnum; pos_bol; pos_cnum} =
74-
pos_lnum = 1 && pos_cnum - pos_bol = 0
75+
(not isInterface) && pos_lnum = 1 && pos_cnum - pos_bol = 0
7576
in
7677
(* Skip if range is all zero, unless it's a module *)
7778
(not locIsModule) && posIsZero loc.loc_start && posIsZero loc.loc_end
@@ -111,8 +112,9 @@ let definition ~file ~line ~col ~extra ~package =
111112
match uriLocOpt with
112113
| None -> Protocol.null
113114
| Some (uri2, loc) ->
115+
let isInterface = file.uri |> Uri2.isInterface in
114116
let posIsZero {Lexing.pos_lnum; pos_bol; pos_cnum} =
115-
pos_lnum = 1 && pos_cnum - pos_bol = 0
117+
(not isInterface) && pos_lnum = 1 && pos_cnum - pos_bol = 0
116118
in
117119
(* Skip if range is all zero, unless it's a module *)
118120
let skipZero =

analysis/src/Uri2.ml

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module Uri : sig
55

66
val fromPath : string -> t
77

8+
val isInterface : t -> bool
9+
810
val stripPath : bool ref
911

1012
val toPath : t -> string
@@ -30,6 +32,8 @@ end = struct
3032
let path = Files.maybeConcat (Unix.getcwd ()) localPath in
3133
fromPath path
3234

35+
let isInterface {path} = Filename.check_suffix path "i"
36+
3337
let toPath {path} = path
3438

3539
let toString {uri} = if !stripPath then Filename.basename uri else uri

analysis/tests/src/expected/Jsx.resi.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Hover tests/src/Jsx.resi 1:4
2-
null
2+
{"contents": "```rescript\n(~first: string, ~?key: string, unit) => {\"first\": string}\n```"}
33

44
Hover tests/src/Jsx.resi 4:4
55
{"contents": "```rescript\nint\n```"}

0 commit comments

Comments
 (0)