legendary.nvim icon indicating copy to clipboard operation
legendary.nvim copied to clipboard

Implement an API to auto-load commands, autocmds, and keymaps from the nvim API

Open mrjones2014 opened this issue 3 years ago • 10 comments

Say you already have keymaps being set up another way, you just want them to be searchable with legendary.nvim.

We could load the commands, autocmds, and keymaps through the nvim APIs, as long as they have the desc key set.

Although I'm not sure how to do this effectively because right now, the API functions use the same table field definition for the description, or if no description is set, it's just the implementation, which we wouldn't wanna show as a description.

mrjones2014 avatar Mar 04 '22 16:03 mrjones2014

Tried getting this unblocked by opening https://github.com/neovim/neovim/issues/17639 but the response was basically just rude, toxic comments over and over basically saying "the description field isn't a description"...

mrjones2014 avatar Mar 07 '22 13:03 mrjones2014

We may be able to do this for keymaps, but not commands. Keymaps have a separate desc field.

mrjones2014 avatar Mar 13 '22 15:03 mrjones2014

I was about to open an issue to request this. Is this the same that telescope shows whith the built in commands selector?

danielo515 avatar Apr 13 '22 16:04 danielo515

Yeah unfortunately there's not a great way to get descriptions and when I asked about it in the Neovim repo I was basically told "the description field isn't a description" 🤔

mrjones2014 avatar Apr 13 '22 16:04 mrjones2014

Yeah unfortunately there's not a great way to get descriptions and when I asked about it in the Neovim repo I was basically told "the description field isn't a description" 🤔

what a ridiculous harsh answer. This is definetively a must have to compete with other mote friendly IDES. Do you plan to add it anyway? even without description?

danielo515 avatar Apr 13 '22 17:04 danielo515

I'm not sure. It's something I've been thinking about a lot, but it doesn't really make sense to add items where the "description" is some long string of Lua code. The description field will be the description if one was set when defining it via the Neovim APIs, but if no description was set in the opts table, the desc field of the items returned from the API is just the Lua code or vim script string implementation of the keymap/command.

In those cases, it doesn't really make sense for Legendary to show that huge description string (it'll totally throw off formatting, not be useful, and look bad), and since the description field behaves like described above, there isn't really a way for legendary to tell whether items have an actual description, or if the description field is just the stringified implementation (Lua code or vim script string).

Here's the Neovim issue I opened about the topic if you want to take a look: https://github.com/neovim/neovim/issues/17639

Perhaps it might be worth opening a new issue and hoping someone else responds.

mrjones2014 avatar Apr 13 '22 18:04 mrjones2014

what about truncate the output to certain length and let the ugly stuff appear? Maybe behind a config flag. I can provide screenshot later, but this doesn't seem to be uncommon in the vim world, telescope and wich-key already do this.

danielo515 avatar Apr 15 '22 01:04 danielo515

Maybe. Not sure. What happens when you have a custom description registered through legendary that exceeds that length, do we really want to cut that off? I'm not sure a simple max truncation length is the solution.

mrjones2014 avatar Apr 15 '22 10:04 mrjones2014

What about implementing some basic heuristics to decide if the description is code or not? If it looks like a function call, it's preceded with Lua then a require etc then just don't display it? Just ideas

danielo515 avatar Apr 16 '22 16:04 danielo515

Heuristics to decide if the description is code or not would be far from basic.

mrjones2014 avatar Apr 17 '22 12:04 mrjones2014

Hi, I think it is also feasible to set a length limit to the description. And if the limit is exceeded, then the description field can be blank or "No description" or display the command itself. I think something like "[cmd itsef] (No description)" is reasonable enough.

The core problem here is that it is not possible to have automatically generated description for all commands. Therefore it might be wise to provide the command and let user to fill in the description themselves if it is necessary for them.

LumenYoung avatar Dec 11 '22 15:12 LumenYoung

So, looking again, it appears that keymaps now have a separate rhs vs. desc field, where the desc is actually a description. So it looks like it is now possible to do this for keymaps.

However the problem still exists for commands, where the definition field may be either an implementation or a description. I propose that this issue is split into two separate issues:

  • Implement loading keymaps from Neovim API - which could be implemented with a PR
  • Implement loading commands from Neovim API - which would remain blocked

mrjones2014 avatar Dec 13 '22 13:12 mrjones2014

Closing this issue in favor of #258 (which could have a PR for it, if anyone wants to take a stab at it) and #259 (which remains blocked).

mrjones2014 avatar Dec 13 '22 13:12 mrjones2014