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

fix: support all whichkey methods #82

Merged
merged 6 commits into from
Jan 12, 2024
Merged

fix: support all whichkey methods #82

merged 6 commits into from
Jan 12, 2024

Conversation

tris203
Copy link
Owner

@tris203 tris203 commented Jan 11, 2024

closes #81

needs further work on method1

I don't really understand the structure though as the section just gets dropped seemingly

@willothy any ideas?

@tris203
Copy link
Owner Author

tris203 commented Jan 11, 2024

Minimal repro here

local wk = require("which-key.mappings")

local str = [[
 return {
     w = {
         name = "file", -- optional group name
         o = { ":lua print('hello')<CR>", "Find File" }, -- create a binding with label
         n = {
             function()
                 print("bar")
             end,
             "Foobar",
         }, -- you can also pass functions!
     },
 }, { prefix = "<leader>" }
]]

-- local str = [[
--  return ({
--      ["<leader>wf"] = { ':lua print("hello")<CR>', "hello" },
--  })
-- ]]

local obj = loadstring(str)()

print(vim.inspect(obj))

local wkd = wk.parse(obj)

print(vim.inspect(wkd))

@tris203
Copy link
Owner Author

tris203 commented Jan 11, 2024

Okay, i think the issue is fixed, but I don't know why the test for the which-key message is now failing....

*edit, that took me an embarrassingly long time to fix...

To explain more there was a few issues at play.
First wrapping the return in params caused it not to return the subobjects properly, then additionally the object needs to be wrapped in a table and unpacked, as otherwise return in the loadstring just returns the first table, not both

@tris203 tris203 requested a review from willothy January 11, 2024 23:47
Copy link
Owner Author

@tris203 tris203 left a comment

Choose a reason for hiding this comment

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

clearer comment

lua/hawtkeys/ts.lua Outdated Show resolved Hide resolved
Copy link
Collaborator

@willothy willothy left a comment

Choose a reason for hiding this comment

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

lgtm - loadstring can definitely be tricky, it would be good if we could figure out an alternative at some point though I'm not sure what that would be.

@tris203 tris203 merged commit e602132 into main Jan 12, 2024
5 checks passed
@tris203 tris203 deleted the issue81 branch January 12, 2024 19:53
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.

Cannot parse which-key mappings
2 participants