mirror of
https://github.com/neovim/neovim.git
synced 2025-10-14 05:46:12 +00:00
feat(lsp): root_markers
can control priority
Problem: root_markers cannot specify "equal priority filenames. Solution: Support nesting: { ... root_markers = { { ".stylua.toml", ".luarc.json" }, { ".git "} } ... } Co-authored-by: Maria José Solano <majosolano99@gmail.com> Co-authored-by: Gregory Anders <github@gpanders.com> Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
This commit is contained in:

committed by
Justin M. Keyes

parent
9dfb429e93
commit
533ec6d492
@@ -41,7 +41,8 @@ Follow these steps to get LSP features:
|
||||
-- current buffer that contains either a ".luarc.json" or a
|
||||
-- ".luarc.jsonc" file. Files that share a root directory will reuse
|
||||
-- the connection to the same LSP server.
|
||||
root_markers = { '.luarc.json', '.luarc.jsonc' },
|
||||
-- Nested lists indicate equal priority, see |vim.lsp.Config|.
|
||||
root_markers = { { '.luarc.json', '.luarc.jsonc' }, '.git' },
|
||||
|
||||
-- Specific settings to send to the server. The schema for this is
|
||||
-- defined by the server. For example the schema for lua-language-server
|
||||
@@ -721,9 +722,37 @@ Lua module: vim.lsp *lsp-core*
|
||||
the buffer. Thus a `root_dir()` function can
|
||||
dynamically decide per-buffer whether to activate (or
|
||||
skip) LSP. See example at |vim.lsp.enable()|.
|
||||
• {root_markers}? (`string[]`) Directory markers (e.g. ".git/",
|
||||
"package.json") used to decide `root_dir`. Unused if
|
||||
`root_dir` is provided.
|
||||
• {root_markers}? (`(string|string[])[]`) Directory markers (.e.g.
|
||||
'.git/') where the LSP server will base its
|
||||
workspaceFolders, rootUri, and rootPath on
|
||||
initialization. Unused if `root_dir` is provided.
|
||||
|
||||
The list order decides the priority. To indicate
|
||||
"equal priority", specify names in a nested list
|
||||
(`{ { 'a', 'b' }, ... }`) Each entry in this list is
|
||||
a set of one or more markers. For each set, Nvim will
|
||||
search upwards for each marker contained in the set.
|
||||
If a marker is found, the directory which contains
|
||||
that marker is used as the root directory. If no
|
||||
markers from the set are found, the process is
|
||||
repeated with the next set in the list.
|
||||
|
||||
Example: >lua
|
||||
root_markers = { 'stylua.toml', '.git' }
|
||||
<
|
||||
|
||||
Find the first parent directory containing the file
|
||||
`stylua.toml`. If not found, find the first parent
|
||||
directory containing the file or directory `.git`.
|
||||
|
||||
Example: >lua
|
||||
root_markers = { { 'stylua.toml', '.luarc.json' }, '.git' }
|
||||
<
|
||||
|
||||
Find the first parent directory containing EITHER
|
||||
`stylua.toml` or `.luarc.json`. If not found, find
|
||||
the first parent directory containing the file or
|
||||
directory `.git`.
|
||||
|
||||
|
||||
buf_attach_client({bufnr}, {client_id}) *vim.lsp.buf_attach_client()*
|
||||
|
@@ -277,6 +277,7 @@ LSP
|
||||
• The `textDocument/completion` request now includes the completion context in
|
||||
its parameters.
|
||||
• |vim.lsp.Config| gained `workspace_required`.
|
||||
• `root_markers` in |vim.lsp.Config| can now be ordered by priority.
|
||||
|
||||
LUA
|
||||
|
||||
|
@@ -292,9 +292,37 @@ end
|
||||
--- example at |vim.lsp.enable()|.
|
||||
--- @field root_dir? string|fun(bufnr: integer, on_dir:fun(root_dir?:string))
|
||||
---
|
||||
--- Directory markers (e.g. ".git/", "package.json") used to decide `root_dir`. Unused if `root_dir`
|
||||
--- is provided.
|
||||
--- @field root_markers? string[]
|
||||
--- Directory markers (.e.g. '.git/') where the LSP server will base its workspaceFolders,
|
||||
--- rootUri, and rootPath on initialization. Unused if `root_dir` is provided.
|
||||
---
|
||||
--- The list order decides the priority. To indicate "equal priority", specify names in a nested list (`{ { 'a', 'b' }, ... }`)
|
||||
--- Each entry in this list is a set of one or more markers. For each set, Nvim
|
||||
--- will search upwards for each marker contained in the set. If a marker is
|
||||
--- found, the directory which contains that marker is used as the root
|
||||
--- directory. If no markers from the set are found, the process is repeated
|
||||
--- with the next set in the list.
|
||||
---
|
||||
--- Example:
|
||||
---
|
||||
--- ```lua
|
||||
--- root_markers = { 'stylua.toml', '.git' }
|
||||
--- ```
|
||||
---
|
||||
--- Find the first parent directory containing the file `stylua.toml`. If not
|
||||
--- found, find the first parent directory containing the file or directory
|
||||
--- `.git`.
|
||||
---
|
||||
--- Example:
|
||||
---
|
||||
--- ```lua
|
||||
--- root_markers = { { 'stylua.toml', '.luarc.json' }, '.git' }
|
||||
--- ```
|
||||
---
|
||||
--- Find the first parent directory containing EITHER `stylua.toml` or
|
||||
--- `.luarc.json`. If not found, find the first parent directory containing the
|
||||
--- file or directory `.git`.
|
||||
---
|
||||
--- @field root_markers? (string|string[])[]
|
||||
|
||||
--- Update the configuration for an LSP client.
|
||||
---
|
||||
@@ -593,7 +621,7 @@ end
|
||||
--- Suppress error reporting if the LSP server fails to start (default false).
|
||||
--- @field silent? boolean
|
||||
---
|
||||
--- @field package _root_markers? string[]
|
||||
--- @field package _root_markers? (string|string[])[]
|
||||
|
||||
--- Create a new LSP client and start a language server or reuses an already
|
||||
--- running client if one is found matching `name` and `root_dir`.
|
||||
@@ -640,8 +668,16 @@ function lsp.start(config, opts)
|
||||
local bufnr = vim._resolve_bufnr(opts.bufnr)
|
||||
|
||||
if not config.root_dir and opts._root_markers then
|
||||
validate('root_markers', opts._root_markers, 'table')
|
||||
config = vim.deepcopy(config)
|
||||
config.root_dir = vim.fs.root(bufnr, opts._root_markers)
|
||||
|
||||
for _, marker in ipairs(opts._root_markers) do
|
||||
local root = vim.fs.root(bufnr, marker)
|
||||
if root ~= nil then
|
||||
config.root_dir = root
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if
|
||||
|
Reference in New Issue
Block a user