Use standard injection.language and injection.content captures (#22268)
Closes #9656. Continuation of #9654, but with the addition of backwards compatibility for the existing captures. Release Notes: - Improved Tree-sitter support with added compatibility for standard injections captures --------- Co-authored-by: Finn Evers <finn.evers@outlook.de>
This commit is contained in:
parent
f3e75d8ff6
commit
d58f006498
21 changed files with 181 additions and 159 deletions
|
@ -1273,23 +1273,45 @@ impl Language {
|
|||
.ok_or_else(|| anyhow!("cannot mutate grammar"))?;
|
||||
let query = Query::new(&grammar.ts_language, source)?;
|
||||
let mut language_capture_ix = None;
|
||||
let mut injection_language_capture_ix = None;
|
||||
let mut content_capture_ix = None;
|
||||
let mut injection_content_capture_ix = None;
|
||||
get_capture_indices(
|
||||
&query,
|
||||
&mut [
|
||||
("language", &mut language_capture_ix),
|
||||
("injection.language", &mut injection_language_capture_ix),
|
||||
("content", &mut content_capture_ix),
|
||||
("injection.content", &mut injection_content_capture_ix),
|
||||
],
|
||||
);
|
||||
language_capture_ix = match (language_capture_ix, injection_language_capture_ix) {
|
||||
(None, Some(ix)) => Some(ix),
|
||||
(Some(_), Some(_)) => {
|
||||
return Err(anyhow!(
|
||||
"both language and injection.language captures are present"
|
||||
));
|
||||
}
|
||||
_ => language_capture_ix,
|
||||
};
|
||||
content_capture_ix = match (content_capture_ix, injection_content_capture_ix) {
|
||||
(None, Some(ix)) => Some(ix),
|
||||
(Some(_), Some(_)) => {
|
||||
return Err(anyhow!(
|
||||
"both content and injection.content captures are present"
|
||||
));
|
||||
}
|
||||
_ => content_capture_ix,
|
||||
};
|
||||
let patterns = (0..query.pattern_count())
|
||||
.map(|ix| {
|
||||
let mut config = InjectionPatternConfig::default();
|
||||
for setting in query.property_settings(ix) {
|
||||
match setting.key.as_ref() {
|
||||
"language" => {
|
||||
"language" | "injection.language" => {
|
||||
config.language.clone_from(&setting.value);
|
||||
}
|
||||
"combined" => {
|
||||
"combined" | "injection.combined" => {
|
||||
config.combined = true;
|
||||
}
|
||||
_ => {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue