from_proto,
global_state::{file_id_to_url, url_to_file_id, GlobalState},
handlers, lsp_ext,
- lsp_utils::{apply_document_changes, is_cancelled, notification_is, Progress},
+ lsp_utils::{apply_document_changes, notification_is, Progress},
mem_docs::DocumentData,
reload::{self, BuildDataProgress, ProjectWorkspaceProgress},
Result,
#[derive(Debug)]
pub(crate) enum Task {
Response(lsp_server::Response),
+ Retry(lsp_server::Request),
Diagnostics(Vec<(FileId, Vec<lsp_types::Diagnostic>)>),
PrimeCaches(PrimeCachesProgress),
FetchWorkspace(ProjectWorkspaceProgress),
let was_quiescent = self.is_quiescent();
match event {
Event::Lsp(msg) => match msg {
- lsp_server::Message::Request(req) => self.on_request(loop_start, req)?,
+ lsp_server::Message::Request(req) => self.on_request(loop_start, req),
lsp_server::Message::Notification(not) => {
self.on_notification(not)?;
}
loop {
match task {
Task::Response(response) => self.respond(response),
+ Task::Retry(req) => self.on_request(loop_start, req),
Task::Diagnostics(diagnostics_per_file) => {
for (file_id, diagnostics) in diagnostics_per_file {
self.diagnostics.set_native_diagnostics(file_id, diagnostics)
Ok(())
}
- fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> {
+ fn on_request(&mut self, request_received: Instant, req: Request) {
self.register_request(&req, request_received);
if self.shutdown_requested {
lsp_server::ErrorCode::InvalidRequest as i32,
"Shutdown already requested.".to_owned(),
));
-
- return Ok(());
+ return;
}
// Avoid flashing a bunch of unresolved references during initial load.
lsp_server::ErrorCode::ContentModified as i32,
"waiting for cargo metadata or cargo check".to_owned(),
));
- return Ok(());
+ return;
}
RequestDispatcher { req: Some(req), global_state: self }
.on_sync_mut::<lsp_types::request::Shutdown>(|s, ()| {
s.shutdown_requested = true;
Ok(())
- })?
- .on_sync_mut::<lsp_ext::ReloadWorkspace>(handlers::handle_workspace_reload)?
- .on_sync_mut::<lsp_ext::MemoryUsage>(handlers::handle_memory_usage)?
- .on_sync_mut::<lsp_ext::ShuffleCrateGraph>(handlers::handle_shuffle_crate_graph)?
- .on_sync::<lsp_ext::JoinLines>(handlers::handle_join_lines)?
- .on_sync::<lsp_ext::OnEnter>(handlers::handle_on_enter)?
- .on_sync::<lsp_types::request::SelectionRangeRequest>(handlers::handle_selection_range)?
- .on_sync::<lsp_ext::MatchingBrace>(handlers::handle_matching_brace)?
+ })
+ .on_sync_mut::<lsp_ext::ReloadWorkspace>(handlers::handle_workspace_reload)
+ .on_sync_mut::<lsp_ext::MemoryUsage>(handlers::handle_memory_usage)
+ .on_sync_mut::<lsp_ext::ShuffleCrateGraph>(handlers::handle_shuffle_crate_graph)
+ .on_sync::<lsp_ext::JoinLines>(handlers::handle_join_lines)
+ .on_sync::<lsp_ext::OnEnter>(handlers::handle_on_enter)
+ .on_sync::<lsp_types::request::SelectionRangeRequest>(handlers::handle_selection_range)
+ .on_sync::<lsp_ext::MatchingBrace>(handlers::handle_matching_brace)
.on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)
.on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)
.on::<lsp_ext::ViewHir>(handlers::handle_view_hir)
.on::<lsp_ext::OpenCargoToml>(handlers::handle_open_cargo_toml)
.on::<lsp_ext::MoveItem>(handlers::handle_move_item)
.on::<lsp_ext::WorkspaceSymbol>(handlers::handle_workspace_symbol)
- .on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting)
+ .on::<lsp_ext::OnTypeFormatting>(handlers::handle_on_type_formatting)
.on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)
.on::<lsp_types::request::GotoDefinition>(handlers::handle_goto_definition)
.on::<lsp_types::request::GotoDeclaration>(handlers::handle_goto_declaration)
.on::<lsp_types::request::WillRenameFiles>(handlers::handle_will_rename_files)
.on::<lsp_ext::Ssr>(handlers::handle_ssr)
.finish();
- Ok(())
}
+
fn on_notification(&mut self, not: Notification) -> Result<()> {
NotificationDispatcher { not: Some(not), global_state: self }
.on::<lsp_types::notification::Cancel>(|this, params| {
})?
.on::<lsp_types::notification::DidOpenTextDocument>(|this, params| {
if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) {
- if this
+ let already_exists = this
.mem_docs
.insert(path.clone(), DocumentData::new(params.text_document.version))
- .is_err()
- {
+ .is_err();
+ if already_exists {
tracing::error!("duplicate DidOpenTextDocument: {}", path)
}
this.vfs
doc.version = params.text_document.version;
}
None => {
- tracing::error!("unexpected DidChangeTextDocument: {}; send DidOpenTextDocument first", path);
+ tracing::error!("unexpected DidChangeTextDocument: {}", path);
return Ok(());
}
};
}
if let Ok(abs_path) = from_proto::abs_path(¶ms.text_document.uri) {
if reload::should_refresh_for_change(&abs_path, ChangeKind::Modify) {
- this.fetch_workspaces_queue.request_op(format!("DidSaveTextDocument {}", abs_path.display()));
+ this.fetch_workspaces_queue
+ .request_op(format!("DidSaveTextDocument {}", abs_path.display()));
}
}
Ok(())
// provide a configuration. This is handled in Config::update below.
let mut config = Config::clone(&*this.config);
if let Err(error) = config.update(json.take()) {
- this.show_message(lsp_types::MessageType::WARNING, error.to_string());
+ this.show_message(
+ lsp_types::MessageType::WARNING,
+ error.to_string(),
+ );
}
this.update_configuration(config);
}
.into_iter()
.filter_map(|file_id| {
handlers::publish_diagnostics(&snapshot, file_id)
- .map_err(|err| {
- if !is_cancelled(&*err) {
- tracing::error!("failed to compute diagnostics: {:?}", err);
- }
- })
.ok()
.map(|diags| (file_id, diags))
})