Make HighlightConfiguration::configure use into iterator instead of a Vec<String>
This commit is contained in:
parent
12207c1f70
commit
9feca80b08
4 changed files with 10 additions and 6 deletions
|
|
@ -661,7 +661,7 @@ impl<'a> LanguageConfiguration<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
result.configure(&all_highlight_names);
|
||||
result.configure(&all_highlight_names.as_slice());
|
||||
Ok(Some(result))
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ pub fn get_highlight_config(
|
|||
&locals_query,
|
||||
)
|
||||
.unwrap();
|
||||
result.configure(highlight_names);
|
||||
result.configure(&highlight_names);
|
||||
result
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ pub extern "C" fn ts_highlighter_add_language(
|
|||
let mut config =
|
||||
HighlightConfiguration::new(language, highlight_query, injection_query, locals_query)
|
||||
.or(Err(ErrorCode::InvalidQuery))?;
|
||||
config.configure(&this.highlight_names);
|
||||
config.configure(&this.highlight_names.as_slice());
|
||||
this.languages.insert(scope_name, (injection_regex, config));
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -293,7 +293,11 @@ impl HighlightConfiguration {
|
|||
///
|
||||
/// When highlighting, results are returned as `Highlight` values, which contain the index
|
||||
/// of the matched highlight this list of highlight names.
|
||||
pub fn configure(&mut self, recognized_names: &[String]) {
|
||||
pub fn configure<'a, I, J>(&mut self, recognized_names: &I)
|
||||
where
|
||||
I: IntoIterator<Item = &'a J> + Copy,
|
||||
J: AsRef<str> + 'a,
|
||||
{
|
||||
let mut capture_parts = Vec::new();
|
||||
self.highlight_indices.clear();
|
||||
self.highlight_indices
|
||||
|
|
@ -303,10 +307,10 @@ impl HighlightConfiguration {
|
|||
|
||||
let mut best_index = None;
|
||||
let mut best_match_len = 0;
|
||||
for (i, recognized_name) in recognized_names.iter().enumerate() {
|
||||
for (i, recognized_name) in recognized_names.into_iter().enumerate() {
|
||||
let mut len = 0;
|
||||
let mut matches = true;
|
||||
for part in recognized_name.split('.') {
|
||||
for part in recognized_name.as_ref().split('.') {
|
||||
len += 1;
|
||||
if !capture_parts.contains(&part) {
|
||||
matches = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue