Skip to content

Commit

Permalink
fix: respect item preSelect capability
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>

ps-id: 3b1a9685-d8f9-4628-9817-5cbd17cf639b
  • Loading branch information
rgrinberg committed Nov 22, 2022
1 parent c918e3f commit 5984580
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

- Fix document syncing for ranges that span an entire line (#927)

- Respect the client's completion item resolve capability (#925)
- Respect the client's completion item resolve and preSelect capabilities
(#925, #936)

## Features

Expand Down
28 changes: 20 additions & 8 deletions ocaml-lsp-server/src/compl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,17 @@ let complete (state : State.t)
match Document.kind doc with
| `Other -> Fiber.return None
| `Merlin merlin ->
let resolve =
let completion_item_capability =
let open Option.O in
let capabilities = State.client_capabilities state in
let* td = capabilities.textDocument in
let* compl = td.completion in
compl.completionItem
in
let resolve =
match
let open Option.O in
let* td = capabilities.textDocument in
let* compl = td.completion in
let* item = compl.completionItem in
let* item = completion_item_capability in
item.resolveSupport
with
| None -> false
Expand All @@ -290,10 +294,18 @@ let complete (state : State.t)
let sortText = Some (sortText_of_index idx) in
{ ci with sortText })
in
let preselect_first = function
| [] -> []
| ci :: rest ->
{ ci with CompletionItem.preselect = Some true } :: rest
let preselect_first =
match
let open Option.O in
let* item = completion_item_capability in
item.preselectSupport
with
| None | Some false -> fun x -> x
| Some true -> (
function
| [] -> []
| ci :: rest ->
{ ci with CompletionItem.preselect = Some true } :: rest)
in
let+ construct_cmd_resp, compl_by_prefix_resp =
Document.Merlin.with_pipeline_exn merlin (fun pipeline ->
Expand Down

0 comments on commit 5984580

Please sign in to comment.