Skip to content

Commit 09ca1cf

Browse files
committed
Remove url display from autocomplete popup
It was noisy
1 parent eb5a494 commit 09ca1cf

File tree

4 files changed

+132
-173
lines changed

4 files changed

+132
-173
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Features:
88
- Show References!
99
- Hover now supports markdown docs!
1010
- Hover on labels in component functions with compiler version 9.1, and labels with type annotation.
11-
- Don't show file path on hover (cleaner).
11+
- Don't show file path on hover and autocomplete (cleaner).
1212
- Autocomplete for props in JSX components.
1313
- `->` autocomplete for built-in list, array, string, option types. And for string and array literals.
1414

analysis/src/NewCompletions.ml

Lines changed: 58 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,16 @@ let localValueCompletions ~pos ~(env : ProcessCmt.queryEnv) suffix =
210210
{(emptyDeclared c.cname.txt) with item = Constructor (c, t)}))
211211
else results
212212
in
213-
let results =
214-
if suffix = "" || not (isCapitalized suffix) then
215-
results
216-
@ completionForDeclareds ~pos env.qFile.stamps.values suffix (fun v ->
217-
Value v)
218-
@ completionForDeclareds ~pos env.qFile.stamps.types suffix (fun t ->
219-
Type t)
220-
@ (completionForFields env.qExported.types env.qFile.stamps.types suffix
221-
|> List.map (fun (f, t) ->
222-
{(emptyDeclared f.fname.txt) with item = Field (f, t)}))
223-
else results
224-
in
225-
results |> List.map (fun x -> (env.qFile.uri, x))
213+
if suffix = "" || not (isCapitalized suffix) then
214+
results
215+
@ completionForDeclareds ~pos env.qFile.stamps.values suffix (fun v ->
216+
Value v)
217+
@ completionForDeclareds ~pos env.qFile.stamps.types suffix (fun t ->
218+
Type t)
219+
@ (completionForFields env.qExported.types env.qFile.stamps.types suffix
220+
|> List.map (fun (f, t) ->
221+
{(emptyDeclared f.fname.txt) with item = Field (f, t)}))
222+
else results
226223

227224
let valueCompletions ~(env : ProcessCmt.queryEnv) suffix =
228225
Log.log (" - Completing in " ^ Uri2.toString env.qFile.uri);
@@ -247,22 +244,17 @@ let valueCompletions ~(env : ProcessCmt.queryEnv) suffix =
247244
{(emptyDeclared c.cname.txt) with item = Constructor (c, t)})))
248245
else results
249246
in
250-
let results =
251-
if suffix = "" || not (isCapitalized suffix) then (
252-
Log.log " -- not capitalized";
253-
results
254-
@ completionForExporteds env.qExported.values env.qFile.stamps.values
255-
suffix (fun v -> Value v)
256-
@ completionForExporteds env.qExported.types env.qFile.stamps.types suffix
257-
(fun t -> Type t)
258-
@ (completionForFields env.qExported.types env.qFile.stamps.types suffix
259-
|> List.map (fun (f, t) ->
260-
{(emptyDeclared f.fname.txt) with item = Field (f, t)})))
261-
else results
262-
in
263-
(* Log.log("Getting value completions " ++ env.file.uri);
264-
Log.log(String.concat(", ", results |. Belt.List.map(x => x.name.txt))); *)
265-
results |> List.map (fun x -> (env.qFile.uri, x))
247+
if suffix = "" || not (isCapitalized suffix) then (
248+
Log.log " -- not capitalized";
249+
results
250+
@ completionForExporteds env.qExported.values env.qFile.stamps.values suffix
251+
(fun v -> Value v)
252+
@ completionForExporteds env.qExported.types env.qFile.stamps.types suffix
253+
(fun t -> Type t)
254+
@ (completionForFields env.qExported.types env.qFile.stamps.types suffix
255+
|> List.map (fun (f, t) ->
256+
{(emptyDeclared f.fname.txt) with item = Field (f, t)})))
257+
else results
266258

267259
let attributeCompletions ~(env : ProcessCmt.queryEnv) ~suffix =
268260
let results = [] in
@@ -273,18 +265,15 @@ let attributeCompletions ~(env : ProcessCmt.queryEnv) ~suffix =
273265
suffix (fun m -> Module m)
274266
else results
275267
in
276-
let results =
277-
if suffix = "" || not (isCapitalized suffix) then
278-
results
279-
@ completionForExporteds env.qExported.values env.qFile.stamps.values
280-
suffix (fun v -> Value v)
281-
(* completionForExporteds(env.exported.types, env.file.stamps.types, suffix, t => Type(t)) @ *)
282-
@ (completionForFields env.qExported.types env.qFile.stamps.types suffix
283-
|> List.map (fun (f, t) ->
284-
{(emptyDeclared f.fname.txt) with item = Field (f, t)}))
285-
else results
286-
in
287-
results |> List.map (fun x -> (env.qFile.uri, x))
268+
if suffix = "" || not (isCapitalized suffix) then
269+
results
270+
@ completionForExporteds env.qExported.values env.qFile.stamps.values suffix
271+
(fun v -> Value v)
272+
(* completionForExporteds(env.exported.types, env.file.stamps.types, suffix, t => Type(t)) @ *)
273+
@ (completionForFields env.qExported.types env.qFile.stamps.types suffix
274+
|> List.map (fun (f, t) ->
275+
{(emptyDeclared f.fname.txt) with item = Field (f, t)}))
276+
else results
288277

289278
(* TODO filter out things that are defined after the current position *)
290279
let resolveRawOpens ~env ~rawOpens ~package =
@@ -330,12 +319,12 @@ let getItems ~full ~package ~rawOpens ~allModules ~pos ~parts =
330319
(fun results env ->
331320
let completionsFromThisOpen = valueCompletions ~env suffix in
332321
List.filter
333-
(fun (_uri, declared) ->
334-
if not (Hashtbl.mem alreadyUsedIdentifiers declared.name.txt)
335-
then (
322+
(fun declared ->
323+
if Hashtbl.mem alreadyUsedIdentifiers declared.name.txt then
324+
false
325+
else (
336326
Hashtbl.add alreadyUsedIdentifiers declared.name.txt true;
337-
true)
338-
else false)
327+
true))
339328
completionsFromThisOpen
340329
@ results)
341330
[]
@@ -344,14 +333,9 @@ let getItems ~full ~package ~rawOpens ~allModules ~pos ~parts =
344333
let localModuleNames =
345334
allModules
346335
|> Utils.filterMap (fun name ->
347-
match
348-
Utils.startsWith name suffix && not (String.contains name '-')
349-
with
350-
| true ->
351-
Some
352-
( env.qFile.uri,
353-
{(emptyDeclared name) with item = FileModule name} )
354-
| false -> None)
336+
if Utils.startsWith name suffix && not (String.contains name '-')
337+
then Some {(emptyDeclared name) with item = FileModule name}
338+
else None)
355339
in
356340
locallyDefinedValues @ valuesFromOpens @ localModuleNames
357341
| multiple -> (
@@ -404,18 +388,17 @@ let getItems ~full ~package ~rawOpens ~allModules ~pos ~parts =
404388
(Some (env, typ))
405389
with
406390
| None -> []
407-
| Some (env, typ) -> (
391+
| Some (_env, typ) -> (
408392
match typ.item.kind with
409393
| Record fields ->
410394
fields
411395
|> Utils.filterMap (fun f ->
412396
if Utils.startsWith f.fname.txt suffix then
413397
Some
414-
( env.qFile.uri,
415-
{
416-
(emptyDeclared f.fname.txt) with
417-
item = Field (f, typ);
418-
} )
398+
{
399+
(emptyDeclared f.fname.txt) with
400+
item = Field (f, typ);
401+
}
419402
else None)
420403
| _ -> []))))))
421404
| `AbsAttribute path -> (
@@ -426,13 +409,11 @@ let getItems ~full ~package ~rawOpens ~allModules ~pos ~parts =
426409
@ List.concat
427410
(opens |> List.map (fun env -> attributeCompletions ~env ~suffix))))
428411

429-
let mkItem ~name ~kind ~detail ~deprecated ~docstring ~uri ~pos_lnum =
412+
let mkItem ~name ~kind ~detail ~deprecated ~docstring =
430413
let valueMessage =
431414
(match deprecated with None -> "" | Some s -> "Deprecated: " ^ s ^ "\n\n")
432-
^ (match docstring with
433-
| [] -> ""
434-
| _ :: _ -> (docstring |> String.concat "\n") ^ "\n\n")
435-
^ "\n" ^ Uri2.toString uri ^ ":" ^ string_of_int pos_lnum
415+
^
416+
match docstring with [] -> "" | _ :: _ -> docstring |> String.concat "\n"
436417
in
437418
let tags =
438419
match deprecated = None with true -> [] | false -> [1 (* deprecated *)]
@@ -446,14 +427,14 @@ let mkItem ~name ~kind ~detail ~deprecated ~docstring ~uri ~pos_lnum =
446427
documentation = {kind = "markdown"; value = valueMessage};
447428
}
448429

449-
let processCompletable ~findItems ~full ~package ~pos ~rawOpens
430+
let processCompletable ~findItems ~package ~rawOpens
450431
(completable : PartialParser.completable) =
451432
match completable with
452433
| Cjsx (componentPath, prefix) ->
453434
let items = findItems ~exact:true (componentPath @ ["make"]) in
454435
let labels =
455436
match items with
456-
| (_uri, {SharedTypes.item = Value typ}) :: _ ->
437+
| {SharedTypes.item = Value typ} :: _ ->
457438
let rec getFields (texp : Types.type_expr) =
458439
match texp.desc with
459440
| Tfield (name, _, t1, t2) ->
@@ -483,7 +464,6 @@ let processCompletable ~findItems ~full ~package ~pos ~rawOpens
483464
in
484465
let mkLabel_ name typString =
485466
mkItem ~name ~kind:4 ~deprecated:None ~detail:typString ~docstring:[]
486-
~uri:full.file.uri ~pos_lnum:(fst pos)
487467
in
488468
let mkLabel (name, typ) = mkLabel_ name (typ |> Shared.typeToString) in
489469
let keyLabel = mkLabel_ "key" "string" in
@@ -498,17 +478,9 @@ let processCompletable ~findItems ~full ~package ~pos ~rawOpens
498478
(* TODO(#107): figure out why we're getting duplicates. *)
499479
items |> Utils.dedup
500480
|> List.map
501-
(fun
502-
( uri,
503-
{
504-
SharedTypes.name = {txt = name; loc = {loc_start = {pos_lnum}}};
505-
deprecated;
506-
docstring;
507-
item;
508-
} )
509-
->
481+
(fun {SharedTypes.name = {txt = name}; deprecated; docstring; item} ->
510482
mkItem ~name ~kind:(kindToInt item) ~deprecated
511-
~detail:(detail name item) ~docstring ~uri ~pos_lnum)
483+
~detail:(detail name item) ~docstring)
512484
| Cpipe (pipe, partialName) -> (
513485
let arrayModulePath = ["Js"; "Array2"] in
514486
let listModulePath = ["Belt"; "List"] in
@@ -530,7 +502,7 @@ let processCompletable ~findItems ~full ~package ~pos ~rawOpens
530502
in
531503
let getLhsPath ~pipeId ~partialName =
532504
match [pipeId] |> findItems ~exact:true with
533-
| (_uri, {SharedTypes.item = Value t}) :: _ ->
505+
| {SharedTypes.item = Value t} :: _ ->
534506
let modulePath =
535507
match t.desc with
536508
| Tconstr (path, _, _) -> getModulePath path
@@ -586,28 +558,18 @@ let processCompletable ~findItems ~full ~package ~pos ~rawOpens
586558
let parts = modulePath @ [partialName] in
587559
let items = parts |> findItems ~exact:false in
588560
items
589-
|> List.filter (fun (_, {item}) ->
561+
|> List.filter (fun {item} ->
590562
match item with Value _ -> true | _ -> false)
591563
|> List.map
592-
(fun
593-
( uri,
594-
{
595-
SharedTypes.name =
596-
{txt = name; loc = {loc_start = {pos_lnum}}};
597-
deprecated;
598-
docstring;
599-
item;
600-
} )
564+
(fun {SharedTypes.name = {txt = name}; deprecated; docstring; item}
601565
->
602566
mkItem ~name:(completionName name) ~kind:(kindToInt item)
603-
~detail:(detail name item) ~deprecated ~docstring ~uri
604-
~pos_lnum)
567+
~detail:(detail name item) ~deprecated ~docstring)
605568
| _ -> [])
606569
| None -> [])
607570
| Cdecorator prefix ->
608571
let mkDecorator name =
609572
mkItem ~name ~kind:4 ~deprecated:None ~detail:"" ~docstring:[]
610-
~uri:full.file.uri ~pos_lnum:(fst pos)
611573
in
612574
[
613575
"as";
@@ -643,7 +605,7 @@ let processCompletable ~findItems ~full ~package ~pos ~rawOpens
643605
| Clabel (funPath, prefix) ->
644606
let labels =
645607
match funPath |> findItems ~exact:true with
646-
| (_uri, {SharedTypes.item = Value typ}) :: _ ->
608+
| {SharedTypes.item = Value typ} :: _ ->
647609
let rec getLabels (t : Types.type_expr) =
648610
match t.desc with
649611
| Tlink t1 | Tsubst t1 -> getLabels t1
@@ -658,7 +620,7 @@ let processCompletable ~findItems ~full ~package ~pos ~rawOpens
658620
let mkLabel (name, typ) =
659621
mkItem ~name ~kind:4 ~deprecated:None
660622
~detail:(typ |> Shared.typeToString)
661-
~docstring:[] ~uri:full.file.uri ~pos_lnum:(fst pos)
623+
~docstring:[]
662624
in
663625
labels
664626
|> List.filter (fun (name, _t) -> Utils.startsWith name prefix)
@@ -684,10 +646,7 @@ let computeCompletions ~full ~maybeText ~package ~pos =
684646
in
685647
match parts |> List.rev with
686648
| last :: _ when exact ->
687-
items
688-
|> List.filter (fun (_uri, {SharedTypes.name = {txt}}) ->
689-
txt = last)
649+
items |> List.filter (fun {SharedTypes.name = {txt}} -> txt = last)
690650
| _ -> items
691651
in
692-
completable
693-
|> processCompletable ~findItems ~full ~package ~pos ~rawOpens))
652+
completable |> processCompletable ~findItems ~package ~rawOpens))

0 commit comments

Comments
 (0)