Skip to content

Commit ba1e27a

Browse files
committed
Clean up Completion.
1 parent 9287e05 commit ba1e27a

File tree

2 files changed

+46
-43
lines changed

2 files changed

+46
-43
lines changed

analysis/src/NewCompletions.ml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,9 @@ let completionForConstructors ~(env : QueryEnv.t) ~suffix =
573573
Utils.startsWith c.Constructor.cname.txt suffix)
574574
|> List.map (fun c ->
575575
Completion.create ~name:c.Constructor.cname.txt
576-
~kind:(Completion.Constructor (c, t))))
576+
~kind:
577+
(Completion.Constructor
578+
(c, t.item.decl |> Shared.declToString t.name.txt))))
577579
@ !res
578580
| _ -> ());
579581
!res
@@ -588,7 +590,9 @@ let completionForFields ~(env : QueryEnv.t) ~suffix =
588590
|> List.filter (fun f -> Utils.startsWith f.fname.txt suffix)
589591
|> List.map (fun f ->
590592
Completion.create ~name:f.fname.txt
591-
~kind:(Completion.Field (f, t))))
593+
~kind:
594+
(Completion.Field
595+
(f, t.item.decl |> Shared.declToString t.name.txt))))
592596
@ !res
593597
| _ -> ());
594598
!res
@@ -676,13 +680,8 @@ let detail name (kind : Completion.kind) =
676680
| Value typ -> typ |> Shared.typeToString
677681
| Module _ -> "module"
678682
| FileModule _ -> "file module"
679-
| Field ({typ}, t) ->
680-
name ^ ": "
681-
^ (typ |> Shared.typeToString)
682-
^ "\n\n"
683-
^ (t.item.decl |> Shared.declToString t.name.txt)
684-
| Constructor (c, t) ->
685-
showConstructor c ^ "\n\n" ^ (t.item.decl |> Shared.declToString t.name.txt)
683+
| Field ({typ}, s) -> name ^ ": " ^ (typ |> Shared.typeToString) ^ "\n\n" ^ s
684+
| Constructor (c, s) -> showConstructor c ^ "\n\n" ^ s
686685

687686
let localValueCompletions ~pos ~(env : QueryEnv.t) suffix =
688687
let results = [] in
@@ -857,7 +856,7 @@ let getCompletions ~full ~rawOpens ~allFiles ~pos ~dotpath =
857856
Log.log ("Found it! " ^ declared.name.txt);
858857
match declared.item |> extractRecordType ~env ~package with
859858
| None -> []
860-
| Some (env, fields, typ) -> (
859+
| Some (env, fields, typDecl) -> (
861860
match
862861
middleFields
863862
|> List.fold_left
@@ -872,16 +871,20 @@ let getCompletions ~full ~rawOpens ~allFiles ~pos ~dotpath =
872871
| Some attr ->
873872
Log.log ("Found attr " ^ name);
874873
attr.typ |> extractRecordType ~env ~package))
875-
(Some (env, fields, typ))
874+
(Some (env, fields, typDecl))
876875
with
877876
| None -> []
878-
| Some (env, fields, typ) ->
877+
| Some (env, fields, typDecl) ->
879878
fields
880879
|> Utils.filterMap (fun field ->
881880
if Utils.startsWith field.fname.txt lastField then
882881
Some
883882
( Completion.create ~name:field.fname.txt
884-
~kind:(Completion.Field (field, typ)),
883+
~kind:
884+
(Completion.Field
885+
( field,
886+
typDecl.item.decl
887+
|> Shared.declToString typDecl.name.txt )),
885888
env )
886889
else None))))
887890
| None -> [])

analysis/src/SharedTypes.ml

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,36 @@ module Module = struct
9494
and t = Ident of Path.t | Structure of structure | Constraint of t * t
9595
end
9696

97+
module Completion = struct
98+
type kind =
99+
| Module of Module.t
100+
| Value of Types.type_expr
101+
| Type of Type.t
102+
| Constructor of Constructor.t * string
103+
| Field of field * string
104+
| FileModule of string
105+
106+
type t = {
107+
name : string;
108+
extentLoc : Location.t;
109+
deprecated : string option;
110+
docstring : string list;
111+
kind : kind;
112+
}
113+
114+
let create ~name ~kind =
115+
{name; extentLoc = Location.none; deprecated = None; docstring = []; kind}
116+
117+
let kindToInt kind =
118+
match kind with
119+
| Module _ -> 9
120+
| FileModule _ -> 9
121+
| Constructor (_, _) -> 4
122+
| Field (_, _) -> 5
123+
| Type _ -> 22
124+
| Value _ -> 12
125+
end
126+
97127
module Declared = struct
98128
type 'item t = {
99129
name : string Location.loc;
@@ -177,36 +207,6 @@ end = struct
177207
stamps
178208
end
179209

180-
module Completion = struct
181-
type kind =
182-
| Module of Module.t
183-
| Value of Types.type_expr
184-
| Type of Type.t
185-
| Constructor of Constructor.t * Type.t Declared.t
186-
| Field of field * Type.t Declared.t
187-
| FileModule of string
188-
189-
type t = {
190-
name : string;
191-
extentLoc : Location.t;
192-
deprecated : string option;
193-
docstring : string list;
194-
kind : kind;
195-
}
196-
197-
let create ~name ~kind =
198-
{name; extentLoc = Location.none; deprecated = None; docstring = []; kind}
199-
200-
let kindToInt kind =
201-
match kind with
202-
| Module _ -> 9
203-
| FileModule _ -> 9
204-
| Constructor (_, _) -> 4
205-
| Field (_, _) -> 5
206-
| Type _ -> 22
207-
| Value _ -> 12
208-
end
209-
210210
module Env = struct
211211
type t = {stamps : Stamps.t; modulePath : modulePath; scope : Location.t}
212212
end

0 commit comments

Comments
 (0)