-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[red-knot] Support
textDocument/didChange
notification (#13042)
## Summary This PR adds support for `textDocument/didChange` notification. There seems to be a bug (probably in Salsa) where it panics with: ``` 2024-08-22 15:33:38.802 [info] panicked at /Users/dhruv/.cargo/git/checkouts/salsa-61760caba2b17ca5/f608ff8/src/tracked_struct.rs:377:9: two concurrent writers to Id(4800), should not be possible ``` ## Test Plan https://github.com/user-attachments/assets/81055feb-ba8e-4acf-ad2f-94084a3efead
- Loading branch information
1 parent
c73a7bb
commit 21c5606
Showing
7 changed files
with
90 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
crates/red_knot_server/src/server/api/notifications/did_change.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use lsp_server::ErrorCode; | ||
use lsp_types::notification::DidChangeTextDocument; | ||
use lsp_types::DidChangeTextDocumentParams; | ||
|
||
use red_knot_workspace::watch::ChangeEvent; | ||
|
||
use crate::server::api::traits::{NotificationHandler, SyncNotificationHandler}; | ||
use crate::server::api::LSPResult; | ||
use crate::server::client::{Notifier, Requester}; | ||
use crate::server::Result; | ||
use crate::session::Session; | ||
use crate::system::url_to_system_path; | ||
|
||
pub(crate) struct DidChangeTextDocumentHandler; | ||
|
||
impl NotificationHandler for DidChangeTextDocumentHandler { | ||
type NotificationType = DidChangeTextDocument; | ||
} | ||
|
||
impl SyncNotificationHandler for DidChangeTextDocumentHandler { | ||
fn run( | ||
session: &mut Session, | ||
_notifier: Notifier, | ||
_requester: &mut Requester, | ||
params: DidChangeTextDocumentParams, | ||
) -> Result<()> { | ||
let Ok(path) = url_to_system_path(¶ms.text_document.uri) else { | ||
return Ok(()); | ||
}; | ||
|
||
let key = session.key_from_url(params.text_document.uri); | ||
|
||
session | ||
.update_text_document(&key, params.content_changes, params.text_document.version) | ||
.with_failure_code(ErrorCode::InternalError)?; | ||
|
||
let db = match session.workspace_db_for_path_mut(path.as_std_path()) { | ||
Some(db) => db, | ||
None => session.default_workspace_db_mut(), | ||
}; | ||
db.apply_changes(vec![ChangeEvent::file_content_changed(path)], None); | ||
|
||
// TODO(dhruvmanila): Publish diagnostics if the client doesnt support pull diagnostics | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters