From 51afeda8e592a29b08b98e86b0e4e29d7eb7d5a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=A9tan=20Lepage?= <33058747+GaetanLepage@users.noreply.github.com> Date: Thu, 25 May 2023 19:41:18 +0200 Subject: [PATCH] plugins/nvim-lsp: add rootDir option for language servers (#387) --- plugins/lsp/helpers.nix | 9 +++++++++ tests/test-sources/plugins/lsp/nvim-lsp.nix | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/plugins/lsp/helpers.nix b/plugins/lsp/helpers.nix index 402fe068..8575e2c1 100644 --- a/plugins/lsp/helpers.nix +++ b/plugins/lsp/helpers.nix @@ -67,6 +67,12 @@ `:LspStart` (|lspconfig-commands|). ''; + rootDir = helpers.mkNullOrOption types.str '' + A function (or function handle) which returns the root of the project used to + determine if lspconfig should launch a new language server, or attach a previously + launched server when you open a new buffer matching the filetype of the server. + ''; + onAttach = helpers.mkCompositeOption "Server specific on_attach behavior." { @@ -123,6 +129,9 @@ extraOptions = { inherit (cfg) cmd filetypes autostart; + root_dir = + helpers.ifNonNull' cfg.rootDir + (helpers.mkRaw cfg.rootDir); on_attach = helpers.ifNonNull' cfg.onAttach ( diff --git a/tests/test-sources/plugins/lsp/nvim-lsp.nix b/tests/test-sources/plugins/lsp/nvim-lsp.nix index f73ba5f2..4b2b38c3 100644 --- a/tests/test-sources/plugins/lsp/nvim-lsp.nix +++ b/tests/test-sources/plugins/lsp/nvim-lsp.nix @@ -49,6 +49,13 @@ filetypes = ["python"]; autostart = false; }; + # rootDir + typst-lsp = { + enable = true; + rootDir = '' + require 'lspconfig.util'.root_pattern('.git', 'main.typ') + ''; + }; }; }; };