mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:53 +00:00

## 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.
45 lines
1.3 KiB
Rust
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(())
|
|
}
|
|
}
|