Skip to content

Commit 722896c

Browse files
committed
Add typeId helper to analysis TypeUtils
1 parent ae01437 commit 722896c

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

analysis/src/Hover.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,12 @@ let expandTypes ~file ~package ~supportsMarkdownLinks typ =
118118
`InlineType )
119119
| all ->
120120
let typesSeen = ref StringSet.empty in
121-
let typeId ~(env : QueryEnv.t) ~name =
122-
env.file.moduleName :: List.rev (name :: env.pathRev) |> String.concat "."
123-
in
124121
( all
125122
(* Don't produce duplicate type definitions for recursive types *)
126-
|> List.filter (fun {env; name} ->
127-
let typeId = typeId ~env ~name in
123+
|> List.filter (fun {env; name; loc} ->
124+
let typeId =
125+
TypeUtils.typeId ~env ~name:(Location.mkloc name loc)
126+
in
128127
if StringSet.mem typeId !typesSeen then false
129128
else (
130129
typesSeen := StringSet.add typeId !typesSeen;

analysis/src/TypeUtils.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,12 @@ let transformCompletionToPipeCompletion ?(synthetic = false) ~env ?posOfDot
11791179
| Some posOfDot -> Some (makeAdditionalTextEditsForRemovingDot posOfDot));
11801180
}
11811181

1182+
(** Light weight type id *)
1183+
let typeId ~(env : QueryEnv.t) ~(name : string Location.loc) =
1184+
(env.file.moduleName :: List.rev (name.txt :: env.pathRev)
1185+
|> String.concat ".")
1186+
^ ":" ^ Loc.toString name.loc
1187+
11821188
(** This takes a type expr and the env that type expr was found in, and produces a globally unique
11831189
id for that specific type. The globally unique id is the full path to the type as seen from the root
11841190
of the project. Example: type x in module SomeModule in file SomeFile would get the globally

0 commit comments

Comments
 (0)