Don't reuse the same diagnostic group id across buffers
This lets us use the group id as the key for an `ElementState`, which fixes a panic that would occur in project diagnostics when opening it while there were multiple diagnostic groups with the same id.
This commit is contained in:
parent
c34b30e739
commit
6baf8b033b
2 changed files with 10 additions and 8 deletions
|
@ -1359,7 +1359,7 @@ async fn test_collaborating_with_diagnostics(
|
||||||
DiagnosticEntry {
|
DiagnosticEntry {
|
||||||
range: Point::new(0, 4)..Point::new(0, 7),
|
range: Point::new(0, 4)..Point::new(0, 7),
|
||||||
diagnostic: Diagnostic {
|
diagnostic: Diagnostic {
|
||||||
group_id: 0,
|
group_id: 1,
|
||||||
message: "message 1".to_string(),
|
message: "message 1".to_string(),
|
||||||
severity: lsp::DiagnosticSeverity::ERROR,
|
severity: lsp::DiagnosticSeverity::ERROR,
|
||||||
is_primary: true,
|
is_primary: true,
|
||||||
|
@ -1369,7 +1369,7 @@ async fn test_collaborating_with_diagnostics(
|
||||||
DiagnosticEntry {
|
DiagnosticEntry {
|
||||||
range: Point::new(0, 10)..Point::new(0, 13),
|
range: Point::new(0, 10)..Point::new(0, 13),
|
||||||
diagnostic: Diagnostic {
|
diagnostic: Diagnostic {
|
||||||
group_id: 1,
|
group_id: 2,
|
||||||
severity: lsp::DiagnosticSeverity::WARNING,
|
severity: lsp::DiagnosticSeverity::WARNING,
|
||||||
message: "message 2".to_string(),
|
message: "message 2".to_string(),
|
||||||
is_primary: true,
|
is_primary: true,
|
||||||
|
|
|
@ -73,6 +73,7 @@ pub struct Project {
|
||||||
next_language_server_id: usize,
|
next_language_server_id: usize,
|
||||||
client: Arc<client::Client>,
|
client: Arc<client::Client>,
|
||||||
next_entry_id: Arc<AtomicUsize>,
|
next_entry_id: Arc<AtomicUsize>,
|
||||||
|
next_diagnostic_group_id: usize,
|
||||||
user_store: ModelHandle<UserStore>,
|
user_store: ModelHandle<UserStore>,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
client_state: ProjectClientState,
|
client_state: ProjectClientState,
|
||||||
|
@ -355,6 +356,7 @@ impl Project {
|
||||||
user_store,
|
user_store,
|
||||||
fs,
|
fs,
|
||||||
next_entry_id: Default::default(),
|
next_entry_id: Default::default(),
|
||||||
|
next_diagnostic_group_id: Default::default(),
|
||||||
language_servers: Default::default(),
|
language_servers: Default::default(),
|
||||||
started_language_servers: Default::default(),
|
started_language_servers: Default::default(),
|
||||||
language_server_statuses: Default::default(),
|
language_server_statuses: Default::default(),
|
||||||
|
@ -424,6 +426,7 @@ impl Project {
|
||||||
user_store: user_store.clone(),
|
user_store: user_store.clone(),
|
||||||
fs,
|
fs,
|
||||||
next_entry_id: Default::default(),
|
next_entry_id: Default::default(),
|
||||||
|
next_diagnostic_group_id: Default::default(),
|
||||||
subscriptions: vec![client.add_model_for_remote_entity(remote_id, cx)],
|
subscriptions: vec![client.add_model_for_remote_entity(remote_id, cx)],
|
||||||
client: client.clone(),
|
client: client.clone(),
|
||||||
client_state: ProjectClientState::Remote {
|
client_state: ProjectClientState::Remote {
|
||||||
|
@ -2121,7 +2124,6 @@ impl Project {
|
||||||
.uri
|
.uri
|
||||||
.to_file_path()
|
.to_file_path()
|
||||||
.map_err(|_| anyhow!("URI is not a file"))?;
|
.map_err(|_| anyhow!("URI is not a file"))?;
|
||||||
let mut next_group_id = 0;
|
|
||||||
let mut diagnostics = Vec::default();
|
let mut diagnostics = Vec::default();
|
||||||
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();
|
||||||
|
@ -2156,7 +2158,7 @@ impl Project {
|
||||||
(diagnostic.severity, is_unnecessary),
|
(diagnostic.severity, is_unnecessary),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let group_id = post_inc(&mut next_group_id);
|
let group_id = post_inc(&mut self.next_diagnostic_group_id);
|
||||||
let is_disk_based = source.map_or(false, |source| {
|
let is_disk_based = source.map_or(false, |source| {
|
||||||
disk_based_sources.contains(&source.as_str())
|
disk_based_sources.contains(&source.as_str())
|
||||||
});
|
});
|
||||||
|
@ -6270,7 +6272,7 @@ mod tests {
|
||||||
severity: DiagnosticSeverity::WARNING,
|
severity: DiagnosticSeverity::WARNING,
|
||||||
message: "unreachable statement".to_string(),
|
message: "unreachable statement".to_string(),
|
||||||
is_disk_based: true,
|
is_disk_based: true,
|
||||||
group_id: 1,
|
group_id: 4,
|
||||||
is_primary: true,
|
is_primary: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
@ -6281,7 +6283,7 @@ mod tests {
|
||||||
severity: DiagnosticSeverity::ERROR,
|
severity: DiagnosticSeverity::ERROR,
|
||||||
message: "undefined variable 'A'".to_string(),
|
message: "undefined variable 'A'".to_string(),
|
||||||
is_disk_based: true,
|
is_disk_based: true,
|
||||||
group_id: 0,
|
group_id: 3,
|
||||||
is_primary: true,
|
is_primary: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
@ -6359,7 +6361,7 @@ mod tests {
|
||||||
severity: DiagnosticSeverity::WARNING,
|
severity: DiagnosticSeverity::WARNING,
|
||||||
message: "undefined variable 'A'".to_string(),
|
message: "undefined variable 'A'".to_string(),
|
||||||
is_disk_based: true,
|
is_disk_based: true,
|
||||||
group_id: 1,
|
group_id: 6,
|
||||||
is_primary: true,
|
is_primary: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
@ -6370,7 +6372,7 @@ mod tests {
|
||||||
severity: DiagnosticSeverity::ERROR,
|
severity: DiagnosticSeverity::ERROR,
|
||||||
message: "undefined variable 'BB'".to_string(),
|
message: "undefined variable 'BB'".to_string(),
|
||||||
is_disk_based: true,
|
is_disk_based: true,
|
||||||
group_id: 0,
|
group_id: 5,
|
||||||
is_primary: true,
|
is_primary: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue