Skip to content

Commit 4d4700d

Browse files
authored
Use file path for detecting package root (#18914)
Ref: astral-sh/ruff#18910 (comment)
1 parent 931a19f commit 4d4700d

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

crates/ruff_server/src/lint.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,18 @@ pub(crate) fn check(
8181
return DiagnosticsMap::default();
8282
}
8383

84-
let package = detect_package_root(
85-
document_path
86-
.parent()
87-
.expect("a path to a document should have a parent path"),
88-
&settings.linter.namespace_packages,
89-
)
90-
.map(PackageRoot::root);
84+
let file_path = query.file_path();
85+
let package = if let Some(file_path) = &file_path {
86+
detect_package_root(
87+
file_path
88+
.parent()
89+
.expect("a path to a document should have a parent path"),
90+
&settings.linter.namespace_packages,
91+
)
92+
.map(PackageRoot::root)
93+
} else {
94+
None
95+
};
9196

9297
let source_type = query.source_type();
9398

0 commit comments

Comments
 (0)