Skip to content

Commit 41d0607

Browse files
committed
[ty] Distribute watched file change events to all dbs
1 parent 081ef08 commit 41d0607

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

crates/ty_server/src/server/api/notifications/did_change_watched_files.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::session::client::Client;
99
use crate::system::AnySystemPath;
1010
use lsp_types as types;
1111
use lsp_types::{FileChangeType, notification as notif};
12-
use rustc_hash::FxHashMap;
12+
use ruff_db::system::SystemPathBuf;
1313
use ty_project::Db as _;
1414
use ty_project::watch::{ChangeEvent, ChangedKind, CreatedKind, DeletedKind};
1515

@@ -25,7 +25,7 @@ impl SyncNotificationHandler for DidChangeWatchedFiles {
2525
client: &Client,
2626
params: types::DidChangeWatchedFilesParams,
2727
) -> Result<()> {
28-
let mut events_by_db: FxHashMap<_, Vec<ChangeEvent>> = FxHashMap::default();
28+
let mut changes = Vec::new();
2929

3030
for change in params.changes {
3131
let path = DocumentKey::from_url(&change.uri).into_file_path();
@@ -38,13 +38,6 @@ impl SyncNotificationHandler for DidChangeWatchedFiles {
3838
}
3939
};
4040

41-
let Some(db) = session.project_db_for_path(&system_path) else {
42-
tracing::trace!(
43-
"Ignoring change event for `{system_path}` because it's not in any workspace"
44-
);
45-
continue;
46-
};
47-
4841
let change_event = match change.typ {
4942
FileChangeType::CREATED => ChangeEvent::Created {
5043
path: system_path,
@@ -67,17 +60,19 @@ impl SyncNotificationHandler for DidChangeWatchedFiles {
6760
}
6861
};
6962

70-
events_by_db
71-
.entry(db.project().root(db).to_path_buf())
72-
.or_default()
73-
.push(change_event);
63+
changes.push(change_event);
7464
}
7565

76-
if events_by_db.is_empty() {
66+
if changes.is_empty() {
7767
return Ok(());
7868
}
7969

80-
for (root, changes) in events_by_db {
70+
let roots: Vec<SystemPathBuf> = session
71+
.project_dbs()
72+
.map(|db| db.project().root(db).to_owned())
73+
.collect();
74+
75+
for root in roots {
8176
tracing::debug!("Applying changes to `{root}`");
8277

8378
session.apply_changes(&AnySystemPath::System(root.clone()), &changes);

crates/ty_server/src/session.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,6 @@ impl Session {
325325
&mut self.project_state_mut(path).db
326326
}
327327

328-
/// Returns a reference to the project's [`ProjectDatabase`] corresponding to the given path, if
329-
/// any.
330-
pub(crate) fn project_db_for_path(
331-
&self,
332-
path: impl AsRef<SystemPath>,
333-
) -> Option<&ProjectDatabase> {
334-
self.project_state_for_path(path).map(|state| &state.db)
335-
}
336-
337328
/// Returns a reference to the project's [`ProjectState`] in which the given `path` belongs.
338329
///
339330
/// If the path is a system path, it will return the project database that is closest to the

0 commit comments

Comments
 (0)