Merge pull request #1113 from edg-l/pr-highlight-intoiter
Make HighlightConfiguration::configure use IntoIterator
This commit is contained in:
commit
0fea8c02ee
5 changed files with 8 additions and 12 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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ tree-sitter-javascript = "0.19"
|
|||
Define the list of highlight names that you will recognize:
|
||||
|
||||
```rust
|
||||
let highlight_names : Vec<String> = [
|
||||
let highlight_names = &[
|
||||
"attribute",
|
||||
"constant",
|
||||
"function.builtin",
|
||||
|
|
@ -37,11 +37,7 @@ let highlight_names : Vec<String> = [
|
|||
"variable",
|
||||
"variable.builtin",
|
||||
"variable.parameter",
|
||||
]
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(String::from)
|
||||
.collect();
|
||||
];
|
||||
```
|
||||
|
||||
Create a highlighter. You need one of these for each thread that you're using for syntax highlighting:
|
||||
|
|
|
|||
|
|
@ -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,7 @@ 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(&mut self, recognized_names: &[impl AsRef<str>]) {
|
||||
let mut capture_parts = Vec::new();
|
||||
self.highlight_indices.clear();
|
||||
self.highlight_indices
|
||||
|
|
@ -303,10 +303,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