Skip to content

Commit 6273b56

Browse files
committed
Remove DocumentRef
1 parent 5edc223 commit 6273b56

28 files changed

+169
-198
lines changed

crates/ty_server/src/document/notebook.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ impl NotebookDocument {
226226
}
227227

228228
/// Get the text document representing the contents of a cell by the cell URI.
229+
#[expect(unused)]
229230
pub(crate) fn cell_document_by_uri(&self, uri: &str) -> Option<&TextDocument> {
230231
self.cells
231232
.get(*self.cell_index.get(uri)?)

crates/ty_server/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub use crate::logging::{LogLevel, init_logging};
88
pub use crate::server::{PartialWorkspaceProgress, PartialWorkspaceProgressParams, Server};
99
pub use crate::session::{ClientOptions, DiagnosticMode};
1010
pub use document::{NotebookDocument, PositionEncoding, TextDocument};
11-
pub(crate) use session::{DocumentRef, Session};
11+
pub(crate) use session::Session;
1212

1313
mod capabilities;
1414
mod document;

crates/ty_server/src/server/api.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ where
273273
});
274274
};
275275

276-
let db = session.project_db(document.file_path()).clone();
276+
let path = document.to_file_path();
277+
let db = session.project_db(&path).clone();
277278

278279
Box::new(move |client| {
279280
let _span = tracing::debug_span!("request", %id, method = R::METHOD).entered();

crates/ty_server/src/server/api/diagnostics.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ use crate::document::{FileRangeExt, ToRangeExt};
1717
use crate::session::DocumentSnapshot;
1818
use crate::session::client::Client;
1919
use crate::system::{AnySystemPath, file_to_url};
20-
use crate::{DocumentRef, PositionEncoding, Session};
20+
use crate::{NotebookDocument, PositionEncoding, Session};
2121

2222
pub(super) struct Diagnostics<'a> {
2323
items: Vec<ruff_db::diagnostic::Diagnostic>,
2424
encoding: PositionEncoding,
25-
document: &'a DocumentRef,
25+
notebook: Option<&'a NotebookDocument>,
2626
}
2727

2828
impl Diagnostics<'_> {
@@ -53,7 +53,7 @@ impl Diagnostics<'_> {
5353
}
5454

5555
pub(super) fn to_lsp_diagnostics(&self, db: &ProjectDatabase) -> LspDiagnostics {
56-
if let Some(notebook) = self.document.as_notebook() {
56+
if let Some(notebook) = self.notebook {
5757
let mut cell_diagnostics: FxHashMap<Url, Vec<Diagnostic>> = FxHashMap::default();
5858

5959
// Populates all relevant URLs with an empty diagnostic list. This ensures that documents
@@ -151,7 +151,7 @@ pub(super) fn publish_diagnostics(session: &Session, url: &lsp_types::Url, clien
151151
}
152152
};
153153

154-
let db = session.project_db(snapshot.file_path());
154+
let db = session.project_db(&snapshot.to_file_path());
155155

156156
let Some(diagnostics) = compute_diagnostics(db, &snapshot) else {
157157
return;
@@ -253,8 +253,11 @@ pub(super) fn compute_diagnostics<'a>(
253253
db: &ProjectDatabase,
254254
snapshot: &'a DocumentSnapshot,
255255
) -> Option<Diagnostics<'a>> {
256-
let Some(file) = snapshot.file(db) else {
257-
tracing::info!("No file found for snapshot for `{}`", snapshot.file_path());
256+
let Some(file) = snapshot.to_file(db) else {
257+
tracing::info!(
258+
"No file found for snapshot for `{}`",
259+
snapshot.to_file_path()
260+
);
258261
return None;
259262
};
260263

@@ -263,7 +266,7 @@ pub(super) fn compute_diagnostics<'a>(
263266
Some(Diagnostics {
264267
items: diagnostics,
265268
encoding: snapshot.encoding(),
266-
document: snapshot.document(),
269+
notebook: snapshot.notebook(),
267270
})
268271
}
269272

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ impl SyncNotificationHandler for DidChangeTextDocumentHandler {
3636
.update_text_document(session, content_changes, version)
3737
.with_failure_code(ErrorCode::InternalError)?;
3838

39-
let changes = match document.file_path() {
39+
let path = document.to_file_path();
40+
let changes = match &*path {
4041
AnySystemPath::System(system_path) => {
4142
vec![ChangeEvent::file_content_changed(system_path.clone())]
4243
}
@@ -45,7 +46,7 @@ impl SyncNotificationHandler for DidChangeTextDocumentHandler {
4546
}
4647
};
4748

48-
session.apply_changes(document.file_path(), changes);
49+
session.apply_changes(&path, changes);
4950

5051
publish_diagnostics(session, document.url(), client);
5152

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ impl SyncNotificationHandler for DidCloseTextDocumentHandler {
3131
.document(&uri)
3232
.with_failure_code(ErrorCode::InternalError)?;
3333

34-
let db = session.project_db_mut(document.file_path());
34+
let path = document.to_file_path();
35+
let db = session.project_db_mut(&path);
3536

36-
match document.file_path() {
37+
match &*path {
3738
AnySystemPath::System(system_path) => {
3839
if let Some(file) = db.files().try_system(db, system_path) {
3940
db.project().close_file(db, file);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ impl SyncNotificationHandler for DidCloseNotebookHandler {
3030
.document(&uri)
3131
.with_failure_code(lsp_server::ErrorCode::InternalError)?;
3232

33-
if let AnySystemPath::SystemVirtual(virtual_path) = document.file_path() {
33+
let path = document.to_file_path();
34+
35+
if let AnySystemPath::SystemVirtual(virtual_path) = &*path {
3436
session.apply_changes(
35-
document.file_path(),
37+
&path,
3638
vec![ChangeEvent::DeletedVirtual(virtual_path.clone())],
3739
);
3840
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ impl SyncNotificationHandler for DidOpenTextDocumentHandler {
3939
TextDocument::new(uri, text, version).with_language_id(&language_id),
4040
);
4141

42-
let path = document.file_path();
42+
let path = document.to_file_path();
4343

4444
// This is a "maybe" because the `File` might've not been interned yet i.e., the
4545
// `try_system` call will return `None` which doesn't mean that the file is new, it's just
4646
// that the server didn't need the file yet.
4747
let is_maybe_new_system_file = path.as_system().is_some_and(|system_path| {
48-
let db = session.project_db(path);
48+
let db = session.project_db(&path);
4949
db.files()
5050
.try_system(db, system_path)
5151
.is_none_or(|file| !file.exists(db))
5252
});
5353

54-
match path {
54+
match &*path {
5555
AnySystemPath::System(system_path) => {
5656
let event = if is_maybe_new_system_file {
5757
ChangeEvent::Created {
@@ -61,16 +61,16 @@ impl SyncNotificationHandler for DidOpenTextDocumentHandler {
6161
} else {
6262
ChangeEvent::Opened(system_path.clone())
6363
};
64-
session.apply_changes(path, vec![event]);
64+
session.apply_changes(&path, vec![event]);
6565

66-
let db = session.project_db_mut(path);
66+
let db = session.project_db_mut(&path);
6767
match system_path_to_file(db, system_path) {
6868
Ok(file) => db.project().open_file(db, file),
6969
Err(err) => tracing::warn!("Failed to open file {system_path}: {err}"),
7070
}
7171
}
7272
AnySystemPath::SystemVirtual(virtual_path) => {
73-
let db = session.project_db_mut(path);
73+
let db = session.project_db_mut(&path);
7474
let virtual_file = db.files().virtual_file(db, virtual_path);
7575
db.project().open_file(db, virtual_file.file());
7676
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ impl SyncNotificationHandler for DidOpenNotebookHandler {
4242
.with_failure_code(ErrorCode::InternalError)?;
4343

4444
let document = session.open_notebook_document(notebook);
45-
let path = document.file_path();
45+
let path = document.to_file_path();
4646

47-
match path {
47+
match &*path {
4848
AnySystemPath::System(system_path) => {
49-
session.apply_changes(path, vec![ChangeEvent::Opened(system_path.clone())]);
49+
session.apply_changes(&path, vec![ChangeEvent::Opened(system_path.clone())]);
5050
}
5151
AnySystemPath::SystemVirtual(virtual_path) => {
52-
let db = session.project_db_mut(path);
52+
let db = session.project_db_mut(&path);
5353
db.files().virtual_file(db, virtual_path);
5454
}
5555
}

crates/ty_server/src/server/api/requests/completion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl BackgroundDocumentRequestHandler for CompletionRequestHandler {
4545
return Ok(None);
4646
}
4747

48-
let Some(file) = snapshot.file(db) else {
48+
let Some(file) = snapshot.to_file(db) else {
4949
return Ok(None);
5050
};
5151

0 commit comments

Comments
 (0)