Skip to content

Comments

fix(stylua): set cmd_cwd to root_dir for config lookup#4082

Closed
rmuir wants to merge 1 commit intoneovim:masterfrom
rmuir:stylua-use-correct-config
Closed

fix(stylua): set cmd_cwd to root_dir for config lookup#4082
rmuir wants to merge 1 commit intoneovim:masterfrom
rmuir:stylua-use-correct-config

Conversation

@rmuir
Copy link
Contributor

@rmuir rmuir commented Sep 19, 2025

PROBLEM

Stylua LSP server does not make use of rootUri in any way. If nvim is launched from a directory where cwd != rootDir, stylua will apply the incorrect configuration (internal defaults), and reformat code with an unexpected style.

SOLUTION

Set the cmd_cwd via reuse_client(), similar to ast_grep. See #3850 for more details.

PROBLEM

Stylua LSP server does not make use of rootUri in any way. If nvim is
launched from a directory where cwd != rootDir, stylua will apply the
incorrect configuration (internal defaults), and reformat code with an
unexpected style.

SOLUTION

Set the cmd_cwd via reuse_client(), similar to ast_grep. See neovim#3850 for
more details.
@justinmk
Copy link
Member

justinmk commented Sep 19, 2025

isn't this a server bug ? it should respect the root_dir that is passed to it, CWD shouldn't matter

was this reported to stylua LS?

@rmuir
Copy link
Contributor Author

rmuir commented Sep 19, 2025

I will take the issue over there: honestly didn't think it was a bug (the spec is super-vague), just another oddity of how stylua processes configuration files, and that we were "holding it wrong".

@rmuir rmuir closed this Sep 19, 2025
@justinmk
Copy link
Member

i'm not objecting to this since it looks pretty low-risk and clever. but also think it's worth reporting and discussing. please link to the upstream issue here

RichGuk added a commit to RichGuk/nvim-lspconfig that referenced this pull request Sep 25, 2025
Problem:

When running from a directory other than root (i.e monorepo), ruby-lsp
does not load correctly. Unsure why, [previous lspconfig](https://github.com/neovim/nvim-lspconfig/blob/33d351cbcc2b12b8e12078515829d042863743a9/lua/lspconfig/manager.lua#L119) had cmd_cwd set
to the same as root_dir.

Solution:

Set the cmd_cwd via reuse_client(), similar to ast_grep. See neovim#3850, neovim#4082 for more details.

Tested both from root_dir and monorepo multi-root project.
RichGuk added a commit to RichGuk/nvim-lspconfig that referenced this pull request Sep 25, 2025
Problem:
When running from a directory other than root (i.e monorepo), ruby-lsp
does not load correctly. Unsure why, [previous
lspconfig](https://github.com/neovim/nvim-lspconfig/blob/33d351cbcc2b12b8e12078515829d042863743a9/lua/lspconfig/manager.lua#L119)
had cmd_cwd set to the same as root_dir.

Solution:
Set the cmd_cwd via reuse_client(), similar to ast_grep. See neovim#3850, neovim#4082 for more details.
Tested both from root_dir and monorepo multi-root project.
RichGuk added a commit to RichGuk/nvim-lspconfig that referenced this pull request Sep 25, 2025
Problem: When running from a directory other than root (i.e monorepo),
ruby-lsp does not load correctly. Unsure why, previous lspconfig had
cmd_cwd set to the same as root_dir.

Solution:
Set the cmd_cwd via reuse_client(), similar to ast_grep. See neovim#3850, neovim#4082 for more details.
Tested both from root_dir and monorepo multi-root project.
justinmk pushed a commit that referenced this pull request Sep 25, 2025
Problem: When running from a directory other than root (i.e monorepo),
ruby-lsp does not load correctly. Unsure why, previous lspconfig had
cmd_cwd set to the same as root_dir.

Solution:
Set the cmd_cwd via reuse_client(), similar to ast_grep. See #3850, #4082 for more details.
Tested both from root_dir and monorepo multi-root project.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants