Skip to content

Commit df172e8

Browse files
committed
fix(service): index pnpm-workspace.yaml and refresh catalogs on change
1 parent 2d5e5a5 commit df172e8

File tree

2 files changed

+71
-17
lines changed

2 files changed

+71
-17
lines changed

crates/biome_service/src/scanner/workspace_scanner_bridge.tests.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,35 @@ fn should_not_index_a_source_file_with_scan_kind_known_files() {
178178
assert!(!workspace.is_indexed(&file_path));
179179
}
180180

181+
#[test]
182+
fn should_index_pnpm_workspace_yaml_as_manifest() {
183+
let pnpm_workspace_path = Utf8PathBuf::from("/project/pnpm-workspace.yaml");
184+
185+
let fs = MemoryFileSystem::default();
186+
fs.insert(
187+
Utf8PathBuf::from("/project/package.json"),
188+
r#"{ "name": "app" }"#,
189+
);
190+
fs.insert(
191+
pnpm_workspace_path.clone(),
192+
"catalog:\n react: 19.0.0\n".as_bytes(),
193+
);
194+
195+
let (workspace, project_key) = setup_workspace_and_open_project(fs, "/project");
196+
197+
workspace
198+
.scan_project(ScanProjectParams {
199+
project_key,
200+
watch: false,
201+
force: false,
202+
scan_kind: ScanKind::Project,
203+
verbose: false,
204+
})
205+
.expect("can scan the project");
206+
207+
assert!(workspace.is_indexed(&pnpm_workspace_path));
208+
}
209+
181210
#[test]
182211
fn should_not_index_an_ignored_file_inside_vcs_ignore_file() {
183212
let file_path = Utf8PathBuf::from("/project/a.js");

crates/biome_service/src/workspace/server.rs

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,14 @@ impl WorkspaceServer {
323323
let path: Utf8PathBuf = biome_path.clone().into();
324324

325325
if document_file_source.is_none() && !DocumentFileSource::can_read(path.as_path()) {
326+
if reason.is_index()
327+
&& path
328+
.file_name()
329+
.is_some_and(|filename| filename == "pnpm-workspace.yaml")
330+
&& let Some(workspace_root) = path.parent()
331+
{
332+
self.refresh_pnpm_workspace_catalogs_for_scope(project_key, workspace_root);
333+
}
326334
return Ok(Default::default());
327335
}
328336

@@ -583,27 +591,38 @@ impl WorkspaceServer {
583591
reason.is_index() || self.is_indexed(&path)
584592
};
585593

586-
// Manifest files need to update the module graph
587-
if is_indexed
588-
&& let Some(root) = syntax
594+
// Manifest files need to update the module graph.
595+
if is_indexed {
596+
if let Some(root) = syntax
589597
.and_then(Result::ok)
590598
.map(|node| node.unwrap_as_send_node())
591-
{
592-
let (dependencies, diagnostics) = self.update_service_data(
593-
&path,
594-
UpdateKind::AddedOrChanged(reason, root, services),
595-
project_key,
596-
)?;
599+
{
600+
let (dependencies, diagnostics) = self.update_service_data(
601+
&path,
602+
UpdateKind::AddedOrChanged(reason, root, services),
603+
project_key,
604+
)?;
597605

598-
Ok(InternalOpenFileResult {
599-
dependencies,
600-
diagnostics,
601-
})
602-
} else {
603-
// If the document was never opened by the scanner, we don't care
604-
// about updating service data.
605-
Ok(InternalOpenFileResult::default())
606+
return Ok(InternalOpenFileResult {
607+
dependencies,
608+
diagnostics,
609+
});
610+
}
611+
612+
// pnpm-workspace.yaml is not a parsed manifest, but updates still need to
613+
// re-apply catalogs to indexed package.json manifests in the same scope.
614+
if path
615+
.file_name()
616+
.is_some_and(|filename| filename == "pnpm-workspace.yaml")
617+
&& let Some(workspace_root) = path.parent()
618+
{
619+
self.refresh_pnpm_workspace_catalogs_for_scope(project_key, workspace_root);
620+
}
606621
}
622+
623+
// If the document was never opened by the scanner, we don't care
624+
// about updating service data.
625+
Ok(InternalOpenFileResult::default())
607626
}
608627

609628
/// Retrieves the parser result for a given file.
@@ -2537,6 +2556,12 @@ impl WorkspaceScannerBridge for WorkspaceServer {
25372556
Some("package.json" | "tsconfig.json" | "turbo.json" | "turbo.jsonc") => {
25382557
self.project_layout.is_indexed(path)
25392558
}
2559+
Some("pnpm-workspace.yaml") => path.parent().is_some_and(|workspace_root| {
2560+
self.project_layout
2561+
.package_paths()
2562+
.into_iter()
2563+
.any(|package_path| package_path.starts_with(workspace_root))
2564+
}),
25402565
_ => self.module_graph.contains(path),
25412566
}
25422567
}

0 commit comments

Comments
 (0)