Remove the blocking call and inline on_lsp_diagnostics_published

This commit is contained in:
Isaac Clayton 2022-07-11 12:11:00 +02:00
parent 14bccb4a90
commit 3ad8d5363c
2 changed files with 22 additions and 37 deletions

View file

@ -14,7 +14,7 @@ use futures::{
future::{BoxFuture, Shared}, future::{BoxFuture, Shared},
FutureExt, TryFutureExt, FutureExt, TryFutureExt,
}; };
use gpui::{AsyncAppContext, MutableAppContext, Task}; use gpui::{MutableAppContext, Task};
use highlight_map::HighlightMap; use highlight_map::HighlightMap;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use parking_lot::{Mutex, RwLock}; use parking_lot::{Mutex, RwLock};

View file

@ -12,7 +12,7 @@ use anyhow::{anyhow, Context, Result};
use client::{proto, Client, PeerId, TypedEnvelope, User, UserStore}; use client::{proto, Client, PeerId, TypedEnvelope, User, UserStore};
use clock::ReplicaId; use clock::ReplicaId;
use collections::{hash_map, BTreeMap, HashMap, HashSet}; use collections::{hash_map, BTreeMap, HashMap, HashSet};
use futures::{future::Shared, AsyncWriteExt, Future, FutureExt, SinkExt, StreamExt, TryFutureExt}; use futures::{future::Shared, AsyncWriteExt, Future, FutureExt, StreamExt, TryFutureExt};
use fuzzy::{PathMatch, PathMatchCandidate, PathMatchCandidateSet}; use fuzzy::{PathMatch, PathMatchCandidate, PathMatchCandidateSet};
use gpui::{ use gpui::{
AnyModelHandle, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, AnyModelHandle, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle,
@ -2118,23 +2118,24 @@ impl Project {
.on_notification::<lsp::notification::PublishDiagnostics, _>({ .on_notification::<lsp::notification::PublishDiagnostics, _>({
let this = this.downgrade(); let this = this.downgrade();
let adapter = adapter.clone(); let adapter = adapter.clone();
move |params, mut cx| { move |mut params, cx| {
if let Some(this) = this.upgrade(&cx) { let this = this.clone();
// cx.spawn(|cx| { let adapter = adapter.clone();
// this.update(&mut cx, |this, cx| { cx.spawn(|mut cx| async move {
// this.on_lsp_diagnostics_published( adapter.process_diagnostics(&mut params).await;
// server_id, params, adapter, cx, if let Some(this) = this.upgrade(&cx) {
// ) this.update(&mut cx, |this, cx| {
// }) this.update_diagnostics(
// }) server_id,
// .detach(); params,
this.update(&mut cx, |this, cx| { &adapter.disk_based_diagnostic_sources,
// TODO(isaac): remove block on cx,
smol::block_on(this.on_lsp_diagnostics_published( )
server_id, params, &adapter, cx, .log_err();
)); });
}); }
} })
.detach();
} }
}) })
.detach(); .detach();
@ -2480,23 +2481,6 @@ impl Project {
.detach(); .detach();
} }
async fn on_lsp_diagnostics_published(
&mut self,
server_id: usize,
mut params: lsp::PublishDiagnosticsParams,
adapter: &Arc<LspAdapter>,
cx: &mut ModelContext<'_, Self>,
) {
adapter.process_diagnostics(&mut params).await;
self.update_diagnostics(
server_id,
params,
&adapter.disk_based_diagnostic_sources,
cx,
)
.log_err();
}
fn on_lsp_progress( fn on_lsp_progress(
&mut self, &mut self,
progress: lsp::ProgressParams, progress: lsp::ProgressParams,
@ -3580,7 +3564,7 @@ impl Project {
continue; continue;
} }
let (old_range, new_text) = match lsp_completion.text_edit.as_ref() { let (old_range, mut new_text) = match lsp_completion.text_edit.as_ref() {
// If the language server provides a range to overwrite, then // If the language server provides a range to overwrite, then
// check that the range is valid. // check that the range is valid.
Some(lsp::CompletionTextEdit::Edit(edit)) => { Some(lsp::CompletionTextEdit::Edit(edit)) => {
@ -3630,6 +3614,7 @@ impl Project {
} }
}; };
LineEnding::normalize(&mut new_text);
let partial_completion = PartialCompletion { let partial_completion = PartialCompletion {
old_range, old_range,
new_text, new_text,