-
Notifications
You must be signed in to change notification settings - Fork 235
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
[mini.completion] Some completions result in extra period #306
Comments
Thanks for the issue! 'mini.completion' doesn't use There is also a way for users to customize items returned from LSP servers by providing custom If you are not comfortable with writing your own
require('mini.completion').setup({
lsp_completion = {
process_items = function(items, base)
_G.args = { items = items, base = base }
return MiniCompletion.default_process_items(items, base)
end,
},
-- There might be some other code from your setup
})
<details><summary>Arguments in my problematic completion</summary>
```
<You table goes here>
```
</details> |
I've reduced it to something with a single completion, my source file is
and I execute completion at Bad completion{
base = "",
items = { {
data = {
entryNames = { "foo" },
file = "/home/thomas/test.ts",
line = 2,
offset = 6
},
kind = 5,
label = "foo",
sortText = "11",
textEdit = {
newText = ".foo",
range = {
["end"] = {
character = 5,
line = 1
},
start = {
character = 4,
line = 1
}
}
}
} }
} When completing from Good completion{
base = "f",
items = { {
data = {
entryNames = { "foo" },
file = "/home/thomas/test.ts",
line = 2,
offset = 7
},
kind = 5,
label = "foo",
sortText = "11"
} }
} From my understanding, the use of I did try making a process_items = function(items, base)
for k,v in ipairs(items) do
v["textEdit"] = nil
end
return MiniCompletion.default_process_items(items, base)
end |
Thanks for the follow-up! This was really helpful!
At the moment I'd suggest using custom
vim.b.minicompletion_config = {
lsp_completion = {
process_items = function(items, base)
-- Remove dots as prefix from `textEdit.newText` as it is used verbatim
for _, item in ipairs(items) do
local new_text = (item.textEdit or {}).newText
if type(new_text) == 'string' then
item.textEdit.newText = new_text:gsub('^%.+', '')
end
end
return MiniCompletion.default_process_items(items, base)
end,
},
} This way it will affect only 'typescript' filetype.
Edit: The issue should now be resolved in |
@echasnovski Thanks for the head-tip. I ran into the same problem and originally wanted to report it on my own. I will try your proposed solution tomorrow morning and hand in some feedback. Cheers! |
@echasnovski As promised, I tried your proposal and - for the sake of completeness - added files for |
That is great to hear! Thanks for the feedback. I still can't think of a better way to resolve this problem, so having a confirmation that it works is good. |
I see this issue with the builtin vim.lsp.omnifunc as well. |
I think utilizing suggested |
There's another few interesting cases that hits these limitations: Optional Chaining
Completes to
It should complete to
Arguments``` { base = "", items = { { data = { entryNames = { "foo" }, file = "/Users/thomas/test.ts", line = 4, offset = 3 }, kind = 5, label = "foo", sortText = "11", textEdit = { newText = "?.foo", range = { ["end"] = { character = 2, line = 3 }, start = { character = 1, line = 3 } } } } } } ```Property Access
Completes to
It should complete to
Arguments``` { base = "", items = { { data = { entryNames = { "f-o" }, file = "/Users/thomas/test.ts", line = 4, offset = 3 }, kind = 5, label = "f-o", sortText = "11", textEdit = { newText = '["f-o"]', range = { ["end"] = { character = 2, line = 3 }, start = { character = 1, line = 3 } } } } } } ```Interestingly, the builtin vim.lsp.omnifunc does not complete anything at all for either of these. I assume it filters these out since it can't actually complete them correctly. If you complete from I don't think these can be worked around aside from removing them as candidates unfortunately. |
Details: - Resolves #306 (comment).
Details: - Resolves #306 (comment).
@thatsmydoing, if you still happen to use 'mini.completion', would you mind please test driving the |
Cool! I gave it a go. The first thing that popped out is that I get these warnings as I type
This is on revision 95d4115 But otherwise, it does seem to work better. The "extra period" case seems to be fixed on In that sense, I guess it's fixed? A bit unfortunate though. I've actually since switched to nvim-cmp since I do use those completions relatively often, but I'd be eager to switch back to mini.completion if you ever get those cases fixed. Though I guess that's more dependent on neovim making omnifunc more powerful. |
Would you mind carving a reproducible example of when you get those errors as you type? All cases from this issue work as expected on |
Oh sorry, I realized I was still setting LSP capabilities based on |
That's very good news! Thanks for the follow up. |
Let me make sure I'm doing what is necessary. I'm using Lazy for package management. I edited my lua/pluging/mini.lua and added branch = "backlog-completion" to the configuration. I also commented out the content of my after/ftplugin/javascript.lua file to remove the hack previously required. I let Lazy install the version from the branch which seemed to go OK. Now, I edit a javascript file and type pageLoaded. and the completions have 2 dots instead of 1. What am I missing? |
Not sure, as I don't entirely know how 'lazy.nvim' operates. Here is the checklist I'd go through:
If both of this is true, then I'd ask for you for a reproducible steps. I.e. which LSP server should I use ( |
In I'll have to look into my Lazy config to see why it isn't checking out the branch. |
My mistake... I told Lazy to Check but not to Update. |
Details: - Resolves #306 (comment).
All examples from this issues should now work on the |
Is it expected that if I do When I do the As opposed to if I do Please let me know if you are not able to reproduce. I have a pretty minimal setup outside of mini modules so shouldn't have anything effecting my setup to cause these issues. |
And if I turn off fuzzy matching and just use the defaults and do NOT set If it helps, here is how I have the lsp_completion = {
process_items = function(items, base)
return MiniFuzzy.process_lsp_items(items, base)
end,
}, |
Ok as an FYI, here is my workaround for now. If I get zero results from fuzzy match for LSP then it just provides the default process items. lsp_completion = {
process_items = function(items, base)
local origItemsCount = #items
local fuzzyResults = MiniFuzzy.process_lsp_items(items, base)
local fuzzyResultsCount = #fuzzyResults
if fuzzyResultsCount == 0 and origItemsCount > 0 then
return MiniCompletion.default_process_items(items, base)
end
return fuzzyResults
end,
}, |
Contributing guidelines
Module(s)
mini.completion
Description
With tsserver LSP, doing a mini completion from a
.
and selecting a completion option injects an extra.
. I don't think the issue is restricted to tsserver though.This is different from typescript-language-server/typescript-language-server#711 since it happens even with the workaround of setting
completionDisableFilterText
.When using the built-in
vim.lsp.omnifunc
, the issue does not occur.I think neovim has some code that adjusts the completion start based on results here https://github.com/neovim/neovim/blob/f1b415b3abbcccb8b0d2aa1a41a45dd52de1a5ff/runtime/lua/vim/lsp.lua#L2145-L2159
Neovim version
0.9
Steps to reproduce
Minimal config
nvim -u minimal.lua
window.
and force completion with<C-space>
Expected behavior
I would expect the result would be
Actual behavior
This results in
The text was updated successfully, but these errors were encountered: