refactor!: remove the apply-all-captures flag, make last-wins precedence the default

This commit is contained in:
Amaan Qureshi 2024-02-07 02:02:32 -05:00
parent bf9154febe
commit e996c32108
9 changed files with 31 additions and 75 deletions

View file

@ -342,7 +342,7 @@ pub fn ansi(
let mut highlighter = Highlighter::new();
let events = highlighter.highlight(config, source, cancellation_flag, |string| {
loader.highlight_config_for_injection_string(string, config.apply_all_captures)
loader.highlight_config_for_injection_string(string)
})?;
let mut style_stack = vec![theme.default_style().ansi];
@ -388,7 +388,7 @@ pub fn html(
let mut highlighter = Highlighter::new();
let events = highlighter.highlight(config, source, cancellation_flag, |string| {
loader.highlight_config_for_injection_string(string, config.apply_all_captures)
loader.highlight_config_for_injection_string(string)
})?;
let mut renderer = HtmlRenderer::new();

View file

@ -194,8 +194,6 @@ struct Test {
help = "Compile parsers to wasm instead of native dynamic libraries"
)]
pub wasm: bool,
#[arg(long, help = "Apply all captures to highlights")]
pub apply_all_captures: bool,
#[arg(
long,
help = "Open `log.html` in the default browser, if `--debug-graph` is supplied"
@ -267,8 +265,6 @@ struct Highlight {
pub paths_file: Option<String>,
#[arg(num_args = 1.., help = "The source file(s) to use")]
pub paths: Option<Vec<String>>,
#[arg(long, help = "Apply all captures to highlights")]
pub apply_all_captures: bool,
}
#[derive(Args)]
@ -583,7 +579,6 @@ fn run() -> Result<()> {
&config.get()?,
&mut highlighter,
&test_highlight_dir,
test_options.apply_all_captures,
)?;
parser = highlighter.parser;
}
@ -674,11 +669,9 @@ fn run() -> Result<()> {
}
};
if let Some(highlight_config) = language_config.highlight_config(
language,
highlight_options.apply_all_captures,
highlight_options.query_paths.as_deref(),
)? {
if let Some(highlight_config) = language_config
.highlight_config(language, highlight_options.query_paths.as_deref())?
{
if highlight_options.check {
let names = if let Some(path) = highlight_options.captures_path.as_deref() {
let path = Path::new(path);

View file

@ -48,17 +48,9 @@ pub fn test_highlights(
loader_config: &Config,
highlighter: &mut Highlighter,
directory: &Path,
apply_all_captures: bool,
) -> Result<()> {
println!("syntax highlighting:");
test_highlights_indented(
loader,
loader_config,
highlighter,
directory,
apply_all_captures,
2,
)
test_highlights_indented(loader, loader_config, highlighter, directory, 2)
}
fn test_highlights_indented(
@ -66,7 +58,6 @@ fn test_highlights_indented(
loader_config: &Config,
highlighter: &mut Highlighter,
directory: &Path,
apply_all_captures: bool,
indent_level: usize,
) -> Result<()> {
let mut failed = false;
@ -87,7 +78,6 @@ fn test_highlights_indented(
loader_config,
highlighter,
&test_file_path,
apply_all_captures,
indent_level + 1,
)
.is_err()
@ -104,7 +94,7 @@ fn test_highlights_indented(
)
})?;
let highlight_config = language_config
.highlight_config(language, apply_all_captures, None)?
.highlight_config(language, None)?
.ok_or_else(|| anyhow!("No highlighting config found for {test_file_path:?}"))?;
match test_highlight(
loader,
@ -235,7 +225,7 @@ pub fn get_highlight_positions(
let source = String::from_utf8_lossy(source);
let mut char_indices = source.char_indices();
for event in highlighter.highlight(highlight_config, source.as_bytes(), None, |string| {
loader.highlight_config_for_injection_string(string, highlight_config.apply_all_captures)
loader.highlight_config_for_injection_string(string)
})? {
match event? {
HighlightEvent::HighlightStart(h) => highlight_stack.push(h),

View file

@ -63,7 +63,6 @@ pub fn get_highlight_config(
&highlights_query,
&injections_query,
&locals_query,
false,
)
.unwrap();
result.configure(highlight_names);

View file

@ -310,7 +310,7 @@ fn test_highlighting_empty_lines() {
.join("\n");
assert_eq!(
&to_html(&source, &JS_HIGHLIGHT,).unwrap(),
&to_html(&source, &JS_HIGHLIGHT).unwrap(),
&[
"<span class=keyword>class</span> <span class=constructor>A</span> <span class=punctuation.bracket>{</span>\n".to_string(),
"\n".to_string(),
@ -529,7 +529,6 @@ fn test_highlighting_via_c_api() {
highlights_query.len() as u32,
injections_query.len() as u32,
locals_query.len() as u32,
false,
);
}
@ -553,7 +552,6 @@ fn test_highlighting_via_c_api() {
highlights_query.len() as u32,
injections_query.len() as u32,
0,
false,
);
}
@ -622,7 +620,7 @@ fn test_highlighting_with_all_captures_applied() {
[ \"{\" \"}\" \"(\" \")\" ] @punctuation.bracket
"};
let mut rust_highlight_reverse =
HighlightConfiguration::new(language, "rust", highlights_query, "", "", true).unwrap();
HighlightConfiguration::new(language, "rust", highlights_query, "", "").unwrap();
rust_highlight_reverse.configure(&HIGHLIGHT_NAMES);
assert_eq!(