Skip to content

Implement completionItem/resolve for more completion types #3535

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

Closed
michaelpj opened this issue Mar 21, 2023 · 11 comments
Closed

Implement completionItem/resolve for more completion types #3535

michaelpj opened this issue Mar 21, 2023 · 11 comments

Comments

@michaelpj
Copy link
Collaborator

LSP allows you to implement completionItem/resolve to delay the computation of some parts of completion items. The advantages are similar to #3534, but mostly it's about avoiding expensive computation.

We got support for completionItem/resolve for Haskell completions in #3204, but we have other completion providers e.g. the pragmas plugin. It would be good to implement completionItem/resolve in more places.

As with #3534, doing this properly would mean figuring out a way to make it easy for plugin authors to opt into it.

@joyfulmantis
Copy link
Collaborator

Upon investigation, this may be a non-issue. From my investigation, plugin authors can already use completionItem/resolve by making a plugin handler for the SCompletionItemResolve type. Furthermore, the pragmas plugin is the only other plugin offering completion, and that plugin does not provide anything for the detail or documentation fields of completionItem, which are the fields that completionItem/resolve is built to provide.

From the spec:

A typical use case is for example: the ‘textDocument/completion’ request doesn’t fill in the documentation property for returned completion items since it is expensive to compute. When the item is selected in the user interface then a ‘completionItem/resolve’ request is sent with the selected completion item as a parameter. The returned completion item should have the documentation property filled in. By default the request can only delay the computation of the detail and documentation properties.

For these reasons, I believe this issue can be closed.

@michaelpj
Copy link
Collaborator Author

Furthermore, the pragmas plugin is the only other plugin offering completion, and that plugin does not provide anything for the detail or documentation fields of completionItem, which are the fields that completionItem/resolve is built to provide.

Right, it's indeed unclear whether any of the actual completions implementations that we have will benefit from this, since most of them are cheap. Pragmas are cheap, probably whatever we end up with for the cabal plugin will be cheap, it's really only the primary Haskell completions that are expensive, and there it's already implemented.

From my investigation, plugin authors can already use completionItem/resolve by making a plugin handler for the SCompletionItemResolve type.

Right, the issue is that (IMO) it's not terribly easy to do. All the /resolve methods give you as a parameter the item you returned in the original request. So you have to

  • Put some identifier in the item so that you can later work out what entity it refers to
  • In the resolve handler, reconstruct any state that you might need in order to work out further information about that entity

Maybe there's nothing really to do here, and we just need some examples for people to follow, but I wonder if we could make it easier, even by just giving people a little interface to implement that gives them both, e.g.

mkCompletionHandlerWithResolve :: (FromJSON key, ToJSON key) => (CompletionItemRequest -> [(CompletionItem, key)]) -> (key -> CompletionItem) -> Handlers

which would compute a serializable key for every completion item, stick it in the data field, and then pull it back out and use it to create a fuller completion item in the resolve handler. Not really doing all that much, but it nudges people in the right direction.

@michaelpj
Copy link
Collaborator Author

I'll leave the issue open for now, but probably not much to do here.

@lf-
Copy link
Contributor

lf- commented Oct 23, 2023

I am not sure if this is a bug in coc.nvim or in HLS [2.1.0.0], since I would class it as a "protocol misunderstanding/disagreement". But: completions are not getting documentation from HLS because HLS promises to have resolveable completions, but then errors the request instead of returning the same documentation that was sent in the textDocument/completion request. The end result is you can't see the module that things come from when invoking completion with coc.nvim, which is pretty bad!

Again, don't know whose bug this is, but HLS is on the scene with odd behaviour.

[Trace - 17:03:42.938] Received response 'textDocument/completion - (13)' in 34ms.
Result: {
    "isIncomplete": true,
    "items": [
        {
            "command": {
                "arguments": [
                    {
                        "doc": "file:///home/jade/.dotfiles/bin/intercept2chrome.hs",
                        "importName": "System.Directory.Internal.Prelude",
                        "importQual": null,
                        "newThing": "getArgs",
                        "thingParent": null
                    }
                ],
                "command": "2827480:ghcide-extend-import-action:extendImport",
                "title": "extend import"
            },
            "detail": "from System.Directory.Internal.Prelude",
            "documentation": {
                "kind": "markdown",
                "value": "*Defined in 'System.Directory.Internal.Prelude'*\n"
            },
            "insertText": "getArgs",
            "insertTextFormat": 2,
            "kind": 3,
            "label": "getArgs",
            "sortText": "00"
        },
        {
            "command": {
                "arguments": [
                    {
                        "doc": "file:///home/jade/.dotfiles/bin/intercept2chrome.hs",
                        "importName": "System.Environment",
                        "importQual": null,
                        "newThing": "getArgs",
                        "thingParent": null
                    }
                ],
                "command": "2827480:ghcide-extend-import-action:extendImport",
                "title": "extend import"
            },
            "detail": "from System.Environment",
            "documentation": {
                "kind": "markdown",
                "value": "*Defined in 'System.Environment'*\n"
            },
            "insertText": "getArgs",
            "insertTextFormat": 2,
            "kind": 3,
            "label": "getArgs",
            "sortText": "01"
        },
(.....)
[Trace - 17:03:43.464] Sending request 'completionItem/resolve - (15)'.
Params: {
    "command": {
        "arguments": [
            {
                "doc": "file:///home/jade/.dotfiles/bin/intercept2chrome.hs",
                "importName": "System.Directory.Internal.Prelude",
                "importQual": null,
                "newThing": "getArgs",
                "thingParent": null
            }
        ],
        "command": "2827480:ghcide-extend-import-action:extendImport",
        "title": "extend import"
    },
    "detail": "from System.Directory.Internal.Prelude",
    "documentation": {
        "kind": "markdown",
        "value": "*Defined in 'System.Directory.Internal.Prelude'*\n"
    },
    "insertText": "getArgs",
    "insertTextFormat": 2,
    "kind": 3,
    "label": "getArgs",
    "sortText": "00"
}


2023-10-23T00:03:43.464592Z | Warning | No plugin enabled for SMethod_CompletionItemResolve
[Trace - 17:03:43.464] Received response 'completionItem/resolve - (15)' in 0ms. Request failed: No plugin enabled for SMethod_CompletionItemResolve, potentially available: ghcide-completions (-32601).
[Error - 17:03:43.465] Sending request completionItem/resolve failed.
  Message: No plugin enabled for SMethod_CompletionItemResolve, potentially available: ghcide-completions
  Code: -32601 
[Error - 17:03:43.465] Request completionItem/resolve failed.
  Message: No plugin enabled for SMethod_CompletionItemResolve, potentially available: ghcide-completions
  Code: -32601 

Probable cause inside of coc.nvim:

https://github.com/lf-/coc.nvim/blob/7aab006ccea9ca3a0f8f240684e37c55a6fe1052/src/completion/floating.ts#L20-L36

@lf-
Copy link
Contributor

lf- commented Oct 23, 2023

Confirmed this is the problem by crudely ripping out the code from coc.nvim that performs the completionItem/resolve request if supported. Should I file another bug? idk

@joyfulmantis
Copy link
Collaborator

@lf- Please see issue #3842

@michaelpj
Copy link
Collaborator Author

I think we mostly did this

@lf-
Copy link
Contributor

lf- commented Jan 21, 2024

@lf- Please see issue #3842

fyi this bug is against a completely unrelated LSP client stack and I suspect it's unrelated. I can test against master I guess and see if completions are still broken.

@michaelpj
Copy link
Collaborator Author

Yes I know, they told me.

@michaelpj
Copy link
Collaborator Author

For at least one bit of the improvement we need a new lsp release.

@createyourpersonalaccount
Copy link

createyourpersonalaccount commented Feb 10, 2025

How to stop this "SMethod_CompletionItemResolve" warning? It's really really annoying.

Edit: Apparently it was fixed in #4478, which was merged recently and hasn't been released yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants