Nvim-lspconfig: Get root directory

Created on 14 Aug 2020  路  7Comments  路  Source: neovim/nvim-lspconfig

Is there a way to query what the LSP detects as the root directory? I can't seem to find one.

Most helpful comment

@himansingh241 you're misunderstanding him. He's asking how query for the _calculated value_ of root_dir, not how to set it.

So for example, given this:

nvim_lsp.clangd.setup {
  root_dir = nvim_lsp.util.root_pattern('foo', 'bar', 'baz')
}

What's the value of root_dir when the language server starts in some directory X?

All 7 comments

There's a root_dir parameter with most of the language servers that you can set to detect root directory.

What would be the syntax to query that? Like with clangd or rust analyzer for example if it's specific to each LS.

I have an understanding of how to set the root directory but I'm still unclear on how to query its value.

You can do something like this :

local nvim_lsp = require'nvim_lsp'
nvim_lsp.clangd.setup{
  root_dir = nvim_lsp.util.root_pattern('.git');
}

@himansingh241 you're misunderstanding him. He's asking how query for the _calculated value_ of root_dir, not how to set it.

So for example, given this:

nvim_lsp.clangd.setup {
  root_dir = nvim_lsp.util.root_pattern('foo', 'bar', 'baz')
}

What's the value of root_dir when the language server starts in some directory X?

I had the same issue. Solved it with #363.

you could use checkhealth with this branch https://github.com/neovim/neovim/pull/12578

@Kyle-Thompson Technically this is exposed via :help vim.lsp.buf.list_workspace_folders() which stores the first root directory on server intitialization by default

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mjlbach picture mjlbach  路  8Comments

justinmk picture justinmk  路  7Comments

nomasprime picture nomasprime  路  5Comments

ahmedelgabri picture ahmedelgabri  路  4Comments

mcepl picture mcepl  路  8Comments