Skip to content

Do not complete from Pervasives by default. #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions analysis/src/NewCompletions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -862,20 +862,6 @@ let findLocalCompletionsWithOpens ~pos ~(env : QueryEnv.t) ~prefix ~exact ~opens
(* There's no local completion for fields *)
[]

(* TODO filter out things that are defined after the current position *)
let resolveRawOpens ~env ~rawOpens ~package =
(* TODO Stdlib instead of Pervasives *)
let packageOpens = "Pervasives" :: package.opens in
Log.log ("Package opens " ^ String.concat " " packageOpens);
let opens =
resolveOpens ~env
~previous:
(List.map QueryEnv.fromFile
(packageOpens |> Utils.filterMap (ProcessCmt.fileForModule ~package)))
(List.rev rawOpens) ~package
in
opens

let rec extractRecordType ~env ~package (t : Types.type_expr) =
match t.desc with
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractRecordType ~env ~package t1
Expand Down Expand Up @@ -1132,15 +1118,21 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos

let getOpens ~rawOpens ~package ~env =
Log.log
("Opens folkz > "
("Raw ppens: "
^ string_of_int (List.length rawOpens)
^ " "
^ String.concat " ... " (rawOpens |> List.map pathToString));
let packageOpens = "Pervasives" :: package.opens in
let packageOpens = package.opens in
Log.log ("Package opens " ^ String.concat " " packageOpens);
let resolvedOpens = resolveRawOpens ~env ~rawOpens ~package in
let resolvedOpens =
resolveOpens ~env
~previous:
(List.map QueryEnv.fromFile
(packageOpens |> Utils.filterMap (ProcessCmt.fileForModule ~package)))
(List.rev rawOpens) ~package
in
Log.log
("Opens nows "
("Resolved opens "
^ string_of_int (List.length resolvedOpens)
^ " "
^ String.concat " "
Expand Down
2 changes: 2 additions & 0 deletions analysis/src/SharedTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ module Completion = struct
let create ~name ~kind ~env =
{name; env; deprecated = None; docstring = []; kind}

(* https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion *)
(* https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItemKind *)
let kindToInt kind =
match kind with
| Module _ -> 9
Expand Down
6 changes: 0 additions & 6 deletions analysis/tests/src/expected/Completion.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1308,12 +1308,6 @@ Completable: Cpath Value[na]
"tags": [],
"detail": "string",
"documentation": null
}, {
"label": "nan",
"kind": 12,
"tags": [],
"detail": "float",
"documentation": null
}]

Complete tests/src/Completion.res 239:17
Expand Down
10 changes: 3 additions & 7 deletions analysis/tests/src/expected/Debug.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,16 @@ Complete tests/src/Debug.res 13:8
posCursor:[13:8] posNoWhite:[13:7] Found expr:[13:5->13:8]
Pexp_ident eqN:[13:5->13:8]
Completable: Cpath Value[eqN]
Opens folkz > 1 Js.place holder
Package opens Pervasives
Package opens Pervasives
fileForModule Impl cmt:tests/node_modules/rescript/lib/ocaml/pervasives.cmti res:tests/node_modules/rescript/lib/ocaml/pervasives.mli
Raw ppens: 1 Js.place holder
Package opens
resolving open Js.place holder
resolvePath path:Js.place holder
Not local
resolvePath path:Js.place holder
fileForModule Impl cmt:tests/node_modules/rescript/lib/ocaml/js.cmt res:tests/node_modules/rescript/lib/ocaml/js.ml
resolvePath path:place holder
Opens nows 2 pervasives.mli js.ml
Resolved opens 1 js.ml
findLocalCompletionsWithOpens uri:Debug.res pos:13:8
findAllCompletions uri:js.ml
findAllCompletions uri:pervasives.mli
[{
"label": "eqNullable",
"kind": 12,
Expand Down
1 change: 1 addition & 0 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ function semanticTokens(msg: p.RequestMessage) {
}

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