diff --git a/analysis/src/Commands.ml b/analysis/src/Commands.ml index 6cb667756..612d9748c 100644 --- a/analysis/src/Commands.ml +++ b/analysis/src/Commands.ml @@ -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 @@ -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 = diff --git a/analysis/src/Uri2.ml b/analysis/src/Uri2.ml index 28535da0f..437632a99 100644 --- a/analysis/src/Uri2.ml +++ b/analysis/src/Uri2.ml @@ -5,6 +5,8 @@ module Uri : sig val fromPath : string -> t + val isInterface : t -> bool + val stripPath : bool ref val toPath : t -> string @@ -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 diff --git a/analysis/test.sh b/analysis/test.sh index 278c31fbf..f913f8158 100755 --- a/analysis/test.sh +++ b/analysis/test.sh @@ -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 diff --git a/analysis/tests/src/Jsx.res b/analysis/tests/src/Jsx.res index 428b797d3..968afc7cf 100644 --- a/analysis/tests/src/Jsx.res +++ b/analysis/tests/src/Jsx.res @@ -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 = +let _ = // ^def //^com React.string(first) + +let y = 44 \ No newline at end of file diff --git a/analysis/tests/src/Jsx.resi b/analysis/tests/src/Jsx.resi new file mode 100644 index 000000000..4c00a5530 --- /dev/null +++ b/analysis/tests/src/Jsx.resi @@ -0,0 +1,6 @@ +@react.component +let make: (~first: string) => React.element +// ^hov + +let y : int +// ^hov \ No newline at end of file diff --git a/analysis/tests/src/expected/Jsx.res.txt b/analysis/tests/src/expected/Jsx.res.txt index 8daa12eb3..3a8f550ae 100644 --- a/analysis/tests/src/expected/Jsx.res.txt +++ b/analysis/tests/src/expected/Jsx.res.txt @@ -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", "documentation": null }, { - "label": "fun", + "label": "first", "kind": 4, "tags": [], - "detail": "option", + "detail": "string", "documentation": null }, { - "label": "second", + "label": "fun", "kind": 4, "tags": [], "detail": "option", "documentation": null }] -Complete tests/src/Jsx.res 10:2 +Complete tests/src/Jsx.res 9:2 [{ "label": "key", "kind": 4, @@ -49,7 +49,7 @@ 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, @@ -57,19 +57,19 @@ Complete tests/src/Jsx.res 12:2 "detail": "string", "documentation": null }, { - "label": "first", + "label": "second", "kind": 4, "tags": [], - "detail": "string", + "detail": "option", "documentation": null }, { - "label": "fun", + "label": "first", "kind": 4, "tags": [], - "detail": "option", + "detail": "string", "documentation": null }, { - "label": "second", + "label": "fun", "kind": 4, "tags": [], "detail": "option", diff --git a/analysis/tests/src/expected/Jsx.resi.txt b/analysis/tests/src/expected/Jsx.resi.txt new file mode 100644 index 000000000..deac2dbe9 --- /dev/null +++ b/analysis/tests/src/expected/Jsx.resi.txt @@ -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```"} +