Skip to content

Commit e5fe2f0

Browse files
committed
refactor and fixes
1 parent 5f7ba41 commit e5fe2f0

File tree

6 files changed

+56
-140
lines changed

6 files changed

+56
-140
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 42 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,8 @@ let completionForExporteds iterExported getDeclared ~prefix ~exact ~env
557557
Hashtbl.add namesUsed declared.name.txt ();
558558
res :=
559559
{
560-
(Completion.create ~name:declared.name.txt ~env
561-
~kind:(transformContents declared.item)
562-
())
560+
(Completion.create declared.name.txt ~env
561+
~kind:(transformContents declared.item))
563562
with
564563
deprecated = declared.deprecated;
565564
docstring = declared.docstring;
@@ -598,11 +597,10 @@ let completionsForExportedConstructors ~(env : QueryEnv.t) ~prefix ~exact
598597
if not (Hashtbl.mem namesUsed name) then
599598
let () = Hashtbl.add namesUsed name () in
600599
Some
601-
(Completion.create ~name ~env ~docstring:c.docstring
600+
(Completion.create name ~env ~docstring:c.docstring
602601
~kind:
603602
(Completion.Constructor
604-
(c, t.item.decl |> Shared.declToString t.name.txt))
605-
())
603+
(c, t.item.decl |> Shared.declToString t.name.txt)))
606604
else None))
607605
@ !res
608606
| _ -> ());
@@ -621,11 +619,10 @@ let completionForExportedFields ~(env : QueryEnv.t) ~prefix ~exact ~namesUsed =
621619
if not (Hashtbl.mem namesUsed name) then
622620
let () = Hashtbl.add namesUsed name () in
623621
Some
624-
(Completion.create ~name ~env ~docstring:f.docstring
622+
(Completion.create name ~env ~docstring:f.docstring
625623
~kind:
626624
(Completion.Field
627-
(f, t.item.decl |> Shared.declToString t.name.txt))
628-
())
625+
(f, t.item.decl |> Shared.declToString t.name.txt)))
629626
else None))
630627
@ !res
631628
| _ -> ());
@@ -803,8 +800,7 @@ let processLocalValue name loc ~prefix ~exact ~env
803800
Hashtbl.add localTables.namesUsed name ();
804801
localTables.resultRev <-
805802
{
806-
(Completion.create ~name:declared.name.txt ~env
807-
~kind:(Value declared.item) ())
803+
(Completion.create declared.name.txt ~env ~kind:(Value declared.item))
808804
with
809805
deprecated = declared.deprecated;
810806
docstring = declared.docstring;
@@ -815,13 +811,12 @@ let processLocalValue name loc ~prefix ~exact ~env
815811
(Printf.sprintf "Completion Value Not Found %s loc:%s\n" name
816812
(Loc.toString loc));
817813
localTables.resultRev <-
818-
Completion.create ~name ~env
814+
Completion.create name ~env
819815
~kind:
820816
(Value
821817
(Ctype.newconstr
822818
(Path.Pident (Ident.create "Type Not Known"))
823819
[]))
824-
()
825820
:: localTables.resultRev
826821

827822
let processLocalConstructor name loc ~prefix ~exact ~env
@@ -835,13 +830,12 @@ let processLocalConstructor name loc ~prefix ~exact ~env
835830
Hashtbl.add localTables.namesUsed name ();
836831
localTables.resultRev <-
837832
{
838-
(Completion.create ~name:declared.name.txt ~env
833+
(Completion.create declared.name.txt ~env
839834
~kind:
840835
(Constructor
841836
( declared.item,
842837
snd declared.item.typeDecl
843-
|> Shared.declToString (fst declared.item.typeDecl) ))
844-
())
838+
|> Shared.declToString (fst declared.item.typeDecl) )))
845839
with
846840
deprecated = declared.deprecated;
847841
docstring = declared.docstring;
@@ -861,8 +855,7 @@ let processLocalType name loc ~prefix ~exact ~env ~(localTables : LocalTables.t)
861855
Hashtbl.add localTables.namesUsed name ();
862856
localTables.resultRev <-
863857
{
864-
(Completion.create ~name:declared.name.txt ~env
865-
~kind:(Type declared.item) ())
858+
(Completion.create declared.name.txt ~env ~kind:(Type declared.item))
866859
with
867860
deprecated = declared.deprecated;
868861
docstring = declared.docstring;
@@ -882,8 +875,8 @@ let processLocalModule name loc ~prefix ~exact ~env
882875
Hashtbl.add localTables.namesUsed name ();
883876
localTables.resultRev <-
884877
{
885-
(Completion.create ~name:declared.name.txt ~env
886-
~kind:(Module declared.item) ())
878+
(Completion.create declared.name.txt ~env
879+
~kind:(Module declared.item))
887880
with
888881
deprecated = declared.deprecated;
889882
docstring = declared.docstring;
@@ -1144,8 +1137,7 @@ let getComplementaryCompletionsForTypedValue ~opens ~allFiles ~scope ~env prefix
11441137
(String.contains name '-')
11451138
then
11461139
Some
1147-
(Completion.create ~name ~env ~kind:(Completion.FileModule name)
1148-
())
1140+
(Completion.create name ~env ~kind:(Completion.FileModule name))
11491141
else None)
11501142
in
11511143
localCompletionsWithOpens @ fileModules
@@ -1169,8 +1161,7 @@ let getCompletionsForPath ~package ~opens ~allFiles ~pos ~exact ~scope
11691161
(String.contains name '-')
11701162
then
11711163
Some
1172-
(Completion.create ~name ~env
1173-
~kind:(Completion.FileModule name) ())
1164+
(Completion.create name ~env ~kind:(Completion.FileModule name))
11741165
else None)
11751166
in
11761167
localCompletionsWithOpens @ fileModules
@@ -1356,35 +1347,31 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
13561347
match contextPath with
13571348
| CPString ->
13581349
[
1359-
Completion.create ~name:"string" ~env
1350+
Completion.create "string" ~env
13601351
~kind:
13611352
(Completion.Value
1362-
(Ctype.newconstr (Path.Pident (Ident.create "string")) []))
1363-
();
1353+
(Ctype.newconstr (Path.Pident (Ident.create "string")) []));
13641354
]
13651355
| CPInt ->
13661356
[
1367-
Completion.create ~name:"int" ~env
1357+
Completion.create "int" ~env
13681358
~kind:
13691359
(Completion.Value
1370-
(Ctype.newconstr (Path.Pident (Ident.create "int")) []))
1371-
();
1360+
(Ctype.newconstr (Path.Pident (Ident.create "int")) []));
13721361
]
13731362
| CPFloat ->
13741363
[
1375-
Completion.create ~name:"float" ~env
1364+
Completion.create "float" ~env
13761365
~kind:
13771366
(Completion.Value
1378-
(Ctype.newconstr (Path.Pident (Ident.create "float")) []))
1379-
();
1367+
(Ctype.newconstr (Path.Pident (Ident.create "float")) []));
13801368
]
13811369
| CPArray ->
13821370
[
1383-
Completion.create ~name:"array" ~env
1371+
Completion.create "array" ~env
13841372
~kind:
13851373
(Completion.Value
1386-
(Ctype.newconstr (Path.Pident (Ident.create "array")) []))
1387-
();
1374+
(Ctype.newconstr (Path.Pident (Ident.create "array")) []));
13881375
]
13891376
| CPId (path, completionContext) ->
13901377
path
@@ -1428,10 +1415,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
14281415
| args, tRet when args <> [] ->
14291416
let args = processApply args labels in
14301417
let retType = reconstructFunctionType args tRet in
1431-
[
1432-
Completion.create ~name:"dummy" ~env ~kind:(Completion.Value retType)
1433-
();
1434-
]
1418+
[Completion.create "dummy" ~env ~kind:(Completion.Value retType)]
14351419
| _ -> [])
14361420
| None -> [])
14371421
| CPField (CPId (path, Module), fieldName) ->
@@ -1453,14 +1437,13 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
14531437
|> Utils.filterMap (fun field ->
14541438
if checkName field.fname.txt ~prefix:fieldName ~exact then
14551439
Some
1456-
(Completion.create ~name:field.fname.txt ~env
1440+
(Completion.create field.fname.txt ~env
14571441
~docstring:field.docstring
14581442
~kind:
14591443
(Completion.Field
14601444
( field,
14611445
typDecl.item.decl
1462-
|> Shared.declToString typDecl.name.txt ))
1463-
())
1446+
|> Shared.declToString typDecl.name.txt )))
14641447
else None)
14651448
| None -> [])
14661449
| None -> [])
@@ -1487,8 +1470,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
14871470
|> Utils.filterMap (fun (field, typ) ->
14881471
if checkName field ~prefix:label ~exact then
14891472
Some
1490-
(Completion.create ~name:field ~env
1491-
~kind:(Completion.ObjLabel typ) ())
1473+
(Completion.create field ~env ~kind:(Completion.ObjLabel typ))
14921474
else None)
14931475
| None -> [])
14941476
| None -> [])
@@ -1670,9 +1652,8 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
16701652
in
16711653
if List.length ctxPaths = List.length typeExrps then
16721654
[
1673-
Completion.create ~name:"dummy" ~env
1674-
~kind:(Completion.Value (Ctype.newty (Ttuple typeExrps)))
1675-
();
1655+
Completion.create "dummy" ~env
1656+
~kind:(Completion.Value (Ctype.newty (Ttuple typeExrps)));
16761657
]
16771658
else []
16781659
| CJsxPropValue {pathToComponent; propName} -> (
@@ -1690,9 +1671,8 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
16901671
| None -> []
16911672
| Some (_, typ, env) ->
16921673
[
1693-
Completion.create ~name:"dummy" ~env
1694-
~kind:(Completion.Value (Utils.unwrapIfOption typ))
1695-
();
1674+
Completion.create "dummy" ~env
1675+
~kind:(Completion.Value (Utils.unwrapIfOption typ));
16961676
])
16971677
| CArgument {functionContextPath; argumentLabel} -> (
16981678
let labels, env =
@@ -1724,11 +1704,10 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
17241704
| None -> []
17251705
| Some (_, typ) ->
17261706
[
1727-
Completion.create ~name:"dummy" ~env
1707+
Completion.create "dummy" ~env
17281708
~kind:
17291709
(Completion.Value
1730-
(if expandOption then Utils.unwrapIfOption typ else typ))
1731-
();
1710+
(if expandOption then Utils.unwrapIfOption typ else typ));
17321711
])
17331712

17341713
let getOpens ~debug ~rawOpens ~package ~env =
@@ -1819,12 +1798,8 @@ let rec completeTypedValue (t : Types.type_expr) ~env ~full ~prefix
18191798
match t |> extractType ~env ~package:full.package with
18201799
| Some (Tbool env) ->
18211800
[
1822-
Completion.create ~name:"true"
1823-
~kind:(Label (t |> Shared.typeToString))
1824-
~env ();
1825-
Completion.create ~name:"false"
1826-
~kind:(Label (t |> Shared.typeToString))
1827-
~env ();
1801+
Completion.create "true" ~kind:(Label (t |> Shared.typeToString)) ~env;
1802+
Completion.create "false" ~kind:(Label (t |> Shared.typeToString)) ~env;
18281803
]
18291804
|> filterItems ~prefix
18301805
| Some (Tvariant {env; constructors; variantDecl; variantName}) ->
@@ -1883,9 +1858,7 @@ let rec completeTypedValue (t : Types.type_expr) ~env ~full ~prefix
18831858
})
18841859
in
18851860
[
1886-
Completion.create ~name:"None"
1887-
~kind:(Label (t |> Shared.typeToString))
1888-
~env ();
1861+
Completion.create "None" ~kind:(Label (t |> Shared.typeToString)) ~env;
18891862
Completion.createWithSnippet ~name:"Some(_)"
18901863
~kind:(Label (t |> Shared.typeToString))
18911864
~env ~insertText:"Some(${1:_})" ();
@@ -1910,9 +1883,9 @@ let rec completeTypedValue (t : Types.type_expr) ~env ~full ~prefix
19101883
|> List.filter (fun (field : field) ->
19111884
List.mem field.fname.txt seenFields = false)
19121885
|> List.map (fun (field : field) ->
1913-
Completion.create ~name:field.fname.txt
1886+
Completion.create field.fname.txt
19141887
~kind:(Field (field, typeExpr |> Shared.typeToString))
1915-
~env ())
1888+
~env)
19161889
|> filterItems ~prefix
19171890
| None ->
19181891
if prefix = "" then
@@ -2016,7 +1989,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
20161989
| Cjsx ([id], prefix, identsSeen) when String.uncapitalize_ascii id = id ->
20171990
(* Lowercase JSX tag means builtin *)
20181991
let mkLabel (name, typString) =
2019-
Completion.create ~name ~kind:(Label typString) ~env ()
1992+
Completion.create name ~kind:(Label typString) ~env
20201993
in
20211994
let keyLabels =
20221995
if Utils.startsWith "key" prefix then [mkLabel ("key", "string")] else []
@@ -2030,7 +2003,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
20302003
| Cjsx (componentPath, prefix, identsSeen) ->
20312004
let labels = getJsxLabels ~componentPath ~findTypeOfValue ~package in
20322005
let mkLabel_ name typString =
2033-
Completion.create ~name ~kind:(Label typString) ~env ()
2006+
Completion.create name ~kind:(Label typString) ~env
20342007
in
20352008
let mkLabel (name, typ, _env) =
20362009
mkLabel_ name (typ |> Shared.typeToString)
@@ -2049,7 +2022,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
20492022
@ keyLabels
20502023
| Cdecorator prefix ->
20512024
let mkDecorator (name, docstring) =
2052-
{(Completion.create ~name ~kind:(Label "") ~env ()) with docstring}
2025+
{(Completion.create name ~kind:(Label "") ~env) with docstring}
20532026
in
20542027
[
20552028
( "as",
@@ -2306,7 +2279,7 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
23062279
| None -> []
23072280
in
23082281
let mkLabel (name, typ) =
2309-
Completion.create ~name ~kind:(Label (typ |> Shared.typeToString)) ~env ()
2282+
Completion.create name ~kind:(Label (typ |> Shared.typeToString)) ~env
23102283
in
23112284
labels
23122285
|> List.filter (fun (name, _t) ->

analysis/src/Hover.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ let getHoverViaCompletions ~debug ~path ~pos ~currentFile ~forHover
156156
let typeString =
157157
hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ
158158
in
159-
let parts = [typeString] @ docstring in
159+
let parts = typeString :: docstring in
160160
Some (Protocol.stringifyHover (String.concat "\n\n" parts))
161161
| None -> None)
162162
| _ -> (
@@ -251,7 +251,7 @@ let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
251251
|> List.map (fun (t, _) -> Shared.typeToString t)
252252
|> String.concat ", " |> Printf.sprintf "(%s)"
253253
in
254-
[Markdown.codeBlock (txt ^ argsString)] @ docstring @ [typeString]
254+
(Markdown.codeBlock (txt ^ argsString) :: docstring) @ [typeString]
255255
| `Field ->
256256
let typeString, docstring = t |> fromType ~docstring in
257257
typeString :: docstring)

0 commit comments

Comments
 (0)