Skip to content

Commit 2d873a0

Browse files
committed
fix(completion)!: update default_process_items to use proper fields
Details: - Use filterText>label instead of textEdit.newText>insertText>label. This is more aligned with LSP specification.
1 parent 8c79890 commit 2d873a0

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
- Show `detail` highlighted as buffer's language at the start of info window, but only if `detail` provides information not already present in `documentation`. It was previously used as extra text in the popup menu (via `menu` field), but this doesn't quite follow LSP specification: `detail` and `documentation` fields can be delayed up until `completionItem/resolve` request which implies they should be treated similarly.
4444
- Show `labelDetails` as a part of the popup menu via `menu` completion item field.
4545
- BREAKING: prefer to not use functions as default config values. In particular, for `lsp_completion.process_items` (use `nil` with explicit fallback) and `fallback_action` (use `'<C-n>'`). This should not have any user facing effects and marked as breaking only because a structure of a default config has changed to be more aligned with other modules.
46+
- BREAKING: update `default_process_items()` to only use `filterText` and `label` item fields during matching (instead of `textEdit.newText`, `insertText`, and `label` as before). This is more aligned with LSP specification.
4647

4748
## mini.doc
4849

lua/mini/completion.lua

+1-5
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,7 @@ end
467467
---
468468
---@return table Array of processed items from LSP response.
469469
MiniCompletion.default_process_items = function(items, base)
470-
local res = vim.tbl_filter(
471-
function(item) return vim.startswith(item.filterText or H.get_completion_word(item), base) end,
472-
items
473-
)
474-
470+
local res = vim.tbl_filter(function(x) return vim.startswith(x.filterText or x.label, base) end, items)
475471
res = vim.deepcopy(res)
476472
table.sort(res, function(a, b) return (a.sortText or a.label) < (b.sortText or b.label) end)
477473

tests/test_completion.lua

+8-5
Original file line numberDiff line numberDiff line change
@@ -767,11 +767,14 @@ end
767767
T['Manual completion']['prefers completion range from LSP response'] = function()
768768
set_lines({})
769769
type_keys('i', 'months.')
770-
-- Mock `textEdit` as in `tsserver` when called after `.`
771-
child.lua([[_G.mock_textEdit = {
772-
pos = vim.api.nvim_win_get_cursor(0),
773-
new_text = function(name) return '.' .. name end,
774-
} ]])
770+
-- Mock `textEdit`+`filterText` as in `tsserver` when called after `.`
771+
child.lua([[
772+
_G.mock_textEdit = {
773+
pos = vim.api.nvim_win_get_cursor(0),
774+
new_text = function(name) return '.' .. name end,
775+
}
776+
_G.mock_filterText = function(name) return '.' .. name end
777+
]])
775778
type_keys('<C-space>')
776779

777780
eq(get_completion('abbr'), { 'April', 'August' })

0 commit comments

Comments
 (0)