Skip to content

feat: add kind param to vim.ui.select function calls #2602

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

Merged
merged 6 commits into from
Dec 31, 2023

Conversation

devansh08
Copy link
Collaborator

This PR adds the optional kind parameter to the vim.ui.select function calls.

Having this parameter set to something will help in differentiating the ui.select prompts of nvim-tree from other sources (like LSP code actions or other plugins). This can help in more finer configurations at the user's end. As an example, with this setup I can configure nvim-tree's select prompts to use the relative to cursor telescope theme, while all other prompts can follow the vertical dropdown telescope theme as default.

This does not create any changes in the UI. It only uses an optional parameter that is already present in the vim.ui API for this sort of finer configuration.

I'm open to changing/discussing the values I've used here. Something more generic (like nvimtree_action) or maybe more specific would be fine as well. For my usage, just having some value that tells me its from nvim-tree works.

For reference, the docs of vim.ui.select that reference kind:

:help vim.ui.select
...
      • {opts}       (table) Additional options
                     • prompt (string|nil) Text of the prompt. Defaults to
                       `Select one of:`
                     • format_item (function item -> text) Function to format
                       an individual item from `items`. Defaults to
                       `tostring`.
                     • kind (string|nil) Arbitrary hint string indicating the
                       item shape. Plugins reimplementing `vim.ui.select` may
                       wish to use this to infer the structure or semantics of
                       `items`, or the context in which select() was called.
...

Do let me know your thoughts on this. Thanks!

@alex-courtis
Copy link
Member

This is fantastic, many thanks for identifying this functionality.

Let's apply it to all places:

╭──────────────────────────────────────────────────────────────────────────────────── LSP References ────────────────────────────────────────────────────────────────────────────────────╮╭─────
│>                                                                                                                                                                                  5 / 5││  if 
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯│    n
╭──────────────────────────────────────────────────────────── /home/alex/src/nvim-tree/fix/hijack_cursor-with-update-focused ────────────────────────────────────────────────────────────╮│    r
│> lua/nvim-tree/actions/fs/copy…▏      lib.prompt(prompt_input, prompt_select, { "", "y", "n" }, { "Rename", "Yes", "No" }, function(item_short)                                        ││  end
│  lua/nvim-tree/actions/fs/remo…▏    lib.prompt(prompt_input, prompt_select, items_short, items_long, function(item_short)                                                              ││     
│  lua/nvim-tree/actions/fs/tras…▏    lib.prompt(prompt_input, prompt_select, items_short, items_long, function(item_short)                                                              ││  loc
│  lua/nvim-tree/marks/bulk-dele…▏    lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, function(item_short)                                                         ││    s
│  lua/nvim-tree/marks/bulk-tras…▏    lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, function(item_short)                                                         ││    i
│                                                                                                                                                                                        ││     

@alex-courtis
Copy link
Member

We need to document this. Please insert a new help section 10 nvim-tree-prompts

Don't be overly concerned about the text - I'll help out once you've got a draft in place.

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for your contribution:

  • all prompts
  • doc

@devansh08
Copy link
Collaborator Author

Done with the requested code changes.

I've also created the help section for prompts. Do let me know if you think it needs any changes (content or formatting). This is my first time writing vim documentation, so I may have missed out on some syntax (Apologies in advance, if so :) ).

@alex-courtis
Copy link
Member

Done with the requested code changes.

I've also created the help section for prompts. Do let me know if you think it needs any changes (content or formatting). This is my first time writing vim documentation, so I may have missed out on some syntax (Apologies in advance, if so :) ).

That's great, tidied a bit and added underscores.

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for your contribution!

@alex-courtis alex-courtis merged commit dc839a7 into nvim-tree:master Dec 31, 2023
@devansh08 devansh08 deleted the ui-select-kind branch December 31, 2023 15:41
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