diff --git a/config/native/after/ftplugin/c.lua b/config/native/after/ftplugin/c.lua deleted file mode 100644 index de0d90a..0000000 --- a/config/native/after/ftplugin/c.lua +++ /dev/null @@ -1,4 +0,0 @@ -local bufnr = vim.api.nvim_get_current_buf() -local lsp = require("pde.lsp") - -lsp.start(require("pde.lsp.configs.clangd").config(bufnr), { bufnr = bufnr }) diff --git a/config/native/after/ftplugin/go.lua b/config/native/after/ftplugin/go.lua index 7c827c5..8a1e83f 100644 --- a/config/native/after/ftplugin/go.lua +++ b/config/native/after/ftplugin/go.lua @@ -1,11 +1 @@ -local bufnr = vim.api.nvim_get_current_buf() - vim.o.expandtab = false - -local lsp = require("pde.lsp") - -lsp.start(require("pde.lsp.configs.gopls").config(bufnr), { bufnr = bufnr }) -lsp.start( - require("pde.lsp.configs.efm").config_from_single("golangci_lint", bufnr), - { bufnr = bufnr } -) diff --git a/config/native/after/ftplugin/gomod.lua b/config/native/after/ftplugin/gomod.lua index 0ba6680..8a1e83f 100644 --- a/config/native/after/ftplugin/gomod.lua +++ b/config/native/after/ftplugin/gomod.lua @@ -1,6 +1 @@ -local bufnr = vim.api.nvim_get_current_buf() - vim.o.expandtab = false - -local lsp = require("pde.lsp") -lsp.start(require("pde.lsp.configs.gopls").config(bufnr), { bufnr = bufnr }) diff --git a/config/native/after/ftplugin/gotmpl.lua b/config/native/after/ftplugin/gotmpl.lua index 0ba6680..8a1e83f 100644 --- a/config/native/after/ftplugin/gotmpl.lua +++ b/config/native/after/ftplugin/gotmpl.lua @@ -1,6 +1 @@ -local bufnr = vim.api.nvim_get_current_buf() - vim.o.expandtab = false - -local lsp = require("pde.lsp") -lsp.start(require("pde.lsp.configs.gopls").config(bufnr), { bufnr = bufnr }) diff --git a/config/native/after/ftplugin/gowork.lua b/config/native/after/ftplugin/gowork.lua index 0ba6680..8a1e83f 100644 --- a/config/native/after/ftplugin/gowork.lua +++ b/config/native/after/ftplugin/gowork.lua @@ -1,6 +1 @@ -local bufnr = vim.api.nvim_get_current_buf() - vim.o.expandtab = false - -local lsp = require("pde.lsp") -lsp.start(require("pde.lsp.configs.gopls").config(bufnr), { bufnr = bufnr }) diff --git a/config/native/after/ftplugin/json.lua b/config/native/after/ftplugin/json.lua deleted file mode 100644 index 39ed98c..0000000 --- a/config/native/after/ftplugin/json.lua +++ /dev/null @@ -1,9 +0,0 @@ -local bufnr = vim.api.nvim_get_current_buf() - -local lsp = require("pde.lsp") - -lsp.start( - require("pde.lsp.configs.efm").config_from_multi("efmson", { "prettier", "jq" }, bufnr), - { bufnr = bufnr } -) -lsp.start(require("pde.lsp.configs.jsonls").config(bufnr), { bufnr = bufnr }) diff --git a/config/native/after/ftplugin/lua.lua b/config/native/after/ftplugin/lua.lua deleted file mode 100644 index c983a8a..0000000 --- a/config/native/after/ftplugin/lua.lua +++ /dev/null @@ -1,6 +0,0 @@ -local bufnr = vim.api.nvim_get_current_buf() - -local lsp = require("pde.lsp") - -lsp.start(require("pde.lsp.configs.efm").config_from_single("stylua", bufnr), { bufnr = bufnr }) -lsp.start(require("pde.lsp.configs.lua_ls").config(bufnr), { bufnr = bufnr }) diff --git a/config/native/after/ftplugin/markdown.lua b/config/native/after/ftplugin/markdown.lua deleted file mode 100644 index 460929c..0000000 --- a/config/native/after/ftplugin/markdown.lua +++ /dev/null @@ -1,6 +0,0 @@ -local bufnr = vim.api.nvim_get_current_buf() - -local lsp = require("pde.lsp") - -lsp.start(require("pde.lsp.configs.efm").config_from_single("prettier", bufnr), { bufnr = bufnr }) -lsp.start(require("pde.lsp.configs.ltex_ls").config(bufnr), { bufnr = bufnr }) diff --git a/config/native/after/ftplugin/nix.lua b/config/native/after/ftplugin/nix.lua index 54103c5..aed0337 100644 --- a/config/native/after/ftplugin/nix.lua +++ b/config/native/after/ftplugin/nix.lua @@ -1,6 +1 @@ -local bufnr = vim.api.nvim_get_current_buf() - vim.o.shiftwidth = 2 - -local lsp = require("pde.lsp") -lsp.start(require("pde.lsp.configs.nixd").config(bufnr), { bufnr = bufnr }) diff --git a/config/native/after/ftplugin/python.lua b/config/native/after/ftplugin/python.lua deleted file mode 100644 index cd6c96a..0000000 --- a/config/native/after/ftplugin/python.lua +++ /dev/null @@ -1,9 +0,0 @@ -local bufnr = vim.api.nvim_get_current_buf() - -local lsp = require("pde.lsp") - -lsp.start( - require("pde.lsp.configs.efm").config_from_multi("pyefm", { "black", "isort" }, bufnr), - { bufnr = bufnr } -) -lsp.start(require("pde.lsp.configs.pyright").config(bufnr), { bufnr = bufnr }) diff --git a/config/native/after/ftplugin/rust.lua b/config/native/after/ftplugin/rust.lua deleted file mode 100644 index 60ced09..0000000 --- a/config/native/after/ftplugin/rust.lua +++ /dev/null @@ -1,5 +0,0 @@ -local bufnr = vim.api.nvim_get_current_buf() - -local lsp = require("pde.lsp") - -lsp.start(require("pde.lsp.configs.rust_analyzer").config(bufnr), { bufnr = bufnr }) diff --git a/config/native/after/ftplugin/sh.lua b/config/native/after/ftplugin/sh.lua deleted file mode 100644 index b9d267c..0000000 --- a/config/native/after/ftplugin/sh.lua +++ /dev/null @@ -1,8 +0,0 @@ -local bufnr = vim.api.nvim_get_current_buf() - -local lsp = require("pde.lsp") - -lsp.start( - require("pde.lsp.configs.efm").config_from_multi("sh", { "shfmt", "shellcheck" }, bufnr), - { bufnr = bufnr } -) diff --git a/config/native/after/ftplugin/terraform-vars.lua b/config/native/after/ftplugin/terraform-vars.lua deleted file mode 100644 index ef40547..0000000 --- a/config/native/after/ftplugin/terraform-vars.lua +++ /dev/null @@ -1,5 +0,0 @@ -local bufnr = vim.api.nvim_get_current_buf() - -local lsp = require("pde.lsp") - -lsp.start(require("pde.lsp.configs.terraformls").config(bufnr), { bufnr = bufnr }) diff --git a/config/native/after/ftplugin/terraform.lua b/config/native/after/ftplugin/terraform.lua index ce93bf8..a799905 100644 --- a/config/native/after/ftplugin/terraform.lua +++ b/config/native/after/ftplugin/terraform.lua @@ -1,8 +1,2 @@ -- default is empty vim.o.commentstring = "// %s" - -local bufnr = vim.api.nvim_get_current_buf() - -local lsp = require("pde.lsp") - -lsp.start(require("pde.lsp.configs.terraformls").config(bufnr), { bufnr = bufnr }) diff --git a/config/native/after/ftplugin/toml.lua b/config/native/after/ftplugin/toml.lua deleted file mode 100644 index ffad066..0000000 --- a/config/native/after/ftplugin/toml.lua +++ /dev/null @@ -1,5 +0,0 @@ -local bufnr = vim.api.nvim_get_current_buf() - -local lsp = require("pde.lsp") - -lsp.start(require("pde.lsp.configs.efm").config_from_single("taplo", bufnr), { bufnr = bufnr }) diff --git a/config/native/after/ftplugin/yaml.lua b/config/native/after/ftplugin/yaml.lua index b4e37bd..aed0337 100644 --- a/config/native/after/ftplugin/yaml.lua +++ b/config/native/after/ftplugin/yaml.lua @@ -1,8 +1 @@ -local bufnr = vim.api.nvim_get_current_buf() - vim.o.shiftwidth = 2 - -local lsp = require("pde.lsp") - -lsp.start(require("pde.lsp.configs.efm").config_from_single("prettier", bufnr), { bufnr = bufnr }) -lsp.start(require("pde.lsp.configs.yamlls").config(bufnr), { bufnr = bufnr }) diff --git a/config/native/after/ftplugin/zig.lua b/config/native/after/ftplugin/zig.lua deleted file mode 100644 index 5b6d296..0000000 --- a/config/native/after/ftplugin/zig.lua +++ /dev/null @@ -1,5 +0,0 @@ -local bufnr = vim.api.nvim_get_current_buf() - -local lsp = require("pde.lsp") - -lsp.start(require("pde.lsp.configs.zls").config(bufnr), { bufnr = bufnr }) diff --git a/config/native/after/ftplugin/zir.lua b/config/native/after/ftplugin/zir.lua deleted file mode 100644 index 5b6d296..0000000 --- a/config/native/after/ftplugin/zir.lua +++ /dev/null @@ -1,5 +0,0 @@ -local bufnr = vim.api.nvim_get_current_buf() - -local lsp = require("pde.lsp") - -lsp.start(require("pde.lsp.configs.zls").config(bufnr), { bufnr = bufnr }) diff --git a/config/native/after/lsp/clangd.lua b/config/native/after/lsp/clangd.lua new file mode 100644 index 0000000..14c8814 --- /dev/null +++ b/config/native/after/lsp/clangd.lua @@ -0,0 +1,14 @@ +local binaries = require("pde.binaries") + +vim.lsp.config("clangd", { + cmd = { binaries.clangd() }, + root_markers = { + ".clangd", + ".clang-tidy", + ".clang-format", + "compile_commands.json", + "compile_flags.txt", + "configure.ac", + }, + filetypes = { "c", "cpp" }, +}) diff --git a/config/native/after/lsp/efmson.lua b/config/native/after/lsp/efmson.lua new file mode 100644 index 0000000..1c44e3c --- /dev/null +++ b/config/native/after/lsp/efmson.lua @@ -0,0 +1,3 @@ +local config = require("pde.lsp.configs.efm").config_from_multi("efmson", { "prettier", "jq" }) +config.filetypes = { "json", "jsonc" } +vim.lsp.config("efmson", config) diff --git a/config/native/after/lsp/golangci_lint.lua b/config/native/after/lsp/golangci_lint.lua new file mode 100644 index 0000000..249d697 --- /dev/null +++ b/config/native/after/lsp/golangci_lint.lua @@ -0,0 +1,3 @@ +local config = require("pde.lsp.configs.efm").config_from_single("golangci_lint") +config.filetypes = { "go" } +vim.lsp.config("golangci_lint", config) diff --git a/config/native/after/lsp/gopls.lua b/config/native/after/lsp/gopls.lua new file mode 100644 index 0000000..592fde8 --- /dev/null +++ b/config/native/after/lsp/gopls.lua @@ -0,0 +1,14 @@ +-- https://github.com/golang/tools/tree/master/gopls +local binaries = require("pde.binaries") + +vim.lsp.config("gopls", { + cmd = { binaries.gopls() }, + -- https://github.com/golang/tools/blob/master/gopls/doc/settings.md + settings = { + gopls = { + allExperiments = true, + }, + }, + root_markers = { "go.work", "go.mod" }, + filetypes = { "go", "gomod", "gotmpl", "gowork" }, +}) diff --git a/config/native/after/lsp/jsonls.lua b/config/native/after/lsp/jsonls.lua new file mode 100644 index 0000000..59197bf --- /dev/null +++ b/config/native/after/lsp/jsonls.lua @@ -0,0 +1,19 @@ +-- https://github.com/hrsh7th/vscode-langservers-extracted + +local binaries = require("pde.binaries") +local schemastore = require("schemastore") + +vim.lsp.config("jsonls", { + cmd = { binaries.jsonls(), "--stdio" }, + init_options = { + provideFormatter = false, -- use prettier instead + }, + settings = { + json = { + format = false, + validate = true, + schemas = schemastore.json.schemas(), + }, + }, + filetypes = { "json", "jsonc" }, +}) diff --git a/config/native/after/lsp/ltex.lua b/config/native/after/lsp/ltex.lua new file mode 100644 index 0000000..5020622 --- /dev/null +++ b/config/native/after/lsp/ltex.lua @@ -0,0 +1,146 @@ +-- https://github.com/valentjn/ltex-ls + +local binaries = require("pde.binaries") +local paths = require("pde.paths") + +local dictionary = {} +local disabledRules = {} +local hiddenFalsePositives = {} + +local name = "ltex" +local current_language = "en-US" + +---@param path string +---@param lines string[] +local function append_to_file(path, lines) + local file = io.open(path, "a") + if file then + for _, line in ipairs(lines) do + file:write(line .. "\n") + end + file:close() + end +end + +---@param command lsp.Command +---@return boolean +local function validate_command(command) + if #command.arguments ~= 1 then + vim.notify("unexpected arguments: " .. vim.inspect(command.arguments), vim.log.levels.ERROR) + return false + end + + return true +end + +---@param path string file to read +---@param target string[] target to append the lines to +local function read_lines_into(path, target) + local file = io.open(path, "r") + if file then + for line in file:lines() do + table.insert(target, line) + end + + file:close() + end +end + +---@param command table +---@param key string +---@param tbl table +---@return table +local function handle_action(command, key, tbl) + if not validate_command(command) then return {} end + + local entries = command.arguments[1][key] + for lang, entry in pairs(entries) do + if not tbl[lang] then tbl[lang] = {} end + vim.list_extend(tbl[lang], entry) + end + return entries +end + +local update_client_with = function(changed_settings) + local client = vim.lsp.get_clients({ name = name })[1] + if not client then return end + client:notify("workspace/didChangeConfiguration", { settings = changed_settings }) +end + +local function get_dictionary_file(language) return paths.get_spellfile(vim.split(language, "-")[1]) end + +local function get_false_positives_file(language) + return paths.get_spellfile(nil) .. "/ltex_false-positives_" .. language .. ".txt" +end + +local function get_disabled_rules_file(language) + return paths.get_spellfile(nil) .. "/ltex_disabled-rules_" .. language .. ".txt" +end + +vim.lsp.config(name, { + cmd = { binaries.ltex_ls() }, + filetypes = { "markdown" }, + before_init = function() + if not dictionary[current_language] then + dictionary[current_language] = {} + read_lines_into(get_dictionary_file(current_language), dictionary[current_language]) + end + + if not hiddenFalsePositives[current_language] then + hiddenFalsePositives[current_language] = {} + read_lines_into( + get_false_positives_file(current_language), + hiddenFalsePositives[current_language] + ) + end + + if not disabledRules[current_language] then + disabledRules[current_language] = {} + read_lines_into( + get_disabled_rules_file(current_language), + disabledRules[current_language] + ) + end + end, + settings = { + ltex = { + enabled = { "html", "markdown" }, + language = current_language, + checkFrequency = "save", + dictionary = dictionary, + disabledRules = disabledRules, + hiddenFalsePositives = hiddenFalsePositives, + }, + }, + on_attach = function(_, buf) + vim.api.nvim_buf_call(buf, function() vim.o.spell = false end) + -- TODO: buf_command for changing the language + end, + commands = { + ["_ltex.addToDictionary"] = function(command) + local new = handle_action(command, "words", dictionary) + update_client_with({ ltex = { dictionary = dictionary } }) + for lang, entries in pairs(new) do + local path = get_dictionary_file(lang) + append_to_file(path, entries) + end + vim.cmd("MkSpell") + end, + ["_ltex.hideFalsePositives"] = function(command) + local new = handle_action(command, "falsePositives", hiddenFalsePositives) + update_client_with({ ltex = { hiddenFalsePositives = hiddenFalsePositives } }) + for lang, entries in pairs(new) do + local path = get_false_positives_file(lang) + append_to_file(path, entries) + end + end, + ["_ltex.disableRules"] = function(command) + local new = handle_action(command, "ruleIds", disabledRules) + update_client_with({ ltex = { disabledRules = disabledRules } }) + for lang, entries in pairs(new) do + local path = get_disabled_rules_file(lang) + append_to_file(path, entries) + end + end, + }, +}) diff --git a/config/native/after/lsp/lua_ls.lua b/config/native/after/lsp/lua_ls.lua new file mode 100644 index 0000000..6d14f1a --- /dev/null +++ b/config/native/after/lsp/lua_ls.lua @@ -0,0 +1,26 @@ +-- https://github.com/LuaLS/lua-language-server +local binaries = require("pde.binaries") + +vim.lsp.config("lua_ls", { + cmd = { binaries.lua_ls() }, + filetypes = { "lua" }, + on_init = function(client) + -- use stylua via efm, this formatter is not great and it clears diagnostic text on save + client.server_capabilities.documentFormattingProvider = nil + client.server_capabilities.documentRangeFormattingProvider = nil + end, + settings = { + Lua = { + addonManager = { enable = false }, + -- use stylua via efm, this formatter is not great and it clears diagnostic text on save + format = { enable = false }, + hint = { enable = true }, + runtime = { version = "LuaJIT" }, + telemetry = { enable = false }, + workspace = { + checkThirdParty = false, + }, + }, + }, + root_markers = { ".luarc.json" }, +}) diff --git a/config/native/after/lsp/nixd.lua b/config/native/after/lsp/nixd.lua new file mode 100644 index 0000000..fad2576 --- /dev/null +++ b/config/native/after/lsp/nixd.lua @@ -0,0 +1,16 @@ +-- https://github.com/nix-community/nixd + +local binaries = require("pde.binaries") + +vim.lsp.config("nixd", { + cmd = { binaries.nixd() }, + filetypes = { "nix" }, + settings = { + nixd = { + formatting = { + command = { binaries.nixfmt() }, + }, + }, + }, + root_markers = { "flake.nix" }, +}) diff --git a/config/native/after/lsp/prettier.lua b/config/native/after/lsp/prettier.lua new file mode 100644 index 0000000..086fd10 --- /dev/null +++ b/config/native/after/lsp/prettier.lua @@ -0,0 +1,3 @@ +local config = require("pde.lsp.configs.efm").config_from_single("prettier") +config.filetypes = { "markdown", "yaml" } +vim.lsp.config("prettier", config) diff --git a/config/native/after/lsp/pyright.lua b/config/native/after/lsp/pyright.lua new file mode 100644 index 0000000..332b10e --- /dev/null +++ b/config/native/after/lsp/pyright.lua @@ -0,0 +1,25 @@ +-- https://github.com/microsoft/pyright + +local binaries = require("pde.binaries") + +vim.lsp.config("pyright", { + cmd = { binaries.pyright(), "--stdio" }, + filetypes = { "python" }, + settings = { + python = { + analysis = { + autoSearchPaths = true, + useLibraryCodeForTypes = true, + diagnosticMode = "openFilesOnly", + }, + }, + }, + root_markers = { + "pyproject.toml", + "setup.py", + "setup.cfg", + "requirements.txt", + "Pipfile", + "pyrightconfig.json", + }, +}) diff --git a/config/native/after/lsp/rust_analyzer.lua b/config/native/after/lsp/rust_analyzer.lua new file mode 100644 index 0000000..ff939fe --- /dev/null +++ b/config/native/after/lsp/rust_analyzer.lua @@ -0,0 +1,122 @@ +local binaries = require("pde.binaries") +local runner = require("pde.runner") +local name = "rust_analyzer" + +local function reload_workspace(bufnr) + local clients = vim.lsp.get_clients({ name = name, bufnr = bufnr }) + for _, client in ipairs(clients) do + vim.notify("Reloading Cargo Workspace") + client:request("rust-analyzer/reloadWorkspace", nil, function(err) + if err then error(tostring(err)) end + vim.notify("Cargo workspace reloaded") + end, 0) + end +end + +---@param command lsp.Command +---@return boolean +local function validate_command(command) + if #command.arguments ~= 1 then + vim.notify("unexpected arguments: " .. vim.inspect(command.arguments), vim.log.levels.ERROR) + return false + end + + ---@type table + ---@diagnostic disable-next-line: assign-type-mismatch + local task = command.arguments[1] + if not task or task.kind ~= "cargo" then + vim.notify("unexpected kind: " .. vim.inspect(task), vim.log.levels.ERROR) + return false + end + + return true +end + +---@param command lsp.Command +local function runSingle(command) + if not validate_command(command) then return end + + ---@type table + ---@diagnostic disable-next-line: assign-type-mismatch + local task = command.arguments[1] + if not task then + vim.notify("no command arguments", vim.log.levels.ERROR) + return + end + local cmd = { + task.kind, + task.args.cargoArgs, + task.args.cargoExtraArgs, + } + if not vim.tbl_isempty(task.args.executableArgs) then + table.insert(cmd, { "--" }) + table.insert(cmd, task.args.executableArgs) + end + + local cwd = task.args.workspaceRoot + + runner.run(vim.iter(cmd):flatten():totable(), { cwd = cwd }) +end + +vim.lsp.config(name, { + cmd = { binaries.rust_analyzer() }, + filetypes = { "rust" }, + capabilities = { + experimental = { + serverStatusNotification = true, + }, + }, + settings = { + ["rust-analyzer"] = { + rustfmt = { + overrideCommand = { + binaries.rustfmt(), + "--edition", + "2021", + "--", + }, + }, + files = { + excludeDirs = { + "./.direnv/", + "./.git/", + "./.github/", + "./.gitlab/", + "./node_modules/", + "./ci/", + "./docs/", + }, + }, + checkOnSave = { + enable = true, + }, + diagnostics = { + enable = true, + experimental = { + enable = true, + }, + }, + }, + }, + commands = { + ["rust-analyzer.runSingle"] = runSingle, + }, + root_markers = { "Cargo.toml", "rust-project.json" }, + on_attach = function(_, buf) + vim.api.nvim_buf_create_user_command( + buf, + "CargoReload", + function() reload_workspace(buf) end, + { desc = "[" .. name .. "] Reload current cargo workspace" } + ) + + vim.api.nvim_create_autocmd("LspDetach", { + group = vim.api.nvim_create_augroup( + "personal-lsp-" .. name .. "-buf-" .. buf, + { clear = true } + ), + buffer = buf, + callback = function() vim.api.nvim_buf_del_user_command(buf, "CargoReload") end, + }) + end, +}) diff --git a/config/native/after/lsp/sh.lua b/config/native/after/lsp/sh.lua new file mode 100644 index 0000000..8cc1fa3 --- /dev/null +++ b/config/native/after/lsp/sh.lua @@ -0,0 +1,3 @@ +local config = require("pde.lsp.configs.efm").config_from_multi("sh", { "shfmt", "shellcheck" }) +config.filetypes = { "sh" } +vim.lsp.config("sh", config) diff --git a/config/native/after/lsp/stylua.lua b/config/native/after/lsp/stylua.lua new file mode 100644 index 0000000..b23226f --- /dev/null +++ b/config/native/after/lsp/stylua.lua @@ -0,0 +1,3 @@ +local config = require("pde.lsp.configs.efm").config_from_single("stylua") +config.filetypes = { "lua" } +vim.lsp.config("stylua", config) diff --git a/config/native/after/lsp/taplo.lua b/config/native/after/lsp/taplo.lua new file mode 100644 index 0000000..f6e6997 --- /dev/null +++ b/config/native/after/lsp/taplo.lua @@ -0,0 +1,3 @@ +local config = require("pde.lsp.configs.efm").config_from_single("taplo") +config.filetypes = { "toml" } +vim.lsp.config("taplo", config) diff --git a/config/native/after/lsp/terraform-ls.lua b/config/native/after/lsp/terraform-ls.lua new file mode 100644 index 0000000..c0f2c53 --- /dev/null +++ b/config/native/after/lsp/terraform-ls.lua @@ -0,0 +1,7 @@ +-- https://github.com/hashicorp/terraform-ls +local binaries = require("pde.binaries") +vim.lsp.config("terraform-ls", { + cmd = { binaries.terraformls(), "serve" }, + filetypes = { "terraform", "terraform-vars" }, + root_markers = { ".terraform" }, +}) diff --git a/config/native/after/lsp/yamlls.lua b/config/native/after/lsp/yamlls.lua new file mode 100644 index 0000000..e89af25 --- /dev/null +++ b/config/native/after/lsp/yamlls.lua @@ -0,0 +1,35 @@ +-- https://github.com/redhat-developer/yaml-language-server +local binaries = require("pde.binaries") +local schemastore = require("schemastore") + +vim.lsp.config("yamlls", { + cmd = { binaries.yamlls(), "--stdio" }, + filetypes = { "yaml" }, + settings = { + redhat = { + telemetry = { + enabled = false, + }, + }, + yaml = { + format = { + enable = false, -- use prettier instead + }, + completion = true, + hover = true, + validate = true, + schemas = vim.tbl_extend("error", schemastore.yaml.schemas(), { + ["kubernetes"] = { "k8s/**/*.yml", "k8s/**/*.yaml" }, + -- or use: + -- # yaml-language-server: $schema= + }), + schemaStore = { + -- we use above + enable = false, + -- https://github.com/dmitmel/dotfiles/blob/master/nvim/dotfiles/lspconfigs/yaml.lua + -- yamlls won't work if we disable schemaStore but don't specify url ¯\_(ツ)_/¯ + url = "", + }, + }, + }, +}) diff --git a/config/native/after/lsp/zls.lua b/config/native/after/lsp/zls.lua new file mode 100644 index 0000000..cf852db --- /dev/null +++ b/config/native/after/lsp/zls.lua @@ -0,0 +1,8 @@ +-- https://github.com/zigtools/zls +local binaries = require("pde.binaries") + +vim.lsp.config("zls", { + cmd = { binaries.zls() }, + filetypes = { "zig", "zir" }, + root_markers = { "zls.json" }, +}) diff --git a/config/native/lua/pde/dap/init.lua b/config/native/lua/pde/dap/init.lua index ed44ff1..7018854 100644 --- a/config/native/lua/pde/dap/init.lua +++ b/config/native/lua/pde/dap/init.lua @@ -1,11 +1,3 @@ -local initialize_once = function() - vim.cmd.packadd("nvim-dap") - -- nio is a dependency of nvim-dap-ui - vim.cmd.packadd("nvim-nio") - vim.cmd.packadd("nvim-dap-ui") - vim.cmd.packadd("nvim-dap-virtual-text") -end - local function load_configs() require("pde.dap.configs.cs") require("pde.dap.configs.go") @@ -15,8 +7,6 @@ end local M = {} function M.setup() - initialize_once() - require("nvim-dap-virtual-text").setup({ enabled = true, enabled_commands = true, @@ -41,10 +31,18 @@ function M.setup() map("db", dap.toggle_breakpoint, "toggle breakpoint") map("d?", dapui.eval, "evaluate under cursor") - dap.listeners.before.attach.dapui_config = function() dapui.open() end - dap.listeners.before.launch.dapui_config = function() dapui.open() end - dap.listeners.before.event_terminated.dapui_config = function() dapui.close() end - dap.listeners.before.event_exited.dapui_config = function() dapui.close() end + dap.listeners.before.attach.dapui_config = function() + dapui.open() + end + dap.listeners.before.launch.dapui_config = function() + dapui.open() + end + dap.listeners.before.event_terminated.dapui_config = function() + dapui.close() + end + dap.listeners.before.event_exited.dapui_config = function() + dapui.close() + end load_configs() end diff --git a/config/native/lua/pde/fs.lua b/config/native/lua/pde/fs.lua index 180bb99..e629449 100644 --- a/config/native/lua/pde/fs.lua +++ b/config/native/lua/pde/fs.lua @@ -1,5 +1,13 @@ local M = {} +---checks if buffer is a real readable file +---@param bufnr integer buffer to check. 0 for current +---@return boolean true if the buffer represents a real, readable file +M.is_buf_readable_file = function(bufnr) + local bufname = vim.api.nvim_buf_get_name(bufnr) + return vim.fn.filereadable(bufname) == 1 +end + ---Get PATH executable, returns nil if not found ---@param binary string ---@return string | nil diff --git a/config/native/lua/pde/lsp/capabilities.lua b/config/native/lua/pde/lsp/capabilities.lua deleted file mode 100644 index 2f26b7a..0000000 --- a/config/native/lua/pde/lsp/capabilities.lua +++ /dev/null @@ -1,15 +0,0 @@ -local M = {} - ----@param config vim.lsp.ClientConfig ----@return vim.lsp.ClientConfig -M.merge_capabilities = function(config) - local nvim = vim.lsp.protocol.make_client_capabilities() - - local default = { - capabilities = nvim, - } - - return vim.tbl_deep_extend("force", default, config) -end - -return M diff --git a/config/native/lua/pde/lsp/commands.lua b/config/native/lua/pde/lsp/commands.lua index ac96d53..6a0ea3a 100644 --- a/config/native/lua/pde/lsp/commands.lua +++ b/config/native/lua/pde/lsp/commands.lua @@ -1,5 +1,3 @@ -local lsp = require("pde.lsp") - ---@param args string ---@return number? local function parse_int_arg(args) @@ -30,7 +28,7 @@ local function restart_servers(filter) local attached_buffers = tuple[2] if client:is_stopped() then for _, buf in ipairs(attached_buffers) do - lsp.start(client.config, { bufnr = buf }) + vim.lsp.start(client.config, { bufnr = buf }) end detach_clients[old_client_id] = nil end @@ -151,10 +149,3 @@ vim.api.nvim_create_user_command( desc = "Opens the Nvim LSP client log.", } ) - -vim.api.nvim_create_user_command("LspAutostartToggle", function() - lsp.toggle_autostart() - print("Setting lsp autostart to: " .. tostring(lsp.is_autostart_enabled())) -end, { - desc = "Disables autostart of all LSPs", -}) diff --git a/config/native/lua/pde/lsp/configs/clangd.lua b/config/native/lua/pde/lsp/configs/clangd.lua deleted file mode 100644 index 0a99188..0000000 --- a/config/native/lua/pde/lsp/configs/clangd.lua +++ /dev/null @@ -1,22 +0,0 @@ -local binaries = require("pde.binaries") - -return { - ---@param bufnr integer - ---@return vim.lsp.ClientConfig - config = function(bufnr) - ---@type vim.lsp.ClientConfig - return { - name = "clangd", - cmd = { binaries.clangd() }, - root_dir = vim.fs.root(bufnr, { - ".clangd", - ".clang-tidy", - ".clang-format", - "compile_commands.json", - "compile_flags.txt", - "configure.ac", - ".git", - }), - } - end, -} diff --git a/config/native/lua/pde/lsp/configs/efm/init.lua b/config/native/lua/pde/lsp/configs/efm/init.lua index 0478de9..243d5a7 100644 --- a/config/native/lua/pde/lsp/configs/efm/init.lua +++ b/config/native/lua/pde/lsp/configs/efm/init.lua @@ -49,9 +49,8 @@ end ---Build an LspConfig table from the specified EFM plugins ---@param name string unique name of this efm instance ---@param plugins string[] names of plugins to add, ex. 'prettier' ----@param bufnr integer? ----@return vim.lsp.ClientConfig -local function build(name, plugins, bufnr) +---@return vim.lsp.Config +local function build(name, plugins) ---@type table local languages = {} local allRootMarkers = { [".git/"] = true } @@ -81,7 +80,6 @@ local function build(name, plugins, bufnr) local rootMarkers = vim.tbl_keys(allRootMarkers) - bufnr = bufnr or 0 return { name = name, cmd = { binaries.efm() }, @@ -97,21 +95,18 @@ local function build(name, plugins, bufnr) rootMarkers = rootMarkers, languages = languages, }, - root_dir = vim.fs.root(bufnr, { ".git" }), } end return { ---Build an LspConfig table from the specified EFM plugin ---@param plugin string unique name of this efm instance - ---@param bufnr integer? - ---@return vim.lsp.ClientConfig - config_from_single = function(plugin, bufnr) return build(plugin, { plugin }, bufnr) end, + ---@return vim.lsp.Config + config_from_single = function(plugin) return build(plugin, { plugin }) end, ---Build an LspConfig table from the specified EFM plugins ---@param name string unique name of this efm instance ---@param plugins string[] names of plugins to add, ex. 'prettier' - ---@param bufnr integer? - ---@return vim.lsp.ClientConfig - config_from_multi = function(name, plugins, bufnr) return build(name, plugins, bufnr) end, + ---@return vim.lsp.Config + config_from_multi = function(name, plugins) return build(name, plugins) end, } diff --git a/config/native/lua/pde/lsp/configs/gopls.lua b/config/native/lua/pde/lsp/configs/gopls.lua deleted file mode 100644 index 1ae3251..0000000 --- a/config/native/lua/pde/lsp/configs/gopls.lua +++ /dev/null @@ -1,21 +0,0 @@ --- https://github.com/golang/tools/tree/master/gopls -local binaries = require("pde.binaries") - -return { - ---@param bufnr integer - ---@return vim.lsp.ClientConfig - config = function(bufnr) - ---@type vim.lsp.ClientConfig - return { - name = "gopls", - cmd = { binaries.gopls() }, - -- https://github.com/golang/tools/blob/master/gopls/doc/settings.md - settings = { - gopls = { - allExperiments = true, - }, - }, - root_dir = vim.fs.root(bufnr, { "go.work", "go.mod", ".git" }), - } - end, -} diff --git a/config/native/lua/pde/lsp/configs/jsonls.lua b/config/native/lua/pde/lsp/configs/jsonls.lua deleted file mode 100644 index 7160bb8..0000000 --- a/config/native/lua/pde/lsp/configs/jsonls.lua +++ /dev/null @@ -1,28 +0,0 @@ --- https://github.com/hrsh7th/vscode-langservers-extracted - -local binaries = require("pde.binaries") -vim.cmd.packadd("SchemaStore.nvim") -local schemastore = require("schemastore") - -return { - ---@param bufnr integer - ---@return vim.lsp.ClientConfig - config = function(bufnr) - ---@type vim.lsp.ClientConfig - return { - name = "jsonls", - cmd = { binaries.jsonls(), "--stdio" }, - init_options = { - provideFormatter = false, -- use prettier instead - }, - settings = { - json = { - format = false, - validate = true, - schemas = schemastore.json.schemas(), - }, - }, - root_dir = vim.fs.root(bufnr, ".git"), - } - end, -} diff --git a/config/native/lua/pde/lsp/configs/ltex_ls.lua b/config/native/lua/pde/lsp/configs/ltex_ls.lua deleted file mode 100644 index be08a7e..0000000 --- a/config/native/lua/pde/lsp/configs/ltex_ls.lua +++ /dev/null @@ -1,157 +0,0 @@ --- https://github.com/valentjn/ltex-ls - -local binaries = require("pde.binaries") -local paths = require("pde.paths") - -local dictionary = {} -local disabledRules = {} -local hiddenFalsePositives = {} - -local name = "ltex" -local current_language = "en-US" - ----@param path string ----@param lines string[] -local function append_to_file(path, lines) - local file = io.open(path, "a") - if file then - for _, line in ipairs(lines) do - file:write(line .. "\n") - end - file:close() - end -end - ----@param command lsp.Command ----@return boolean -local function validate_command(command) - if #command.arguments ~= 1 then - vim.notify("unexpected arguments: " .. vim.inspect(command.arguments), vim.log.levels.ERROR) - return false - end - - return true -end - ----@param path string file to read ----@param target string[] target to append the lines to -local function read_lines_into(path, target) - local file = io.open(path, "r") - if file then - for line in file:lines() do - table.insert(target, line) - end - - file:close() - end -end - ----@param command table ----@param key string ----@param tbl table ----@return table -local function handle_action(command, key, tbl) - if not validate_command(command) then return {} end - - local entries = command.arguments[1][key] - for lang, entry in pairs(entries) do - if not tbl[lang] then tbl[lang] = {} end - vim.list_extend(tbl[lang], entry) - end - return entries -end - -local update_client_with = function(changed_settings) - local client = vim.lsp.get_clients({ name = name })[1] - if not client then return end - client:notify("workspace/didChangeConfiguration", { settings = changed_settings }) -end - -local function get_dictionary_file(language) return paths.get_spellfile(vim.split(language, "-")[1]) end - -local function get_false_positives_file(language) - return paths.get_spellfile(nil) .. "/ltex_false-positives_" .. language .. ".txt" -end - -local function get_disabled_rules_file(language) - return paths.get_spellfile(nil) .. "/ltex_disabled-rules_" .. language .. ".txt" -end - -return { - ---@param bufnr integer - ---@return vim.lsp.ClientConfig - config = function(bufnr) - ---@type vim.lsp.ClientConfig - return { - name = name, - cmd = { binaries.ltex_ls() }, - before_init = function() - if not dictionary[current_language] then - dictionary[current_language] = {} - read_lines_into( - get_dictionary_file(current_language), - dictionary[current_language] - ) - end - - if not hiddenFalsePositives[current_language] then - hiddenFalsePositives[current_language] = {} - read_lines_into( - get_false_positives_file(current_language), - hiddenFalsePositives[current_language] - ) - end - - if not disabledRules[current_language] then - disabledRules[current_language] = {} - read_lines_into( - get_disabled_rules_file(current_language), - disabledRules[current_language] - ) - end - end, - settings = { - ltex = { - enabled = { "html", "markdown" }, - language = current_language, - checkFrequency = "save", - dictionary = dictionary, - disabledRules = disabledRules, - hiddenFalsePositives = hiddenFalsePositives, - }, - }, - root_dir = vim.fs.root(bufnr, ".git"), - on_attach = function(_, buf) - vim.api.nvim_buf_call(buf, function() vim.o.spell = false end) - -- TODO: buf_command for changing the language - end, - commands = { - ["_ltex.addToDictionary"] = function(command) - local new = handle_action(command, "words", dictionary) - update_client_with({ ltex = { dictionary = dictionary } }) - for lang, entries in pairs(new) do - local path = get_dictionary_file(lang) - append_to_file(path, entries) - end - vim.cmd("MkSpell") - end, - ["_ltex.hideFalsePositives"] = function(command) - local new = handle_action(command, "falsePositives", hiddenFalsePositives) - update_client_with({ ltex = { hiddenFalsePositives = hiddenFalsePositives } }) - for lang, entries in pairs(new) do - local path = get_false_positives_file(lang) - append_to_file(path, entries) - end - end, - ["_ltex.disableRules"] = function(command) - local new = handle_action(command, "ruleIds", disabledRules) - update_client_with({ ltex = { disabledRules = disabledRules } }) - for lang, entries in pairs(new) do - local path = get_disabled_rules_file(lang) - append_to_file(path, entries) - end - end, - }, - } - end, -} diff --git a/config/native/lua/pde/lsp/configs/lua_ls.lua b/config/native/lua/pde/lsp/configs/lua_ls.lua deleted file mode 100644 index 54c7a78..0000000 --- a/config/native/lua/pde/lsp/configs/lua_ls.lua +++ /dev/null @@ -1,33 +0,0 @@ --- https://github.com/LuaLS/lua-language-server -local binaries = require("pde.binaries") - -return { - ---@param bufnr integer - ---@return vim.lsp.ClientConfig - config = function(bufnr) - ---@type vim.lsp.ClientConfig - return { - name = "lua_ls", - cmd = { binaries.lua_ls() }, - on_init = function(client) - -- use stylua via efm, this formatter is not great and it clears diagnostic text on save - client.server_capabilities.documentFormattingProvider = nil - client.server_capabilities.documentRangeFormattingProvider = nil - end, - settings = { - Lua = { - addonManager = { enable = false }, - -- use stylua via efm, this formatter is not great and it clears diagnostic text on save - format = { enable = false }, - hint = { enable = true }, - runtime = { version = "LuaJIT" }, - telemetry = { enable = false }, - workspace = { - checkThirdParty = false, - }, - }, - }, - root_dir = vim.fs.root(bufnr, ".luarc.json") or vim.fs.root(0, { "lua", ".git" }), - } - end, -} diff --git a/config/native/lua/pde/lsp/configs/nixd.lua b/config/native/lua/pde/lsp/configs/nixd.lua deleted file mode 100644 index 12ed7dd..0000000 --- a/config/native/lua/pde/lsp/configs/nixd.lua +++ /dev/null @@ -1,23 +0,0 @@ --- https://github.com/nix-community/nixd - -local binaries = require("pde.binaries") - -return { - ---@param bufnr integer - ---@return vim.lsp.ClientConfig - config = function(bufnr) - ---@type vim.lsp.ClientConfig - return { - name = "nixd", - cmd = { binaries.nixd() }, - settings = { - nixd = { - formatting = { - command = { binaries.nixfmt() }, - }, - }, - }, - root_dir = vim.fs.root(bufnr, { "flake.nix", ".git" }), - } - end, -} diff --git a/config/native/lua/pde/lsp/configs/pyright.lua b/config/native/lua/pde/lsp/configs/pyright.lua deleted file mode 100644 index 61f82b7..0000000 --- a/config/native/lua/pde/lsp/configs/pyright.lua +++ /dev/null @@ -1,33 +0,0 @@ --- https://github.com/microsoft/pyright - -local binaries = require("pde.binaries") - -return { - ---@param bufnr integer - ---@return vim.lsp.ClientConfig - config = function(bufnr) - ---@type vim.lsp.ClientConfig - return { - name = "pyright", - cmd = { binaries.pyright(), "--stdio" }, - settings = { - python = { - analysis = { - autoSearchPaths = true, - useLibraryCodeForTypes = true, - diagnosticMode = "openFilesOnly", - }, - }, - }, - root_dir = vim.fs.root(bufnr, { - "pyproject.toml", - "setup.py", - "setup.cfg", - "requirements.txt", - "Pipfile", - "pyrightconfig.json", - ".git", - }), - } - end, -} diff --git a/config/native/lua/pde/lsp/configs/rust_analyzer.lua b/config/native/lua/pde/lsp/configs/rust_analyzer.lua deleted file mode 100644 index 4b7ea0f..0000000 --- a/config/native/lua/pde/lsp/configs/rust_analyzer.lua +++ /dev/null @@ -1,129 +0,0 @@ -local binaries = require("pde.binaries") -local runner = require("pde.runner") -local name = "rust_analyzer" - -local function reload_workspace(bufnr) - local clients = vim.lsp.get_clients({ name = name, bufnr = bufnr }) - for _, client in ipairs(clients) do - vim.notify("Reloading Cargo Workspace") - client:request("rust-analyzer/reloadWorkspace", nil, function(err) - if err then error(tostring(err)) end - vim.notify("Cargo workspace reloaded") - end, 0) - end -end - ----@param command lsp.Command ----@return boolean -local function validate_command(command) - if #command.arguments ~= 1 then - vim.notify("unexpected arguments: " .. vim.inspect(command.arguments), vim.log.levels.ERROR) - return false - end - - ---@type table - ---@diagnostic disable-next-line: assign-type-mismatch - local task = command.arguments[1] - if not task or task.kind ~= "cargo" then - vim.notify("unexpected kind: " .. vim.inspect(task), vim.log.levels.ERROR) - return false - end - - return true -end - ----@param command lsp.Command -local function runSingle(command) - if not validate_command(command) then return end - - ---@type table - ---@diagnostic disable-next-line: assign-type-mismatch - local task = command.arguments[1] - if not task then - vim.notify("no command arguments", vim.log.levels.ERROR) - return - end - local cmd = { - task.kind, - task.args.cargoArgs, - task.args.cargoExtraArgs, - } - if not vim.tbl_isempty(task.args.executableArgs) then - table.insert(cmd, { "--" }) - table.insert(cmd, task.args.executableArgs) - end - - local cwd = task.args.workspaceRoot - - runner.run(vim.iter(cmd):flatten():totable(), { cwd = cwd }) -end - -return { - ---@param bufnr integer - ---@return vim.lsp.ClientConfig - config = function(bufnr) - ---@type vim.lsp.ClientConfig - return { - name = name, - cmd = { binaries.rust_analyzer() }, - capabilities = { - experimental = { - serverStatusNotification = true, - }, - }, - settings = { - ["rust-analyzer"] = { - rustfmt = { - overrideCommand = { - binaries.rustfmt(), - "--edition", - "2021", - "--", - }, - }, - files = { - excludeDirs = { - "./.direnv/", - "./.git/", - "./.github/", - "./.gitlab/", - "./node_modules/", - "./ci/", - "./docs/", - }, - }, - checkOnSave = { - enable = true, - }, - diagnostics = { - enable = true, - experimental = { - enable = true, - }, - }, - }, - }, - commands = { - ["rust-analyzer.runSingle"] = runSingle, - }, - root_dir = vim.fs.root(bufnr, { "Cargo.toml", "rust-project.json" }), - on_attach = function(_, buf) - vim.api.nvim_buf_create_user_command( - buf, - "CargoReload", - function() reload_workspace(buf) end, - { desc = "[" .. name .. "] Reload current cargo workspace" } - ) - - vim.api.nvim_create_autocmd("LspDetach", { - group = vim.api.nvim_create_augroup( - "personal-lsp-" .. name .. "-buf-" .. buf, - { clear = true } - ), - buffer = buf, - callback = function() vim.api.nvim_buf_del_user_command(buf, "CargoReload") end, - }) - end, - } - end, -} diff --git a/config/native/lua/pde/lsp/configs/terraformls.lua b/config/native/lua/pde/lsp/configs/terraformls.lua deleted file mode 100644 index f261863..0000000 --- a/config/native/lua/pde/lsp/configs/terraformls.lua +++ /dev/null @@ -1,15 +0,0 @@ --- https://github.com/hashicorp/terraform-ls -local binaries = require("pde.binaries") - -return { - ---@param bufnr integer - ---@return vim.lsp.ClientConfig - config = function(bufnr) - ---@type vim.lsp.ClientConfig - return { - name = "terraform-ls", - cmd = { binaries.terraformls(), "serve" }, - root_dir = vim.fs.root(bufnr, { ".terraform", ".git" }), - } - end, -} diff --git a/config/native/lua/pde/lsp/configs/yamlls.lua b/config/native/lua/pde/lsp/configs/yamlls.lua deleted file mode 100644 index 644bc1d..0000000 --- a/config/native/lua/pde/lsp/configs/yamlls.lua +++ /dev/null @@ -1,46 +0,0 @@ --- https://github.com/redhat-developer/yaml-language-server -local binaries = require("pde.binaries") - -vim.cmd.packadd("SchemaStore.nvim") -local schemastore = require("schemastore") -local schemas = vim.tbl_extend("error", schemastore.yaml.schemas(), { - ["kubernetes"] = { "k8s/**/*.yml", "k8s/**/*.yaml" }, - -- or use: - -- # yaml-language-server: $schema= -}) - -return { - ---@param bufnr integer - ---@return vim.lsp.ClientConfig - config = function(bufnr) - ---@type vim.lsp.ClientConfig - return { - name = "yamlls", - cmd = { binaries.yamlls(), "--stdio" }, - settings = { - redhat = { - telemetry = { - enabled = false, - }, - }, - yaml = { - format = { - enable = false, -- use prettier instead - }, - completion = true, - hover = true, - validate = true, - schemas = schemas, - schemaStore = { - -- we use above - enable = false, - -- https://github.com/dmitmel/dotfiles/blob/master/nvim/dotfiles/lspconfigs/yaml.lua - -- yamlls won't work if we disable schemaStore but don't specify url ¯\_(ツ)_/¯ - url = "", - }, - }, - }, - root_dir = vim.fs.root(bufnr, ".git"), - } - end, -} diff --git a/config/native/lua/pde/lsp/configs/zls.lua b/config/native/lua/pde/lsp/configs/zls.lua deleted file mode 100644 index 62355be..0000000 --- a/config/native/lua/pde/lsp/configs/zls.lua +++ /dev/null @@ -1,15 +0,0 @@ --- https://github.com/zigtools/zls -local binaries = require("pde.binaries") - -return { - ---@param bufnr integer - ---@return vim.lsp.ClientConfig - config = function(bufnr) - ---@type vim.lsp.ClientConfig - return { - name = "zls", - cmd = { binaries.zls() }, - root_dir = vim.fs.root(bufnr, { "zls.json", ".git" }), - } - end, -} diff --git a/config/native/lua/pde/lsp/init.lua b/config/native/lua/pde/lsp/init.lua index e8a7807..a69cadc 100644 --- a/config/native/lua/pde/lsp/init.lua +++ b/config/native/lua/pde/lsp/init.lua @@ -1,46 +1,11 @@ -local autostart_enabled = true - ----useful for example when deciding if to attach LSP client to that buffer ----@param bufnr integer buffer to check. 0 for current ----@return boolean true if the buffer represents a real, readable file -local function is_buf_readable_file(bufnr) - local bufname = vim.api.nvim_buf_get_name(bufnr) - return vim.fn.filereadable(bufname) == 1 -end - local M = {} -M.toggle_autostart = function() autostart_enabled = not autostart_enabled end - -function M.is_autostart_enabled() return autostart_enabled end - ----Same arguments as vim.lsp.start ---- @param config vim.lsp.ClientConfig Configuration for the server. ---- @param opts vim.lsp.start.Opts? Optional keyword arguments ---- @return integer? client_id -function M.start(config, opts) - if not autostart_enabled then - vim.notify_once("LSP autostart is disabled", vim.log.levels.INFO) - return - end - - opts = opts or {} - opts.bufnr = opts.bufnr or vim.api.nvim_get_current_buf() - - if not is_buf_readable_file(opts.bufnr) then return end - - local made_config = require("pde.lsp.capabilities").merge_capabilities(config) +---@class LspConfig +---@field enabled_configs string[] list of config names from {rtp}/lsp/*.lua - if not made_config.root_dir then made_config.root_dir = vim.uv.os_tmpdir() end - - local client_id = vim.lsp.start(made_config, opts) - if not client_id then - vim.notify("cannot start lsp: " .. made_config.cmd[1], vim.log.levels.WARN) - end - return client_id -end - -function M.initialize_once() +---Initialize lsp configurations +---@param config LspConfig +function M.setup(config) require("pde.lsp.commands") require("pde.lsp.progress") @@ -71,6 +36,16 @@ function M.initialize_once() end end, }) + + vim.lsp.config("*", { + root_markers = { + ".git", + }, + }) + + for _, name in ipairs(config.enabled_configs or {}) do + vim.lsp.enable(name, true) + end end return M diff --git a/config/native/plugin/lsp.lua b/config/native/plugin/lsp.lua index 63ab722..292593d 100644 --- a/config/native/plugin/lsp.lua +++ b/config/native/plugin/lsp.lua @@ -1 +1,22 @@ -require("pde.lsp").initialize_once() +require("pde.lsp").setup({ + enabled_configs = { + "clangd", + "efmson", + "gopls", + "golangci_lint", + "gopls", + "jsonls", + "ltex", + "lua_ls", + "nixd", + "prettier", + "pyright", + "rust_analyzer", + "sh", + "stylua", + "taplo", + "terraform-ls", + "yamlls", + "zls", + }, +}) diff --git a/flake/packages/plugins.nix b/flake/packages/plugins.nix index c21df00..e80ec50 100644 --- a/flake/packages/plugins.nix +++ b/flake/packages/plugins.nix @@ -208,10 +208,7 @@ in ]; } # LSP - { - plugin = SchemaStore-nvim; - optional = true; - } + SchemaStore-nvim { plugin = roslyn-nvim; optional = true; @@ -219,21 +216,17 @@ in # DAP { plugin = nvim-dap; - optional = true; deps = [ { plugin = nvim-dap-ui; - optional = true; deps = [ { plugin = nvim-nio; - optional = true; } ]; } { plugin = nvim-dap-virtual-text; - optional = true; } ]; }