Compare commits

...

4 commits

Author SHA1 Message Date
6435a7b51a
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.
2025-06-10 18:31:41 +02:00
99098f56a1
nvim: Move typescript and vue LSP config into lsp dir 2025-06-10 18:31:40 +02:00
bb6f401ff3
nvim: Move arduino LSP config into lsp dir
Also ensure that clangd and arduino-cli are installed since the lsp
otherwise won't work.
2025-06-10 18:31:39 +02:00
07e820ac00
nvim: Move ruff/pyright lsp settings into after/lsp/ dir 2025-06-10 18:31:39 +02:00
7 changed files with 94 additions and 110 deletions

View file

@ -0,0 +1,3 @@
return {
on_new_config = require("arduino").on_new_config,
}

View file

@ -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 = { "*" },
},
},
},
}

View file

@ -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,
}

View file

@ -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,
}

View file

@ -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 {}

View file

@ -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 = {} },

View file

@ -87,115 +87,9 @@ 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,
})
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", {
on_new_config = require("arduino").on_new_config,
})
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" },
})
-- arduino lsp only works if arduino-cli is installed
if vim.fn.executable("arduino-cli") == 1 then
register("arduino_language_server")
end
-- attach ltex for fitting ft only when spell checking becomes enabled