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

Provide description for additional mappings #2981

Open
helins opened this issue Mar 12, 2024 · 2 comments
Open

Provide description for additional mappings #2981

helins opened this issue Mar 12, 2024 · 2 comments
Labels
enhancement Enhancement to performance, inner workings or existent features

Comments

@helins
Copy link

helins commented Mar 12, 2024

Is your feature request related to a problem? Please describe.
When adding mappings in the configuration of a picker, there does not seem to be a way for providing a description that would be rendered by which_key.

Describe the solution you'd like
Ideally, a description could be provided under desc in the opts of the mapping, to mimick the standard way.

Additional context
Without a description, which_key shows as a description some gibberish like _13_.

@helins helins added the enhancement Enhancement to performance, inner workings or existent features label Mar 12, 2024
@Conni2461
Copy link
Member

we kinda already support this but i think not consistently, or there is some bug. e.g. it doesnt work for key_func.type == "command" but it just works if you pass in a function: ["<c-c>"] = { function() vim.cmd [[ stopinsert ]] end, opts = { desc = "stopinsert" } },. at least on latest master, it does not work on 0.1.5 yet because it would be a new feature, so semver says we are not allowed to backport new features 😆

can you provide the additional mappings that you've added? because i think there should never be a _13_.

@ColinKennedy
Copy link

ColinKennedy commented Mar 27, 2024

Came here to comment the same issue. Here's a not-so-minimal example

  pickers.new(
    opts,
    {
      prompt_title = "Session Viewer",
      finder = finders.new_table(
        {
          results = vim.tbl_flatten(sessions),
          entry_maker = function(entry)
            -- ... More stuff here ...
            return result
          end,
        }
      ),
      sorter = telescope_config.file_sorter(opts),
      attach_mappings = function(prompt_buffer, map)
        map(
          "n",
          "n",
          function() _USE_NICE_NAMES = not _USE_NICE_NAMES end,
          -- NOTE: `desc` is currently unsupported by telescope.nvim
          -- Reference: https://github.com/nvim-telescope/telescope.nvim/issues/2981
          --
          {desc = "Toggle [n]ice names or full path displays."}
        )

        map(
          "i",
          "<CR>",
          function()
            actions.close(prompt_buffer)

            local selection = state.get_selected_entry()

            -- Schedule buffers cleanup to avoid callback issues and source the session
            vim.schedule(
              function()
                local path = selection.value

                configuration.DATA.run_pre_switch_hook(path)

                vim.cmd.wall()
                vim.cmd[[%bwipeout]]
                vim.cmd.source(path)

                configuration.DATA.run_post_switch_hook(path)
              end
            )
          end,
          -- NOTE: `desc` is currently unsupported by telescope.nvim
          -- Reference: https://github.com/nvim-telescope/telescope.nvim/issues/2981
          --
          {desc = "Select a session to load."}
        )

        return true
      end,
    }):find()

When you press ? in the Telescope floating window, it renders ()_USE_NICE_NAMESnot_USE_NICE… rather than the intended desc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to performance, inner workings or existent features
Projects
None yet
Development

No branches or pull requests

3 participants