Skip to content

Commit 0555f73

Browse files
Resolve the whichkey warning
1 parent 21f2ee7 commit 0555f73

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

init.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,29 @@ require('lazy').setup({
396396
end,
397397
})
398398

399+
vim.api.nvim_create_autocmd('BufWritePre', {
400+
pattern = '*.go',
401+
callback = function()
402+
local params = vim.lsp.util.make_range_params()
403+
params.context = { only = { 'source.organizeImports' } }
404+
-- buf_request_sync defaults to a 1000ms timeout. Depending on your
405+
-- machine and codebase, you may want longer. Add an additional
406+
-- argument after params if you find that you have to write the file
407+
-- twice for changes to be saved.
408+
-- E.g., vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, 3000)
409+
local result = vim.lsp.buf_request_sync(0, 'textDocument/codeAction', params)
410+
for cid, res in pairs(result or {}) do
411+
for _, r in pairs(res.result or {}) do
412+
if r.edit then
413+
local enc = (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or 'utf-16'
414+
vim.lsp.util.apply_workspace_edit(r.edit, enc)
415+
end
416+
end
417+
end
418+
vim.lsp.buf.format { async = false }
419+
end,
420+
})
421+
399422
-- LSP servers and clients are able to communicate to each other what features they support.
400423
-- By default, Neovim doesn't support everything that is in the LSP specification.
401424
-- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities.

lua/custom/plugins/which-key.lua

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,6 @@ return {
2121
require('which-key').setup()
2222

2323
-- Document existing key chains
24-
require('which-key').register {
25-
{ '', group = 'Git [H]unk' },
26-
{ '', group = '[W]orkspace' },
27-
{ '', group = '[S]earch' },
28-
{ '', group = '[C]ode' },
29-
{ '', group = '[R]ename' },
30-
{ '', group = '[T]oggle' },
31-
{ '', group = '[D]ocument' },
32-
{ '', desc = '', hidden = true, mode = { 'n', 'n', 'n', 'n', 'n', 'n', 'n' } },
33-
}
34-
-- visual mode
35-
require('which-key').register({
36-
{ '', desc = '<leader>h', mode = 'v' },
37-
}, { mode = 'v' })
3824
end,
3925
},
4026
}

0 commit comments

Comments
 (0)