Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fixed comments lost from expression after parentheses are removed when we are attempting to "hang" the expression. ([#1033](https://github.com/JohnnyMorganz/StyLua/issues/1033))
- Fixed `document_range_formatting_provider` capability missing from `ServerCapabilities` in language server mode
- Fixed current working directory incorrectly used as config search root in language server mode -- now, the root of the opened workspace is used instead ([#1032](https://github.com/JohnnyMorganz/StyLua/issues/1032))

## [2.2.0] - 2025-09-14

Expand Down
23 changes: 18 additions & 5 deletions src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,28 @@ impl ConfigResolver<'_> {
/// Returns the root used when searching for configuration
/// If `--search-parent-directories`, then there is no root, and we keep searching
/// Else, the root is the current working directory, and we do not search higher than the cwd
fn get_configuration_search_root(&self) -> Option<PathBuf> {
fn get_configuration_search_root(
&self,
search_root_override: Option<PathBuf>,
) -> Option<PathBuf> {
match self.opt.search_parent_directories {
true => None,
false => Some(self.current_directory.to_path_buf()),
false => {
Some(search_root_override.unwrap_or_else(|| self.current_directory.to_path_buf()))
}
}
}

pub fn load_configuration(&mut self, path: &Path) -> Result<Config> {
pub(crate) fn load_configuration_with_search_root(
&mut self,
path: &Path,
search_root_override: Option<PathBuf>,
) -> Result<Config> {
if let Some(configuration) = self.forced_configuration {
return Ok(configuration);
}

let root = self.get_configuration_search_root();
let root = self.get_configuration_search_root(search_root_override);

let absolute_path = self.current_directory.join(path);
let parent_path = &absolute_path
Expand All @@ -93,12 +102,16 @@ impl ConfigResolver<'_> {
}
}

pub fn load_configuration(&mut self, path: &Path) -> Result<Config> {
self.load_configuration_with_search_root(path, None)
}

pub fn load_configuration_for_stdin(&mut self) -> Result<Config> {
if let Some(configuration) = self.forced_configuration {
return Ok(configuration);
}

let root = self.get_configuration_search_root();
let root = self.get_configuration_search_root(None);
let my_current_directory = self.current_directory.to_owned();

match &self.opt.stdin_filepath {
Expand Down
Loading
Loading