-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(config): Allow overriding the root_dir #402
Conversation
Review ChecklistDoes this PR follow the Contribution Guidelines? Following is a partial checklist: Proper conventional commit scoping:
If applicable:
|
Hey 👋 Thanks for the PR 🙏
🤔 Is it possible to override the If the lua-ls linter complains, it ought to be possible to disable the warning for the next line (I do that in some places). |
Thanks for taking a look. I've updated the PR. Renaming Type checks pass with
I don't think we should accept a simple string for this value (instead of a function), as (outside of contrived tests like I'm running) you'd never want a fixed value for the |
Thanks for the thorough and thoughtful review. I'll revise this PR with the suggested changes soon. |
I'm working in a repository with git submodules, which leads to nested cargo workspaces. When working in the top-level repository, I always want rust-analyzer to use the top-level repository as the root, so that I don't end up with multiple overlapping instances of rust-analyzer. This is a niche use-case, but it would be nice to have a way to override the default behavior. This is loosely modeled after nvim-lspconfig's `root_dir` option: https://github.com/neovim/nvim-lspconfig/blob/94513a5b246cf32a8f87ca714af50911df63351c/CONTRIBUTING.md#adding-a-server-to-lspconfig - **Why `get_root_dir` and not `root_dir`?** `RustaceanLspClientConfig` is a subtype of `vim.lsp.ClientConfig`. This is taken advantage of when constructing the config for each individual client. The `vim.lsp.ClientConfig` type has a conflicting `root_dir` field that's typed as a string (not a function). - **Why does it not take `bufnr`, like nvim-lspconfig's API?** There's no way to get the `bufnr` value in the neotest adapter. It's also probably not needed in most cases.
- Add a validator to config/check.lua - Accept a string for `root_dir` - Don't mention the default implementation as the private `rustaceanvim.cargo.get_root_dir` function. - Pass an extra "default" argument with the default implementation. - Update documentation/comments where relevant.
I've updated the PR with the suggested changes! Let me know if there's any further changes I should make. |
Thanks again 🙏 |
I'm working in a repository with git submodules. Each submodule has a
Cargo.toml
with a workspace definition. The parent repository's workspace is a carefully-configured superset of all of the the child repository workspaces.When working in the top-level repository, I always want rust-analyzer to use the top-level repository as the root, so that I don't end up with multiple overlapping instances of rust-analyzer.
Cargo doesn't really support nested workspaces, and its default behavior is to find the nearest/innermost workspace, which is not what I want.
This is a niche use-case, but it would be nice to have a way to override the default behavior.
This is loosely modeled after
nvim-lspconfig
'sroot_dir
option: https://github.com/neovim/nvim-lspconfig/blob/94513a5b246cf32a8f87ca714af50911df63351c/CONTRIBUTING.md#adding-a-server-to-lspconfigWhy
get_root_dir
and notroot_dir
?RustaceanLspClientConfig
is a subtype ofvim.lsp.ClientConfig
. Thevim.lsp.ClientConfig
type has a conflictingroot_dir
field that's typed as a string (not a function).Why does it not also take
bufnr
, like nvim-lspconfig's API? There's no way to get thebufnr
value in the neotest adapter. It's also probably not needed in most cases.Testing
Run tests:
Configure a
get_root_dir
function to return a hardcoded value, and inspect the results with:LspInfo
.Configure neotest, and use the neotest summary to see the appropriate tests listed for my hardcoded root.