Skip to content

Commit

Permalink
Don't crash on hover when a dependency contains lident application.
Browse files Browse the repository at this point in the history
Fixes #350

Lonident applications in types are only possible in ml, not in rescript. They might show up in the AST with OCaml dependencies.
  • Loading branch information
cristianoc committed Jan 24, 2022
1 parent 27a5aa5 commit a0bb9fd
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## master
- Fix issue with highlighting of templates introduced in release 1.2.0.
- Fix crash when the project contains OCaml files that have warnings.
- Fix crash on hover when a dependency (OCaml) contains a type with functor application.

## 1.2.0

Expand Down
17 changes: 9 additions & 8 deletions analysis/src/ProcessCmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,7 @@ let fromCompilerPath ~(env : QueryEnv.t) path =

module F (Collector : sig
val extra : extra

val file : File.t

val scopeExtent : Location.t list ref
end) =
struct
Expand Down Expand Up @@ -852,8 +850,14 @@ struct
if List.length !Collector.scopeExtent > 1 then
Collector.scopeExtent := List.tl !Collector.scopeExtent

let rec lidIsComplex (lid : Longident.t) =
match lid with
| Lapply _ -> true
| Ldot (lid, _) -> lidIsComplex lid
| _ -> false

let rec addForLongident top (path : Path.t) (txt : Longident.t) loc =
if not loc.Location.loc_ghost then (
if (not loc.Location.loc_ghost) && not (lidIsComplex txt) then (
let idLength =
String.length (String.concat "." (Longident.flatten txt))
in
Expand All @@ -879,7 +883,8 @@ struct
match expr with
| Tmod_constraint (expr, _, _, _) -> handle_module_expr expr.mod_desc
| Tmod_ident (path, {txt; loc}) ->
Log.log ("Ident!! " ^ String.concat "." (Longident.flatten txt));
if not (lidIsComplex txt) then
Log.log ("Ident!! " ^ String.concat "." (Longident.flatten txt));
addForLongident None path txt loc
| Tmod_functor (_ident, _argName, _maybeType, resultExpr) ->
handle_module_expr resultExpr.mod_desc
Expand Down Expand Up @@ -1052,9 +1057,7 @@ let extraForStructureItems ~(file : File.t)
(* TODO look through parts and extend the extent *)
let module Iter = TypedtreeIter.MakeIterator (F (struct
let scopeExtent = ref [extent]

let extra = extra

let file = file
end)) in
List.iter Iter.iter_structure_item items;
Expand Down Expand Up @@ -1089,9 +1092,7 @@ let extraForSignatureItems ~(file : File.t)
(* TODO look through parts and extend the extent *)
let module Iter = TypedtreeIter.MakeIterator (F (struct
let scopeExtent = ref [extent]

let extra = extra

let file = file
end)) in
List.iter Iter.iter_signature_item items;
Expand Down
4 changes: 4 additions & 0 deletions analysis/tests/src/LongIdentTest.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Map = TableclothMap

let zz = Map.add
// ^hov
11 changes: 11 additions & 0 deletions analysis/tests/src/TableclothMap.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let add = 3

module Of (M : sig end) = struct
type t = int
end

module M = struct end

module Int = struct
type t = Of(M).t
end
1 change: 1 addition & 0 deletions analysis/tests/src/TableclothMap.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val add : int
4 changes: 3 additions & 1 deletion analysis/tests/src/expected/Debug.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Dependencies: @rescript/react
Source directories: tests/node_modules/@rescript/react/./src tests/node_modules/@rescript/react/./src/legacy
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
Source directories: tests/src
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
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
Impl cmt:tests/lib/bs/./src/Auto.cmt res:tests/src/Auto.res
Impl cmt:tests/lib/bs/./src/CompletePrioritize1.cmt res:tests/src/CompletePrioritize1.res
Impl cmt:tests/lib/bs/./src/CompletePrioritize2.cmt res:tests/src/CompletePrioritize2.res
Expand All @@ -18,6 +18,7 @@ Impl cmt:tests/lib/bs/./src/Div.cmt res:tests/src/Div.res
Impl cmt:tests/lib/bs/./src/Fragment.cmt res:tests/src/Fragment.res
Impl cmt:tests/lib/bs/./src/Hover.cmt res:tests/src/Hover.res
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
Impl cmt:tests/lib/bs/./src/LongIdentTest.cmt res:tests/src/LongIdentTest.res
Impl cmt:tests/lib/bs/./src/Obj.cmt res:tests/src/Obj.res
Impl cmt:tests/lib/bs/./src/Patterns.cmt res:tests/src/Patterns.res
Impl cmt:tests/lib/bs/./src/RecModules.cmt res:tests/src/RecModules.res
Expand All @@ -26,6 +27,7 @@ Impl cmt:tests/lib/bs/./src/References.cmt res:tests/src/References.res
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
Impl cmt:tests/lib/bs/./src/Rename.cmt res:tests/src/Rename.res
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
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
Impl cmt:tests/lib/bs/./src/TypeDefinition.cmt res:tests/src/TypeDefinition.res
Dependency dirs: tests/node_modules/@rescript/react/lib/bs/./src tests/node_modules/@rescript/react/lib/bs/./src/legacy
Opens from bsconfig:
Expand Down
3 changes: 3 additions & 0 deletions analysis/tests/src/expected/LongIdentTest.res.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Hover tests/src/LongIdentTest.res 2:13
{"contents": "```rescript\nint\n```"}

0 comments on commit a0bb9fd

Please sign in to comment.