Improve editor config

This commit is contained in:
Torjus Håkestad 2024-03-06 19:58:59 +01:00
parent 993c40225e
commit 6a82a8638d
2 changed files with 35 additions and 4 deletions

View File

@ -21,6 +21,11 @@ vim.keymap.set('n', '<leader>ff', require('telescope.builtin').find_files,
vim.keymap.set('n', '<leader>fg', require('telescope.builtin').live_grep,
{ desc = '[F]ind by [G]rep' })
-- Tabs
vim.keymap.set('n', '<leader>tt', ':tabnew<cr>')
vim.keymap.set('n', '<leader>tn', ':tabnext<cr>')
vim.keymap.set('n', '<leader>tp', ':tabprevious<cr>')
-- LSP
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition)

View File

@ -20,7 +20,7 @@ lsp_zero.format_on_save({
['tsserver'] = { 'typescript', 'javascript' },
},
})
-- LSP: go
local lspconfig = require('lspconfig')
lspconfig.gopls.setup({
settings = {
@ -33,7 +33,30 @@ lspconfig.gopls.setup({
}
}
})
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*.go",
callback = function()
local params = vim.lsp.util.make_range_params()
params.context = { only = { "source.organizeImports" } }
-- buf_request_sync defaults to a 1000ms timeout. Depending on your
-- machine and codebase, you may want longer. Add an additional
-- argument after params if you find that you have to write the file
-- twice for changes to be saved.
-- E.g., vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, 3000)
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params)
for cid, res in pairs(result or {}) do
for _, r in pairs(res.result or {}) do
if r.edit then
local enc = (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-16"
vim.lsp.util.apply_workspace_edit(r.edit, enc)
end
end
end
vim.lsp.buf.format({ async = false })
end
})
-- LSP: nix
lspconfig.nil_ls.setup({
autostart = true,
settings = {
@ -45,6 +68,7 @@ lspconfig.nil_ls.setup({
},
})
-- LSP: lua
lspconfig.lua_ls.setup({
on_init = function(client)
local path = client.workspace_folders[1].name
@ -85,6 +109,7 @@ lspconfig.lua_ls.setup({
}
})
-- LSP: ts/js
lspconfig.tsserver.setup({
init_options = {
plugins = {
@ -206,9 +231,10 @@ cmp.setup({
}),
sources = cmp.config.sources({
}, {
{ name = "copilot", group_index = 2 },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "copilot", group_index = 2 },
{ name = "nvim_lsp", group_index = 2 },
-- { name = "luasnip" },
-- { name = "buffer" },
})
})