mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-22 19:34:23 +00:00
Fix automatic configuration reloading for text and notebook documents (#11492)
## Summary
Recent changes made in the [Jupyter Notebook feature
PR](https://github.com/astral-sh/ruff/pull/11206) caused automatic
configuration reloading to stop working. This was because we would check
for paths to reload using the changed path, when we should have been
using the parent path of the changed path (to get the directory it was
changed in).
Additionally, this PR fixes an issue where `ruff.toml` and `.ruff.toml`
files were not being automatically reloaded.
Finally, this PR improves configuration reloading by actively publishing
diagnostics for notebook documents (which won't be affected by the
workspace refresh since they don't use pull diagnostics). It will also
publish diagnostics for text documents if pull diagnostics aren't
supported.
## Test Plan
To test this, open an existing configuration file in a codebase, and
make modifications that will affect one or more open Python / Jupyter
Notebook files. You should observe that the diagnostics for both kinds
of files update automatically when the file changes are saved.
Here's a test video showing what a successful test should look like:
7172b598
-d6de-4965-b33c-6cb8b911ef6c
This commit is contained in:
parent
3cb2e677aa
commit
573facd2ba
4 changed files with 61 additions and 7 deletions
|
@ -1,3 +1,4 @@
|
|||
use crate::server::api::diagnostics::publish_diagnostics_for_document;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::server::schedule::Task;
|
||||
|
@ -15,7 +16,7 @@ impl super::NotificationHandler for DidChangeWatchedFiles {
|
|||
impl super::SyncNotificationHandler for DidChangeWatchedFiles {
|
||||
fn run(
|
||||
session: &mut Session,
|
||||
_notifier: Notifier,
|
||||
notifier: Notifier,
|
||||
requester: &mut Requester,
|
||||
params: types::DidChangeWatchedFilesParams,
|
||||
) -> Result<()> {
|
||||
|
@ -23,10 +24,28 @@ impl super::SyncNotificationHandler for DidChangeWatchedFiles {
|
|||
session.reload_settings(&change.uri.to_file_path().unwrap());
|
||||
}
|
||||
|
||||
if session.resolved_client_capabilities().workspace_refresh && !params.changes.is_empty() {
|
||||
requester
|
||||
.request::<types::request::WorkspaceDiagnosticRefresh>((), |()| Task::nothing())
|
||||
.with_failure_code(lsp_server::ErrorCode::InternalError)?;
|
||||
if !params.changes.is_empty() {
|
||||
if session.resolved_client_capabilities().workspace_refresh {
|
||||
requester
|
||||
.request::<types::request::WorkspaceDiagnosticRefresh>((), |()| Task::nothing())
|
||||
.with_failure_code(lsp_server::ErrorCode::InternalError)?;
|
||||
} else {
|
||||
// publish diagnostics for text documents
|
||||
for url in session.text_document_urls() {
|
||||
let snapshot = session
|
||||
.take_snapshot(&url)
|
||||
.expect("snapshot should be available");
|
||||
publish_diagnostics_for_document(&snapshot, ¬ifier)?;
|
||||
}
|
||||
}
|
||||
|
||||
// always publish diagnostics for notebook files (since they don't use pull diagnostics)
|
||||
for url in session.notebook_document_urls() {
|
||||
let snapshot = session
|
||||
.take_snapshot(&url)
|
||||
.expect("snapshot should be available");
|
||||
publish_diagnostics_for_document(&snapshot, ¬ifier)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue