From 07e820ac00060ee328504da94f281ce9fe9c7c30 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 10 Jun 2025 14:55:45 +0200 Subject: [PATCH 1/4] nvim: Move ruff/pyright lsp settings into after/lsp/ dir --- nvim/.config/nvim/after/lsp/basedpyright.lua | 22 ++++++++++++ nvim/.config/nvim/after/lsp/ruff.lua | 9 +++++ nvim/.config/nvim/lua/plugins/lsp.lua | 37 -------------------- 3 files changed, 31 insertions(+), 37 deletions(-) create mode 100644 nvim/.config/nvim/after/lsp/basedpyright.lua create mode 100644 nvim/.config/nvim/after/lsp/ruff.lua diff --git a/nvim/.config/nvim/after/lsp/basedpyright.lua b/nvim/.config/nvim/after/lsp/basedpyright.lua new file mode 100644 index 0000000..84d1033 --- /dev/null +++ b/nvim/.config/nvim/after/lsp/basedpyright.lua @@ -0,0 +1,22 @@ +-- ensure python virtualenv is determined automatically on lsp start +-- we primarily use pyright for cmp lsp completion & hover info +return { + on_attach = function(client, _) + require("core.util").set_python_env() + local python_path, _ = vim.fn.expand(require("core.util").get_python_venv_bin(client.config.root_dir)) + client.config.settings.python = {} or client.config.settings.python + client.config.settings.python.pythonPath = python_path + end, + settings = { + -- disable imports and linting since, using ruff for it + pyright = { + disableOrganizeImports = true, + }, + python = { + analysis = { + -- ignore all files, use ruff for linting + ignore = { "*" }, + }, + }, + }, +} diff --git a/nvim/.config/nvim/after/lsp/ruff.lua b/nvim/.config/nvim/after/lsp/ruff.lua new file mode 100644 index 0000000..b3fbdb6 --- /dev/null +++ b/nvim/.config/nvim/after/lsp/ruff.lua @@ -0,0 +1,9 @@ +return { + on_attach = function(client, _) + require("core.util").set_python_env() + client.server_capabilities.hoverProvider = false -- we use pyright for hover info + local python_path, _ = vim.fn.expand(require("core.util").get_python_venv_bin(client.config.root_dir)) + client.config.settings.python = {} or client.config.settings.python + client.config.settings.python.pythonPath = python_path + end, +} diff --git a/nvim/.config/nvim/lua/plugins/lsp.lua b/nvim/.config/nvim/lua/plugins/lsp.lua index 3f6151b..291cdb6 100644 --- a/nvim/.config/nvim/lua/plugins/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/lsp.lua @@ -137,43 +137,6 @@ local lsp = { end, }) - local python_path - -- ensure python virtualenv is determined automatically on lsp start - -- we primarily use pyright for cmp lsp completion & hover info - register("basedpyright", { - on_attach = function(client, _) - require("core.util").set_python_env() - if python_path == nil then - python_path, _ = vim.fn.expand(require("core.util").get_python_venv_bin(client.config.root_dir)) - end - client.config.settings.python = {} or client.config.settings.python - client.config.settings.python.pythonPath = python_path - end, - settings = { - -- disable imports and linting since, using ruff for it - pyright = { - disableOrganizeImports = true, - }, - python = { - analysis = { - -- ignore all files, use ruff for linting - ignore = { "*" }, - }, - }, - }, - }) - register("ruff", { - on_attach = function(client, _) - require("core.util").set_python_env() - client.server_capabilities.hoverProvider = false -- we use pyright for hover info - if python_path == nil then - python_path, _ = vim.fn.expand(require("core.util").get_python_venv_bin(client.config.root_dir)) - end - client.config.settings.python = {} or client.config.settings.python - client.config.settings.python.pythonPath = python_path - end, - }) - -- set up arduino with the help of arduino.nvim plugin if require("core.util").is_available("arduino") then register("arduino_language_server", { From bb6f401ff3540ed361f4c63202ef2e29f3013d34 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 10 Jun 2025 15:28:30 +0200 Subject: [PATCH 2/4] nvim: Move arduino LSP config into lsp dir Also ensure that clangd and arduino-cli are installed since the lsp otherwise won't work. --- nvim/.config/nvim/after/lsp/arduino.lua | 3 +++ nvim/.config/nvim/lua/core/languages.lua | 2 +- nvim/.config/nvim/lua/plugins/lsp.lua | 8 +++----- 3 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 nvim/.config/nvim/after/lsp/arduino.lua diff --git a/nvim/.config/nvim/after/lsp/arduino.lua b/nvim/.config/nvim/after/lsp/arduino.lua new file mode 100644 index 0000000..70ca6ab --- /dev/null +++ b/nvim/.config/nvim/after/lsp/arduino.lua @@ -0,0 +1,3 @@ +return { + on_new_config = require("arduino").on_new_config, +} diff --git a/nvim/.config/nvim/lua/core/languages.lua b/nvim/.config/nvim/lua/core/languages.lua index fb32cd4..8fa0595 100644 --- a/nvim/.config/nvim/lua/core/languages.lua +++ b/nvim/.config/nvim/lua/core/languages.lua @@ -26,7 +26,7 @@ local function mason_dir() end local languages = { - arduino = { lsp = { arduino_language_server = {} }, ts = { "arduino" } }, + arduino = { lsp = { clangd = {}, arduino_language_server = { disable = true } }, ts = { "arduino" } }, awk = { ts = { "awk" }, format = { awk = { "gawk" } } }, astro = { lsp = { astro = {} }, diff --git a/nvim/.config/nvim/lua/plugins/lsp.lua b/nvim/.config/nvim/lua/plugins/lsp.lua index 291cdb6..0fec760 100644 --- a/nvim/.config/nvim/lua/plugins/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/lsp.lua @@ -137,11 +137,9 @@ local lsp = { end, }) - -- set up arduino with the help of arduino.nvim plugin - if require("core.util").is_available("arduino") then - register("arduino_language_server", { - on_new_config = require("arduino").on_new_config, - }) + -- arduino lsp only works if arduino-cli is installed + if vim.fn.executable("arduino-cli") == 1 then + register("arduino_language_server") end if vim.lsp.is_enabled("vue_ls") then From 99098f56a1dcd7d604a812ca35b37b7a3dcccbea Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 10 Jun 2025 15:51:28 +0200 Subject: [PATCH 3/4] nvim: Move typescript and vue LSP config into lsp dir --- nvim/.config/nvim/after/lsp/vue_ls.lua | 17 +++++++++++++++++ nvim/.config/nvim/lua/plugins/lsp.lua | 17 ----------------- 2 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 nvim/.config/nvim/after/lsp/vue_ls.lua diff --git a/nvim/.config/nvim/after/lsp/vue_ls.lua b/nvim/.config/nvim/after/lsp/vue_ls.lua new file mode 100644 index 0000000..0c42edd --- /dev/null +++ b/nvim/.config/nvim/after/lsp/vue_ls.lua @@ -0,0 +1,17 @@ +-- we have to set up ts server with an additional vue plugin +vim.lsp.config("ts_ls", { + init_options = { + plugins = { + { + name = "@vue/typescript-plugin", + location = vim.fn.expand("$MASON/packages") + .. "/vue-language-server" + .. "/node_modules/@vue/language-server", + languages = { "vue" }, + }, + }, + }, + filetypes = { "typescript", "javascript", "javascriptreact", "typescriptsreact", "vue" }, +}) + +return {} diff --git a/nvim/.config/nvim/lua/plugins/lsp.lua b/nvim/.config/nvim/lua/plugins/lsp.lua index 0fec760..27086e1 100644 --- a/nvim/.config/nvim/lua/plugins/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/lsp.lua @@ -142,23 +142,6 @@ local lsp = { register("arduino_language_server") end - if vim.lsp.is_enabled("vue_ls") then - register("ts_ls", { - init_options = { - plugins = { - { - name = "@vue/typescript-plugin", - location = vim.fn.expand("$MASON/packages") - .. "/vue-language-server" - .. "/node_modules/@vue/language-server", - languages = { "vue" }, - }, - }, - }, - filetypes = { "typescript", "javascript", "javascriptreact", "typescriptsreact", "vue" }, - }) - end - -- attach ltex for fitting ft only when spell checking becomes enabled vim.api.nvim_create_autocmd("User", { pattern = "SpellEnable", From 6435a7b51aaf5369bec383c83b08cc1420445d98 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 10 Jun 2025 16:18:34 +0200 Subject: [PATCH 4/4] nvim: Improve marksman diagnostic filtering in zk dirs When in a ZK dir I do not want any marksman diagnostics polluting my interface since the linking in (my) ZK is based on anchor IDs and not full filenames/titles. Thus, every single link will be detected as non-existent by marksman. This commit ensures that when in a zk-enabled directory, each non-existent link diagnostic will be filtered before presenting diagnostics. --- nvim/.config/nvim/after/lsp/marksman.lua | 39 ++++++++++++++++++ nvim/.config/nvim/lua/plugins/lsp.lua | 50 ------------------------ 2 files changed, 39 insertions(+), 50 deletions(-) create mode 100644 nvim/.config/nvim/after/lsp/marksman.lua diff --git a/nvim/.config/nvim/after/lsp/marksman.lua b/nvim/.config/nvim/after/lsp/marksman.lua new file mode 100644 index 0000000..cece8ba --- /dev/null +++ b/nvim/.config/nvim/after/lsp/marksman.lua @@ -0,0 +1,39 @@ +local util = require("lspconfig.util") + +local function filter_marksman_diagnostics(diagnostic) + -- code == 2 filters all 'non-existent link' diagnostics + if diagnostic.source == "marksman" and diagnostic.code == 2 then + return false + end + return true +end + +local function handle_diagnostics(err, result, _) + result.diagnostics = vim.tbl_filter(filter_marksman_diagnostics, result.diagnostics) + return result, err +end + +return { + filetypes = { "markdown", "quarto", "djot" }, + on_attach = function(client, bufnr) + local fname = vim.api.nvim_buf_get_name(bufnr) + local is_zk_root_dir = util.root_pattern(".zk") + + -- turn off diagnostics if we are in a ZK directory + if is_zk_root_dir(fname) then + client.capabilities.completionProvider = false + client.capabilities.hoverProvider = false + client.capabilities.publishDiagnostics = false + client.capabilities.diagnostic = false + local namespace = vim.lsp.diagnostic.get_namespace(client.id) + + -- hides diagnostics from displaying in buffer + vim.diagnostic.enable(false, { ns_id = namespace, bufnr = bufnr }) + vim.diagnostic.get() + + -- actually removes all marksman diagnostics + client["handlers"] = client.handlers or {} + client.handlers["textDocument/publishDiagnostics"] = handle_diagnostics + end + end, +} diff --git a/nvim/.config/nvim/lua/plugins/lsp.lua b/nvim/.config/nvim/lua/plugins/lsp.lua index 27086e1..5d0a9d3 100644 --- a/nvim/.config/nvim/lua/plugins/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/lsp.lua @@ -87,56 +87,6 @@ local lsp = { register("nushell") end - register("marksman", { - filetypes = { "markdown", "quarto" }, - on_attach = function(client, _) - -- TODO: for some reason this stays true even after rootdir switch? - if client.config.in_zk_notebook then - local default_handler = vim.diagnostic.handlers.virtual_text - vim.diagnostic.handlers.virtual_text = { - show = function(namespace, bufnrr, diagnostics, opts) - for i, diagnostic in ipairs(diagnostics) do - if - diagnostic.source - == "Marksman" -- You need to check what the correct value should be here - then - table.remove(diagnostics, i) - end - end - default_handler.show(namespace, bufnrr, diagnostics, opts) - end, - hide = function(...) - default_handler.hide(...) - end, - } - default_handler = vim.diagnostic.handlers.signs - vim.diagnostic.handlers.signs = { - show = function(namespace, bufnrr, diagnostics, opts) - for i, diagnostic in ipairs(diagnostics) do - if - diagnostic.source - == "Marksman" -- You need to check what the correct value should be here - then - table.remove(diagnostics, i) - end - end - default_handler.show(namespace, bufnrr, diagnostics, opts) - end, - hide = function(...) - default_handler.hide(...) - end, - } - end - end, - on_new_config = function(conf, new_root) - if require("lspconfig.util").root_pattern(".zk")(new_root) then - conf.in_zk_notebook = true - else - conf.in_zk_notebook = false - end - end, - }) - -- arduino lsp only works if arduino-cli is installed if vim.fn.executable("arduino-cli") == 1 then register("arduino_language_server")