From 894b7ff175ba874aa19b3dfb080e46000f0e768d Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 27 Jun 2024 17:22:03 +0200 Subject: [PATCH] nvim: Disable marksman lsp in zk notebook directories When a `.zk` directory is found in the current root directory of the marksman project, the lsp is disabled. This is because zk delivers its own lsp server with correct following of note ids instead of full file names which marksman expects and fails to find. --- nvim/.config/nvim/lua/plugins/config/lsp.lua | 23 +++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/nvim/.config/nvim/lua/plugins/config/lsp.lua b/nvim/.config/nvim/lua/plugins/config/lsp.lua index d81fb37..b4e3236 100644 --- a/nvim/.config/nvim/lua/plugins/config/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/config/lsp.lua @@ -35,9 +35,7 @@ local servers = { }, }, }, - marksman = { - filetypes = { "markdown", "quarto" }, - }, + marksman = {}, basedpyright = {}, ruff = {}, serve_d = {}, @@ -157,6 +155,25 @@ lsp.setup({ local lspconfig = require("lspconfig") lspconfig.nushell.setup({}) +lspconfig.marksman.setup({ + filetypes = { "markdown", "quarto" }, + on_attach = function(client, bufnr) + -- TODO: for some reason this is always true even though it shouldn't be + if client.config.in_zk_notebook then + vim.defer_fn(function() + vim.lsp.buf_detach_client(bufnr, client.id) + end, 1000) + 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 lspconfig.basedpyright.setup({