Skip to content

Commit b72ba2e

Browse files
committed
plugins/lsp/servers: replace rootDir with rootMarkers
nvim-lspconfig historically used `root_dir`, along with util functions like `root_pattern`. Now that neovim's own LSP API is used, `root_dir` appears to be subtly different and `root_markers` is introduced to replace `util.root_pattern`. Since we cannot easily warn about the `root_dir` differences, it can usually be replaced with `root_markers`, and can still be manually configured via `extraOptions` if needed; the simplest approach here is to remove the `rootDir` option.
1 parent a21504f commit b72ba2e

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

plugins/lsp/language-servers/_mk-lsp.nix

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,16 @@ in
106106
`:LspStart` (|lspconfig-commands|).
107107
'';
108108

109-
rootDir = lib.nixvim.defaultNullOpts.mkLuaFn "nil" ''
110-
A function (or function handle) which returns the root of the project used to
111-
determine if lspconfig should launch a new language server, or attach a previously
112-
launched server when you open a new buffer matching the filetype of the server.
109+
rootMarkers = lib.nixvim.defaultNullOpts.mkListOf types.str null ''
110+
A list of files that mark the root of the project/workspace.
111+
112+
Vim's LSP will try to share the same language server instance for all
113+
buffers matching `filetypes` within the same project.
114+
115+
A new server instance is only spawned when opening a buffer with a
116+
different project root.
117+
118+
See `:h lsp-config` and `:h vim.fs.root()`.
113119
'';
114120

115121
onAttach = lib.nixvim.mkCompositeOption "Server specific on_attach behavior." {
@@ -149,7 +155,7 @@ in
149155
name = serverName;
150156
extraOptions = {
151157
inherit (cfg) cmd filetypes autostart;
152-
root_dir = cfg.rootDir;
158+
root_markers = cfg.rootMarkers;
153159
on_attach = lib.nixvim.ifNonNull' cfg.onAttach (
154160
lib.nixvim.mkRaw ''
155161
function(client, bufnr)
@@ -183,6 +189,13 @@ in
183189
(lib.mkRemovedOptionModule (
184190
basePluginPath ++ [ "extraSettings" ]
185191
) "You can use `${basePluginPathString}.extraOptions.settings` instead.")
192+
(lib.mkRemovedOptionModule (basePluginPath ++ [ "rootDir" ]) ''
193+
194+
nvim-lspconfig has switched from its own `root_dir` implementation to using neovim's built-in LSP API.
195+
196+
In most cases you can use `${opts.rootMarkers}` instead. It should be a list of files that mark the root of the project.
197+
In more complex cases you can still use `${opts.extraOptions}.root_dir`.
198+
'')
186199
]
187200
++ lib.optional (args ? extraConfig) (
188201
lib.nixvim.plugins.utils.applyExtraConfig {

tests/test-sources/plugins/lsp/_lsp.nix

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,13 @@
8484
filetypes = [ "python" ];
8585
autostart = false;
8686
};
87-
# rootDir
87+
# rootMarkers
8888
tinymist = {
8989
enable = true;
90-
rootDir = ''
91-
require 'lspconfig.util'.root_pattern('.git', 'main.typ')
92-
'';
90+
rootMarkers = [
91+
".git"
92+
"main.typ"
93+
];
9394
};
9495
};
9596
};

0 commit comments

Comments
 (0)