From f1150b73ebaae94c83d15e9def14acf0bbe704d5 Mon Sep 17 00:00:00 2001 From: Stefan Weigl-Bosker Date: Thu, 3 Apr 2025 22:30:43 -0400 Subject: update --- modules/neovim/default.nix | 3 +- modules/neovim/nvim/lua/config/lsp.lua | 85 ------------------------ modules/neovim/nvim/lua/config/lsp/clangd.lua | 21 ++++++ modules/neovim/nvim/lua/config/lsp/init.lua | 95 +++++++++++++++++++++++++++ modules/neovim/nvim/lua/config/lsp/zls.lua | 11 ++++ 5 files changed, 129 insertions(+), 86 deletions(-) delete mode 100644 modules/neovim/nvim/lua/config/lsp.lua create mode 100644 modules/neovim/nvim/lua/config/lsp/clangd.lua create mode 100644 modules/neovim/nvim/lua/config/lsp/init.lua create mode 100644 modules/neovim/nvim/lua/config/lsp/zls.lua (limited to 'modules/neovim') diff --git a/modules/neovim/default.nix b/modules/neovim/default.nix index 8052535..d3c1096 100644 --- a/modules/neovim/default.nix +++ b/modules/neovim/default.nix @@ -45,13 +45,14 @@ in type = "lua"; } plenary-nvim -# blink-cmp nvim-lspconfig base16-nvim telescope-nvim telescope-fzf-native-nvim vim-obsession ]; + # extraLuaPackages = ps: with ps; [ + # ]; extraLuaConfig = '' ${builtins.readFile ./nvim/init.lua} ''; diff --git a/modules/neovim/nvim/lua/config/lsp.lua b/modules/neovim/nvim/lua/config/lsp.lua deleted file mode 100644 index d0a9827..0000000 --- a/modules/neovim/nvim/lua/config/lsp.lua +++ /dev/null @@ -1,85 +0,0 @@ -vim.opt.cot = "menu,menuone,noinsert" -vim.opt.pumblend=5 - -local methods = vim.lsp.protocol.Methods -local map = vim.keymap.set - -local servers = { - clangd = {}, - zls = {}, - rust_analyzer = {} -} - -local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview -function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...) - opts = opts or {} - opts.border = opts.border or "rounded" - return orig_util_open_floating_preview(contents, syntax, opts, ...) -end - -vim.diagnostic.config({ --- virtual_text = { prefix = "", virt_text_pos = "eol_right_align", }, --- virtual_text = true, - float = { border = "rounded" }, - signs = false, - underline = true, - update_in_insert = false, - float = true, - jump = { float = true }, -}) - --- is completion visible -local function pumvisible() - return tonumber(vim.fn.pumvisible()) ~= 0 -end - -vim.api.nvim_create_autocmd("LspAttach", { callback = function(args) - local client = vim.lsp.get_client_by_id(args.data.client_id) - - vim.keymap.set('n', 'grr', function() - vim.lsp.buf.references() - end, { desc = "Code references (LSP)" }) - - vim.keymap.set('n', 'gd', function() - vim.lsp.buf.definition() - end, { desc = "Goto definition (LSP)" }) - - if client:supports_method(methods.textDocument_completion) then - vim.lsp.completion.enable(true, client.id, args.buf, { autotrigger = false }) - - map('i', "", function() - return pumvisible() and '' or '' - end, { expr = true }) - - - -- TODO: this ignores/overwrites default omnifunc rn - map('i', "", function() - return pumvisible() and '' or vim.lsp.completion.trigger() - end, { expr = true }) - - map('i', '', function() - return pumvisible() and '' or '' - end, { expr = true }) - end - - vim.keymap.set('n', 'E', 'lua vim.lsp.buf.hover()', { silent = true }) - -- if client:supports_method(methods.textDocument_inlayHint) then - -- vim.lsp.inlay_hint.enable() - -- end - - if client:supports_method(methods.textDocument_formatting) then - vim.api.nvim_create_autocmd("BufWritePre", { - buffer = args.buf, - callback = function() - vim.lsp.buf.format({bufnr = args.buf, id = client_id}) - end - }) - end -end}) - -local lspconfig = require('lspconfig') - -for server, config in pairs(servers) do --- config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities) - lspconfig[server].setup({}) -end diff --git a/modules/neovim/nvim/lua/config/lsp/clangd.lua b/modules/neovim/nvim/lua/config/lsp/clangd.lua new file mode 100644 index 0000000..14554a4 --- /dev/null +++ b/modules/neovim/nvim/lua/config/lsp/clangd.lua @@ -0,0 +1,21 @@ +return { + cmd = { "clangd" }, + filetypes = { "c", "cpp", "cuda" }, + root_markers = { + "meson.build", + ".clang-format", + ".clang-tidy", + "compile_commands.json", + "compile_flags.txt", + "configure.ac" + }, + single_file_support = true, + capabilities = { + textDocument = { + completion = { + editsNearCursor = true, + }, + }, + offsetEncoding = { "utf-8", "utf-16" }, + }, +} diff --git a/modules/neovim/nvim/lua/config/lsp/init.lua b/modules/neovim/nvim/lua/config/lsp/init.lua new file mode 100644 index 0000000..d618df2 --- /dev/null +++ b/modules/neovim/nvim/lua/config/lsp/init.lua @@ -0,0 +1,95 @@ +vim.opt.cot = "menu,menuone,noinsert" +vim.opt.pumblend=5 + +local methods = vim.lsp.protocol.Methods +local map = vim.keymap.set + +vim.lsp.config = { + ['clangd'] = require("config.lsp.clangd"), + ['zls'] = require("config.lsp.zls") +} + +local servers = { + clangd = {}, + zls = {}, +-- rust_analyzer = {} +} + +local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview +function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...) + opts = opts or {} + opts.border = opts.border or "rounded" + return orig_util_open_floating_preview(contents, syntax, opts, ...) +end + +vim.diagnostic.config({ +-- virtual_text = { prefix = "", virt_text_pos = "eol_right_align", }, +-- virtual_text = true, + float = { border = "rounded" }, + signs = false, + underline = true, + update_in_insert = false, + float = true, + jump = { float = true }, +}) + +-- is completion visible +local function pumvisible() + return tonumber(vim.fn.pumvisible()) ~= 0 +end + +vim.api.nvim_create_autocmd("LspAttach", { callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + + vim.keymap.set('n', 'grr', function() + vim.lsp.buf.references() + end, { desc = "Code references (LSP)" }) + + vim.keymap.set('n', 'gd', function() + vim.lsp.buf.definition() + end, { desc = "Goto definition (LSP)" }) + + if client:supports_method(methods.textDocument_completion) then + vim.lsp.completion.enable(true, client.id, args.buf, { autotrigger = false }) + + map('i', "", function() + return pumvisible() and '' or '' + end, { expr = true }) + + + -- TODO: this ignores/overwrites default omnifunc rn + map('i', "", function() + return pumvisible() and '' or vim.lsp.completion.trigger() + end, { expr = true }) + + map('i', '', function() + return pumvisible() and '' or '' + end, { expr = true }) + end + + vim.keymap.set('n', 'E', 'lua vim.lsp.buf.hover()', { silent = true }) + -- if client:supports_method(methods.textDocument_inlayHint) then + -- vim.lsp.inlay_hint.enable() + -- end + + if client:supports_method(methods.textDocument_formatting) then + vim.api.nvim_create_autocmd("BufWritePre", { + buffer = args.buf, + callback = function() + vim.lsp.buf.format({bufnr = args.buf, id = client_id}) + end + }) + end +end}) + +local lspconfig = require('lspconfig') + +for server, config in pairs(servers) do +-- config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities) + vim.lsp.config[server].settings = config + vim.lsp.enable(server) +-- lspconfig[server].setup({}) +end + +-- vim.lsp.config['clangd'] = require('config.lsp.clangd') +-- vim.lsp.enable('clangd') diff --git a/modules/neovim/nvim/lua/config/lsp/zls.lua b/modules/neovim/nvim/lua/config/lsp/zls.lua new file mode 100644 index 0000000..d2013a4 --- /dev/null +++ b/modules/neovim/nvim/lua/config/lsp/zls.lua @@ -0,0 +1,11 @@ +return { + cmd = { "zls" }, + filetypes = { "zig", "zir" }, + on_new_config = function(new, old) + if vim.fn.filereadable(vim.fs.joinpath(new_root_dir, "zls.json")) ~= 0 then + new.cmd = { "zls", "--config-path", "zls.json" } + end + end, + root_markers = { "zls.json", "build.zig", ".git" }, + single_file_support = true, +} -- cgit v1.2.3