-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add commands from nvim_get_commands #425
base: master
Are you sure you want to change the base?
Conversation
This adds commands from nvim_get_commands and attempts to filter out non-human-friendly descriptions. Contributes mrjones2014#259
a4f9b8a
to
0327d07
Compare
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.
Hey, thanks for the PR! Please make sure to read CONTRIBUTING.md.
A couple of additional thoughts; with this approach, we'll likely get duplicated items, e.g. if you're using any extensions to load commands from other plugins, this approach would load them again. It will also load all the commands that are already specified in the static builtins tables.
Also what happens if new commands are registered later after startup? This approach won't load those.
If you're fine with those tradeoffs, then this functionality would be perfectly suited to be implemented as an extension (in a separate repository), but I don't think this approach is well suited to be built into the core plugin.
However, I do think there's room to improve the approach here (maybe we can monkey-patch nvim_create_user_command
or something?). I'll leave the PR open and see if anyone else from the community has comments.
return string.len(description) > 0 | ||
and not string.find(description, "^exe ") | ||
and not string.find(description, "^:exe ") | ||
and not string.find(description, "^call ") | ||
and not string.find(description, "^:call ") | ||
and not string.find(description, "^echoerr ") | ||
and not string.find(description, "^lua require") |
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.
Pattern matching this many times may have performance issues. We can use this tool to test Lua patterns, we should use a single pattern match that would match any of these.
@@ -1,5 +1,37 @@ | |||
local M = {} | |||
-- commented out ones need a way to get input after selecting | |||
|
|||
-- get global user-commands |
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.
Additionally, these aren't necessarily built in unless you pass { builtin = false }
, so I don't think builtins.lua
is the right place for this.
State.items:add(vim.tbl_map(function(keymap) | ||
return Command:parse(keymap, true) | ||
end, Builtins.get_commands())) |
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.
Doing this here also means we only get commands during startup, not commands that might be registered later, e.g. by lazy-loaded plugins.
-- description cannot be the empty string or the command doesn't show | ||
description = " " |
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 by design; we shouldn't be using a blank space to circumvent our own rules.
This adds commands from nvim_get_commands and attempts to filter out non-human-friendly descriptions.
Contributes #259
How to Test
Please leave detailed testing instructions
Enable built in commands
Run
:Legendary
Look for added commands and check to make sure that non-human-friendly descriptions are not present.
Testing for Regressions
I have tested the following:
legendary.nvim
in all modes (normal, insert, visual)legendary.nvim
, then triggering via the keymap in all modes (normal, insert, visual)legendary.nvim
in all modes (normal, insert, visual)legendary.nvim
, then running the command manually from the command lineaugroup
/autocmd
s created throughlegendary.nvim
work correctly