johmsalas / text-case.nvim

An all in one plugin for converting text case in Neovim
447 stars 18 forks source link

Mappings doesn't registered to whichkey correctly #144

Closed sahinakkaya closed 10 months ago

sahinakkaya commented 10 months ago

My config:

  {
    "folke/which-key.nvim",
    keys = keys.which_key,
    init = function()
      vim.o.timeout = true
      vim.o.timeoutlen = 500
    end,
    config = function()
      require("configs.ui.whichkey")
    end,
  },
  {
    "johmsalas/text-case.nvim",
    dependencies = { "nvim-telescope/telescope.nvim" },
    -- Author's Note: If default keymappings fail to register (possible config issue in my local setup),
    -- verify lazy loading functionality. On failure, disable lazy load and report issue
    lazy = false,
    config = function()
      require("textcase").setup({})
      require("telescope").load_extension("textcase")
    end,
    keys = {
      { "ga.", "<cmd>TextCaseOpenTelescope<CR>", mode = { "n", "v" }, desc = "Telescope" },
    },
  }

At first I was lazy loading this plugin but after seeing that I can't see keybindings in whichkey, I disabled lazy loading with lazy=false. However, I still can't see the mappings in whichkey.

In normal mode after pressing g: 20240102_11h27m50s_grim

In normal mode after pressing ga: 20240102_11h28m16s_grim

The keybindings are working perfectly fine though. gac, gas etc. It would be nice to also see them in whichkey with their descriptions because I will definitely forget some of the mappings in the future.

johmsalas commented 10 months ago

What happens if you search using telescope ga.? Do the keybindings get register in which-key at that moment?

Thanks for reporting it, ~now that I know it is not only happening in my local setup will prioritize it~

sahinakkaya commented 10 months ago

No, the mappings are still not registered to whichkey after ga.

sahinakkaya commented 10 months ago

I examined the code a little bit. These lines caught my attention: https://github.com/johmsalas/text-case.nvim/blob/d6f121ec471118afb4fc7ed8cafb08eef3e9b307/lua/textcase/plugin/presets.lua#L25-L40

Shouldn't there be more mappings? With the current code, I think it is normal that nothing is visible in whichkey. Only o is mapped and it is shown in the screenshot above as expected.

sahinakkaya commented 10 months ago

I don't know internals of neither whichkey nor this plugin though. You might have wrote it that way on purpose.

johmsalas commented 10 months ago

There is a loop that iterates all the default_keymapping_definitions and registers the enabled keybindings

sahinakkaya commented 10 months ago

Ok, as far as I can see, it registers them using vim.keymap.set. I don't know if this is enough for whichkey to pick it up. There are other plugins I am using which is supposed to show up in whichkey but doesn't. ~Maybe there is some whichkey setting that needs to be enabled for picking up vim.keymap.set mappings.~

Yes, there is. See https://github.com/johmsalas/text-case.nvim/issues/144#issuecomment-1874405579 below.

johmsalas commented 10 months ago

Which-key is capable of reading nvim registered keymaps. Usually, there is no need to make any extra effort.

Specifically, text-case registers the keymaps directly in which-key, because those are directory-ish records, they don't execute an action but serve as a place to "classify" other keymaps

Is this bug happening only in text-case? would you create an issue in which-key?

sahinakkaya commented 10 months ago

I have changed whichkey setup with default setup:

 require("which-key").setup {}

And now after pressing ga*: 20240102_21h15m02s_grim

Most of the other issues are fixed too. Like marks or registers not showing up. Looks like my old whichkey config was a bit too old. I need to rewrite it from scratch.

*: Actually, at first it only showed ga. mapping after pressing ga. But once I activated telescope, all the other mappings are registered. This was required only once. When I close and reopen neovim, the mappings were available after pressing ga which was a bit surprising to me. But hey, it works now :partying_face:

You can close this issue or keep it open to make it remind you about the thing I mentioned in * if that is a problem for you.

Last but not least, thank you very much for the help!

sahinakkaya commented 10 months ago

Also I am sorry if this issue was a waste of time for you. Looks like I have broken whichkey config for maybe months but I didn't bother fixing it because I didn't feel like I am missing something. But this plugin was so good that I didn't want to forget its keybindings. Thanks again :)

johmsalas commented 10 months ago

I can agree this plugin highly depends on Which-Key given the amount of bindings xD. We are now working on a milestones to provide "Ergonomics" (not sure that's the name yet, but will be v2), the idea is to make the plugin more accessible

Thanks for sharing your mental process publicly, I keep learning Neovim and this was an enriching issue

sahinakkaya commented 10 months ago

And I found the setting in whichkey which is causing this problem:

  ignore_missing = true,  -- enable this to hide mappings for which you didn't specify a label

My old config was perfectly fine. I just had to change this line from true to false.

johmsalas commented 10 months ago

@sahinakkaya by the way. Does it work when lazy=true?

sahinakkaya commented 10 months ago

@johmsalas yes, it works.