-
Notifications
You must be signed in to change notification settings - Fork 399
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
Implement nvim_create_user_command #922
Conversation
LGTM. |
plugin/cmp.lua
Outdated
vim.cmd [[command! CmpStatus lua require('cmp').status()]] | ||
vim.api.nvim_create_user_command( | ||
'CmpStatus', | ||
require('cmp').status, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please be aware that it will require cmp at the time that command is created. To avoid that it should be wrapped in lambda/anonymous function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking this as well. By the time this file is loaded doesn't that imply that cmp
is available at the time? Is there a case where this plugin/cmp.lua
file will be loaded but the plugin itself will not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this nvim_create_user_command
with some pretty heavy lazy loading in different cases and couldn't get it in a state where this caused issues when the vim.api.nvim_create_user_command
was called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but plugin/cmp.lua
will be sourced by nvim as a startup script (if added to rtp). So those requires are happening any way https://github.com/mehalter/nvim-cmp/blob/command_api/plugin/cmp.lua#L6-L10.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so just to clarify, should I update it to wrap it in an anonymous function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hrsh7th Have you got an opinion here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my personal taste, I think it's better to wrap it in an anonymous function. (This is because we can eliminate the assumption that the arguments given to the anonymous function implicitly match the status function.)
google translated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great point @hrsh7th I have updated the commit to wrap it in an anonymous function.
Signed-off-by: Micah Halter <micah@balena.io>
LGTM. Thank you! |
Signed-off-by: Micah Halter <micah@balena.io>
* Adjust empty line count * Implement vim.api.nvim_create_autocmd (#844) * Implement vim.api.nvim_create_autocmd * Only use vim.api.nvim_create_autocmd on nighly * Cleanup * cleanup * Rename autos.lua to autocmds.lua * Fix forgot to rename autos to autocmds * Remove legacy autocmd * Add descriptions on autocmds * Update descriptions on autocmds * Update CmpStatus command to lua API (#922) Signed-off-by: Micah Halter <micah@balena.io> * Move highlights to nvim_set_hl lua API (#925) Signed-off-by: Micah Halter <micah@balena.io> * Add default to highlight * Refactor autocmds * fmt * Improve performance * Fix bug * Improve matching logic Fixes #954 * Fix format * Improve performance Fix #825 * Fix cmdline redraw bug * Fix event Co-authored-by: hrsh7th <> Co-authored-by: zer09 <zer09@users.noreply.github.com> Co-authored-by: Micah Halter <micah@mehalter.com>
This moves the creation of the
:CmpStatus
command to the newvim.api.nvim_create_user_command
APIThis requires neovim 0.7 so it should be done along with #844