commit 8fba898f01359e0bc32b125885ab5d7348725078
parent af8757bb448acd4929954ab34e3bad1d71780ca9
Author: Thomas Vigouroux <thomas.vigouroux@protonmail.com>
Date: Sat, 13 May 2023 08:57:41 +0200
lsp: simplify config
Diffstat:
3 files changed, 14 insertions(+), 17 deletions(-)
diff --git a/lua/lsp_config.lua b/lua/lsp_config.lua
@@ -8,16 +8,14 @@ vim.diagnostic.config {
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'single' })
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'single' })
-local function on_attach(attach_opts, client, bufnr)
- local function set_keymap(lhs, func, ...)
- local args = { ... }
+local function on_attach(client, bufnr)
+ local function set_keymap(lhs, func)
+ -- vim.api.nvim_echo({ {"Setup "}, {lhs} }, true, {})
vim.keymap.set("n", lhs, "", {
remap = false,
silent = true,
buffer = bufnr,
- callback = function()
- func(unpack(args))
- end
+ callback = func
})
end
@@ -27,13 +25,10 @@ local function on_attach(attach_opts, client, bufnr)
callback = function() pcall(func) end
})
end
- if attach_opts.no_semantic_tokens then
- client.server_capabilities.semanticTokensProvider = nil
- end
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
- if client.server_capabilities.hoverProvider then
+ if client.server_capabilities and client.server_capabilities.hoverProvider then
set_keymap('K', vim.lsp.buf.hover)
end
set_keymap('<Leader>d', vim.lsp.buf.definition)
@@ -46,6 +41,7 @@ local function on_attach(attach_opts, client, bufnr)
set_keymap('gR', require "azy.builtins".lsp.references())
set_keymap('<Leader>s', require "azy.builtins".lsp.workspace_symbols())
+
vim.opt_local.tagfunc = "v:lua.vim.lsp.tagfunc"
set_keymap('<Leader>e', require"azy.builtins".files(vim.tbl_filter(function(p)
@@ -174,7 +170,7 @@ local function setup_lsp(name, filetypes, command, ucommands, config)
if not cfg.root_dir then
cfg.root_dir = find_root(cfg.root_markers or { ".git" }, args.file)
end
- vim.lsp.start(cfg)
+ vim.lsp.start(cfg, { bufnr = args.buf })
end
})
end
@@ -184,9 +180,8 @@ end
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
capabilities.workspace.configuration = true
-local function mk_config(extras)
- return { capabilities = capabilities, on_attach = function(...) on_attach(extras, ...) end}
-end
+
+local default_cfg = { capabilities = capabilities, on_attach = on_attach }
-- A bit of notes for the future me
-- filetypes (table) List of filetypes for this lsp
@@ -206,6 +201,8 @@ local system_lsps = {
filetypes = { "zig" },
root_markers = { "build.zig", ".git" },
cfg = {
+ capabilities = capabilities,
+ on_attach = on_attach,
settings = {
zig = {
enable_snippets = true
@@ -371,7 +368,7 @@ for lname, config in pairs(system_lsps) do
if not config.filetypes then
vim.notify(string.format("No filetypes defined for %s", lname))
else
- setup_lsp(lname, config.filetypes, config.command or { lname }, config.ucommands or {}, config.cfg or mk_config(config.attach_opts or {}))
+ setup_lsp(lname, config.filetypes, config.command or { lname }, config.ucommands or {}, config.cfg or default_cfg)
end
end
diff --git a/lua/plugins.lua b/lua/plugins.lua
@@ -97,7 +97,7 @@ return packer.startup(function(use)
end }
-- Treesitter related
- localuse 'nvim-treesitter/nvim-treesitter'
+ use 'nvim-treesitter/nvim-treesitter'
use { 'nvim-treesitter/playground', opt = true }
localuse 'vigoux/architext.nvim'
diff --git a/lua/ts_config.lua b/lua/ts_config.lua
@@ -26,5 +26,5 @@ require'nvim-treesitter.configs'.setup {
}
},
playground = { enable = true },
- ensure_installed = {'rust', 'c', 'lua', 'query', 'fennel', 'python', 'vim', 'bash', 'latex'} -- one of 'all', 'language', or a list of languages
+ ensure_installed = {'c', 'lua', 'query', 'fennel', 'python', 'vim', 'bash', 'latex'} -- one of 'all', 'language', or a list of languages
}