WIP: Use cargo check
for on-disk diagnostics
Co-Authored-By: Nathan Sobo <nathan@zed.dev> Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
parent
b9d1ca4341
commit
7b453beebc
7 changed files with 84 additions and 16 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2605,6 +2605,7 @@ name = "language"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"async-trait",
|
||||||
"clock",
|
"clock",
|
||||||
"collections",
|
"collections",
|
||||||
"ctor",
|
"ctor",
|
||||||
|
|
|
@ -162,12 +162,12 @@ impl ItemView for Editor {
|
||||||
let (language, language_server) = worktree.update(&mut cx, |worktree, cx| {
|
let (language, language_server) = worktree.update(&mut cx, |worktree, cx| {
|
||||||
let worktree = worktree.as_local_mut().unwrap();
|
let worktree = worktree.as_local_mut().unwrap();
|
||||||
let language = worktree
|
let language = worktree
|
||||||
.languages()
|
.language_registry()
|
||||||
.select_language(new_file.full_path())
|
.select_language(new_file.full_path())
|
||||||
.cloned();
|
.cloned();
|
||||||
let language_server = language
|
let language_server = language
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|language| worktree.ensure_language_server(language, cx));
|
.and_then(|language| worktree.register_language(language, cx));
|
||||||
(language, language_server.clone())
|
(language, language_server.clone())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ text = { path = "../text" }
|
||||||
theme = { path = "../theme" }
|
theme = { path = "../theme" }
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
anyhow = "1.0.38"
|
anyhow = "1.0.38"
|
||||||
|
async-trait = "0.1"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
|
@ -6,6 +6,7 @@ pub mod proto;
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
use async_trait::async_trait;
|
||||||
pub use buffer::Operation;
|
pub use buffer::Operation;
|
||||||
pub use buffer::*;
|
pub use buffer::*;
|
||||||
use collections::HashSet;
|
use collections::HashSet;
|
||||||
|
@ -15,7 +16,11 @@ use highlight_map::HighlightMap;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{path::Path, str, sync::Arc};
|
use std::{
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
str,
|
||||||
|
sync::Arc,
|
||||||
|
};
|
||||||
use theme::SyntaxTheme;
|
use theme::SyntaxTheme;
|
||||||
use tree_sitter::{self, Query};
|
use tree_sitter::{self, Query};
|
||||||
pub use tree_sitter::{Parser, Tree};
|
pub use tree_sitter::{Parser, Tree};
|
||||||
|
@ -59,9 +64,18 @@ pub struct BracketPair {
|
||||||
pub newline: bool,
|
pub newline: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
pub trait DiagnosticSource: 'static + Send + Sync {
|
||||||
|
async fn diagnose(
|
||||||
|
&self,
|
||||||
|
path: Arc<Path>,
|
||||||
|
) -> Result<Vec<(PathBuf, Vec<DiagnosticEntry<Point>>)>>;
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Language {
|
pub struct Language {
|
||||||
pub(crate) config: LanguageConfig,
|
pub(crate) config: LanguageConfig,
|
||||||
pub(crate) grammar: Option<Arc<Grammar>>,
|
pub(crate) grammar: Option<Arc<Grammar>>,
|
||||||
|
pub(crate) diagnostic_source: Option<Arc<dyn DiagnosticSource>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Grammar {
|
pub struct Grammar {
|
||||||
|
@ -126,6 +140,7 @@ impl Language {
|
||||||
highlight_map: Default::default(),
|
highlight_map: Default::default(),
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
diagnostic_source: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,6 +174,11 @@ impl Language {
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_diagnostic_source(mut self, source: impl DiagnosticSource) -> Self {
|
||||||
|
self.diagnostic_source = Some(Arc::new(source));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
self.config.name.as_str()
|
self.config.name.as_str()
|
||||||
}
|
}
|
||||||
|
@ -192,6 +212,10 @@ impl Language {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn diagnostic_source(&self) -> Option<&Arc<dyn DiagnosticSource>> {
|
||||||
|
self.diagnostic_source.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn disk_based_diagnostic_sources(&self) -> Option<&HashSet<String>> {
|
pub fn disk_based_diagnostic_sources(&self) -> Option<&HashSet<String>> {
|
||||||
self.config
|
self.config
|
||||||
.language_server
|
.language_server
|
||||||
|
|
|
@ -226,7 +226,11 @@ impl LanguageServer {
|
||||||
process_id: Default::default(),
|
process_id: Default::default(),
|
||||||
root_path: Default::default(),
|
root_path: Default::default(),
|
||||||
root_uri: Some(root_uri),
|
root_uri: Some(root_uri),
|
||||||
initialization_options: Default::default(),
|
initialization_options: Some(json!({
|
||||||
|
"checkOnSave": {
|
||||||
|
"enable": false
|
||||||
|
},
|
||||||
|
})),
|
||||||
capabilities: lsp_types::ClientCapabilities {
|
capabilities: lsp_types::ClientCapabilities {
|
||||||
experimental: Some(json!({
|
experimental: Some(json!({
|
||||||
"serverStatusNotification": true,
|
"serverStatusNotification": true,
|
||||||
|
|
|
@ -11,14 +11,14 @@ use fuzzy::{PathMatch, PathMatchCandidate, PathMatchCandidateSet};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task,
|
AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task,
|
||||||
};
|
};
|
||||||
use language::{Buffer, DiagnosticEntry, LanguageRegistry};
|
use language::{Buffer, DiagnosticEntry, Language, LanguageRegistry};
|
||||||
use lsp::DiagnosticSeverity;
|
use lsp::DiagnosticSeverity;
|
||||||
use postage::{prelude::Stream, watch};
|
use postage::{prelude::Stream, watch};
|
||||||
use std::{
|
use std::{
|
||||||
path::Path,
|
path::Path,
|
||||||
sync::{atomic::AtomicBool, Arc},
|
sync::{atomic::AtomicBool, Arc},
|
||||||
};
|
};
|
||||||
use util::TryFutureExt as _;
|
use util::{ResultExt, TryFutureExt as _};
|
||||||
|
|
||||||
pub use fs::*;
|
pub use fs::*;
|
||||||
pub use worktree::*;
|
pub use worktree::*;
|
||||||
|
@ -503,6 +503,31 @@ impl Project {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn diagnose(&self, cx: &mut ModelContext<Self>) {
|
||||||
|
for worktree_handle in &self.worktrees {
|
||||||
|
if let Some(worktree) = worktree_handle.read(cx).as_local() {
|
||||||
|
for language in worktree.languages() {
|
||||||
|
if let Some(diagnostic_source) = language.diagnostic_source().cloned() {
|
||||||
|
let worktree_path = worktree.abs_path().clone();
|
||||||
|
let worktree_handle = worktree_handle.downgrade();
|
||||||
|
cx.spawn_weak(|_, cx| async move {
|
||||||
|
if let Some(diagnostics) =
|
||||||
|
diagnostic_source.diagnose(worktree_path).await.log_err()
|
||||||
|
{
|
||||||
|
if let Some(worktree_handle) = worktree_handle.upgrade(&cx) {
|
||||||
|
worktree_handle.update(&mut cx, |worktree, cx| {
|
||||||
|
for (path, diagnostics) in diagnostics {}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn diagnostic_summaries<'a>(
|
pub fn diagnostic_summaries<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
cx: &'a AppContext,
|
cx: &'a AppContext,
|
||||||
|
|
|
@ -291,7 +291,7 @@ impl Worktree {
|
||||||
|
|
||||||
pub fn languages(&self) -> &Arc<LanguageRegistry> {
|
pub fn languages(&self) -> &Arc<LanguageRegistry> {
|
||||||
match self {
|
match self {
|
||||||
Worktree::Local(worktree) => &worktree.languages,
|
Worktree::Local(worktree) => &worktree.language_registry,
|
||||||
Worktree::Remote(worktree) => &worktree.languages,
|
Worktree::Remote(worktree) => &worktree.languages,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -853,10 +853,11 @@ pub struct LocalWorktree {
|
||||||
diagnostics: HashMap<Arc<Path>, Vec<DiagnosticEntry<PointUtf16>>>,
|
diagnostics: HashMap<Arc<Path>, Vec<DiagnosticEntry<PointUtf16>>>,
|
||||||
diagnostic_summaries: BTreeMap<Arc<Path>, DiagnosticSummary>,
|
diagnostic_summaries: BTreeMap<Arc<Path>, DiagnosticSummary>,
|
||||||
queued_operations: Vec<(u64, Operation)>,
|
queued_operations: Vec<(u64, Operation)>,
|
||||||
languages: Arc<LanguageRegistry>,
|
language_registry: Arc<LanguageRegistry>,
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
user_store: ModelHandle<UserStore>,
|
user_store: ModelHandle<UserStore>,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
|
languages: Vec<Arc<Language>>,
|
||||||
language_servers: HashMap<String, Arc<LanguageServer>>,
|
language_servers: HashMap<String, Arc<LanguageServer>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -960,10 +961,11 @@ impl LocalWorktree {
|
||||||
diagnostics: Default::default(),
|
diagnostics: Default::default(),
|
||||||
diagnostic_summaries: Default::default(),
|
diagnostic_summaries: Default::default(),
|
||||||
queued_operations: Default::default(),
|
queued_operations: Default::default(),
|
||||||
languages,
|
language_registry: languages,
|
||||||
client,
|
client,
|
||||||
user_store,
|
user_store,
|
||||||
fs,
|
fs,
|
||||||
|
languages: Default::default(),
|
||||||
language_servers: Default::default(),
|
language_servers: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1004,15 +1006,23 @@ impl LocalWorktree {
|
||||||
self.config.collaborators.clone()
|
self.config.collaborators.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn languages(&self) -> &LanguageRegistry {
|
pub fn language_registry(&self) -> &LanguageRegistry {
|
||||||
|
&self.language_registry
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn languages(&self) -> &[Arc<Language>] {
|
||||||
&self.languages
|
&self.languages
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ensure_language_server(
|
pub fn register_language(
|
||||||
&mut self,
|
&mut self,
|
||||||
language: &Language,
|
language: &Arc<Language>,
|
||||||
cx: &mut ModelContext<Worktree>,
|
cx: &mut ModelContext<Worktree>,
|
||||||
) -> Option<Arc<LanguageServer>> {
|
) -> Option<Arc<LanguageServer>> {
|
||||||
|
if !self.languages.iter().any(|l| Arc::ptr_eq(l, language)) {
|
||||||
|
self.languages.push(language.clone());
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(server) = self.language_servers.get(language.name()) {
|
if let Some(server) = self.language_servers.get(language.name()) {
|
||||||
return Some(server.clone());
|
return Some(server.clone());
|
||||||
}
|
}
|
||||||
|
@ -1090,10 +1100,13 @@ impl LocalWorktree {
|
||||||
let (diagnostics, language, language_server) = this.update(&mut cx, |this, cx| {
|
let (diagnostics, language, language_server) = this.update(&mut cx, |this, cx| {
|
||||||
let this = this.as_local_mut().unwrap();
|
let this = this.as_local_mut().unwrap();
|
||||||
let diagnostics = this.diagnostics.remove(&path);
|
let diagnostics = this.diagnostics.remove(&path);
|
||||||
let language = this.languages.select_language(file.full_path()).cloned();
|
let language = this
|
||||||
|
.language_registry
|
||||||
|
.select_language(file.full_path())
|
||||||
|
.cloned();
|
||||||
let server = language
|
let server = language
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|language| this.ensure_language_server(language, cx));
|
.and_then(|language| this.register_language(language, cx));
|
||||||
(diagnostics, language, server)
|
(diagnostics, language, server)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1191,8 +1204,8 @@ impl LocalWorktree {
|
||||||
self.snapshot.clone()
|
self.snapshot.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn abs_path(&self) -> &Path {
|
pub fn abs_path(&self) -> &Arc<Path> {
|
||||||
self.snapshot.abs_path.as_ref()
|
&self.snapshot.abs_path
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn contains_abs_path(&self, path: &Path) -> bool {
|
pub fn contains_abs_path(&self, path: &Path) -> bool {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue