Skip to content

Commit 5c92d59

Browse files
committed
Address additional review comments
1 parent 6c17102 commit 5c92d59

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
use lsp_types::notification::DidCloseNotebookDocument;
22
use lsp_types::DidCloseNotebookDocumentParams;
33

4+
use ruff_db::files::File;
5+
46
use crate::server::api::traits::{NotificationHandler, SyncNotificationHandler};
57
use crate::server::api::LSPResult;
68
use crate::server::client::{Notifier, Requester};
79
use crate::server::Result;
810
use crate::session::Session;
11+
use crate::system::url_to_system_path;
912

1013
pub(crate) struct DidCloseNotebookHandler;
1114

@@ -20,12 +23,18 @@ impl SyncNotificationHandler for DidCloseNotebookHandler {
2023
_requester: &mut Requester,
2124
params: DidCloseNotebookDocumentParams,
2225
) -> Result<()> {
26+
let Ok(path) = url_to_system_path(&params.notebook_document.uri) else {
27+
return Ok(());
28+
};
29+
2330
let key = session.key_from_url(params.notebook_document.uri);
2431
session
2532
.close_document(&key)
2633
.with_failure_code(lsp_server::ErrorCode::InternalError)?;
2734

28-
// TODO(dhruvmanila): Close the file in the `RootDatabase`
35+
if let Some(db) = session.workspace_db_for_path_mut(path.as_std_path()) {
36+
File::sync_path(db.get_mut(), &path);
37+
}
2938

3039
Ok(())
3140
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use lsp_types::notification::DidOpenTextDocument;
22
use lsp_types::DidOpenTextDocumentParams;
3-
use ruff_db::files::{system_path_to_file, File};
3+
4+
use ruff_db::files::system_path_to_file;
45

56
use crate::server::api::traits::{NotificationHandler, SyncNotificationHandler};
67
use crate::server::client::{Notifier, Requester};
@@ -30,12 +31,12 @@ impl SyncNotificationHandler for DidOpenTextDocumentHandler {
3031
session.open_text_document(params.text_document.uri, document);
3132

3233
if let Some(db) = session.workspace_db_for_path_mut(path.as_std_path()) {
33-
// TODO(dhruvmanila): Store the `file` in `TextDocument`
34-
let _file = system_path_to_file(&**db, &path).unwrap();
35-
File::sync_path(db.get_mut(), &path);
34+
// TODO(dhruvmanila): Store the `file` in `DocumentController`
35+
let file = system_path_to_file(&**db, &path).unwrap();
36+
file.sync(db.get_mut());
3637
}
3738

38-
// Publish diagnostics if the client doesn't support pull diagnostics
39+
// TODO(dhruvmanila): Publish diagnostics if the client doesn't support pull diagnostics
3940

4041
Ok(())
4142
}

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ use lsp_server::ErrorCode;
22
use lsp_types::notification::DidOpenNotebookDocument;
33
use lsp_types::DidOpenNotebookDocumentParams;
44

5+
use ruff_db::files::system_path_to_file;
6+
57
use crate::edit::NotebookDocument;
68
use crate::server::api::traits::{NotificationHandler, SyncNotificationHandler};
79
use crate::server::api::LSPResult;
810
use crate::server::client::{Notifier, Requester};
911
use crate::server::Result;
1012
use crate::session::Session;
13+
use crate::system::url_to_system_path;
1114

1215
pub(crate) struct DidOpenNotebookHandler;
1316

@@ -22,19 +25,26 @@ impl SyncNotificationHandler for DidOpenNotebookHandler {
2225
_requester: &mut Requester,
2326
params: DidOpenNotebookDocumentParams,
2427
) -> Result<()> {
28+
let Ok(path) = url_to_system_path(&params.notebook_document.uri) else {
29+
return Ok(());
30+
};
31+
2532
let notebook = NotebookDocument::new(
2633
params.notebook_document.version,
2734
params.notebook_document.cells,
2835
params.notebook_document.metadata.unwrap_or_default(),
2936
params.cell_text_documents,
3037
)
3138
.with_failure_code(ErrorCode::InternalError)?;
32-
3339
session.open_notebook_document(params.notebook_document.uri.clone(), notebook);
3440

35-
// TODO(dhruvmanila): Open the file in the `RootDatabase`
41+
if let Some(db) = session.workspace_db_for_path_mut(path.as_std_path()) {
42+
// TODO(dhruvmanila): Store the `file` in `DocumentController`
43+
let file = system_path_to_file(&**db, &path).unwrap();
44+
file.sync(db.get_mut());
45+
}
3646

37-
// Publish diagnostics if the client doesn't support pull diagnostics
47+
// TODO(dhruvmanila): Publish diagnostics if the client doesn't support pull diagnostics
3848

3949
Ok(())
4050
}

crates/red_knot_server/src/session.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ mod capabilities;
2828
pub(crate) mod index;
2929
mod settings;
3030

31+
// TODO(dhruvmanila): In general, the server shouldn't use any salsa queries directly and instead
32+
// should use methods on `RootDatabase`.
33+
3134
/// The global state for the LSP
3235
pub struct Session {
3336
/// Used to retrieve information about open documents and settings.

0 commit comments

Comments
 (0)