vscode-stylua: search configuration file for Lua files not in workspace
Hi,
The current VSCode StyLua extension is unable to search for configuration files in parent directories of a Lua file not in the current workspace.
I fixed that issue by setting the cwd parameter to the parent directory of the currently opened file.
Can you consider merging this PR?
Thanks!
Can you explain the use-case of this and what it's solving? This seems like it's probably better solved by changing the StyLua binary to search for configuration recursively upward rather than adding an additional one-level-up check in the extension.
Hi, thanks for reviewing the PR!
It won't break the original case if stylua.searchParentDirectories is set to true.
The typical use case here is that suppose you're working in the workspace ~/workspace-1 but need to edit a Lua file in a folder outside it, say ~/workspace-2/foo/bar.lua and the configuration file is ~/workspace-2/.stylua.toml
The current code that use ~/workkspace-1 as CWD won't be able to format ~/workspace-2/foo/bar.lua
To resolve your example, I think the better solution is to set stylua.searchParentDirectories to true, in addition to the new changes in this PR.
To resolve your example, I think the better solution is to set stylua.searchParentDirectories to true, in addition to the new changes in this PR.
This has unintended side-effects, which is why the setting is not enabled by default in the first place.
I can see the issue the PR is trying to solve. What if instead we check if the file we are trying to format falls outside of the current workspace, then apply this change? If yes, then use its parent directory as the cwd. If no, then use the current workspace as cwd, as it does right now.
Codecov Report
Patch and project coverage have no change.
Comparison is base (
0fb1c15) 97.59% compared to head (d936951) 97.59%. Report is 1 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #735 +/- ##
=======================================
Coverage 97.59% 97.59%
=======================================
Files 16 16
Lines 6119 6119
=======================================
Hits 5972 5972
Misses 147 147
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@JohnnyMorganz: I just updated the PR according to your suggestion. Can you take a look?