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

fix(cmdline): make completion work for <sid> and s: viml function #925

Merged
merged 2 commits into from
Jan 11, 2025

Conversation

rainerborene
Copy link
Contributor

@rainerborene rainerborene commented Jan 7, 2025

This branch fixes completion issues with commands like :Rename in plugins such as vim-eunuch. You can test it by running :Rename, and the completion should work without errors.

The issue was caused by s: and <sid> functions being scoped to their script, which led to errors like:

Error while fetching completions: Vim:E120: Using not in a script context: s:RenameComplete

This fix ensures proper handling of these functions, resolving the issue.

@rainerborene rainerborene force-pushed the fix_cmdline_completion branch from 277835a to aacb98a Compare January 7, 2025 00:49
@rainerborene
Copy link
Contributor Author

ping @Saghen

@Saghen
Copy link
Owner

Saghen commented Jan 9, 2025

Does this work with <sid> scripts used with input? The motivation for this getcmdcompltype() code was the following: #696 (comment). My knowledge of vimscript is very limited but does this case still work with an <sid> script? I'm likely missing a more elegant solution here (i.e. is there a vim.fn.getcompletion(_, mode) that gives completions in inputs?)

@rainerborene
Copy link
Contributor Author

rainerborene commented Jan 9, 2025 via email

@Saghen
Copy link
Owner

Saghen commented Jan 9, 2025

Try the linked code snippet with vim.fn.getcompletion(query, 'cmdline') and it shouldn't return the correct completions, hence the workaround with getcmdcompltype

@rainerborene
Copy link
Contributor Author

rainerborene commented Jan 9, 2025

I'm sorry for the dumb question. Why input has anything to do with cmdline? I did the following test and it works:

function! s:LocalAutocomplete(A,L,P) abort
  return ['one', 'two', 'three']
endfunction

function! s:StillComplete(A,L,P) abort
  return ['one', 'two', 'three']
endfunction

command! -nargs=1 -complete=customlist,s:LocalAutocomplete LocalComplete echo 'oi'
command! -nargs=1 -complete=customlist,<sid>StillComplete StillComplete echo 'oi'

lua =vim.fn.getcompletion("StillComplete ", "cmdline")
" => { "one", "two", "three" }

Edit: Oh, I think I got your point. My changes does not break the input completion at all because as I said you cannot call s: and <sid> functions in the first place.

@rainerborene
Copy link
Contributor Author

Hmm. Maybe it works because I had to insert an extra space to complete it?

This works:

lua =vim.fn.getcompletion("StillComplete ", "cmdline")

But this won't work:

lua =vim.fn.getcompletion("StillComplete", "cmdline")

@Saghen Saghen merged commit fd8859e into Saghen:main Jan 11, 2025
3 checks passed
@Saghen
Copy link
Owner

Saghen commented Jan 11, 2025

Thank you!

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

Successfully merging this pull request may close these issues.

2 participants