Skip to content

Commit 0e26539

Browse files
authored
Merge pull request #155 from rescript-lang/intf
Add tests showing hover on components not working in interface files.
2 parents 170dcc8 + 9e70e8e commit 0e26539

File tree

7 files changed

+40
-18
lines changed

7 files changed

+40
-18
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/test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function exp {
22
echo "$(dirname $1)/expected/$(basename $1).txt"
33
}
44

5-
for file in tests/src/*.res; do
5+
for file in tests/src/*.res[i]; do
66
./run.exe test $file &> $(exp $file)
77
done
88

analysis/tests/src/Jsx.res

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
module M = {
22
@react.component
3-
let make = (~first, ~fun="", ~second="") => React.string(first ++ fun++ second)
3+
let make = (~first, ~fun="", ~second="") => React.string(first ++ fun ++ second)
44
}
55

6-
let d = <M first="abc" />
6+
let _ = <M first="abc" />
77
// ^def
88

99
//^com <M second=fi
1010

11-
1211
//^com <M second="abc" f
1312

1413
//^com let e = <M
14+
15+
@react.component
16+
let make = (~first) => React.string(first)
17+
18+
let y = 44

analysis/tests/src/Jsx.resi

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@react.component
2+
let make: (~first: string) => React.element
3+
// ^hov
4+
5+
let y : int
6+
// ^hov

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

+12-12
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ Complete tests/src/Jsx.res 7:2
99
"detail": "string",
1010
"documentation": null
1111
}, {
12-
"label": "first",
12+
"label": "second",
1313
"kind": 4,
1414
"tags": [],
15-
"detail": "string",
15+
"detail": "option<string>",
1616
"documentation": null
1717
}, {
18-
"label": "fun",
18+
"label": "first",
1919
"kind": 4,
2020
"tags": [],
21-
"detail": "option<string>",
21+
"detail": "string",
2222
"documentation": null
2323
}, {
24-
"label": "second",
24+
"label": "fun",
2525
"kind": 4,
2626
"tags": [],
2727
"detail": "option<string>",
2828
"documentation": null
2929
}]
3030

31-
Complete tests/src/Jsx.res 10:2
31+
Complete tests/src/Jsx.res 9:2
3232
[{
3333
"label": "key",
3434
"kind": 4,
@@ -49,27 +49,27 @@ Complete tests/src/Jsx.res 10:2
4949
"documentation": null
5050
}]
5151

52-
Complete tests/src/Jsx.res 12:2
52+
Complete tests/src/Jsx.res 11:2
5353
[{
5454
"label": "key",
5555
"kind": 4,
5656
"tags": [],
5757
"detail": "string",
5858
"documentation": null
5959
}, {
60-
"label": "first",
60+
"label": "second",
6161
"kind": 4,
6262
"tags": [],
63-
"detail": "string",
63+
"detail": "option<string>",
6464
"documentation": null
6565
}, {
66-
"label": "fun",
66+
"label": "first",
6767
"kind": 4,
6868
"tags": [],
69-
"detail": "option<string>",
69+
"detail": "string",
7070
"documentation": null
7171
}, {
72-
"label": "second",
72+
"label": "fun",
7373
"kind": 4,
7474
"tags": [],
7575
"detail": "option<string>",
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Hover tests/src/Jsx.resi 1:4
2+
{"contents": "```rescript\n(~first: string, ~?key: string, unit) => {\"first\": string}\n```"}
3+
4+
Hover tests/src/Jsx.resi 4:4
5+
{"contents": "```rescript\nint\n```"}
6+

0 commit comments

Comments
 (0)