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")