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

Add tests showing hover on components not working in interface files. #155

Merged
merged 2 commits into from
Apr 26, 2021
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
6 changes: 4 additions & 2 deletions analysis/src/Commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ let hover ~file ~line ~col ~extra ~package =
match uriLocOpt with
| None -> false
| Some (_, loc) ->
let isInterface = file.uri |> Uri2.isInterface in
let posIsZero {Lexing.pos_lnum; pos_bol; pos_cnum} =
pos_lnum = 1 && pos_cnum - pos_bol = 0
(not isInterface) && pos_lnum = 1 && pos_cnum - pos_bol = 0
in
(* Skip if range is all zero, unless it's a module *)
(not locIsModule) && posIsZero loc.loc_start && posIsZero loc.loc_end
Expand Down Expand Up @@ -111,8 +112,9 @@ let definition ~file ~line ~col ~extra ~package =
match uriLocOpt with
| None -> Protocol.null
| Some (uri2, loc) ->
let isInterface = file.uri |> Uri2.isInterface in
let posIsZero {Lexing.pos_lnum; pos_bol; pos_cnum} =
pos_lnum = 1 && pos_cnum - pos_bol = 0
(not isInterface) && pos_lnum = 1 && pos_cnum - pos_bol = 0
in
(* Skip if range is all zero, unless it's a module *)
let skipZero =
Expand Down
4 changes: 4 additions & 0 deletions analysis/src/Uri2.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Uri : sig

val fromPath : string -> t

val isInterface : t -> bool

val stripPath : bool ref

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

let isInterface {path} = Filename.check_suffix path "i"

let toPath {path} = path

let toString {uri} = if !stripPath then Filename.basename uri else uri
Expand Down
2 changes: 1 addition & 1 deletion analysis/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function exp {
echo "$(dirname $1)/expected/$(basename $1).txt"
}

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

Expand Down
10 changes: 7 additions & 3 deletions analysis/tests/src/Jsx.res
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
module M = {
@react.component
let make = (~first, ~fun="", ~second="") => React.string(first ++ fun++ second)
let make = (~first, ~fun="", ~second="") => React.string(first ++ fun ++ second)
}

let d = <M first="abc" />
let _ = <M first="abc" />
// ^def

//^com <M second=fi


//^com <M second="abc" f

//^com let e = <M

@react.component
let make = (~first) => React.string(first)

let y = 44
6 changes: 6 additions & 0 deletions analysis/tests/src/Jsx.resi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@react.component
let make: (~first: string) => React.element
// ^hov

let y : int
// ^hov
24 changes: 12 additions & 12 deletions analysis/tests/src/expected/Jsx.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ Complete tests/src/Jsx.res 7:2
"detail": "string",
"documentation": null
}, {
"label": "first",
"label": "second",
"kind": 4,
"tags": [],
"detail": "string",
"detail": "option<string>",
"documentation": null
}, {
"label": "fun",
"label": "first",
"kind": 4,
"tags": [],
"detail": "option<string>",
"detail": "string",
"documentation": null
}, {
"label": "second",
"label": "fun",
"kind": 4,
"tags": [],
"detail": "option<string>",
"documentation": null
}]

Complete tests/src/Jsx.res 10:2
Complete tests/src/Jsx.res 9:2
[{
"label": "key",
"kind": 4,
Expand All @@ -49,27 +49,27 @@ Complete tests/src/Jsx.res 10:2
"documentation": null
}]

Complete tests/src/Jsx.res 12:2
Complete tests/src/Jsx.res 11:2
[{
"label": "key",
"kind": 4,
"tags": [],
"detail": "string",
"documentation": null
}, {
"label": "first",
"label": "second",
"kind": 4,
"tags": [],
"detail": "string",
"detail": "option<string>",
"documentation": null
}, {
"label": "fun",
"label": "first",
"kind": 4,
"tags": [],
"detail": "option<string>",
"detail": "string",
"documentation": null
}, {
"label": "second",
"label": "fun",
"kind": 4,
"tags": [],
"detail": "option<string>",
Expand Down
6 changes: 6 additions & 0 deletions analysis/tests/src/expected/Jsx.resi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Hover tests/src/Jsx.resi 1:4
{"contents": "```rescript\n(~first: string, ~?key: string, unit) => {\"first\": string}\n```"}

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