1 //! The main loop of `rust-analyzer` responsible for dispatching LSP
2 //! requests/replies and notifications back to the client.
6 time::{Duration, Instant},
9 use always_assert::always;
10 use crossbeam_channel::{select, Receiver};
11 use ide_db::base_db::{SourceDatabaseExt, VfsPath};
12 use itertools::Itertools;
13 use lsp_server::{Connection, Notification, Request};
14 use lsp_types::notification::Notification as _;
15 use vfs::{ChangeKind, FileId};
19 dispatch::{NotificationDispatcher, RequestDispatcher},
21 global_state::{file_id_to_url, url_to_file_id, GlobalState},
23 lsp_utils::{apply_document_changes, is_cancelled, notification_is, Progress},
24 mem_docs::DocumentData,
25 reload::{self, BuildDataProgress, ProjectWorkspaceProgress},
29 pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
30 tracing::info!("initial config: {:#?}", config);
32 // Windows scheduler implements priority boosts: if thread waits for an
33 // event (like a condvar), and event fires, priority of the thread is
34 // temporary bumped. This optimization backfires in our case: each time the
35 // `main_loop` schedules a task to run on a threadpool, the worker threads
36 // gets a higher priority, and (on a machine with fewer cores) displaces the
37 // main loop! We work-around this by marking the main loop as a
38 // higher-priority thread.
40 // https://docs.microsoft.com/en-us/windows/win32/procthread/scheduling-priorities
41 // https://docs.microsoft.com/en-us/windows/win32/procthread/priority-boosts
42 // https://github.com/rust-analyzer/rust-analyzer/issues/2835
45 use winapi::um::processthreadsapi::*;
46 let thread = GetCurrentThread();
47 let thread_priority_above_normal = 1;
48 SetThreadPriority(thread, thread_priority_above_normal);
51 GlobalState::new(connection.sender, config).run(connection.receiver)
55 Lsp(lsp_server::Message),
57 Vfs(vfs::loader::Message),
58 Flycheck(flycheck::Message),
62 pub(crate) enum Task {
63 Response(lsp_server::Response),
64 Diagnostics(Vec<(FileId, Vec<lsp_types::Diagnostic>)>),
65 PrimeCaches(PrimeCachesProgress),
66 FetchWorkspace(ProjectWorkspaceProgress),
67 FetchBuildData(BuildDataProgress),
71 pub(crate) enum PrimeCachesProgress {
73 Report(ide::PrimeCachesProgress),
74 End { cancelled: bool },
77 impl fmt::Debug for Event {
78 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
79 let debug_verbose_not = |not: &Notification, f: &mut fmt::Formatter| {
80 f.debug_struct("Notification").field("method", ¬.method).finish()
84 Event::Lsp(lsp_server::Message::Notification(not)) => {
85 if notification_is::<lsp_types::notification::DidOpenTextDocument>(not)
86 || notification_is::<lsp_types::notification::DidChangeTextDocument>(not)
88 return debug_verbose_not(not, f);
91 Event::Task(Task::Response(resp)) => {
93 .debug_struct("Response")
94 .field("id", &resp.id)
95 .field("error", &resp.error)
101 Event::Lsp(it) => fmt::Debug::fmt(it, f),
102 Event::Task(it) => fmt::Debug::fmt(it, f),
103 Event::Vfs(it) => fmt::Debug::fmt(it, f),
104 Event::Flycheck(it) => fmt::Debug::fmt(it, f),
110 fn run(mut self, inbox: Receiver<lsp_server::Message>) -> Result<()> {
111 if self.config.linked_projects().is_empty()
112 && self.config.detached_files().is_empty()
113 && self.config.notifications().cargo_toml_not_found
116 lsp_types::MessageType::ERROR,
117 "rust-analyzer failed to discover workspace".to_string(),
121 if self.config.did_save_text_document_dynamic_registration() {
122 let save_registration_options = lsp_types::TextDocumentSaveRegistrationOptions {
123 include_text: Some(false),
124 text_document_registration_options: lsp_types::TextDocumentRegistrationOptions {
125 document_selector: Some(vec![
126 lsp_types::DocumentFilter {
129 pattern: Some("**/*.rs".into()),
131 lsp_types::DocumentFilter {
134 pattern: Some("**/Cargo.toml".into()),
136 lsp_types::DocumentFilter {
139 pattern: Some("**/Cargo.lock".into()),
145 let registration = lsp_types::Registration {
146 id: "textDocument/didSave".to_string(),
147 method: "textDocument/didSave".to_string(),
148 register_options: Some(serde_json::to_value(save_registration_options).unwrap()),
150 self.send_request::<lsp_types::request::RegisterCapability>(
151 lsp_types::RegistrationParams { registrations: vec![registration] },
156 self.fetch_workspaces_queue.request_op();
157 if self.fetch_workspaces_queue.should_start_op() {
158 self.fetch_workspaces();
161 while let Some(event) = self.next_event(&inbox) {
162 if let Event::Lsp(lsp_server::Message::Notification(not)) = &event {
163 if not.method == lsp_types::notification::Exit::METHOD {
167 self.handle_event(event)?
170 return Err("client exited without proper shutdown sequence".into());
173 fn next_event(&self, inbox: &Receiver<lsp_server::Message>) -> Option<Event> {
175 recv(inbox) -> msg =>
176 msg.ok().map(Event::Lsp),
178 recv(self.task_pool.receiver) -> task =>
179 Some(Event::Task(task.unwrap())),
181 recv(self.loader.receiver) -> task =>
182 Some(Event::Vfs(task.unwrap())),
184 recv(self.flycheck_receiver) -> task =>
185 Some(Event::Flycheck(task.unwrap())),
189 fn handle_event(&mut self, event: Event) -> Result<()> {
190 let loop_start = Instant::now();
191 // NOTE: don't count blocking select! call as a loop-turn time
192 let _p = profile::span("GlobalState::handle_event");
194 tracing::info!("handle_event({:?})", event);
195 let task_queue_len = self.task_pool.handle.len();
196 if task_queue_len > 0 {
197 tracing::info!("task queue len: {}", task_queue_len);
200 let was_quiescent = self.is_quiescent();
202 Event::Lsp(msg) => match msg {
203 lsp_server::Message::Request(req) => self.on_request(loop_start, req)?,
204 lsp_server::Message::Notification(not) => {
205 self.on_notification(not)?;
207 lsp_server::Message::Response(resp) => self.complete_request(resp),
209 Event::Task(mut task) => {
210 let _p = profile::span("GlobalState::handle_event/task");
211 let mut prime_caches_progress = Vec::new();
214 Task::Response(response) => self.respond(response),
215 Task::Diagnostics(diagnostics_per_file) => {
216 for (file_id, diagnostics) in diagnostics_per_file {
217 self.diagnostics.set_native_diagnostics(file_id, diagnostics)
220 Task::PrimeCaches(progress) => match progress {
221 PrimeCachesProgress::Begin => prime_caches_progress.push(progress),
222 PrimeCachesProgress::Report(_) => {
223 match prime_caches_progress.last_mut() {
224 Some(last @ PrimeCachesProgress::Report(_)) => {
225 // Coalesce subsequent update events.
228 _ => prime_caches_progress.push(progress),
231 PrimeCachesProgress::End { .. } => prime_caches_progress.push(progress),
233 Task::FetchWorkspace(progress) => {
234 let (state, msg) = match progress {
235 ProjectWorkspaceProgress::Begin => (Progress::Begin, None),
236 ProjectWorkspaceProgress::Report(msg) => {
237 (Progress::Report, Some(msg))
239 ProjectWorkspaceProgress::End(workspaces) => {
240 self.fetch_workspaces_queue.op_completed(workspaces);
242 let old = Arc::clone(&self.workspaces);
243 self.switch_workspaces();
244 let workspaces_updated = !Arc::ptr_eq(&old, &self.workspaces);
246 if self.config.run_build_scripts() && workspaces_updated {
247 self.fetch_build_data_queue.request_op()
250 (Progress::End, None)
254 self.report_progress("Fetching", state, msg, None);
256 Task::FetchBuildData(progress) => {
257 let (state, msg) = match progress {
258 BuildDataProgress::Begin => (Some(Progress::Begin), None),
259 BuildDataProgress::Report(msg) => {
260 (Some(Progress::Report), Some(msg))
262 BuildDataProgress::End(build_data_result) => {
263 self.fetch_build_data_queue.op_completed(build_data_result);
265 self.switch_workspaces();
267 (Some(Progress::End), None)
271 if let Some(state) = state {
272 self.report_progress("Loading", state, msg, None);
277 // Coalesce multiple task events into one loop turn
278 task = match self.task_pool.receiver.try_recv() {
284 for progress in prime_caches_progress {
285 let (state, message, fraction);
287 PrimeCachesProgress::Begin => {
288 state = Progress::Begin;
292 PrimeCachesProgress::Report(report) => {
293 state = Progress::Report;
294 message = Some(format!(
296 report.n_done, report.n_total, report.on_crate
298 fraction = Progress::fraction(report.n_done, report.n_total);
300 PrimeCachesProgress::End { cancelled } => {
301 state = Progress::End;
305 self.prime_caches_queue.op_completed(());
307 self.prime_caches_queue.request_op();
312 self.report_progress("Indexing", state, message, Some(fraction));
315 Event::Vfs(mut task) => {
316 let _p = profile::span("GlobalState::handle_event/vfs");
319 vfs::loader::Message::Loaded { files } => {
320 let vfs = &mut self.vfs.write().0;
321 for (path, contents) in files {
322 let path = VfsPath::from(path);
323 if !self.mem_docs.contains(&path) {
324 vfs.set_file_contents(path, contents);
328 vfs::loader::Message::Progress { n_total, n_done, config_version } => {
329 always!(config_version <= self.vfs_config_version);
331 self.vfs_progress_config_version = config_version;
332 self.vfs_progress_n_total = n_total;
333 self.vfs_progress_n_done = n_done;
335 let state = if n_done == 0 {
337 } else if n_done < n_total {
340 assert_eq!(n_done, n_total);
343 self.report_progress(
346 Some(format!("{}/{}", n_done, n_total)),
347 Some(Progress::fraction(n_done, n_total)),
351 // Coalesce many VFS event into a single loop turn
352 task = match self.loader.receiver.try_recv() {
358 Event::Flycheck(mut task) => {
359 let _p = profile::span("GlobalState::handle_event/flycheck");
362 flycheck::Message::AddDiagnostic { workspace_root, diagnostic } => {
364 crate::diagnostics::to_proto::map_rust_diagnostic_to_lsp(
365 &self.config.diagnostics_map(),
369 for diag in diagnostics {
370 match url_to_file_id(&self.vfs.read().0, &diag.url) {
371 Ok(file_id) => self.diagnostics.add_check_diagnostic(
378 "File with cargo diagnostic not found in VFS: {}",
386 flycheck::Message::Progress { id, progress } => {
387 let (state, message) = match progress {
388 flycheck::Progress::DidStart => {
389 self.diagnostics.clear_check();
390 (Progress::Begin, None)
392 flycheck::Progress::DidCheckCrate(target) => {
393 (Progress::Report, Some(target))
395 flycheck::Progress::DidCancel => (Progress::End, None),
396 flycheck::Progress::DidFinish(result) => {
397 if let Err(err) = result {
399 lsp_types::MessageType::ERROR,
400 format!("cargo check failed: {}", err),
403 (Progress::End, None)
407 // When we're running multiple flychecks, we have to include a disambiguator in
408 // the title, or the editor complains. Note that this is a user-facing string.
409 let title = if self.flycheck.len() == 1 {
410 match self.config.flycheck() {
411 Some(config) => format!("{}", config),
412 None => "cargo check".to_string(),
415 format!("cargo check (#{})", id + 1)
417 self.report_progress(&title, state, message, None);
420 // Coalesce many flycheck updates into a single loop turn
421 task = match self.flycheck_receiver.try_recv() {
429 let state_changed = self.process_changes();
430 let memdocs_added_or_removed = self.mem_docs.take_changes();
432 if self.is_quiescent() {
434 for flycheck in &self.flycheck {
437 if self.config.prefill_caches() {
438 self.prime_caches_queue.request_op();
442 if !was_quiescent || state_changed {
443 // Refresh semantic tokens if the client supports it.
444 if self.config.semantic_tokens_refresh() {
445 self.semantic_tokens_cache.lock().clear();
446 self.send_request::<lsp_types::request::SemanticTokensRefesh>((), |_, _| ());
449 // Refresh code lens if the client supports it.
450 if self.config.code_lens_refresh() {
451 self.send_request::<lsp_types::request::CodeLensRefresh>((), |_, _| ());
455 if !was_quiescent || state_changed || memdocs_added_or_removed {
456 if self.config.publish_diagnostics() {
457 self.update_diagnostics()
462 if let Some(diagnostic_changes) = self.diagnostics.take_changes() {
463 for file_id in diagnostic_changes {
464 let db = self.analysis_host.raw_database();
465 let source_root = db.file_source_root(file_id);
466 if db.source_root(source_root).is_library {
467 // Only publish diagnostics for files in the workspace, not from crates.io deps
469 // While theoretically these should never have errors, we have quite a few false
470 // positives particularly in the stdlib, and those diagnostics would stay around
471 // forever if we emitted them here.
475 let url = file_id_to_url(&self.vfs.read().0, file_id);
476 let diagnostics = self.diagnostics.diagnostics_for(file_id).cloned().collect();
477 let version = from_proto::vfs_path(&url)
478 .map(|path| self.mem_docs.get(&path).map(|it| it.version))
479 .unwrap_or_default();
481 self.send_notification::<lsp_types::notification::PublishDiagnostics>(
482 lsp_types::PublishDiagnosticsParams { uri: url, diagnostics, version },
487 if self.config.cargo_autoreload() {
488 if self.fetch_workspaces_queue.should_start_op() {
489 self.fetch_workspaces();
492 if self.fetch_build_data_queue.should_start_op() {
493 self.fetch_build_data();
495 if self.prime_caches_queue.should_start_op() {
496 self.task_pool.handle.spawn_with_sender({
497 let analysis = self.snapshot().analysis;
499 sender.send(Task::PrimeCaches(PrimeCachesProgress::Begin)).unwrap();
500 let res = analysis.prime_caches(|progress| {
501 let report = PrimeCachesProgress::Report(progress);
502 sender.send(Task::PrimeCaches(report)).unwrap();
505 .send(Task::PrimeCaches(PrimeCachesProgress::End {
506 cancelled: res.is_err(),
513 let status = self.current_status();
514 if self.last_reported_status.as_ref() != Some(&status) {
515 self.last_reported_status = Some(status.clone());
517 if let (lsp_ext::Health::Error, Some(message)) = (status.health, &status.message) {
518 self.show_message(lsp_types::MessageType::ERROR, message.clone());
521 if self.config.server_status_notification() {
522 self.send_notification::<lsp_ext::ServerStatusNotification>(status);
526 let loop_duration = loop_start.elapsed();
527 if loop_duration > Duration::from_millis(100) {
528 tracing::warn!("overly long loop turn: {:?}", loop_duration);
529 self.poke_rust_analyzer_developer(format!(
530 "overly long loop turn: {:?}",
537 fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> {
538 self.register_request(&req, request_received);
540 if self.shutdown_requested {
541 self.respond(lsp_server::Response::new_err(
543 lsp_server::ErrorCode::InvalidRequest as i32,
544 "Shutdown already requested.".to_owned(),
550 // Avoid flashing a bunch of unresolved references during initial load.
551 if self.workspaces.is_empty() && !self.is_quiescent() {
552 self.respond(lsp_server::Response::new_err(
554 // FIXME: i32 should impl From<ErrorCode> (from() guarantees lossless conversion)
555 lsp_server::ErrorCode::ContentModified as i32,
556 "waiting for cargo metadata or cargo check".to_owned(),
561 RequestDispatcher { req: Some(req), global_state: self }
562 .on_sync_mut::<lsp_ext::ReloadWorkspace>(|s, ()| {
563 s.fetch_workspaces_queue.request_op();
566 .on_sync_mut::<lsp_types::request::Shutdown>(|s, ()| {
567 s.shutdown_requested = true;
570 .on_sync_mut::<lsp_ext::MemoryUsage>(handlers::handle_memory_usage)?
571 .on_sync_mut::<lsp_ext::ShuffleCrateGraph>(handlers::handle_shuffle_crate_graph)?
572 .on_sync::<lsp_ext::JoinLines>(handlers::handle_join_lines)?
573 .on_sync::<lsp_ext::OnEnter>(handlers::handle_on_enter)?
574 .on_sync::<lsp_types::request::SelectionRangeRequest>(handlers::handle_selection_range)?
575 .on_sync::<lsp_ext::MatchingBrace>(handlers::handle_matching_brace)?
576 .on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)
577 .on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)
578 .on::<lsp_ext::ViewHir>(handlers::handle_view_hir)
579 .on::<lsp_ext::ViewCrateGraph>(handlers::handle_view_crate_graph)
580 .on::<lsp_ext::ViewItemTree>(handlers::handle_view_item_tree)
581 .on::<lsp_ext::ExpandMacro>(handlers::handle_expand_macro)
582 .on::<lsp_ext::ParentModule>(handlers::handle_parent_module)
583 .on::<lsp_ext::Runnables>(handlers::handle_runnables)
584 .on::<lsp_ext::RelatedTests>(handlers::handle_related_tests)
585 .on::<lsp_ext::InlayHints>(handlers::handle_inlay_hints)
586 .on::<lsp_ext::CodeActionRequest>(handlers::handle_code_action)
587 .on::<lsp_ext::CodeActionResolveRequest>(handlers::handle_code_action_resolve)
588 .on::<lsp_ext::HoverRequest>(handlers::handle_hover)
589 .on::<lsp_ext::ExternalDocs>(handlers::handle_open_docs)
590 .on::<lsp_ext::OpenCargoToml>(handlers::handle_open_cargo_toml)
591 .on::<lsp_ext::MoveItem>(handlers::handle_move_item)
592 .on::<lsp_ext::WorkspaceSymbol>(handlers::handle_workspace_symbol)
593 .on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting)
594 .on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)
595 .on::<lsp_types::request::GotoDefinition>(handlers::handle_goto_definition)
596 .on::<lsp_types::request::GotoDeclaration>(handlers::handle_goto_declaration)
597 .on::<lsp_types::request::GotoImplementation>(handlers::handle_goto_implementation)
598 .on::<lsp_types::request::GotoTypeDefinition>(handlers::handle_goto_type_definition)
599 .on::<lsp_types::request::Completion>(handlers::handle_completion)
600 .on::<lsp_types::request::ResolveCompletionItem>(handlers::handle_completion_resolve)
601 .on::<lsp_types::request::CodeLensRequest>(handlers::handle_code_lens)
602 .on::<lsp_types::request::CodeLensResolve>(handlers::handle_code_lens_resolve)
603 .on::<lsp_types::request::FoldingRangeRequest>(handlers::handle_folding_range)
604 .on::<lsp_types::request::SignatureHelpRequest>(handlers::handle_signature_help)
605 .on::<lsp_types::request::PrepareRenameRequest>(handlers::handle_prepare_rename)
606 .on::<lsp_types::request::Rename>(handlers::handle_rename)
607 .on::<lsp_types::request::References>(handlers::handle_references)
608 .on::<lsp_types::request::Formatting>(handlers::handle_formatting)
609 .on::<lsp_types::request::RangeFormatting>(handlers::handle_range_formatting)
610 .on::<lsp_types::request::DocumentHighlightRequest>(handlers::handle_document_highlight)
611 .on::<lsp_types::request::CallHierarchyPrepare>(handlers::handle_call_hierarchy_prepare)
612 .on::<lsp_types::request::CallHierarchyIncomingCalls>(
613 handlers::handle_call_hierarchy_incoming,
615 .on::<lsp_types::request::CallHierarchyOutgoingCalls>(
616 handlers::handle_call_hierarchy_outgoing,
618 .on::<lsp_types::request::SemanticTokensFullRequest>(
619 handlers::handle_semantic_tokens_full,
621 .on::<lsp_types::request::SemanticTokensFullDeltaRequest>(
622 handlers::handle_semantic_tokens_full_delta,
624 .on::<lsp_types::request::SemanticTokensRangeRequest>(
625 handlers::handle_semantic_tokens_range,
627 .on::<lsp_types::request::WillRenameFiles>(handlers::handle_will_rename_files)
628 .on::<lsp_ext::Ssr>(handlers::handle_ssr)
632 fn on_notification(&mut self, not: Notification) -> Result<()> {
633 NotificationDispatcher { not: Some(not), global_state: self }
634 .on::<lsp_types::notification::Cancel>(|this, params| {
635 let id: lsp_server::RequestId = match params.id {
636 lsp_types::NumberOrString::Number(id) => id.into(),
637 lsp_types::NumberOrString::String(id) => id.into(),
642 .on::<lsp_types::notification::WorkDoneProgressCancel>(|_this, _params| {
643 // Just ignore this. It is OK to continue sending progress
644 // notifications for this token, as the client can't know when
645 // we accepted notification.
648 .on::<lsp_types::notification::DidOpenTextDocument>(|this, params| {
649 if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) {
652 .insert(path.clone(), DocumentData::new(params.text_document.version))
655 tracing::error!("duplicate DidOpenTextDocument: {}", path)
660 .set_file_contents(path, Some(params.text_document.text.into_bytes()));
664 .on::<lsp_types::notification::DidChangeTextDocument>(|this, params| {
665 if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) {
666 match this.mem_docs.get_mut(&path) {
668 // The version passed in DidChangeTextDocument is the version after all edits are applied
669 // so we should apply it before the vfs is notified.
670 doc.version = params.text_document.version;
673 tracing::error!("unexpected DidChangeTextDocument: {}; send DidOpenTextDocument first", path);
678 let vfs = &mut this.vfs.write().0;
679 let file_id = vfs.file_id(&path).unwrap();
680 let mut text = String::from_utf8(vfs.file_contents(file_id).to_vec()).unwrap();
681 apply_document_changes(&mut text, params.content_changes);
683 vfs.set_file_contents(path, Some(text.into_bytes()));
687 .on::<lsp_types::notification::DidCloseTextDocument>(|this, params| {
688 if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) {
689 if this.mem_docs.remove(&path).is_err() {
690 tracing::error!("orphan DidCloseTextDocument: {}", path);
693 this.semantic_tokens_cache.lock().remove(¶ms.text_document.uri);
695 if let Some(path) = path.as_path() {
696 this.loader.handle.invalidate(path.to_path_buf());
701 .on::<lsp_types::notification::DidSaveTextDocument>(|this, params| {
702 for flycheck in &this.flycheck {
705 if let Ok(abs_path) = from_proto::abs_path(¶ms.text_document.uri) {
706 if reload::should_refresh_for_change(&abs_path, ChangeKind::Modify) {
707 this.fetch_workspaces_queue.request_op();
712 .on::<lsp_types::notification::DidChangeConfiguration>(|this, _params| {
713 // As stated in https://github.com/microsoft/language-server-protocol/issues/676,
714 // this notification's parameters should be ignored and the actual config queried separately.
715 this.send_request::<lsp_types::request::WorkspaceConfiguration>(
716 lsp_types::ConfigurationParams {
717 items: vec![lsp_types::ConfigurationItem {
719 section: Some("rust-analyzer".to_string()),
723 tracing::debug!("config update response: '{:?}", resp);
724 let lsp_server::Response { error, result, .. } = resp;
726 match (error, result) {
728 tracing::error!("failed to fetch the server settings: {:?}", err)
730 (None, Some(mut configs)) => {
731 if let Some(json) = configs.get_mut(0) {
732 // Note that json can be null according to the spec if the client can't
733 // provide a configuration. This is handled in Config::update below.
734 let mut config = Config::clone(&*this.config);
735 if let Err(errors) = config.update(json.take()) {
738 .format_with("\n", |(key, e),f| {
743 let msg= format!("Failed to deserialize config key(s):\n{}", errors);
744 this.show_message(lsp_types::MessageType::WARNING, msg);
746 this.update_configuration(config);
749 (None, None) => tracing::error!(
750 "received empty server settings response from the client"
758 .on::<lsp_types::notification::DidChangeWatchedFiles>(|this, params| {
759 for change in params.changes {
760 if let Ok(path) = from_proto::abs_path(&change.uri) {
761 this.loader.handle.invalidate(path);
770 fn update_diagnostics(&mut self) {
771 let subscriptions = self
774 .map(|path| self.vfs.read().0.file_id(path).unwrap())
775 .collect::<Vec<_>>();
777 tracing::trace!("updating notifications for {:?}", subscriptions);
779 let snapshot = self.snapshot();
780 self.task_pool.handle.spawn(move || {
781 let diagnostics = subscriptions
783 .filter_map(|file_id| {
784 handlers::publish_diagnostics(&snapshot, file_id)
786 if !is_cancelled(&*err) {
787 tracing::error!("failed to compute diagnostics: {:?}", err);
791 .map(|diags| (file_id, diags))
793 .collect::<Vec<_>>();
794 Task::Diagnostics(diagnostics)