mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-27 12:54:42 +00:00
Minor cleanup in Buffer::update_diagnostics
This commit is contained in:
parent
bc906fef9c
commit
3c26f67ea3
2 changed files with 14 additions and 17 deletions
|
@ -730,6 +730,9 @@ impl Buffer {
|
|||
let version = version.map(|version| version as usize);
|
||||
let content = if let Some(version) = version {
|
||||
let language_server = self.language_server.as_mut().unwrap();
|
||||
language_server
|
||||
.pending_snapshots
|
||||
.retain(|&v, _| v >= version);
|
||||
let snapshot = language_server
|
||||
.pending_snapshots
|
||||
.get(&version)
|
||||
|
@ -756,6 +759,10 @@ impl Buffer {
|
|||
let entry = &mut diagnostics[ix];
|
||||
let mut start = entry.range.start;
|
||||
let mut end = entry.range.end;
|
||||
|
||||
// Some diagnostics are based on files on disk instead of buffers'
|
||||
// current contents. Adjust these diagnostics' ranges to reflect
|
||||
// any unsaved edits.
|
||||
if entry
|
||||
.diagnostic
|
||||
.source
|
||||
|
@ -781,6 +788,8 @@ impl Buffer {
|
|||
|
||||
entry.range = content.clip_point_utf16(start, Bias::Left)
|
||||
..content.clip_point_utf16(end, Bias::Right);
|
||||
|
||||
// Expand empty ranges by one character
|
||||
if entry.range.start == entry.range.end {
|
||||
entry.range.end.column += 1;
|
||||
entry.range.end = content.clip_point_utf16(entry.range.end, Bias::Right);
|
||||
|
@ -794,19 +803,6 @@ impl Buffer {
|
|||
|
||||
drop(edits_since_save);
|
||||
self.diagnostics = DiagnosticSet::new(diagnostics, content);
|
||||
|
||||
if let Some(version) = version {
|
||||
let language_server = self.language_server.as_mut().unwrap();
|
||||
let versions_to_delete = language_server
|
||||
.pending_snapshots
|
||||
.range(..version)
|
||||
.map(|(v, _)| *v)
|
||||
.collect::<Vec<_>>();
|
||||
for version in versions_to_delete {
|
||||
language_server.pending_snapshots.remove(&version);
|
||||
}
|
||||
}
|
||||
|
||||
self.diagnostics_update_count += 1;
|
||||
cx.notify();
|
||||
cx.emit(Event::DiagnosticsUpdated);
|
||||
|
|
|
@ -9,10 +9,9 @@ use anyhow::{anyhow, Result};
|
|||
pub use buffer::Operation;
|
||||
pub use buffer::*;
|
||||
pub use diagnostic_set::DiagnosticEntry;
|
||||
use gpui::{executor::Background, AppContext};
|
||||
use gpui::AppContext;
|
||||
use highlight_map::HighlightMap;
|
||||
use lazy_static::lazy_static;
|
||||
use lsp::LanguageServer;
|
||||
use parking_lot::Mutex;
|
||||
use serde::Deserialize;
|
||||
use std::{collections::HashSet, path::Path, str, sync::Arc};
|
||||
|
@ -48,7 +47,7 @@ pub struct LanguageServerConfig {
|
|||
pub disk_based_diagnostic_sources: HashSet<String>,
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
#[serde(skip)]
|
||||
pub fake_server: Option<(Arc<LanguageServer>, Arc<std::sync::atomic::AtomicBool>)>,
|
||||
pub fake_server: Option<(Arc<lsp::LanguageServer>, Arc<std::sync::atomic::AtomicBool>)>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
|
@ -219,7 +218,9 @@ impl Grammar {
|
|||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
impl LanguageServerConfig {
|
||||
pub async fn fake(executor: Arc<Background>) -> (Self, lsp::FakeLanguageServer) {
|
||||
pub async fn fake(
|
||||
executor: Arc<gpui::executor::Background>,
|
||||
) -> (Self, lsp::FakeLanguageServer) {
|
||||
let (server, fake) = lsp::LanguageServer::fake(executor).await;
|
||||
fake.started
|
||||
.store(false, std::sync::atomic::Ordering::SeqCst);
|
||||
|
|
Loading…
Reference in a new issue