mirror of
https://github.com/neovim/neovim.git
synced 2025-12-09 08:02:38 +00:00
vim-patch:9.1.1933: completion: complete_match() is not useful (#36726)
Problem: completion: complete_match() Vim script function and
'isexpand' option are not that useful and confusing
(after v9.1.1341)
Solution: Remove function and option and clean up code and documentation
(Girish Palya).
complete_match() and 'isexpand' add no real functionality to Vim. They
duplicate what `strridx()` already does, yet pretend to be part of the
completion system. They have nothing to do with the completion mechanism.
* `f_complete_match()` in `insexpand.c` does not call any completion code.
It’s just a `STRNCMP()` wrapper with fluff logic.
* `'isexpand'` exists only as a proxy argument to that function.
It does nothing on its own and amounts to misuse of a new option.
The following Vim script function can be used to implement the same
functionality:
```vim
func CompleteMatch(triggers, sep=',')
let line = getline('.')->strpart(0, col('.') - 1)
let result = []
for trig in split(a:triggers, a:sep)
let idx = strridx(line, trig)
if l:idx >= 0
call add(result, [idx + 1, trig])
endif
endfor
return result
endfunc
```
related: vim/vim#16716
fixes: vim/vim#18563
closes: vim/vim#18790
cbcbff8712
Co-authored-by: Girish Palya <girishji@gmail.com>
This commit is contained in:
@@ -93,7 +93,7 @@ Vim would never have become what it is now, without the help of these people!
|
||||
improvements
|
||||
Doug Kearns Runtime file maintainer
|
||||
Foxe Chen Wayland support, new features
|
||||
glepnir completion feature
|
||||
glepnir work on improving completion feature, fixes
|
||||
Girish Palya autocompletion (ins/cmdline), omnifunc
|
||||
composing, search/subst completion, and more.
|
||||
Hirohito Higashi lots of patches and fixes
|
||||
|
||||
@@ -33,7 +33,7 @@ LSP
|
||||
|
||||
OPTIONS
|
||||
|
||||
• `'completefuzzycollect'` has been removed.
|
||||
• `'completefuzzycollect'` and `'isexpand'` have been removed.
|
||||
|
||||
TREESITTER
|
||||
|
||||
@@ -43,6 +43,9 @@ UI
|
||||
|
||||
• `progress` attribute removed form |ui-messages| msg_show event
|
||||
|
||||
VIMSCRIPT
|
||||
|
||||
• `complete_match()` has been removed.
|
||||
|
||||
==============================================================================
|
||||
BREAKING CHANGES *news-breaking*
|
||||
|
||||
@@ -3739,23 +3739,6 @@ A jump table for the options with a short description can be found at |Q_op|.
|
||||
and there is a letter before it, the completed part is made uppercase.
|
||||
With 'noinfercase' the match is used as-is.
|
||||
|
||||
*'isexpand'* *'ise'*
|
||||
'isexpand' 'ise' string (default "")
|
||||
global or local to buffer |global-local|
|
||||
Defines characters and patterns for completion in insert mode. Used
|
||||
by the |complete_match()| function to determine the starting position
|
||||
for completion. This is a comma-separated list of triggers. Each
|
||||
trigger can be:
|
||||
- A single character like "." or "/"
|
||||
- A sequence of characters like "->", "/*", or "/**"
|
||||
|
||||
Note: Use "\\," to add a literal comma as trigger character, see
|
||||
|option-backslash|.
|
||||
|
||||
Examples: >vim
|
||||
set isexpand=.,->,/*,\\,
|
||||
<
|
||||
|
||||
*'isfname'* *'isf'*
|
||||
'isfname' 'isf' string (default for Windows:
|
||||
"@,48-57,/,\,.,-,_,+,,,#,$,%,{,},[,],@-@,!,~,="
|
||||
|
||||
@@ -943,8 +943,6 @@ Insert mode completion: *completion-functions*
|
||||
complete_add() add to found matches
|
||||
complete_check() check if completion should be aborted
|
||||
complete_info() get current completion information
|
||||
complete_match() get insert completion start match col and
|
||||
trigger text
|
||||
preinserted() check if text is inserted after cursor
|
||||
pumvisible() check if the popup menu is displayed
|
||||
pum_getpos() position and size of popup menu if visible
|
||||
|
||||
@@ -1281,56 +1281,6 @@ complete_info([{what}]) *complete_info()*
|
||||
Return: ~
|
||||
(`table`)
|
||||
|
||||
complete_match([{lnum}, {col}]) *complete_match()*
|
||||
Searches backward from the given position and returns a List
|
||||
of matches according to the 'isexpand' option. When no
|
||||
arguments are provided, uses the current cursor position.
|
||||
|
||||
Each match is represented as a List containing
|
||||
[startcol, trigger_text] where:
|
||||
- startcol: column position where completion should start,
|
||||
or -1 if no trigger position is found. For multi-character
|
||||
triggers, returns the column of the first character.
|
||||
- trigger_text: the matching trigger string from 'isexpand',
|
||||
or empty string if no match was found or when using the
|
||||
default 'iskeyword' pattern.
|
||||
|
||||
When 'isexpand' is empty, uses the 'iskeyword' pattern "\k\+$"
|
||||
to find the start of the current keyword.
|
||||
|
||||
Examples: >vim
|
||||
set isexpand=.,->,/,/*,abc
|
||||
func CustomComplete()
|
||||
let res = complete_match()
|
||||
if res->len() == 0 | return | endif
|
||||
let [col, trigger] = res[0]
|
||||
let items = []
|
||||
if trigger == '/*'
|
||||
let items = ['/** */']
|
||||
elseif trigger == '/'
|
||||
let items = ['/*! */', '// TODO:', '// fixme:']
|
||||
elseif trigger == '.'
|
||||
let items = ['length()']
|
||||
elseif trigger =~ '^\->'
|
||||
let items = ['map()', 'reduce()']
|
||||
elseif trigger =~ '^\abc'
|
||||
let items = ['def', 'ghk']
|
||||
endif
|
||||
if items->len() > 0
|
||||
let startcol = trigger =~ '^/' ? col : col + len(trigger)
|
||||
call complete(startcol, items)
|
||||
endif
|
||||
endfunc
|
||||
inoremap <Tab> <Cmd>call CustomComplete()<CR>
|
||||
<
|
||||
|
||||
Parameters: ~
|
||||
• {lnum} (`integer?`)
|
||||
• {col} (`integer?`)
|
||||
|
||||
Return: ~
|
||||
(`table`)
|
||||
|
||||
confirm({msg} [, {choices} [, {default} [, {type}]]]) *confirm()*
|
||||
confirm() offers the user a dialog, from which a choice can be
|
||||
made. It returns the number of the choice. For the first
|
||||
|
||||
25
runtime/lua/vim/_meta/options.lua
generated
25
runtime/lua/vim/_meta/options.lua
generated
@@ -3656,31 +3656,6 @@ vim.o.inf = vim.o.infercase
|
||||
vim.bo.infercase = vim.o.infercase
|
||||
vim.bo.inf = vim.bo.infercase
|
||||
|
||||
--- Defines characters and patterns for completion in insert mode. Used
|
||||
--- by the `complete_match()` function to determine the starting position
|
||||
--- for completion. This is a comma-separated list of triggers. Each
|
||||
--- trigger can be:
|
||||
--- - A single character like "." or "/"
|
||||
--- - A sequence of characters like "->", "/*", or "/**"
|
||||
---
|
||||
--- Note: Use "\\," to add a literal comma as trigger character, see
|
||||
--- `option-backslash`.
|
||||
---
|
||||
--- Examples:
|
||||
---
|
||||
--- ```vim
|
||||
--- set isexpand=.,->,/*,\\,
|
||||
--- ```
|
||||
---
|
||||
---
|
||||
--- @type string
|
||||
vim.o.isexpand = ""
|
||||
vim.o.ise = vim.o.isexpand
|
||||
vim.bo.isexpand = vim.o.isexpand
|
||||
vim.bo.ise = vim.bo.isexpand
|
||||
vim.go.isexpand = vim.o.isexpand
|
||||
vim.go.ise = vim.go.isexpand
|
||||
|
||||
--- The characters specified by this option are included in file names and
|
||||
--- path names. Filenames are used for commands like "gf", "[i" and in
|
||||
--- the tags file. It is also used for "\f" in a `pattern`.
|
||||
|
||||
47
runtime/lua/vim/_meta/vimfn.lua
generated
47
runtime/lua/vim/_meta/vimfn.lua
generated
@@ -1127,53 +1127,6 @@ function vim.fn.complete_check() end
|
||||
--- @return table
|
||||
function vim.fn.complete_info(what) end
|
||||
|
||||
--- Searches backward from the given position and returns a List
|
||||
--- of matches according to the 'isexpand' option. When no
|
||||
--- arguments are provided, uses the current cursor position.
|
||||
---
|
||||
--- Each match is represented as a List containing
|
||||
--- [startcol, trigger_text] where:
|
||||
--- - startcol: column position where completion should start,
|
||||
--- or -1 if no trigger position is found. For multi-character
|
||||
--- triggers, returns the column of the first character.
|
||||
--- - trigger_text: the matching trigger string from 'isexpand',
|
||||
--- or empty string if no match was found or when using the
|
||||
--- default 'iskeyword' pattern.
|
||||
---
|
||||
--- When 'isexpand' is empty, uses the 'iskeyword' pattern "\k\+$"
|
||||
--- to find the start of the current keyword.
|
||||
---
|
||||
--- Examples: >vim
|
||||
--- set isexpand=.,->,/,/*,abc
|
||||
--- func CustomComplete()
|
||||
--- let res = complete_match()
|
||||
--- if res->len() == 0 | return | endif
|
||||
--- let [col, trigger] = res[0]
|
||||
--- let items = []
|
||||
--- if trigger == '/*'
|
||||
--- let items = ['/** */']
|
||||
--- elseif trigger == '/'
|
||||
--- let items = ['/*! */', '// TODO:', '// fixme:']
|
||||
--- elseif trigger == '.'
|
||||
--- let items = ['length()']
|
||||
--- elseif trigger =~ '^\->'
|
||||
--- let items = ['map()', 'reduce()']
|
||||
--- elseif trigger =~ '^\abc'
|
||||
--- let items = ['def', 'ghk']
|
||||
--- endif
|
||||
--- if items->len() > 0
|
||||
--- let startcol = trigger =~ '^/' ? col : col + len(trigger)
|
||||
--- call complete(startcol, items)
|
||||
--- endif
|
||||
--- endfunc
|
||||
--- inoremap <Tab> <Cmd>call CustomComplete()<CR>
|
||||
--- <
|
||||
---
|
||||
--- @param lnum? integer
|
||||
--- @param col? integer
|
||||
--- @return table
|
||||
function vim.fn.complete_match(lnum, col) end
|
||||
|
||||
--- confirm() offers the user a dialog, from which a choice can be
|
||||
--- made. It returns the number of the choice. For the first
|
||||
--- choice this is 1.
|
||||
|
||||
@@ -406,7 +406,6 @@ local options_list = {
|
||||
header = N_ 'language specific',
|
||||
{ 'isfname', N_ 'specifies the characters in a file name' },
|
||||
{ 'isident', N_ 'specifies the characters in an identifier' },
|
||||
{ 'isexpand', N_ 'defines trigger strings for complete_match()' },
|
||||
{ 'iskeyword', N_ 'specifies the characters in a keyword' },
|
||||
{ 'isprint', N_ 'specifies printable characters' },
|
||||
{ 'quoteescape', N_ 'specifies escape characters in a string' },
|
||||
|
||||
Reference in New Issue
Block a user