Add support for detecting tests in source files, and implement it for Rust (#11195)
Continuing work from #10873 Release Notes: - N/A --------- Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
14c7782ce6
commit
5a71d8c7f1
29 changed files with 1148 additions and 606 deletions
|
@ -56,6 +56,7 @@ use std::{
|
|||
},
|
||||
};
|
||||
use syntax_map::{QueryCursorHandle, SyntaxSnapshot};
|
||||
use task::RunnableTag;
|
||||
pub use task_context::{BasicContextProvider, ContextProvider, ContextProviderWithTasks};
|
||||
use theme::SyntaxTheme;
|
||||
use tree_sitter::{self, wasmtime, Query, QueryCursor, WasmStore};
|
||||
|
@ -836,6 +837,7 @@ pub struct Grammar {
|
|||
pub(crate) highlights_query: Option<Query>,
|
||||
pub(crate) brackets_config: Option<BracketConfig>,
|
||||
pub(crate) redactions_config: Option<RedactionConfig>,
|
||||
pub(crate) runnable_config: Option<RunnableConfig>,
|
||||
pub(crate) indents_config: Option<IndentConfig>,
|
||||
pub outline_config: Option<OutlineConfig>,
|
||||
pub embedding_config: Option<EmbeddingConfig>,
|
||||
|
@ -882,6 +884,14 @@ struct RedactionConfig {
|
|||
pub redaction_capture_ix: u32,
|
||||
}
|
||||
|
||||
struct RunnableConfig {
|
||||
pub query: Query,
|
||||
/// A mapping from captures indices to known test tags
|
||||
pub runnable_tags: HashMap<u32, RunnableTag>,
|
||||
/// index of the capture that corresponds to @run
|
||||
pub run_capture_ix: u32,
|
||||
}
|
||||
|
||||
struct OverrideConfig {
|
||||
query: Query,
|
||||
values: HashMap<u32, (String, LanguageConfigOverride)>,
|
||||
|
@ -923,6 +933,7 @@ impl Language {
|
|||
injection_config: None,
|
||||
override_config: None,
|
||||
redactions_config: None,
|
||||
runnable_config: None,
|
||||
error_query: Query::new(&ts_language, "(ERROR) @error").unwrap(),
|
||||
ts_language,
|
||||
highlight_map: Default::default(),
|
||||
|
@ -978,6 +989,11 @@ impl Language {
|
|||
.with_redaction_query(query.as_ref())
|
||||
.context("Error loading redaction query")?;
|
||||
}
|
||||
if let Some(query) = queries.runnables {
|
||||
self = self
|
||||
.with_runnable_query(query.as_ref())
|
||||
.context("Error loading tests query")?;
|
||||
}
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
|
@ -989,6 +1005,33 @@ impl Language {
|
|||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with_runnable_query(mut self, source: &str) -> Result<Self> {
|
||||
let grammar = self
|
||||
.grammar_mut()
|
||||
.ok_or_else(|| anyhow!("cannot mutate grammar"))?;
|
||||
|
||||
let query = Query::new(&grammar.ts_language, source)?;
|
||||
let mut run_capture_index = None;
|
||||
let mut runnable_tags = HashMap::default();
|
||||
for (ix, name) in query.capture_names().iter().enumerate() {
|
||||
if *name == "run" {
|
||||
run_capture_index = Some(ix as u32);
|
||||
} else if !name.starts_with('_') {
|
||||
runnable_tags.insert(ix as u32, RunnableTag(name.to_string().into()));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(run_capture_ix) = run_capture_index {
|
||||
grammar.runnable_config = Some(RunnableConfig {
|
||||
query,
|
||||
run_capture_ix,
|
||||
runnable_tags,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with_outline_query(mut self, source: &str) -> Result<Self> {
|
||||
let grammar = self
|
||||
.grammar_mut()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue