ruff/crates/ruff_server/src/server/api/notifications/did_change.rs
Jane Lewis 0a6327418d
ruff server refreshes diagnostics for open files when file configuration is changed (#10988)
## Summary

The server now requests a [workspace diagnostic
refresh](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnostic_refresh)
when a configuration file gets changed. This means that diagnostics for
all open files will be automatically re-requested by the client on a
config change.

## Test Plan

You can test this by opening several files in VS Code, setting `select`
in your file configuration to `[]`, and observing that the diagnostics
go away once the file is saved (besides any `Pylance` diagnostics).
Restore it to what it was before, and you should see the diagnostics
automatically return once a save happens.
2024-04-17 09:14:45 -07:00

45 lines
1.3 KiB
Rust

use crate::server::api::LSPResult;
use crate::server::client::{Notifier, Requester};
use crate::server::Result;
use crate::session::Session;
use lsp_types as types;
use lsp_types::notification as notif;
pub(crate) struct DidChange;
impl super::NotificationHandler for DidChange {
type NotificationType = notif::DidChangeTextDocument;
}
impl super::SyncNotificationHandler for DidChange {
#[tracing::instrument(skip_all, fields(file=%uri))]
fn run(
session: &mut Session,
_notifier: Notifier,
_requester: &mut Requester,
types::DidChangeTextDocumentParams {
text_document:
types::VersionedTextDocumentIdentifier {
uri,
version: new_version,
},
content_changes,
}: types::DidChangeTextDocumentParams,
) -> Result<()> {
let encoding = session.encoding();
let document = session
.document_controller(&uri)
.with_failure_code(lsp_server::ErrorCode::InvalidParams)?;
if content_changes.is_empty() {
document.make_mut().update_version(new_version);
return Ok(());
}
document
.make_mut()
.apply_changes(content_changes, new_version, encoding);
Ok(())
}
}