Skip to content

Completion: for perf reasons first check completion context. #255

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
May 26, 2021
Merged
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
11 changes: 4 additions & 7 deletions analysis/src/Commands.ml
Original file line number Diff line number Diff line change
@@ -34,13 +34,10 @@ let dump files =
let completion ~path ~line ~col ~currentFile =
let uri = Uri2.fromPath path in
let result =
match ProcessCmt.getFullFromCmt ~uri with
| None -> "[]"
| Some full ->
let maybeText = Files.readFile currentFile in
NewCompletions.computeCompletions ~full ~maybeText ~pos:(line, col)
|> List.map Protocol.stringifyCompletionItem
|> Protocol.array
let textOpt = Files.readFile currentFile in
NewCompletions.computeCompletions ~uri ~textOpt ~pos:(line, col)
|> List.map Protocol.stringifyCompletionItem
|> Protocol.array
in
print_endline result

35 changes: 20 additions & 15 deletions analysis/src/NewCompletions.ml
Original file line number Diff line number Diff line change
@@ -1133,26 +1133,31 @@ let processCompletable ~findItems ~full ~package ~rawOpens
Utils.startsWith name prefix && not (List.mem name identsSeen))
|> List.map mkLabel

let computeCompletions ~full ~maybeText ~pos =
let package = full.package in
match maybeText with
let computeCompletions ~uri ~textOpt ~pos =
match textOpt with
| None -> []
| Some text -> (
match PartialParser.positionToOffset text pos with
| None -> []
| Some offset -> (
match PartialParser.findCompletable text offset with
| None -> []
| Some completable ->
let rawOpens = PartialParser.findOpens text offset in
let allModules = package.localModules @ package.dependencyModules in
let findItems ~exact parts =
let items =
getItems ~full ~package ~rawOpens ~allModules ~pos ~parts
| Some completable -> (
match ProcessCmt.getFullFromCmt ~uri with
| None -> []
| Some full ->
let rawOpens = PartialParser.findOpens text offset in
let package = full.package in
let allModules = package.localModules @ package.dependencyModules in
let findItems ~exact parts =
let items =
getItems ~full ~package ~rawOpens ~allModules ~pos ~parts
in
match parts |> List.rev with
| last :: _ when exact ->
items
|> List.filter (fun {SharedTypes.name = {txt}} -> txt = last)
| _ -> items
in
match parts |> List.rev with
| last :: _ when exact ->
items |> List.filter (fun {SharedTypes.name = {txt}} -> txt = last)
| _ -> items
in
completable |> processCompletable ~findItems ~full ~package ~rawOpens))
completable |> processCompletable ~findItems ~full ~package ~rawOpens)
))