Skip to content

Commit 6e1a4a4

Browse files
committed
Don't crash on hover when a dependency contains lident application.
Fixes #350 Lonident applications in types are only possible in ml, not in rescript. They might show up in the AST with OCaml dependencies.
1 parent 27a5aa5 commit 6e1a4a4

File tree

7 files changed

+32
-9
lines changed

7 files changed

+32
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## master
22
- Fix issue with highlighting of templates introduced in release 1.2.0.
33
- Fix crash when the project contains OCaml files that have warnings.
4+
- Fix crash on hover when a dependency (OCaml) contains a type with functor application.
45

56
## 1.2.0
67

analysis/src/ProcessCmt.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,7 @@ let fromCompilerPath ~(env : QueryEnv.t) path =
657657

658658
module F (Collector : sig
659659
val extra : extra
660-
661660
val file : File.t
662-
663661
val scopeExtent : Location.t list ref
664662
end) =
665663
struct
@@ -852,8 +850,14 @@ struct
852850
if List.length !Collector.scopeExtent > 1 then
853851
Collector.scopeExtent := List.tl !Collector.scopeExtent
854852

853+
let rec lidIsComplex (lid : Longident.t) =
854+
match lid with
855+
| Lapply _ -> true
856+
| Ldot (lid, _) -> lidIsComplex lid
857+
| _ -> false
858+
855859
let rec addForLongident top (path : Path.t) (txt : Longident.t) loc =
856-
if not loc.Location.loc_ghost then (
860+
if (not loc.Location.loc_ghost) && not (lidIsComplex txt) then (
857861
let idLength =
858862
String.length (String.concat "." (Longident.flatten txt))
859863
in
@@ -879,7 +883,8 @@ struct
879883
match expr with
880884
| Tmod_constraint (expr, _, _, _) -> handle_module_expr expr.mod_desc
881885
| Tmod_ident (path, {txt; loc}) ->
882-
Log.log ("Ident!! " ^ String.concat "." (Longident.flatten txt));
886+
if not (lidIsComplex txt) then
887+
Log.log ("Ident!! " ^ String.concat "." (Longident.flatten txt));
883888
addForLongident None path txt loc
884889
| Tmod_functor (_ident, _argName, _maybeType, resultExpr) ->
885890
handle_module_expr resultExpr.mod_desc
@@ -1052,9 +1057,7 @@ let extraForStructureItems ~(file : File.t)
10521057
(* TODO look through parts and extend the extent *)
10531058
let module Iter = TypedtreeIter.MakeIterator (F (struct
10541059
let scopeExtent = ref [extent]
1055-
10561060
let extra = extra
1057-
10581061
let file = file
10591062
end)) in
10601063
List.iter Iter.iter_structure_item items;
@@ -1089,9 +1092,7 @@ let extraForSignatureItems ~(file : File.t)
10891092
(* TODO look through parts and extend the extent *)
10901093
let module Iter = TypedtreeIter.MakeIterator (F (struct
10911094
let scopeExtent = ref [extent]
1092-
10931095
let extra = extra
1094-
10951096
let file = file
10961097
end)) in
10971098
List.iter Iter.iter_signature_item items;

analysis/tests/src/LongIdentTest.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Map = TableclothMap
2+
3+
let zz = Map.add
4+
// ^hov

analysis/tests/src/TableclothMap.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
let add = 3
2+
3+
module Of (M : sig end) = struct
4+
type t = int
5+
end
6+
7+
module M = struct end
8+
9+
module Int = struct
10+
type t = Of(M).t
11+
end

analysis/tests/src/TableclothMap.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val add : int

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Dependencies: @rescript/react
44
Source directories: tests/node_modules/@rescript/react/./src tests/node_modules/@rescript/react/./src/legacy
55
Source files: tests/node_modules/@rescript/react/./src/React.res tests/node_modules/@rescript/react/./src/ReactDOM.res tests/node_modules/@rescript/react/./src/ReactDOMServer.res tests/node_modules/@rescript/react/./src/ReactDOMStyle.res tests/node_modules/@rescript/react/./src/ReactEvent.res tests/node_modules/@rescript/react/./src/ReactEvent.resi tests/node_modules/@rescript/react/./src/ReactTestUtils.res tests/node_modules/@rescript/react/./src/ReactTestUtils.resi tests/node_modules/@rescript/react/./src/RescriptReactErrorBoundary.res tests/node_modules/@rescript/react/./src/RescriptReactErrorBoundary.resi tests/node_modules/@rescript/react/./src/RescriptReactRouter.res tests/node_modules/@rescript/react/./src/RescriptReactRouter.resi tests/node_modules/@rescript/react/./src/legacy/ReactDOMRe.res tests/node_modules/@rescript/react/./src/legacy/ReasonReact.res
66
Source directories: tests/src
7-
Source files: tests/src/Auto.res tests/src/CompletePrioritize1.res tests/src/CompletePrioritize2.res tests/src/Completion.res tests/src/Component.res tests/src/Component.resi tests/src/Cross.res tests/src/Debug.res tests/src/Definition.res tests/src/DefinitionWithInterface.res tests/src/DefinitionWithInterface.resi tests/src/Div.res tests/src/Fragment.res tests/src/Hover.res tests/src/Jsx.res tests/src/Jsx.resi tests/src/Obj.res tests/src/Patterns.res tests/src/RecModules.res tests/src/RecordCompletion.res tests/src/References.res tests/src/ReferencesWithInterface.res tests/src/ReferencesWithInterface.resi tests/src/Rename.res tests/src/RenameWithInterface.res tests/src/RenameWithInterface.resi tests/src/TypeDefinition.res
7+
Source files: tests/src/Auto.res tests/src/CompletePrioritize1.res tests/src/CompletePrioritize2.res tests/src/Completion.res tests/src/Component.res tests/src/Component.resi tests/src/Cross.res tests/src/Debug.res tests/src/Definition.res tests/src/DefinitionWithInterface.res tests/src/DefinitionWithInterface.resi tests/src/Div.res tests/src/Fragment.res tests/src/Hover.res tests/src/Jsx.res tests/src/Jsx.resi tests/src/LongIdentTest.res tests/src/Obj.res tests/src/Patterns.res tests/src/RecModules.res tests/src/RecordCompletion.res tests/src/References.res tests/src/ReferencesWithInterface.res tests/src/ReferencesWithInterface.resi tests/src/Rename.res tests/src/RenameWithInterface.res tests/src/RenameWithInterface.resi tests/src/TableclothMap.ml tests/src/TableclothMap.mli tests/src/TypeDefinition.res
88
Impl cmt:tests/lib/bs/./src/Auto.cmt res:tests/src/Auto.res
99
Impl cmt:tests/lib/bs/./src/CompletePrioritize1.cmt res:tests/src/CompletePrioritize1.res
1010
Impl cmt:tests/lib/bs/./src/CompletePrioritize2.cmt res:tests/src/CompletePrioritize2.res
@@ -18,6 +18,7 @@ Impl cmt:tests/lib/bs/./src/Div.cmt res:tests/src/Div.res
1818
Impl cmt:tests/lib/bs/./src/Fragment.cmt res:tests/src/Fragment.res
1919
Impl cmt:tests/lib/bs/./src/Hover.cmt res:tests/src/Hover.res
2020
IntfAndImpl cmti:tests/lib/bs/./src/Jsx.cmti resi:tests/src/Jsx.resi cmt:tests/lib/bs/./src/Jsx.cmt res:tests/src/Jsx.res
21+
Impl cmt:tests/lib/bs/./src/LongIdentTest.cmt res:tests/src/LongIdentTest.res
2122
Impl cmt:tests/lib/bs/./src/Obj.cmt res:tests/src/Obj.res
2223
Impl cmt:tests/lib/bs/./src/Patterns.cmt res:tests/src/Patterns.res
2324
Impl cmt:tests/lib/bs/./src/RecModules.cmt res:tests/src/RecModules.res
@@ -26,6 +27,7 @@ Impl cmt:tests/lib/bs/./src/References.cmt res:tests/src/References.res
2627
IntfAndImpl cmti:tests/lib/bs/./src/ReferencesWithInterface.cmti resi:tests/src/ReferencesWithInterface.resi cmt:tests/lib/bs/./src/ReferencesWithInterface.cmt res:tests/src/ReferencesWithInterface.res
2728
Impl cmt:tests/lib/bs/./src/Rename.cmt res:tests/src/Rename.res
2829
IntfAndImpl cmti:tests/lib/bs/./src/RenameWithInterface.cmti resi:tests/src/RenameWithInterface.resi cmt:tests/lib/bs/./src/RenameWithInterface.cmt res:tests/src/RenameWithInterface.res
30+
IntfAndImpl cmti:tests/lib/bs/./src/TableclothMap.cmti resi:tests/src/TableclothMap.mli cmt:tests/lib/bs/./src/TableclothMap.cmt res:tests/src/TableclothMap.ml
2931
Impl cmt:tests/lib/bs/./src/TypeDefinition.cmt res:tests/src/TypeDefinition.res
3032
Dependency dirs: tests/node_modules/@rescript/react/lib/bs/./src tests/node_modules/@rescript/react/lib/bs/./src/legacy
3133
Opens from bsconfig:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Hover tests/src/LongIdentTest.res 2:13
2+
{"contents": "```rescript\nint\n```"}
3+

0 commit comments

Comments
 (0)