Skip to content

Commit dd25648

Browse files
committed
Do not complete from Pervasives by default.
Pervasives can lead to very noisy autocompletion. Don't use values from Pervasives by default. Can be explicitly triggered by `Pervasives.`.
1 parent 9e9b3f7 commit dd25648

File tree

5 files changed

+16
-31
lines changed

5 files changed

+16
-31
lines changed

analysis/src/NewCompletions.ml

+10-18
Original file line numberDiff line numberDiff line change
@@ -862,20 +862,6 @@ let findLocalCompletionsWithOpens ~pos ~(env : QueryEnv.t) ~prefix ~exact ~opens
862862
(* There's no local completion for fields *)
863863
[]
864864

865-
(* TODO filter out things that are defined after the current position *)
866-
let resolveRawOpens ~env ~rawOpens ~package =
867-
(* TODO Stdlib instead of Pervasives *)
868-
let packageOpens = "Pervasives" :: package.opens in
869-
Log.log ("Package opens " ^ String.concat " " packageOpens);
870-
let opens =
871-
resolveOpens ~env
872-
~previous:
873-
(List.map QueryEnv.fromFile
874-
(packageOpens |> Utils.filterMap (ProcessCmt.fileForModule ~package)))
875-
(List.rev rawOpens) ~package
876-
in
877-
opens
878-
879865
let rec extractRecordType ~env ~package (t : Types.type_expr) =
880866
match t.desc with
881867
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractRecordType ~env ~package t1
@@ -1132,15 +1118,21 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
11321118

11331119
let getOpens ~rawOpens ~package ~env =
11341120
Log.log
1135-
("Opens folkz > "
1121+
("Raw ppens: "
11361122
^ string_of_int (List.length rawOpens)
11371123
^ " "
11381124
^ String.concat " ... " (rawOpens |> List.map pathToString));
1139-
let packageOpens = "Pervasives" :: package.opens in
1125+
let packageOpens = package.opens in
11401126
Log.log ("Package opens " ^ String.concat " " packageOpens);
1141-
let resolvedOpens = resolveRawOpens ~env ~rawOpens ~package in
1127+
let resolvedOpens =
1128+
resolveOpens ~env
1129+
~previous:
1130+
(List.map QueryEnv.fromFile
1131+
(packageOpens |> Utils.filterMap (ProcessCmt.fileForModule ~package)))
1132+
(List.rev rawOpens) ~package
1133+
in
11421134
Log.log
1143-
("Opens nows "
1135+
("Resolved opens "
11441136
^ string_of_int (List.length resolvedOpens)
11451137
^ " "
11461138
^ String.concat " "

analysis/src/SharedTypes.ml

+2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ module Completion = struct
225225
let create ~name ~kind ~env =
226226
{name; env; deprecated = None; docstring = []; kind}
227227

228+
(* https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion *)
229+
(* https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItemKind *)
228230
let kindToInt kind =
229231
match kind with
230232
| Module _ -> 9

analysis/tests/src/expected/Completion.res.txt

-6
Original file line numberDiff line numberDiff line change
@@ -1308,12 +1308,6 @@ Completable: Cpath Value[na]
13081308
"tags": [],
13091309
"detail": "string",
13101310
"documentation": null
1311-
}, {
1312-
"label": "nan",
1313-
"kind": 12,
1314-
"tags": [],
1315-
"detail": "float",
1316-
"documentation": null
13171311
}]
13181312

13191313
Complete tests/src/Completion.res 239:17

analysis/tests/src/expected/Debug.res.txt

+3-7
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,16 @@ Complete tests/src/Debug.res 13:8
6363
posCursor:[13:8] posNoWhite:[13:7] Found expr:[13:5->13:8]
6464
Pexp_ident eqN:[13:5->13:8]
6565
Completable: Cpath Value[eqN]
66-
Opens folkz > 1 Js.place holder
67-
Package opens Pervasives
68-
Package opens Pervasives
69-
fileForModule Impl cmt:tests/node_modules/rescript/lib/ocaml/pervasives.cmti res:tests/node_modules/rescript/lib/ocaml/pervasives.mli
66+
Raw ppens: 1 Js.place holder
67+
Package opens
7068
resolving open Js.place holder
7169
resolvePath path:Js.place holder
7270
Not local
73-
resolvePath path:Js.place holder
7471
fileForModule Impl cmt:tests/node_modules/rescript/lib/ocaml/js.cmt res:tests/node_modules/rescript/lib/ocaml/js.ml
7572
resolvePath path:place holder
76-
Opens nows 2 pervasives.mli js.ml
73+
Resolved opens 1 js.ml
7774
findLocalCompletionsWithOpens uri:Debug.res pos:13:8
7875
findAllCompletions uri:js.ml
79-
findAllCompletions uri:pervasives.mli
8076
[{
8177
"label": "eqNullable",
8278
"kind": 12,

server/src/server.ts

+1
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ function semanticTokens(msg: p.RequestMessage) {
428428
}
429429

430430
function completion(msg: p.RequestMessage) {
431+
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
431432
let params = msg.params as p.ReferenceParams;
432433
let filePath = fileURLToPath(params.textDocument.uri);
433434
let extension = path.extname(params.textDocument.uri);

0 commit comments

Comments
 (0)