WIP
Co-Authored-By: Antonio Scandurra <me@as-cii.com> Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
parent
7b453beebc
commit
e3ecd87081
6 changed files with 156 additions and 58 deletions
|
@ -77,7 +77,7 @@ pub struct Buffer {
|
|||
pub struct BufferSnapshot {
|
||||
text: text::BufferSnapshot,
|
||||
tree: Option<Tree>,
|
||||
diagnostics: DiagnosticSet,
|
||||
diagnostics: HashMap<&'static str, DiagnosticSet>,
|
||||
remote_selections: TreeMap<ReplicaId, Arc<[Selection<Anchor>]>>,
|
||||
diagnostics_update_count: usize,
|
||||
is_parsing: bool,
|
||||
|
@ -115,7 +115,7 @@ struct LanguageServerSnapshot {
|
|||
pub enum Operation {
|
||||
Buffer(text::Operation),
|
||||
UpdateDiagnostics {
|
||||
diagnostics: Arc<[DiagnosticEntry<Anchor>]>,
|
||||
diagnostic_set: Arc<DiagnosticSet>,
|
||||
lamport_timestamp: clock::Lamport,
|
||||
},
|
||||
UpdateSelections {
|
||||
|
@ -298,10 +298,12 @@ impl Buffer {
|
|||
proto::deserialize_selections(selection_set.selections),
|
||||
);
|
||||
}
|
||||
this.apply_diagnostic_update(
|
||||
Arc::from(proto::deserialize_diagnostics(message.diagnostics)),
|
||||
cx,
|
||||
);
|
||||
for diagnostic_set in message.diagnostic_sets {
|
||||
this.apply_diagnostic_update(
|
||||
Arc::from(proto::deserialize_diagnostics(diagnostic_set)),
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
||||
Ok(this)
|
||||
}
|
||||
|
@ -323,7 +325,7 @@ impl Buffer {
|
|||
selections: proto::serialize_selections(selections),
|
||||
})
|
||||
.collect(),
|
||||
diagnostics: proto::serialize_diagnostics(self.diagnostics.iter()),
|
||||
diagnostics: proto::serialize_diagnostic_set(self.diagnostics.iter()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,9 @@ use std::{
|
|||
use sum_tree::{self, Bias, SumTree};
|
||||
use text::{Anchor, FromAnchor, PointUtf16, ToOffset};
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct DiagnosticSet {
|
||||
provider_name: String,
|
||||
diagnostics: SumTree<DiagnosticEntry<Anchor>>,
|
||||
}
|
||||
|
||||
|
@ -34,22 +35,32 @@ pub struct Summary {
|
|||
}
|
||||
|
||||
impl DiagnosticSet {
|
||||
pub fn from_sorted_entries<I>(iter: I, buffer: &text::BufferSnapshot) -> Self
|
||||
pub fn provider_name(&self) -> &str {
|
||||
&self.provider_name
|
||||
}
|
||||
|
||||
pub fn from_sorted_entries<I>(
|
||||
provider_name: String,
|
||||
iter: I,
|
||||
buffer: &text::BufferSnapshot,
|
||||
) -> Self
|
||||
where
|
||||
I: IntoIterator<Item = DiagnosticEntry<Anchor>>,
|
||||
{
|
||||
Self {
|
||||
provider_name,
|
||||
diagnostics: SumTree::from_iter(iter, buffer),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new<I>(iter: I, buffer: &text::BufferSnapshot) -> Self
|
||||
pub fn new<I>(provider_name: &'static str, iter: I, buffer: &text::BufferSnapshot) -> Self
|
||||
where
|
||||
I: IntoIterator<Item = DiagnosticEntry<PointUtf16>>,
|
||||
{
|
||||
let mut entries = iter.into_iter().collect::<Vec<_>>();
|
||||
entries.sort_unstable_by_key(|entry| (entry.range.start, Reverse(entry.range.end)));
|
||||
Self {
|
||||
provider_name,
|
||||
diagnostics: SumTree::from_iter(
|
||||
entries.into_iter().map(|entry| DiagnosticEntry {
|
||||
range: buffer.anchor_before(entry.range.start)
|
||||
|
|
|
@ -66,6 +66,8 @@ pub struct BracketPair {
|
|||
|
||||
#[async_trait]
|
||||
pub trait DiagnosticSource: 'static + Send + Sync {
|
||||
fn name(&self) -> &'static str;
|
||||
|
||||
async fn diagnose(
|
||||
&self,
|
||||
path: Arc<Path>,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{diagnostic_set::DiagnosticEntry, Diagnostic, Operation};
|
||||
use crate::{diagnostic_set::DiagnosticEntry, Diagnostic, DiagnosticSet, Operation};
|
||||
use anyhow::{anyhow, Result};
|
||||
use clock::ReplicaId;
|
||||
use lsp::DiagnosticSeverity;
|
||||
|
@ -57,12 +57,12 @@ pub fn serialize_operation(operation: &Operation) -> proto::Operation {
|
|||
lamport_timestamp: lamport_timestamp.value,
|
||||
}),
|
||||
Operation::UpdateDiagnostics {
|
||||
diagnostics,
|
||||
diagnostic_set,
|
||||
lamport_timestamp,
|
||||
} => proto::operation::Variant::UpdateDiagnostics(proto::UpdateDiagnostics {
|
||||
} => proto::operation::Variant::UpdateDiagnosticSet(proto::UpdateDiagnosticSet {
|
||||
replica_id: lamport_timestamp.replica_id as u32,
|
||||
lamport_timestamp: lamport_timestamp.value,
|
||||
diagnostics: serialize_diagnostics(diagnostics.iter()),
|
||||
diagnostic_set: Some(serialize_diagnostic_set(&diagnostic_set)),
|
||||
}),
|
||||
}),
|
||||
}
|
||||
|
@ -99,29 +99,30 @@ pub fn serialize_selections(selections: &Arc<[Selection<Anchor>]>) -> Vec<proto:
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn serialize_diagnostics<'a>(
|
||||
diagnostics: impl IntoIterator<Item = &'a DiagnosticEntry<Anchor>>,
|
||||
) -> Vec<proto::Diagnostic> {
|
||||
diagnostics
|
||||
.into_iter()
|
||||
.map(|entry| proto::Diagnostic {
|
||||
start: Some(serialize_anchor(&entry.range.start)),
|
||||
end: Some(serialize_anchor(&entry.range.end)),
|
||||
message: entry.diagnostic.message.clone(),
|
||||
severity: match entry.diagnostic.severity {
|
||||
DiagnosticSeverity::ERROR => proto::diagnostic::Severity::Error,
|
||||
DiagnosticSeverity::WARNING => proto::diagnostic::Severity::Warning,
|
||||
DiagnosticSeverity::INFORMATION => proto::diagnostic::Severity::Information,
|
||||
DiagnosticSeverity::HINT => proto::diagnostic::Severity::Hint,
|
||||
_ => proto::diagnostic::Severity::None,
|
||||
} as i32,
|
||||
group_id: entry.diagnostic.group_id as u64,
|
||||
is_primary: entry.diagnostic.is_primary,
|
||||
is_valid: entry.diagnostic.is_valid,
|
||||
code: entry.diagnostic.code.clone(),
|
||||
is_disk_based: entry.diagnostic.is_disk_based,
|
||||
})
|
||||
.collect()
|
||||
pub fn serialize_diagnostic_set(set: &DiagnosticSet) -> proto::DiagnosticSet {
|
||||
proto::DiagnosticSet {
|
||||
provider_name: set.provider_name().to_string(),
|
||||
diagnostics: set
|
||||
.iter()
|
||||
.map(|entry| proto::Diagnostic {
|
||||
start: Some(serialize_anchor(&entry.range.start)),
|
||||
end: Some(serialize_anchor(&entry.range.end)),
|
||||
message: entry.diagnostic.message.clone(),
|
||||
severity: match entry.diagnostic.severity {
|
||||
DiagnosticSeverity::ERROR => proto::diagnostic::Severity::Error,
|
||||
DiagnosticSeverity::WARNING => proto::diagnostic::Severity::Warning,
|
||||
DiagnosticSeverity::INFORMATION => proto::diagnostic::Severity::Information,
|
||||
DiagnosticSeverity::HINT => proto::diagnostic::Severity::Hint,
|
||||
_ => proto::diagnostic::Severity::None,
|
||||
} as i32,
|
||||
group_id: entry.diagnostic.group_id as u64,
|
||||
is_primary: entry.diagnostic.is_primary,
|
||||
is_valid: entry.diagnostic.is_valid,
|
||||
code: entry.diagnostic.code.clone(),
|
||||
is_disk_based: entry.diagnostic.is_disk_based,
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_anchor(anchor: &Anchor) -> proto::Anchor {
|
||||
|
@ -207,13 +208,15 @@ pub fn deserialize_operation(message: proto::Operation) -> Result<Operation> {
|
|||
value: message.lamport_timestamp,
|
||||
},
|
||||
},
|
||||
proto::operation::Variant::UpdateDiagnostics(message) => Operation::UpdateDiagnostics {
|
||||
diagnostics: Arc::from(deserialize_diagnostics(message.diagnostics)),
|
||||
lamport_timestamp: clock::Lamport {
|
||||
replica_id: message.replica_id as ReplicaId,
|
||||
value: message.lamport_timestamp,
|
||||
},
|
||||
},
|
||||
proto::operation::Variant::UpdateDiagnosticSet(message) => {
|
||||
Operation::UpdateDiagnostics {
|
||||
diagnostics: Arc::from(deserialize_diagnostic_set(message.diagnostic_set?)),
|
||||
lamport_timestamp: clock::Lamport {
|
||||
replica_id: message.replica_id as ReplicaId,
|
||||
value: message.lamport_timestamp,
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -253,12 +256,13 @@ pub fn deserialize_selections(selections: Vec<proto::Selection>) -> Arc<[Selecti
|
|||
)
|
||||
}
|
||||
|
||||
pub fn deserialize_diagnostics(
|
||||
diagnostics: Vec<proto::Diagnostic>,
|
||||
) -> Vec<DiagnosticEntry<Anchor>> {
|
||||
diagnostics
|
||||
.into_iter()
|
||||
.filter_map(|diagnostic| {
|
||||
pub fn deserialize_diagnostic_set(
|
||||
message: proto::DiagnosticSet,
|
||||
buffer: &BufferSnapshot,
|
||||
) -> DiagnosticSet {
|
||||
DiagnosticSet::from_sorted_entries(
|
||||
message.provider_name,
|
||||
message.diagnostics.into_iter().filter_map(|diagnostic| {
|
||||
Some(DiagnosticEntry {
|
||||
range: deserialize_anchor(diagnostic.start?)?..deserialize_anchor(diagnostic.end?)?,
|
||||
diagnostic: Diagnostic {
|
||||
|
@ -277,8 +281,9 @@ pub fn deserialize_diagnostics(
|
|||
is_disk_based: diagnostic.is_disk_based,
|
||||
},
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}),
|
||||
buffer,
|
||||
)
|
||||
}
|
||||
|
||||
fn deserialize_anchor(anchor: proto::Anchor) -> Option<Anchor> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue