diff options
Diffstat (limited to 'lua/bee/LSPs')
| -rw-r--r-- | lua/bee/LSPs/init.lua | 325 | ||||
| -rw-r--r-- | lua/bee/LSPs/on_attach.lua | 80 |
2 files changed, 221 insertions, 184 deletions
diff --git a/lua/bee/LSPs/init.lua b/lua/bee/LSPs/init.lua index 3bc86a5..69f34cf 100644 --- a/lua/bee/LSPs/init.lua +++ b/lua/bee/LSPs/init.lua @@ -1,148 +1,185 @@ local MP = ... local get_nixd_opts = nixInfo(nil, "info", "nixdExtras", "get_configs") return { - { - "mason.nvim", - auto_enable = true, - priority = 55, - on_plugin = { "nvim-lspconfig" }, - lsp = function(plugin) - vim.cmd.MasonInstall(plugin.name) - end, - }, - { - "nvim-lspconfig", - auto_enable = true, - priority = 50, - lsp = function(plugin) - vim.lsp.config(plugin.name, plugin.lsp or {}) - vim.lsp.enable(plugin.name) - end, - before = function(_) - vim.lsp.config("*", { - on_attach = require(MP:relpath("on_attach")), - }) - end, - }, - { - "lua_ls", - for_cat = "lua", - lsp = { - filetypes = { "lua" }, - settings = { - Lua = { - runtime = { version = "LuaJIT" }, - formatters = { - ignoreComments = true, - }, - signatureHelp = { enabled = true }, - diagnostics = { - globals = { "vim", "make_test" }, - disable = {}, - }, - workspace = { - checkThirdParty = false, - library = { - -- '${3rd}/luv/library', - -- unpack(vim.api.nvim_get_runtime_file('', true)), - }, - }, - completion = { - callSnippet = "Replace", - }, - telemetry = { enabled = false }, - }, - }, - }, - }, - { - "nixd", - for_cat = "nix", - after = function(_) - vim.api.nvim_create_user_command("StartNilLSP", function() - vim.lsp.start(vim.lsp.config.nil_ls) - end, { desc = "Run nil-ls (when you really need docs for the builtins and nixd refuse)" }) - end, - lsp = { - filetypes = { "nix" }, - settings = { - nixd = { - nixpkgs = { - expr = nixInfo("import <nixpkgs> {}", "info", "nixdExtras", "nixpkgs"), - }, - formatting = { - command = { "nixfmt" }, - }, - options = { - -- (builtins.getFlake "path:${builtins.toString <path_to_system_flake>}").legacyPackages.<system>.nixosConfigurations."<user@host>".options - nixos = { - expr = get_nixd_opts - and get_nixd_opts("nixos", nixInfo(nil, "info", "nixdExtras", "flake-path")), - }, - -- (builtins.getFlake "path:${builtins.toString <path_to_system_flake>}").legacyPackages.<system>.homeConfigurations."<user@host>".options - ["home-manager"] = { - expr = get_nixd_opts - and get_nixd_opts("home-manager", nixInfo(nil, "info", "nixdExtras", "flake-path")), -- <- if flake-path is nil it will be lsp root dir - }, - }, - diagnostic = { - suppress = { - "sema-escaping-with", - }, - }, - }, - }, - }, - }, - { - "clangd", - for_cat = "C", - lsp = { - filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto" }, - on_attach = function(client, bufnr) - require(MP:relpath("on_attach"))(client, bufnr) - -- the stuff they were adding that was overriding my on_attach - dofile(nixInfo.utils.get_nix_plugin_path("nvim-lspconfig") .. "/lsp/clangd.lua").on_attach( - client, - bufnr - ) - end, - -- unneded thanks to clangd_extensions-nvim I think - -- settings = { - -- clangd_config = { - -- init_options = { - -- compilationDatabasePath="./build", - -- }, - -- } - -- } - }, - }, - { - "gopls", - for_cat = "go", - lsp = { - filetypes = { "go", "gomod", "gowork", "gotmpl", "templ" }, - }, - }, - { - "zls", - for_cat = "zig", - lsp = { - filetypes = { "zig", "zir" }, - }, - }, - { - "rust_analyzer", - for_cat = "rust", - lsp = { - filetypes = { "rust" }, - }, - }, - { - "bashls", - for_cat = "bash", - lsp = { - filetypes = { "bash", "sh" }, - }, - }, + { + "mason.nvim", + auto_enable = true, + priority = 55, + on_plugin = { "nvim-lspconfig" }, + lsp = function(plugin) + vim.cmd.MasonInstall(plugin.name) + end, + }, + { + "nvim-lspconfig", + auto_enable = true, + priority = 50, + lsp = function(plugin) + vim.lsp.config(plugin.name, plugin.lsp or {}) + vim.lsp.enable(plugin.name) + end, + before = function(_) + vim.lsp.config("*", { + on_attach = require(MP:relpath("on_attach")), + }) + end, + }, + { + "rustaceanvim", + auto_enable = true, + lazy = false, -- lazy loaded by default + before = function(_) + local RustLsp = function(mode, keymap, action, bufnr) + vim.keymap.set(mode, keymap, function() + vim.cmd.RustLsp(action) + end, { silent = true, buffer = bufnr }) + end + + vim.g.rustaceanvim = { + tools = {}, + server = { + on_attach = function(client, bufnr) + RustLsp({ "n", "x" }, "<leader>ca", "codeAction", bufnr) + RustLsp("n", "<leader>ee", "explainError", bufnr) + RustLsp("n", "K", { "hover", "actions" }, bufnr) + RustLsp("n", "L", { "hover", "range" }, bufnr) + RustLsp("n", "<F5>", "debuggables", bufnr) + end, + default_settings = { + ["rust-analyzer"] = { + checkOnSave = { + enable = true, + command = "clippy", + }, + procMacro = { + enable = true, + }, + }, + }, + }, + -- dap = {}, + } + end, + }, + { + "lua_ls", + for_cat = "lua", + lsp = { + filetypes = { "lua" }, + settings = { + Lua = { + runtime = { version = "LuaJIT" }, + formatters = { + ignoreComments = true, + }, + signatureHelp = { enabled = true }, + diagnostics = { + globals = { "vim", "make_test" }, + disable = {}, + }, + workspace = { + checkThirdParty = false, + library = { + -- '${3rd}/luv/library', + -- unpack(vim.api.nvim_get_runtime_file('', true)), + }, + }, + completion = { + callSnippet = "Replace", + }, + telemetry = { enabled = false }, + }, + }, + }, + }, + { + "nixd", + for_cat = "nix", + after = function(_) + vim.api.nvim_create_user_command("StartNilLSP", function() + vim.lsp.start(vim.lsp.config.nil_ls) + end, { desc = "Run nil-ls (when you really need docs for the builtins and nixd refuse)" }) + end, + lsp = { + filetypes = { "nix" }, + settings = { + nixd = { + nixpkgs = { + expr = nixInfo("import <nixpkgs> {}", "info", "nixdExtras", "nixpkgs"), + }, + formatting = { + command = { "nixfmt" }, + }, + options = { + -- (builtins.getFlake "path:${builtins.toString <path_to_system_flake>}").legacyPackages.<system>.nixosConfigurations."<user@host>".options + nixos = { + expr = get_nixd_opts + and get_nixd_opts("nixos", nixInfo(nil, "info", "nixdExtras", "flake-path")), + }, + -- (builtins.getFlake "path:${builtins.toString <path_to_system_flake>}").legacyPackages.<system>.homeConfigurations."<user@host>".options + ["home-manager"] = { + expr = get_nixd_opts + and get_nixd_opts("home-manager", nixInfo(nil, "info", "nixdExtras", "flake-path")), -- <- if flake-path is nil it will be lsp root dir + }, + }, + diagnostic = { + suppress = { + "sema-escaping-with", + }, + }, + }, + }, + }, + }, + { + "clangd", + for_cat = "C", + lsp = { + filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto" }, + on_attach = function(client, bufnr) + require(MP:relpath("on_attach"))(client, bufnr) + -- the stuff they were adding that was overriding my on_attach + dofile(nixInfo.utils.get_nix_plugin_path("nvim-lspconfig") .. "/lsp/clangd.lua").on_attach( + client, + bufnr + ) + end, + -- unneded thanks to clangd_extensions-nvim I think + -- settings = { + -- clangd_config = { + -- init_options = { + -- compilationDatabasePath="./build", + -- }, + -- } + -- } + }, + }, + { + "gopls", + for_cat = "go", + lsp = { + filetypes = { "go", "gomod", "gowork", "gotmpl", "templ" }, + }, + }, + { + "zls", + for_cat = "zig", + lsp = { + filetypes = { "zig", "zir" }, + }, + }, + -- { + -- "rust_analyzer", + -- for_cat = "rust", + -- lsp = { + -- filetypes = { "rust" }, + -- }, + -- }, + { + "bashls", + for_cat = "bash", + lsp = { + filetypes = { "bash", "sh" }, + }, + }, } diff --git a/lua/bee/LSPs/on_attach.lua b/lua/bee/LSPs/on_attach.lua index d4d69e4..8199fb1 100644 --- a/lua/bee/LSPs/on_attach.lua +++ b/lua/bee/LSPs/on_attach.lua @@ -5,50 +5,50 @@ -- end, -- }) return function(_, bufnr) - -- we create a function that lets us more easily define mappings specific - -- for LSP related items. It sets the mode, buffer and description for us each time. + -- we create a function that lets us more easily define mappings specific + -- for LSP related items. It sets the mode, buffer and description for us each time. - local map = function(keys, func, desc, mode) - if desc then - desc = "LSP: " .. desc - end - vim.keymap.set(mode or "n", keys, func, { buffer = bufnr, desc = desc }) - end + local map = function(keys, func, desc, mode) + if desc then + desc = "LSP: " .. desc + end + vim.keymap.set(mode or "n", keys, func, { buffer = bufnr, desc = desc }) + end - map("<leader>rn", vim.lsp.buf.rename, "[R]e[n]ame") - map("<leader>la", vim.lsp.buf.code_action, "[L]sp [A]ction") + map("<leader>rn", vim.lsp.buf.rename, "[R]e[n]ame") + map("<leader>la", vim.lsp.buf.code_action, "[L]sp [A]ction") - -- See `:help K` for why this keymap - map("K", vim.lsp.buf.hover, "Hover Documentation") - map("<C-k>", vim.lsp.buf.signature_help, "Signature Documentation") + -- See `:help K` for why this keymap + map("K", vim.lsp.buf.hover, "Hover Documentation") + map("<C-k>", vim.lsp.buf.signature_help, "Signature Documentation") - -- Lesser used LSP functionality - map("<leader>wa", vim.lsp.buf.add_workspace_folder, "[W]orkspace [A]dd Folder") - map("<leader>wr", vim.lsp.buf.remove_workspace_folder, "[W]orkspace [R]emove Folder") - map("<leader>wl", function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, "[W]orkspace [L]ist Folders") + -- Lesser used LSP functionality + map("<leader>wa", vim.lsp.buf.add_workspace_folder, "[W]orkspace [A]dd Folder") + map("<leader>wr", vim.lsp.buf.remove_workspace_folder, "[W]orkspace [R]emove Folder") + map("<leader>wl", function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, "[W]orkspace [L]ist Folders") - -- Create a command `:Format` local to the LSP buffer - vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_) - vim.lsp.buf.format() - end, { desc = "Format current buffer with LSP" }) - map("<leader>Fl", ":Format<CR>", "[F]ormat with [l]sp") - map("<leader>FL", ":Format<CR>", "[F]ormat with [L]SP") - -- The following two autocommands are used to highlight references of the - -- word under your cursor when your cursor rests there for a little while. - -- See `:help CursorHold` for information about when this is executed - -- When you move your cursor, the highlights will be cleared (the second autocommand). - -- local client = vim.lsp.get_client_by_id(event.data.client_id) - -- if client and client.server_capabilities.documentHighlightProvider then - -- vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { - -- buffer = event.buf, - -- callback = vim.lsp.buf.document_highlight, - -- }) + -- Create a command `:Format` local to the LSP buffer + vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_) + vim.lsp.buf.format() + end, { desc = "Format current buffer with LSP" }) + map("<leader>Fl", ":Format<CR>", "[F]ormat with [l]sp") + map("<leader>FL", ":Format<CR>", "[F]ormat with [L]SP") + -- The following two autocommands are used to highlight references of the + -- word under your cursor when your cursor rests there for a little while. + -- See `:help CursorHold` for information about when this is executed + -- When you move your cursor, the highlights will be cleared (the second autocommand). + -- local client = vim.lsp.get_client_by_id(event.data.client_id) + -- if client and client.server_capabilities.documentHighlightProvider then + -- vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { + -- buffer = event.buf, + -- callback = vim.lsp.buf.document_highlight, + -- }) - -- vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { - -- buffer = event.buf, - -- callback = vim.lsp.buf.clear_references, - -- }) - -- end + -- vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { + -- buffer = event.buf, + -- callback = vim.lsp.buf.clear_references, + -- }) + -- end end |
