Skip to content
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

Completion items not properly matching full 'word' #46

Open
julienvincent opened this issue Oct 8, 2024 · 3 comments
Open

Completion items not properly matching full 'word' #46

julienvincent opened this issue Oct 8, 2024 · 3 comments

Comments

@julienvincent
Copy link
Contributor

julienvincent commented Oct 8, 2024

I suppose this is a continuation of #38. The issue reported there was resolved by 655d2ee but there is still an issue with the word selection logic.

The issue is that the replacement doesn't always match all the relevant text.

Example:

(ns example
  (:require
   [clojure.test :as test]))

(test/use|)

;; Press accept

;; Result:
(test/test/use-fixtures|)

;; Expected:
(test/use-fixtures|)

So it's not replacing the entire text of test/use it's just replacing the use component.

I wonder if the lsp completion items contain context about the range they are operating over.

@julienvincent
Copy link
Contributor Author

julienvincent commented Oct 9, 2024

Another example of this issue, still in clojure:

(ns example
  (:require
   [clojure.test :as scope.test]))

scope.te|
;; autocompletes to
scope.scope.test

@Saghen
Copy link
Owner

Saghen commented Oct 9, 2024

I wonder if the lsp completion items contain context about the range they are operating over.

They typically do (textEdit field on completion items) but it sounds like clojure doesn't include these. It sounds like it instead passes through an insertText which gets converted into a textEdit interally here. I'm not sure how to handle this without writing custom context regexs (line 53) for each language.

It could be the LSP supports it, but disables the behavior, due to not broadcasting the capabilities correctly as per #13

@julienvincent
Copy link
Contributor Author

julienvincent commented Oct 9, 2024

I don't think its #13 as I copied over the capabilities config from nvim-cmp-lsp into my own config.

You're right about the textEdit - I did some inspection and it's not being set. I also took a peek at how nvim-cmp does it but it was too much to untangle and I didn't have much time.

But similarly to blink, nvim-cmp has a fallback to guess the range. At a glance It's implementation looks completely language agnostic so there is probably something there to base off of.


For reference:

Looks like there is this function to get the range: https://github.com/hrsh7th/nvim-cmp/blob/ae644feb7b67bf1ce4260c231d1d4300b19c6f30/lua/cmp/core.lua#L449

And then this plus a bunch of other functions for guessing the range: https://github.com/hrsh7th/nvim-cmp/blob/ae644feb7b67bf1ce4260c231d1d4300b19c6f30/lua/cmp/entry.lua#L316

Looks a bit gnarly to untangle

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

No branches or pull requests

2 participants