mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-24 02:46:43 +00:00
Add files to project diagnostics view in order
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
c7eb6a6a60
commit
747d9e8784
3 changed files with 27 additions and 26 deletions
|
@ -1,7 +1,7 @@
|
||||||
pub mod items;
|
pub mod items;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use collections::{HashMap, HashSet};
|
use collections::{HashMap, HashSet, BTreeSet};
|
||||||
use editor::{
|
use editor::{
|
||||||
context_header_renderer, diagnostic_block_renderer, diagnostic_header_renderer,
|
context_header_renderer, diagnostic_block_renderer, diagnostic_header_renderer,
|
||||||
display_map::{BlockDisposition, BlockId, BlockProperties},
|
display_map::{BlockDisposition, BlockId, BlockProperties},
|
||||||
|
@ -15,7 +15,7 @@ use gpui::{
|
||||||
use language::{Bias, Buffer, DiagnosticEntry, Point, Selection, SelectionGoal};
|
use language::{Bias, Buffer, DiagnosticEntry, Point, Selection, SelectionGoal};
|
||||||
use postage::watch;
|
use postage::watch;
|
||||||
use project::{Project, ProjectPath, WorktreeId};
|
use project::{Project, ProjectPath, WorktreeId};
|
||||||
use std::{cmp::Ordering, mem, ops::Range, path::Path, sync::Arc};
|
use std::{cmp::Ordering, mem, ops::Range};
|
||||||
use util::TryFutureExt;
|
use util::TryFutureExt;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
|
@ -48,8 +48,8 @@ struct ProjectDiagnosticsEditor {
|
||||||
workspace: WeakViewHandle<Workspace>,
|
workspace: WeakViewHandle<Workspace>,
|
||||||
editor: ViewHandle<Editor>,
|
editor: ViewHandle<Editor>,
|
||||||
excerpts: ModelHandle<MultiBuffer>,
|
excerpts: ModelHandle<MultiBuffer>,
|
||||||
path_states: Vec<(Arc<Path>, Vec<DiagnosticGroupState>)>,
|
path_states: Vec<(ProjectPath, Vec<DiagnosticGroupState>)>,
|
||||||
paths_to_update: HashMap<WorktreeId, HashSet<ProjectPath>>,
|
paths_to_update: HashMap<WorktreeId, BTreeSet<ProjectPath>>,
|
||||||
build_settings: BuildSettings,
|
build_settings: BuildSettings,
|
||||||
settings: watch::Receiver<workspace::Settings>,
|
settings: watch::Receiver<workspace::Settings>,
|
||||||
}
|
}
|
||||||
|
@ -206,15 +206,21 @@ impl ProjectDiagnosticsEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_excerpts(&self, paths: HashSet<ProjectPath>, cx: &mut ViewContext<Self>) {
|
fn update_excerpts(
|
||||||
|
&self,
|
||||||
|
paths: BTreeSet<ProjectPath>,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) {
|
||||||
let project = self.model.read(cx).project.clone();
|
let project = self.model.read(cx).project.clone();
|
||||||
cx.spawn(|this, mut cx| {
|
cx.spawn(|this, mut cx| {
|
||||||
async move {
|
async move {
|
||||||
for path in paths {
|
for path in paths {
|
||||||
let buffer = project
|
let buffer = project
|
||||||
.update(&mut cx, |project, cx| project.open_buffer(path, cx))
|
.update(&mut cx, |project, cx| project.open_buffer(path.clone(), cx))
|
||||||
.await?;
|
.await?;
|
||||||
this.update(&mut cx, |view, cx| view.populate_excerpts(buffer, cx))
|
this.update(&mut cx, |view, cx| {
|
||||||
|
view.populate_excerpts(path, buffer, cx)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
Result::<_, anyhow::Error>::Ok(())
|
Result::<_, anyhow::Error>::Ok(())
|
||||||
}
|
}
|
||||||
|
@ -223,23 +229,17 @@ impl ProjectDiagnosticsEditor {
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn populate_excerpts(&mut self, buffer: ModelHandle<Buffer>, cx: &mut ViewContext<Self>) {
|
fn populate_excerpts(
|
||||||
let snapshot;
|
&mut self,
|
||||||
let path;
|
path: ProjectPath,
|
||||||
{
|
buffer: ModelHandle<Buffer>,
|
||||||
let buffer = buffer.read(cx);
|
cx: &mut ViewContext<Self>,
|
||||||
snapshot = buffer.snapshot();
|
) {
|
||||||
if let Some(file) = buffer.file() {
|
|
||||||
path = file.path().clone();
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let was_empty = self.path_states.is_empty();
|
let was_empty = self.path_states.is_empty();
|
||||||
|
let snapshot = buffer.read(cx).snapshot();
|
||||||
let path_ix = match self
|
let path_ix = match self
|
||||||
.path_states
|
.path_states
|
||||||
.binary_search_by_key(&path.as_ref(), |e| e.0.as_ref())
|
.binary_search_by_key(&&path, |e| &e.0)
|
||||||
{
|
{
|
||||||
Ok(ix) => ix,
|
Ok(ix) => ix,
|
||||||
Err(ix) => {
|
Err(ix) => {
|
||||||
|
@ -445,11 +445,11 @@ impl ProjectDiagnosticsEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.editor.update(cx, |editor, cx| {
|
self.editor.update(cx, |editor, cx| {
|
||||||
let groups = self.path_states.get(path_ix)?.1.as_slice();
|
let groups;
|
||||||
|
|
||||||
let mut selections;
|
let mut selections;
|
||||||
let new_excerpt_ids_by_selection_id;
|
let new_excerpt_ids_by_selection_id;
|
||||||
if was_empty {
|
if was_empty {
|
||||||
|
groups = self.path_states.first()?.1.as_slice();
|
||||||
new_excerpt_ids_by_selection_id = [(0, ExcerptId::min())].into_iter().collect();
|
new_excerpt_ids_by_selection_id = [(0, ExcerptId::min())].into_iter().collect();
|
||||||
selections = vec![Selection {
|
selections = vec![Selection {
|
||||||
id: 0,
|
id: 0,
|
||||||
|
@ -459,6 +459,7 @@ impl ProjectDiagnosticsEditor {
|
||||||
goal: SelectionGoal::None,
|
goal: SelectionGoal::None,
|
||||||
}];
|
}];
|
||||||
} else {
|
} else {
|
||||||
|
groups = self.path_states.get(path_ix)?.1.as_slice();
|
||||||
new_excerpt_ids_by_selection_id = editor.refresh_selections(cx);
|
new_excerpt_ids_by_selection_id = editor.refresh_selections(cx);
|
||||||
selections = editor.local_selections::<usize>(cx);
|
selections = editor.local_selections::<usize>(cx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ pub enum Event {
|
||||||
DiagnosticsUpdated(ProjectPath),
|
DiagnosticsUpdated(ProjectPath),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
|
||||||
pub struct ProjectPath {
|
pub struct ProjectPath {
|
||||||
pub worktree_id: WorktreeId,
|
pub worktree_id: WorktreeId,
|
||||||
pub path: Arc<Path>,
|
pub path: Arc<Path>,
|
||||||
|
|
|
@ -57,7 +57,7 @@ enum ScanState {
|
||||||
Err(Arc<anyhow::Error>),
|
Err(Arc<anyhow::Error>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
|
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, PartialOrd, Ord)]
|
||||||
pub struct WorktreeId(usize);
|
pub struct WorktreeId(usize);
|
||||||
|
|
||||||
pub enum Worktree {
|
pub enum Worktree {
|
||||||
|
@ -711,7 +711,7 @@ impl Worktree {
|
||||||
let mut primary_diagnostic_group_ids = HashMap::default();
|
let mut primary_diagnostic_group_ids = HashMap::default();
|
||||||
let mut sources_by_group_id = HashMap::default();
|
let mut sources_by_group_id = HashMap::default();
|
||||||
let mut supporting_diagnostic_severities = HashMap::default();
|
let mut supporting_diagnostic_severities = HashMap::default();
|
||||||
for diagnostic in ¶ms.diagnostics {
|
for diagnostic in dbg!(¶ms.diagnostics) {
|
||||||
let source = diagnostic.source.as_ref();
|
let source = diagnostic.source.as_ref();
|
||||||
let code = diagnostic.code.as_ref().map(|code| match code {
|
let code = diagnostic.code.as_ref().map(|code| match code {
|
||||||
lsp::NumberOrString::Number(code) => code.to_string(),
|
lsp::NumberOrString::Number(code) => code.to_string(),
|
||||||
|
|
Loading…
Reference in a new issue