aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-09 13:09:15 +0000
committerGitHub <[email protected]>2021-01-09 13:09:15 +0000
commit939ca83b34f9a5648d196f85e5cc7d844ba22604 (patch)
treea007952a8870e4d8c0b5fa1e0e0a088b399a8c8d /crates
parent625ec9e1ae69168f194cbc5bf20846870f03e149 (diff)
parent4a8d2c098d88da6f36f3cf95f424b471987c5daa (diff)
Merge #7216
7216: Highlighting improvements r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/lib.rs8
-rw-r--r--crates/ide/src/syntax_highlighting.rs267
-rw-r--r--crates/ide/src/syntax_highlighting/format.rs12
-rw-r--r--crates/ide/src/syntax_highlighting/highlights.rs61
-rw-r--r--crates/ide/src/syntax_highlighting/html.rs16
-rw-r--r--crates/ide/src/syntax_highlighting/injection.rs105
-rw-r--r--crates/ide/src/syntax_highlighting/injector.rs12
-rw-r--r--crates/ide/src/syntax_highlighting/macro_rules.rs8
-rw-r--r--crates/ide/src/syntax_highlighting/tags.rs138
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html20
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/injection.html4
-rw-r--r--crates/rust-analyzer/src/to_proto.rs67
12 files changed, 329 insertions, 389 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index cea2a13c8..409507bd0 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -76,8 +76,8 @@ pub use crate::{
76 references::{rename::RenameError, Declaration, ReferenceSearchResult}, 76 references::{rename::RenameError, Declaration, ReferenceSearchResult},
77 runnables::{Runnable, RunnableKind, TestId}, 77 runnables::{Runnable, RunnableKind, TestId},
78 syntax_highlighting::{ 78 syntax_highlighting::{
79 tags::{Highlight, HighlightModifier, HighlightModifiers, HighlightTag}, 79 tags::{Highlight, HlMod, HlMods, HlTag},
80 HighlightedRange, 80 HlRange,
81 }, 81 },
82}; 82};
83pub use assists::{Assist, AssistConfig, AssistId, AssistKind, InsertUseConfig}; 83pub use assists::{Assist, AssistConfig, AssistId, AssistKind, InsertUseConfig};
@@ -449,12 +449,12 @@ impl Analysis {
449 } 449 }
450 450
451 /// Computes syntax highlighting for the given file 451 /// Computes syntax highlighting for the given file
452 pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { 452 pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HlRange>> {
453 self.with_db(|db| syntax_highlighting::highlight(db, file_id, None, false)) 453 self.with_db(|db| syntax_highlighting::highlight(db, file_id, None, false))
454 } 454 }
455 455
456 /// Computes syntax highlighting for the given file range. 456 /// Computes syntax highlighting for the given file range.
457 pub fn highlight_range(&self, frange: FileRange) -> Cancelable<Vec<HighlightedRange>> { 457 pub fn highlight_range(&self, frange: FileRange) -> Cancelable<Vec<HlRange>> {
458 self.with_db(|db| { 458 self.with_db(|db| {
459 syntax_highlighting::highlight(db, frange.file_id, Some(frange.range), false) 459 syntax_highlighting::highlight(db, frange.file_id, Some(frange.range), false)
460 }) 460 })
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index 2eb63a0b7..ad456bc00 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -1,11 +1,13 @@
1pub(crate) mod tags;
2
1mod highlights; 3mod highlights;
2mod injector; 4mod injector;
3 5
4mod format; 6mod format;
5mod html;
6mod injection; 7mod injection;
7mod macro_rules; 8mod macro_rules;
8pub(crate) mod tags; 9
10mod html;
9#[cfg(test)] 11#[cfg(test)]
10mod tests; 12mod tests;
11 13
@@ -26,13 +28,13 @@ use crate::{
26 syntax_highlighting::{ 28 syntax_highlighting::{
27 format::FormatStringHighlighter, macro_rules::MacroRulesHighlighter, tags::Highlight, 29 format::FormatStringHighlighter, macro_rules::MacroRulesHighlighter, tags::Highlight,
28 }, 30 },
29 FileId, HighlightModifier, HighlightTag, SymbolKind, 31 FileId, HlMod, HlTag, SymbolKind,
30}; 32};
31 33
32pub(crate) use html::highlight_as_html; 34pub(crate) use html::highlight_as_html;
33 35
34#[derive(Debug, Clone)] 36#[derive(Debug, Clone, Copy)]
35pub struct HighlightedRange { 37pub struct HlRange {
36 pub range: TextRange, 38 pub range: TextRange,
37 pub highlight: Highlight, 39 pub highlight: Highlight,
38 pub binding_hash: Option<u64>, 40 pub binding_hash: Option<u64>,
@@ -52,7 +54,7 @@ pub(crate) fn highlight(
52 file_id: FileId, 54 file_id: FileId,
53 range_to_highlight: Option<TextRange>, 55 range_to_highlight: Option<TextRange>,
54 syntactic_name_ref_highlighting: bool, 56 syntactic_name_ref_highlighting: bool,
55) -> Vec<HighlightedRange> { 57) -> Vec<HlRange> {
56 let _p = profile::span("highlight"); 58 let _p = profile::span("highlight");
57 let sema = Semantics::new(db); 59 let sema = Semantics::new(db);
58 60
@@ -72,7 +74,7 @@ pub(crate) fn highlight(
72 }; 74 };
73 75
74 let mut bindings_shadow_count: FxHashMap<Name, u32> = FxHashMap::default(); 76 let mut bindings_shadow_count: FxHashMap<Name, u32> = FxHashMap::default();
75 let mut stack = highlights::Highlights::new(range_to_highlight); 77 let mut hl = highlights::Highlights::new(range_to_highlight);
76 78
77 let mut current_macro_call: Option<ast::MacroCall> = None; 79 let mut current_macro_call: Option<ast::MacroCall> = None;
78 let mut current_macro_rules: Option<ast::MacroRules> = None; 80 let mut current_macro_rules: Option<ast::MacroRules> = None;
@@ -96,9 +98,9 @@ pub(crate) fn highlight(
96 match event.clone().map(|it| it.into_node().and_then(ast::MacroCall::cast)) { 98 match event.clone().map(|it| it.into_node().and_then(ast::MacroCall::cast)) {
97 WalkEvent::Enter(Some(mc)) => { 99 WalkEvent::Enter(Some(mc)) => {
98 if let Some(range) = macro_call_range(&mc) { 100 if let Some(range) = macro_call_range(&mc) {
99 stack.add(HighlightedRange { 101 hl.add(HlRange {
100 range, 102 range,
101 highlight: HighlightTag::Symbol(SymbolKind::Macro).into(), 103 highlight: HlTag::Symbol(SymbolKind::Macro).into(),
102 binding_hash: None, 104 binding_hash: None,
103 }); 105 });
104 } 106 }
@@ -134,7 +136,7 @@ pub(crate) fn highlight(
134 inside_attribute = false 136 inside_attribute = false
135 } 137 }
136 if let Some((new_comments, inj)) = injection::extract_doc_comments(node) { 138 if let Some((new_comments, inj)) = injection::extract_doc_comments(node) {
137 injection::highlight_doc_comment(new_comments, inj, &mut stack); 139 injection::highlight_doc_comment(new_comments, inj, &mut hl);
138 } 140 }
139 } 141 }
140 WalkEvent::Enter(NodeOrToken::Node(node)) if ast::Attr::can_cast(node.kind()) => { 142 WalkEvent::Enter(NodeOrToken::Node(node)) if ast::Attr::can_cast(node.kind()) => {
@@ -179,7 +181,7 @@ pub(crate) fn highlight(
179 if let Some(token) = element.as_token().cloned().and_then(ast::String::cast) { 181 if let Some(token) = element.as_token().cloned().and_then(ast::String::cast) {
180 if token.is_raw() { 182 if token.is_raw() {
181 let expanded = element_to_highlight.as_token().unwrap().clone(); 183 let expanded = element_to_highlight.as_token().unwrap().clone();
182 if injection::highlight_injection(&mut stack, &sema, token, expanded).is_some() { 184 if injection::highlight_injection(&mut hl, &sema, token, expanded).is_some() {
183 continue; 185 continue;
184 } 186 }
185 } 187 }
@@ -192,24 +194,24 @@ pub(crate) fn highlight(
192 element_to_highlight.clone(), 194 element_to_highlight.clone(),
193 ) { 195 ) {
194 if inside_attribute { 196 if inside_attribute {
195 highlight = highlight | HighlightModifier::Attribute; 197 highlight = highlight | HlMod::Attribute;
196 } 198 }
197 199
198 if macro_rules_highlighter.highlight(element_to_highlight.clone()).is_none() { 200 if macro_rules_highlighter.highlight(element_to_highlight.clone()).is_none() {
199 stack.add(HighlightedRange { range, highlight, binding_hash }); 201 hl.add(HlRange { range, highlight, binding_hash });
200 } 202 }
201 203
202 if let Some(string) = 204 if let Some(string) =
203 element_to_highlight.as_token().cloned().and_then(ast::String::cast) 205 element_to_highlight.as_token().cloned().and_then(ast::String::cast)
204 { 206 {
205 format_string_highlighter.highlight_format_string(&mut stack, &string, range); 207 format_string_highlighter.highlight_format_string(&mut hl, &string, range);
206 // Highlight escape sequences 208 // Highlight escape sequences
207 if let Some(char_ranges) = string.char_ranges() { 209 if let Some(char_ranges) = string.char_ranges() {
208 for (piece_range, _) in char_ranges.iter().filter(|(_, char)| char.is_ok()) { 210 for (piece_range, _) in char_ranges.iter().filter(|(_, char)| char.is_ok()) {
209 if string.text()[piece_range.start().into()..].starts_with('\\') { 211 if string.text()[piece_range.start().into()..].starts_with('\\') {
210 stack.add(HighlightedRange { 212 hl.add(HlRange {
211 range: piece_range + range.start(), 213 range: piece_range + range.start(),
212 highlight: HighlightTag::EscapeSequence.into(), 214 highlight: HlTag::EscapeSequence.into(),
213 binding_hash: None, 215 binding_hash: None,
214 }); 216 });
215 } 217 }
@@ -219,7 +221,7 @@ pub(crate) fn highlight(
219 } 221 }
220 } 222 }
221 223
222 stack.to_vec() 224 hl.to_vec()
223} 225}
224 226
225fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> { 227fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> {
@@ -292,22 +294,20 @@ fn highlight_element(
292 }; 294 };
293 295
294 match name_kind { 296 match name_kind {
295 Some(NameClass::ExternCrate(_)) => HighlightTag::Symbol(SymbolKind::Module).into(), 297 Some(NameClass::ExternCrate(_)) => HlTag::Symbol(SymbolKind::Module).into(),
296 Some(NameClass::Definition(def)) => { 298 Some(NameClass::Definition(def)) => highlight_def(db, def) | HlMod::Definition,
297 highlight_def(db, def) | HighlightModifier::Definition
298 }
299 Some(NameClass::ConstReference(def)) => highlight_def(db, def), 299 Some(NameClass::ConstReference(def)) => highlight_def(db, def),
300 Some(NameClass::PatFieldShorthand { field_ref, .. }) => { 300 Some(NameClass::PatFieldShorthand { field_ref, .. }) => {
301 let mut h = HighlightTag::Symbol(SymbolKind::Field).into(); 301 let mut h = HlTag::Symbol(SymbolKind::Field).into();
302 if let Definition::Field(field) = field_ref { 302 if let Definition::Field(field) = field_ref {
303 if let VariantDef::Union(_) = field.parent_def(db) { 303 if let VariantDef::Union(_) = field.parent_def(db) {
304 h |= HighlightModifier::Unsafe; 304 h |= HlMod::Unsafe;
305 } 305 }
306 } 306 }
307 307
308 h 308 h
309 } 309 }
310 None => highlight_name_by_syntax(name) | HighlightModifier::Definition, 310 None => highlight_name_by_syntax(name) | HlMod::Definition,
311 } 311 }
312 } 312 }
313 313
@@ -315,16 +315,14 @@ fn highlight_element(
315 NAME_REF if element.ancestors().any(|it| it.kind() == ATTR) => { 315 NAME_REF if element.ancestors().any(|it| it.kind() == ATTR) => {
316 // even though we track whether we are in an attribute or not we still need this special case 316 // even though we track whether we are in an attribute or not we still need this special case
317 // as otherwise we would emit unresolved references for name refs inside attributes 317 // as otherwise we would emit unresolved references for name refs inside attributes
318 Highlight::from(HighlightTag::Symbol(SymbolKind::Function)) 318 Highlight::from(HlTag::Symbol(SymbolKind::Function))
319 } 319 }
320 NAME_REF => { 320 NAME_REF => {
321 let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap(); 321 let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap();
322 highlight_func_by_name_ref(sema, &name_ref).unwrap_or_else(|| { 322 highlight_func_by_name_ref(sema, &name_ref).unwrap_or_else(|| {
323 match NameRefClass::classify(sema, &name_ref) { 323 match NameRefClass::classify(sema, &name_ref) {
324 Some(name_kind) => match name_kind { 324 Some(name_kind) => match name_kind {
325 NameRefClass::ExternCrate(_) => { 325 NameRefClass::ExternCrate(_) => HlTag::Symbol(SymbolKind::Module).into(),
326 HighlightTag::Symbol(SymbolKind::Module).into()
327 }
328 NameRefClass::Definition(def) => { 326 NameRefClass::Definition(def) => {
329 if let Definition::Local(local) = &def { 327 if let Definition::Local(local) = &def {
330 if let Some(name) = local.name(db) { 328 if let Some(name) = local.name(db) {
@@ -338,7 +336,7 @@ fn highlight_element(
338 336
339 if let Definition::Local(local) = &def { 337 if let Definition::Local(local) = &def {
340 if is_consumed_lvalue(name_ref.syntax().clone().into(), local, db) { 338 if is_consumed_lvalue(name_ref.syntax().clone().into(), local, db) {
341 h |= HighlightModifier::Consuming; 339 h |= HlMod::Consuming;
342 } 340 }
343 } 341 }
344 342
@@ -346,7 +344,7 @@ fn highlight_element(
346 if matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD) { 344 if matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD) {
347 if let Definition::Field(field) = def { 345 if let Definition::Field(field) = def {
348 if let VariantDef::Union(_) = field.parent_def(db) { 346 if let VariantDef::Union(_) = field.parent_def(db) {
349 h |= HighlightModifier::Unsafe; 347 h |= HlMod::Unsafe;
350 } 348 }
351 } 349 }
352 } 350 }
@@ -355,13 +353,13 @@ fn highlight_element(
355 h 353 h
356 } 354 }
357 NameRefClass::FieldShorthand { .. } => { 355 NameRefClass::FieldShorthand { .. } => {
358 HighlightTag::Symbol(SymbolKind::Field).into() 356 HlTag::Symbol(SymbolKind::Field).into()
359 } 357 }
360 }, 358 },
361 None if syntactic_name_ref_highlighting => { 359 None if syntactic_name_ref_highlighting => {
362 highlight_name_ref_by_syntax(name_ref, sema) 360 highlight_name_ref_by_syntax(name_ref, sema)
363 } 361 }
364 None => HighlightTag::UnresolvedReference.into(), 362 None => HlTag::UnresolvedReference.into(),
365 } 363 }
366 }) 364 })
367 } 365 }
@@ -369,60 +367,53 @@ fn highlight_element(
369 // Simple token-based highlighting 367 // Simple token-based highlighting
370 COMMENT => { 368 COMMENT => {
371 let comment = element.into_token().and_then(ast::Comment::cast)?; 369 let comment = element.into_token().and_then(ast::Comment::cast)?;
372 let h = HighlightTag::Comment; 370 let h = HlTag::Comment;
373 match comment.kind().doc { 371 match comment.kind().doc {
374 Some(_) => h | HighlightModifier::Documentation, 372 Some(_) => h | HlMod::Documentation,
375 None => h.into(), 373 None => h.into(),
376 } 374 }
377 } 375 }
378 STRING | BYTE_STRING => HighlightTag::StringLiteral.into(), 376 STRING | BYTE_STRING => HlTag::StringLiteral.into(),
379 ATTR => HighlightTag::Attribute.into(), 377 ATTR => HlTag::Attribute.into(),
380 INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(), 378 INT_NUMBER | FLOAT_NUMBER => HlTag::NumericLiteral.into(),
381 BYTE => HighlightTag::ByteLiteral.into(), 379 BYTE => HlTag::ByteLiteral.into(),
382 CHAR => HighlightTag::CharLiteral.into(), 380 CHAR => HlTag::CharLiteral.into(),
383 QUESTION => Highlight::new(HighlightTag::Operator) | HighlightModifier::ControlFlow, 381 QUESTION => Highlight::new(HlTag::Operator) | HlMod::ControlFlow,
384 LIFETIME => { 382 LIFETIME => {
385 let lifetime = element.into_node().and_then(ast::Lifetime::cast).unwrap(); 383 let lifetime = element.into_node().and_then(ast::Lifetime::cast).unwrap();
386 384
387 match NameClass::classify_lifetime(sema, &lifetime) { 385 match NameClass::classify_lifetime(sema, &lifetime) {
388 Some(NameClass::Definition(def)) => { 386 Some(NameClass::Definition(def)) => highlight_def(db, def) | HlMod::Definition,
389 highlight_def(db, def) | HighlightModifier::Definition
390 }
391 None => match NameRefClass::classify_lifetime(sema, &lifetime) { 387 None => match NameRefClass::classify_lifetime(sema, &lifetime) {
392 Some(NameRefClass::Definition(def)) => highlight_def(db, def), 388 Some(NameRefClass::Definition(def)) => highlight_def(db, def),
393 _ => Highlight::new(HighlightTag::Symbol(SymbolKind::LifetimeParam)), 389 _ => Highlight::new(HlTag::Symbol(SymbolKind::LifetimeParam)),
394 }, 390 },
395 _ => { 391 _ => Highlight::new(HlTag::Symbol(SymbolKind::LifetimeParam)) | HlMod::Definition,
396 Highlight::new(HighlightTag::Symbol(SymbolKind::LifetimeParam))
397 | HighlightModifier::Definition
398 }
399 } 392 }
400 } 393 }
401 p if p.is_punct() => match p { 394 p if p.is_punct() => match p {
402 T![&] => { 395 T![&] => {
403 let h = HighlightTag::Operator.into(); 396 let h = HlTag::Operator.into();
404 let is_unsafe = element 397 let is_unsafe = element
405 .parent() 398 .parent()
406 .and_then(ast::RefExpr::cast) 399 .and_then(ast::RefExpr::cast)
407 .map(|ref_expr| sema.is_unsafe_ref_expr(&ref_expr)) 400 .map(|ref_expr| sema.is_unsafe_ref_expr(&ref_expr))
408 .unwrap_or(false); 401 .unwrap_or(false);
409 if is_unsafe { 402 if is_unsafe {
410 h | HighlightModifier::Unsafe 403 h | HlMod::Unsafe
411 } else { 404 } else {
412 h 405 h
413 } 406 }
414 } 407 }
415 T![::] | T![->] | T![=>] | T![..] | T![=] | T![@] | T![.] => { 408 T![::] | T![->] | T![=>] | T![..] | T![=] | T![@] | T![.] => HlTag::Operator.into(),
416 HighlightTag::Operator.into()
417 }
418 T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { 409 T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => {
419 HighlightTag::Symbol(SymbolKind::Macro).into() 410 HlTag::Symbol(SymbolKind::Macro).into()
420 } 411 }
421 T![!] if element.parent().and_then(ast::NeverType::cast).is_some() => { 412 T![!] if element.parent().and_then(ast::NeverType::cast).is_some() => {
422 HighlightTag::BuiltinType.into() 413 HlTag::BuiltinType.into()
423 } 414 }
424 T![*] if element.parent().and_then(ast::PtrType::cast).is_some() => { 415 T![*] if element.parent().and_then(ast::PtrType::cast).is_some() => {
425 HighlightTag::Keyword.into() 416 HlTag::Keyword.into()
426 } 417 }
427 T![*] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { 418 T![*] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
428 let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; 419 let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?;
@@ -430,11 +421,11 @@ fn highlight_element(
430 let expr = prefix_expr.expr()?; 421 let expr = prefix_expr.expr()?;
431 let ty = sema.type_of_expr(&expr)?; 422 let ty = sema.type_of_expr(&expr)?;
432 if ty.is_raw_ptr() { 423 if ty.is_raw_ptr() {
433 HighlightTag::Operator | HighlightModifier::Unsafe 424 HlTag::Operator | HlMod::Unsafe
434 } else if let Some(ast::PrefixOp::Deref) = prefix_expr.op_kind() { 425 } else if let Some(ast::PrefixOp::Deref) = prefix_expr.op_kind() {
435 HighlightTag::Operator.into() 426 HlTag::Operator.into()
436 } else { 427 } else {
437 HighlightTag::Punctuation.into() 428 HlTag::Punctuation.into()
438 } 429 }
439 } 430 }
440 T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { 431 T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
@@ -442,34 +433,26 @@ fn highlight_element(
442 433
443 let expr = prefix_expr.expr()?; 434 let expr = prefix_expr.expr()?;
444 match expr { 435 match expr {
445 ast::Expr::Literal(_) => HighlightTag::NumericLiteral, 436 ast::Expr::Literal(_) => HlTag::NumericLiteral,
446 _ => HighlightTag::Operator, 437 _ => HlTag::Operator,
447 } 438 }
448 .into() 439 .into()
449 } 440 }
450 _ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { 441 _ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
451 HighlightTag::Operator.into() 442 HlTag::Operator.into()
452 }
453 _ if element.parent().and_then(ast::BinExpr::cast).is_some() => {
454 HighlightTag::Operator.into()
455 } 443 }
444 _ if element.parent().and_then(ast::BinExpr::cast).is_some() => HlTag::Operator.into(),
456 _ if element.parent().and_then(ast::RangeExpr::cast).is_some() => { 445 _ if element.parent().and_then(ast::RangeExpr::cast).is_some() => {
457 HighlightTag::Operator.into() 446 HlTag::Operator.into()
458 }
459 _ if element.parent().and_then(ast::RangePat::cast).is_some() => {
460 HighlightTag::Operator.into()
461 }
462 _ if element.parent().and_then(ast::RestPat::cast).is_some() => {
463 HighlightTag::Operator.into()
464 }
465 _ if element.parent().and_then(ast::Attr::cast).is_some() => {
466 HighlightTag::Attribute.into()
467 } 447 }
468 _ => HighlightTag::Punctuation.into(), 448 _ if element.parent().and_then(ast::RangePat::cast).is_some() => HlTag::Operator.into(),
449 _ if element.parent().and_then(ast::RestPat::cast).is_some() => HlTag::Operator.into(),
450 _ if element.parent().and_then(ast::Attr::cast).is_some() => HlTag::Attribute.into(),
451 _ => HlTag::Punctuation.into(),
469 }, 452 },
470 453
471 k if k.is_keyword() => { 454 k if k.is_keyword() => {
472 let h = Highlight::new(HighlightTag::Keyword); 455 let h = Highlight::new(HlTag::Keyword);
473 match k { 456 match k {
474 T![break] 457 T![break]
475 | T![continue] 458 | T![continue]
@@ -479,10 +462,10 @@ fn highlight_element(
479 | T![match] 462 | T![match]
480 | T![return] 463 | T![return]
481 | T![while] 464 | T![while]
482 | T![in] => h | HighlightModifier::ControlFlow, 465 | T![in] => h | HlMod::ControlFlow,
483 T![for] if !is_child_of_impl(&element) => h | HighlightModifier::ControlFlow, 466 T![for] if !is_child_of_impl(&element) => h | HlMod::ControlFlow,
484 T![unsafe] => h | HighlightModifier::Unsafe, 467 T![unsafe] => h | HlMod::Unsafe,
485 T![true] | T![false] => HighlightTag::BoolLiteral.into(), 468 T![true] | T![false] => HlTag::BoolLiteral.into(),
486 T![self] => { 469 T![self] => {
487 let self_param_is_mut = element 470 let self_param_is_mut = element
488 .parent() 471 .parent()
@@ -495,7 +478,7 @@ fn highlight_element(
495 .and_then(SyntaxNode::parent) 478 .and_then(SyntaxNode::parent)
496 .and_then(ast::Path::cast) 479 .and_then(ast::Path::cast)
497 .and_then(|p| sema.resolve_path(&p)); 480 .and_then(|p| sema.resolve_path(&p));
498 let mut h = HighlightTag::Symbol(SymbolKind::SelfParam).into(); 481 let mut h = HlTag::Symbol(SymbolKind::SelfParam).into();
499 if self_param_is_mut 482 if self_param_is_mut
500 || matches!(self_path, 483 || matches!(self_path,
501 Some(hir::PathResolution::Local(local)) 484 Some(hir::PathResolution::Local(local))
@@ -503,12 +486,12 @@ fn highlight_element(
503 && (local.is_mut(db) || local.ty(db).is_mutable_reference()) 486 && (local.is_mut(db) || local.ty(db).is_mutable_reference())
504 ) 487 )
505 { 488 {
506 h |= HighlightModifier::Mutable 489 h |= HlMod::Mutable
507 } 490 }
508 491
509 if let Some(hir::PathResolution::Local(local)) = self_path { 492 if let Some(hir::PathResolution::Local(local)) = self_path {
510 if is_consumed_lvalue(element, &local, db) { 493 if is_consumed_lvalue(element, &local, db) {
511 h |= HighlightModifier::Consuming; 494 h |= HlMod::Consuming;
512 } 495 }
513 } 496 }
514 497
@@ -519,7 +502,7 @@ fn highlight_element(
519 .and_then(ast::IdentPat::cast) 502 .and_then(ast::IdentPat::cast)
520 .and_then(|ident_pat| { 503 .and_then(|ident_pat| {
521 if sema.is_unsafe_ident_pat(&ident_pat) { 504 if sema.is_unsafe_ident_pat(&ident_pat) {
522 Some(HighlightModifier::Unsafe) 505 Some(HlMod::Unsafe)
523 } else { 506 } else {
524 None 507 None
525 } 508 }
@@ -568,21 +551,21 @@ fn highlight_method_call(
568 method_call: &ast::MethodCallExpr, 551 method_call: &ast::MethodCallExpr,
569) -> Option<Highlight> { 552) -> Option<Highlight> {
570 let func = sema.resolve_method_call(&method_call)?; 553 let func = sema.resolve_method_call(&method_call)?;
571 let mut h = HighlightTag::Symbol(SymbolKind::Function).into(); 554 let mut h = HlTag::Symbol(SymbolKind::Function).into();
572 h |= HighlightModifier::Associated; 555 h |= HlMod::Associated;
573 if func.is_unsafe(sema.db) || sema.is_unsafe_method_call(&method_call) { 556 if func.is_unsafe(sema.db) || sema.is_unsafe_method_call(&method_call) {
574 h |= HighlightModifier::Unsafe; 557 h |= HlMod::Unsafe;
575 } 558 }
576 if let Some(self_param) = func.self_param(sema.db) { 559 if let Some(self_param) = func.self_param(sema.db) {
577 match self_param.access(sema.db) { 560 match self_param.access(sema.db) {
578 hir::Access::Shared => (), 561 hir::Access::Shared => (),
579 hir::Access::Exclusive => h |= HighlightModifier::Mutable, 562 hir::Access::Exclusive => h |= HlMod::Mutable,
580 hir::Access::Owned => { 563 hir::Access::Owned => {
581 if let Some(receiver_ty) = 564 if let Some(receiver_ty) =
582 method_call.receiver().and_then(|it| sema.type_of_expr(&it)) 565 method_call.receiver().and_then(|it| sema.type_of_expr(&it))
583 { 566 {
584 if !receiver_ty.is_copy(sema.db) { 567 if !receiver_ty.is_copy(sema.db) {
585 h |= HighlightModifier::Consuming 568 h |= HlMod::Consuming
586 } 569 }
587 } 570 }
588 } 571 }
@@ -593,78 +576,78 @@ fn highlight_method_call(
593 576
594fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { 577fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
595 match def { 578 match def {
596 Definition::Macro(_) => HighlightTag::Symbol(SymbolKind::Macro), 579 Definition::Macro(_) => HlTag::Symbol(SymbolKind::Macro),
597 Definition::Field(_) => HighlightTag::Symbol(SymbolKind::Field), 580 Definition::Field(_) => HlTag::Symbol(SymbolKind::Field),
598 Definition::ModuleDef(def) => match def { 581 Definition::ModuleDef(def) => match def {
599 hir::ModuleDef::Module(_) => HighlightTag::Symbol(SymbolKind::Module), 582 hir::ModuleDef::Module(_) => HlTag::Symbol(SymbolKind::Module),
600 hir::ModuleDef::Function(func) => { 583 hir::ModuleDef::Function(func) => {
601 let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::Function)); 584 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Function));
602 if func.as_assoc_item(db).is_some() { 585 if func.as_assoc_item(db).is_some() {
603 h |= HighlightModifier::Associated; 586 h |= HlMod::Associated;
604 if func.self_param(db).is_none() { 587 if func.self_param(db).is_none() {
605 h |= HighlightModifier::Static 588 h |= HlMod::Static
606 } 589 }
607 } 590 }
608 if func.is_unsafe(db) { 591 if func.is_unsafe(db) {
609 h |= HighlightModifier::Unsafe; 592 h |= HlMod::Unsafe;
610 } 593 }
611 return h; 594 return h;
612 } 595 }
613 hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Symbol(SymbolKind::Struct), 596 hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HlTag::Symbol(SymbolKind::Struct),
614 hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Symbol(SymbolKind::Enum), 597 hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HlTag::Symbol(SymbolKind::Enum),
615 hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Symbol(SymbolKind::Union), 598 hir::ModuleDef::Adt(hir::Adt::Union(_)) => HlTag::Symbol(SymbolKind::Union),
616 hir::ModuleDef::Variant(_) => HighlightTag::Symbol(SymbolKind::Variant), 599 hir::ModuleDef::Variant(_) => HlTag::Symbol(SymbolKind::Variant),
617 hir::ModuleDef::Const(konst) => { 600 hir::ModuleDef::Const(konst) => {
618 let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::Const)); 601 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Const));
619 if konst.as_assoc_item(db).is_some() { 602 if konst.as_assoc_item(db).is_some() {
620 h |= HighlightModifier::Associated 603 h |= HlMod::Associated
621 } 604 }
622 return h; 605 return h;
623 } 606 }
624 hir::ModuleDef::Trait(_) => HighlightTag::Symbol(SymbolKind::Trait), 607 hir::ModuleDef::Trait(_) => HlTag::Symbol(SymbolKind::Trait),
625 hir::ModuleDef::TypeAlias(type_) => { 608 hir::ModuleDef::TypeAlias(type_) => {
626 let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::TypeAlias)); 609 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::TypeAlias));
627 if type_.as_assoc_item(db).is_some() { 610 if type_.as_assoc_item(db).is_some() {
628 h |= HighlightModifier::Associated 611 h |= HlMod::Associated
629 } 612 }
630 return h; 613 return h;
631 } 614 }
632 hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType, 615 hir::ModuleDef::BuiltinType(_) => HlTag::BuiltinType,
633 hir::ModuleDef::Static(s) => { 616 hir::ModuleDef::Static(s) => {
634 let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::Static)); 617 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Static));
635 if s.is_mut(db) { 618 if s.is_mut(db) {
636 h |= HighlightModifier::Mutable; 619 h |= HlMod::Mutable;
637 h |= HighlightModifier::Unsafe; 620 h |= HlMod::Unsafe;
638 } 621 }
639 return h; 622 return h;
640 } 623 }
641 }, 624 },
642 Definition::SelfType(_) => HighlightTag::Symbol(SymbolKind::Impl), 625 Definition::SelfType(_) => HlTag::Symbol(SymbolKind::Impl),
643 Definition::TypeParam(_) => HighlightTag::Symbol(SymbolKind::TypeParam), 626 Definition::TypeParam(_) => HlTag::Symbol(SymbolKind::TypeParam),
644 Definition::ConstParam(_) => HighlightTag::Symbol(SymbolKind::ConstParam), 627 Definition::ConstParam(_) => HlTag::Symbol(SymbolKind::ConstParam),
645 Definition::Local(local) => { 628 Definition::Local(local) => {
646 let tag = if local.is_param(db) { 629 let tag = if local.is_param(db) {
647 HighlightTag::Symbol(SymbolKind::ValueParam) 630 HlTag::Symbol(SymbolKind::ValueParam)
648 } else { 631 } else {
649 HighlightTag::Symbol(SymbolKind::Local) 632 HlTag::Symbol(SymbolKind::Local)
650 }; 633 };
651 let mut h = Highlight::new(tag); 634 let mut h = Highlight::new(tag);
652 if local.is_mut(db) || local.ty(db).is_mutable_reference() { 635 if local.is_mut(db) || local.ty(db).is_mutable_reference() {
653 h |= HighlightModifier::Mutable; 636 h |= HlMod::Mutable;
654 } 637 }
655 if local.ty(db).as_callable(db).is_some() || local.ty(db).impls_fnonce(db) { 638 if local.ty(db).as_callable(db).is_some() || local.ty(db).impls_fnonce(db) {
656 h |= HighlightModifier::Callable; 639 h |= HlMod::Callable;
657 } 640 }
658 return h; 641 return h;
659 } 642 }
660 Definition::LifetimeParam(_) => HighlightTag::Symbol(SymbolKind::LifetimeParam), 643 Definition::LifetimeParam(_) => HlTag::Symbol(SymbolKind::LifetimeParam),
661 Definition::Label(_) => HighlightTag::Symbol(SymbolKind::Label), 644 Definition::Label(_) => HlTag::Symbol(SymbolKind::Label),
662 } 645 }
663 .into() 646 .into()
664} 647}
665 648
666fn highlight_name_by_syntax(name: ast::Name) -> Highlight { 649fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
667 let default = HighlightTag::UnresolvedReference; 650 let default = HlTag::UnresolvedReference;
668 651
669 let parent = match name.syntax().parent() { 652 let parent = match name.syntax().parent() {
670 Some(it) => it, 653 Some(it) => it,
@@ -672,19 +655,19 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
672 }; 655 };
673 656
674 let tag = match parent.kind() { 657 let tag = match parent.kind() {
675 STRUCT => HighlightTag::Symbol(SymbolKind::Struct), 658 STRUCT => HlTag::Symbol(SymbolKind::Struct),
676 ENUM => HighlightTag::Symbol(SymbolKind::Enum), 659 ENUM => HlTag::Symbol(SymbolKind::Enum),
677 VARIANT => HighlightTag::Symbol(SymbolKind::Variant), 660 VARIANT => HlTag::Symbol(SymbolKind::Variant),
678 UNION => HighlightTag::Symbol(SymbolKind::Union), 661 UNION => HlTag::Symbol(SymbolKind::Union),
679 TRAIT => HighlightTag::Symbol(SymbolKind::Trait), 662 TRAIT => HlTag::Symbol(SymbolKind::Trait),
680 TYPE_ALIAS => HighlightTag::Symbol(SymbolKind::TypeAlias), 663 TYPE_ALIAS => HlTag::Symbol(SymbolKind::TypeAlias),
681 TYPE_PARAM => HighlightTag::Symbol(SymbolKind::TypeParam), 664 TYPE_PARAM => HlTag::Symbol(SymbolKind::TypeParam),
682 RECORD_FIELD => HighlightTag::Symbol(SymbolKind::Field), 665 RECORD_FIELD => HlTag::Symbol(SymbolKind::Field),
683 MODULE => HighlightTag::Symbol(SymbolKind::Module), 666 MODULE => HlTag::Symbol(SymbolKind::Module),
684 FN => HighlightTag::Symbol(SymbolKind::Function), 667 FN => HlTag::Symbol(SymbolKind::Function),
685 CONST => HighlightTag::Symbol(SymbolKind::Const), 668 CONST => HlTag::Symbol(SymbolKind::Const),
686 STATIC => HighlightTag::Symbol(SymbolKind::Static), 669 STATIC => HlTag::Symbol(SymbolKind::Static),
687 IDENT_PAT => HighlightTag::Symbol(SymbolKind::Local), 670 IDENT_PAT => HlTag::Symbol(SymbolKind::Local),
688 _ => default, 671 _ => default,
689 }; 672 };
690 673
@@ -692,7 +675,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
692} 675}
693 676
694fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabase>) -> Highlight { 677fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabase>) -> Highlight {
695 let default = HighlightTag::UnresolvedReference; 678 let default = HlTag::UnresolvedReference;
696 679
697 let parent = match name.syntax().parent() { 680 let parent = match name.syntax().parent() {
698 Some(it) => it, 681 Some(it) => it,
@@ -703,10 +686,10 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas
703 METHOD_CALL_EXPR => { 686 METHOD_CALL_EXPR => {
704 return ast::MethodCallExpr::cast(parent) 687 return ast::MethodCallExpr::cast(parent)
705 .and_then(|method_call| highlight_method_call(sema, &method_call)) 688 .and_then(|method_call| highlight_method_call(sema, &method_call))
706 .unwrap_or_else(|| HighlightTag::Symbol(SymbolKind::Function).into()); 689 .unwrap_or_else(|| HlTag::Symbol(SymbolKind::Function).into());
707 } 690 }
708 FIELD_EXPR => { 691 FIELD_EXPR => {
709 let h = HighlightTag::Symbol(SymbolKind::Field); 692 let h = HlTag::Symbol(SymbolKind::Field);
710 let is_union = ast::FieldExpr::cast(parent) 693 let is_union = ast::FieldExpr::cast(parent)
711 .and_then(|field_expr| { 694 .and_then(|field_expr| {
712 let field = sema.resolve_field(&field_expr)?; 695 let field = sema.resolve_field(&field_expr)?;
@@ -718,7 +701,7 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas
718 }) 701 })
719 .unwrap_or(false); 702 .unwrap_or(false);
720 if is_union { 703 if is_union {
721 h | HighlightModifier::Unsafe 704 h | HlMod::Unsafe
722 } else { 705 } else {
723 h.into() 706 h.into()
724 } 707 }
@@ -733,9 +716,9 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas
733 _ => { 716 _ => {
734 // within path, decide whether it is module or adt by checking for uppercase name 717 // within path, decide whether it is module or adt by checking for uppercase name
735 return if name.text().chars().next().unwrap_or_default().is_uppercase() { 718 return if name.text().chars().next().unwrap_or_default().is_uppercase() {
736 HighlightTag::Symbol(SymbolKind::Struct) 719 HlTag::Symbol(SymbolKind::Struct)
737 } else { 720 } else {
738 HighlightTag::Symbol(SymbolKind::Module) 721 HlTag::Symbol(SymbolKind::Module)
739 } 722 }
740 .into(); 723 .into();
741 } 724 }
@@ -746,11 +729,11 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas
746 }; 729 };
747 730
748 match parent.kind() { 731 match parent.kind() {
749 CALL_EXPR => HighlightTag::Symbol(SymbolKind::Function).into(), 732 CALL_EXPR => HlTag::Symbol(SymbolKind::Function).into(),
750 _ => if name.text().chars().next().unwrap_or_default().is_uppercase() { 733 _ => if name.text().chars().next().unwrap_or_default().is_uppercase() {
751 HighlightTag::Symbol(SymbolKind::Struct) 734 HlTag::Symbol(SymbolKind::Struct)
752 } else { 735 } else {
753 HighlightTag::Symbol(SymbolKind::Const) 736 HlTag::Symbol(SymbolKind::Const)
754 } 737 }
755 .into(), 738 .into(),
756 } 739 }
diff --git a/crates/ide/src/syntax_highlighting/format.rs b/crates/ide/src/syntax_highlighting/format.rs
index ab66b406c..d807ad0ad 100644
--- a/crates/ide/src/syntax_highlighting/format.rs
+++ b/crates/ide/src/syntax_highlighting/format.rs
@@ -4,7 +4,7 @@ use syntax::{
4 AstNode, AstToken, SyntaxElement, SyntaxKind, SyntaxNode, TextRange, 4 AstNode, AstToken, SyntaxElement, SyntaxKind, SyntaxNode, TextRange,
5}; 5};
6 6
7use crate::{HighlightTag, HighlightedRange, SymbolKind}; 7use crate::{HlRange, HlTag, SymbolKind};
8 8
9use super::highlights::Highlights; 9use super::highlights::Highlights;
10 10
@@ -46,7 +46,7 @@ impl FormatStringHighlighter {
46 if self.format_string.as_ref() == Some(&SyntaxElement::from(string.syntax().clone())) { 46 if self.format_string.as_ref() == Some(&SyntaxElement::from(string.syntax().clone())) {
47 string.lex_format_specifier(|piece_range, kind| { 47 string.lex_format_specifier(|piece_range, kind| {
48 if let Some(highlight) = highlight_format_specifier(kind) { 48 if let Some(highlight) = highlight_format_specifier(kind) {
49 stack.add(HighlightedRange { 49 stack.add(HlRange {
50 range: piece_range + range.start(), 50 range: piece_range + range.start(),
51 highlight: highlight.into(), 51 highlight: highlight.into(),
52 binding_hash: None, 52 binding_hash: None,
@@ -57,7 +57,7 @@ impl FormatStringHighlighter {
57 } 57 }
58} 58}
59 59
60fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HighlightTag> { 60fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HlTag> {
61 Some(match kind { 61 Some(match kind {
62 FormatSpecifier::Open 62 FormatSpecifier::Open
63 | FormatSpecifier::Close 63 | FormatSpecifier::Close
@@ -69,8 +69,8 @@ fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HighlightTag> {
69 | FormatSpecifier::DollarSign 69 | FormatSpecifier::DollarSign
70 | FormatSpecifier::Dot 70 | FormatSpecifier::Dot
71 | FormatSpecifier::Asterisk 71 | FormatSpecifier::Asterisk
72 | FormatSpecifier::QuestionMark => HighlightTag::FormatSpecifier, 72 | FormatSpecifier::QuestionMark => HlTag::FormatSpecifier,
73 FormatSpecifier::Integer | FormatSpecifier::Zero => HighlightTag::NumericLiteral, 73 FormatSpecifier::Integer | FormatSpecifier::Zero => HlTag::NumericLiteral,
74 FormatSpecifier::Identifier => HighlightTag::Symbol(SymbolKind::Local), 74 FormatSpecifier::Identifier => HlTag::Symbol(SymbolKind::Local),
75 }) 75 })
76} 76}
diff --git a/crates/ide/src/syntax_highlighting/highlights.rs b/crates/ide/src/syntax_highlighting/highlights.rs
index 3e733c87c..11c11ed28 100644
--- a/crates/ide/src/syntax_highlighting/highlights.rs
+++ b/crates/ide/src/syntax_highlighting/highlights.rs
@@ -4,33 +4,29 @@ use std::{cmp::Ordering, iter};
4use stdx::equal_range_by; 4use stdx::equal_range_by;
5use syntax::TextRange; 5use syntax::TextRange;
6 6
7use crate::{HighlightTag, HighlightedRange}; 7use crate::{HlRange, HlTag};
8 8
9pub(super) struct Highlights { 9pub(super) struct Highlights {
10 root: Node, 10 root: Node,
11} 11}
12 12
13struct Node { 13struct Node {
14 highlighted_range: HighlightedRange, 14 hl_range: HlRange,
15 nested: Vec<Node>, 15 nested: Vec<Node>,
16} 16}
17 17
18impl Highlights { 18impl Highlights {
19 pub(super) fn new(range: TextRange) -> Highlights { 19 pub(super) fn new(range: TextRange) -> Highlights {
20 Highlights { 20 Highlights {
21 root: Node::new(HighlightedRange { 21 root: Node::new(HlRange { range, highlight: HlTag::None.into(), binding_hash: None }),
22 range,
23 highlight: HighlightTag::Dummy.into(),
24 binding_hash: None,
25 }),
26 } 22 }
27 } 23 }
28 24
29 pub(super) fn add(&mut self, highlighted_range: HighlightedRange) { 25 pub(super) fn add(&mut self, hl_range: HlRange) {
30 self.root.add(highlighted_range); 26 self.root.add(hl_range);
31 } 27 }
32 28
33 pub(super) fn to_vec(self) -> Vec<HighlightedRange> { 29 pub(super) fn to_vec(self) -> Vec<HlRange> {
34 let mut res = Vec::new(); 30 let mut res = Vec::new();
35 self.root.flatten(&mut res); 31 self.root.flatten(&mut res);
36 res 32 res
@@ -38,59 +34,54 @@ impl Highlights {
38} 34}
39 35
40impl Node { 36impl Node {
41 fn new(highlighted_range: HighlightedRange) -> Node { 37 fn new(hl_range: HlRange) -> Node {
42 Node { highlighted_range, nested: Vec::new() } 38 Node { hl_range, nested: Vec::new() }
43 } 39 }
44 40
45 fn add(&mut self, highlighted_range: HighlightedRange) { 41 fn add(&mut self, hl_range: HlRange) {
46 assert!(self.highlighted_range.range.contains_range(highlighted_range.range)); 42 assert!(self.hl_range.range.contains_range(hl_range.range));
47 43
48 // Fast path 44 // Fast path
49 if let Some(last) = self.nested.last_mut() { 45 if let Some(last) = self.nested.last_mut() {
50 if last.highlighted_range.range.contains_range(highlighted_range.range) { 46 if last.hl_range.range.contains_range(hl_range.range) {
51 return last.add(highlighted_range); 47 return last.add(hl_range);
52 } 48 }
53 if last.highlighted_range.range.end() <= highlighted_range.range.start() { 49 if last.hl_range.range.end() <= hl_range.range.start() {
54 return self.nested.push(Node::new(highlighted_range)); 50 return self.nested.push(Node::new(hl_range));
55 } 51 }
56 } 52 }
57 53
58 let (start, len) = equal_range_by(&self.nested, |n| { 54 let (start, len) =
59 ordering(n.highlighted_range.range, highlighted_range.range) 55 equal_range_by(&self.nested, |n| ordering(n.hl_range.range, hl_range.range));
60 });
61 56
62 if len == 1 57 if len == 1 && self.nested[start].hl_range.range.contains_range(hl_range.range) {
63 && self.nested[start].highlighted_range.range.contains_range(highlighted_range.range) 58 return self.nested[start].add(hl_range);
64 {
65 return self.nested[start].add(highlighted_range);
66 } 59 }
67 60
68 let nested = self 61 let nested = self
69 .nested 62 .nested
70 .splice(start..start + len, iter::once(Node::new(highlighted_range))) 63 .splice(start..start + len, iter::once(Node::new(hl_range)))
71 .collect::<Vec<_>>(); 64 .collect::<Vec<_>>();
72 self.nested[start].nested = nested; 65 self.nested[start].nested = nested;
73 } 66 }
74 67
75 fn flatten(&self, acc: &mut Vec<HighlightedRange>) { 68 fn flatten(&self, acc: &mut Vec<HlRange>) {
76 let mut start = self.highlighted_range.range.start(); 69 let mut start = self.hl_range.range.start();
77 let mut nested = self.nested.iter(); 70 let mut nested = self.nested.iter();
78 loop { 71 loop {
79 let next = nested.next(); 72 let next = nested.next();
80 let end = next.map_or(self.highlighted_range.range.end(), |it| { 73 let end = next.map_or(self.hl_range.range.end(), |it| it.hl_range.range.start());
81 it.highlighted_range.range.start()
82 });
83 if start < end { 74 if start < end {
84 acc.push(HighlightedRange { 75 acc.push(HlRange {
85 range: TextRange::new(start, end), 76 range: TextRange::new(start, end),
86 highlight: self.highlighted_range.highlight, 77 highlight: self.hl_range.highlight,
87 binding_hash: self.highlighted_range.binding_hash, 78 binding_hash: self.hl_range.binding_hash,
88 }); 79 });
89 } 80 }
90 start = match next { 81 start = match next {
91 Some(child) => { 82 Some(child) => {
92 child.flatten(acc); 83 child.flatten(acc);
93 child.highlighted_range.range.end() 84 child.hl_range.range.end()
94 } 85 }
95 None => break, 86 None => break,
96 } 87 }
diff --git a/crates/ide/src/syntax_highlighting/html.rs b/crates/ide/src/syntax_highlighting/html.rs
index 44f611b25..0ee7bc96e 100644
--- a/crates/ide/src/syntax_highlighting/html.rs
+++ b/crates/ide/src/syntax_highlighting/html.rs
@@ -20,26 +20,26 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
20 ) 20 )
21 } 21 }
22 22
23 let ranges = highlight(db, file_id, None, false); 23 let hl_ranges = highlight(db, file_id, None, false);
24 let text = parse.tree().syntax().to_string(); 24 let text = parse.tree().syntax().to_string();
25 let mut buf = String::new(); 25 let mut buf = String::new();
26 buf.push_str(&STYLE); 26 buf.push_str(&STYLE);
27 buf.push_str("<pre><code>"); 27 buf.push_str("<pre><code>");
28 for range in &ranges { 28 for r in &hl_ranges {
29 let curr = &text[range.range]; 29 let chunk = html_escape(&text[r.range]);
30 if range.highlight.is_empty() { 30 if r.highlight.is_empty() {
31 format_to!(buf, "{}", html_escape(curr)); 31 format_to!(buf, "{}", chunk);
32 continue; 32 continue;
33 } 33 }
34 34
35 let class = range.highlight.to_string().replace('.', " "); 35 let class = r.highlight.to_string().replace('.', " ");
36 let color = match (rainbow, range.binding_hash) { 36 let color = match (rainbow, r.binding_hash) {
37 (true, Some(hash)) => { 37 (true, Some(hash)) => {
38 format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash)) 38 format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash))
39 } 39 }
40 _ => "".into(), 40 _ => "".into(),
41 }; 41 };
42 format_to!(buf, "<span class=\"{}\"{}>{}</span>", class, color, html_escape(curr)); 42 format_to!(buf, "<span class=\"{}\"{}>{}</span>", class, color, chunk);
43 } 43 }
44 buf.push_str("</code></pre>"); 44 buf.push_str("</code></pre>");
45 buf 45 buf
diff --git a/crates/ide/src/syntax_highlighting/injection.rs b/crates/ide/src/syntax_highlighting/injection.rs
index 98ee03e0d..008d5ce24 100644
--- a/crates/ide/src/syntax_highlighting/injection.rs
+++ b/crates/ide/src/syntax_highlighting/injection.rs
@@ -7,12 +7,12 @@ use ide_db::call_info::ActiveParameter;
7use itertools::Itertools; 7use itertools::Itertools;
8use syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; 8use syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize};
9 9
10use crate::{Analysis, HighlightModifier, HighlightTag, HighlightedRange, RootDatabase}; 10use crate::{Analysis, HlMod, HlRange, HlTag, RootDatabase};
11 11
12use super::{highlights::Highlights, injector::Injector}; 12use super::{highlights::Highlights, injector::Injector};
13 13
14pub(super) fn highlight_injection( 14pub(super) fn highlight_injection(
15 acc: &mut Highlights, 15 hl: &mut Highlights,
16 sema: &Semantics<RootDatabase>, 16 sema: &Semantics<RootDatabase>,
17 literal: ast::String, 17 literal: ast::String,
18 expanded: SyntaxToken, 18 expanded: SyntaxToken,
@@ -22,80 +22,53 @@ pub(super) fn highlight_injection(
22 return None; 22 return None;
23 } 23 }
24 let value = literal.value()?; 24 let value = literal.value()?;
25 let marker_info = MarkerInfo::new(&*value);
26 let (analysis, tmp_file_id) = Analysis::from_single_file(marker_info.cleaned_text.clone());
27 25
28 if let Some(range) = literal.open_quote_text_range() { 26 if let Some(range) = literal.open_quote_text_range() {
29 acc.add(HighlightedRange { 27 hl.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None })
30 range,
31 highlight: HighlightTag::StringLiteral.into(),
32 binding_hash: None,
33 })
34 } 28 }
35 29
36 for mut h in analysis.highlight(tmp_file_id).unwrap() { 30 let mut inj = Injector::default();
37 let range = marker_info.map_range_up(h.range);
38 if let Some(range) = literal.map_range_up(range) {
39 h.range = range;
40 acc.add(h);
41 }
42 }
43 31
44 if let Some(range) = literal.close_quote_text_range() { 32 let mut text = &*value;
45 acc.add(HighlightedRange { 33 let mut offset: TextSize = 0.into();
46 range,
47 highlight: HighlightTag::StringLiteral.into(),
48 binding_hash: None,
49 })
50 }
51 34
52 Some(()) 35 while !text.is_empty() {
53} 36 let marker = "$0";
37 let idx = text.find(marker).unwrap_or(text.len());
38 let (chunk, next) = text.split_at(idx);
39 inj.add(chunk, TextRange::at(offset, TextSize::of(chunk)));
54 40
55/// Data to remove `$0` from string and map ranges 41 text = next;
56#[derive(Default, Debug)] 42 offset += TextSize::of(chunk);
57struct MarkerInfo {
58 cleaned_text: String,
59 markers: Vec<TextRange>,
60}
61 43
62impl MarkerInfo { 44 if let Some(next) = text.strip_prefix(marker) {
63 fn new(mut text: &str) -> Self { 45 if let Some(range) = literal.map_range_up(TextRange::at(offset, TextSize::of(marker))) {
64 let marker = "$0"; 46 hl.add(HlRange { range, highlight: HlTag::Keyword.into(), binding_hash: None });
47 }
65 48
66 let mut res = MarkerInfo::default();
67 let mut offset: TextSize = 0.into();
68 while !text.is_empty() {
69 let idx = text.find(marker).unwrap_or(text.len());
70 let (chunk, next) = text.split_at(idx);
71 text = next; 49 text = next;
72 res.cleaned_text.push_str(chunk);
73 offset += TextSize::of(chunk);
74
75 if let Some(next) = text.strip_prefix(marker) {
76 text = next;
77 50
78 let marker_len = TextSize::of(marker); 51 let marker_len = TextSize::of(marker);
79 res.markers.push(TextRange::at(offset, marker_len)); 52 offset += marker_len;
80 offset += marker_len;
81 }
82 } 53 }
83 res
84 } 54 }
85 fn map_range_up(&self, range: TextRange) -> TextRange { 55
86 TextRange::new( 56 let (analysis, tmp_file_id) = Analysis::from_single_file(inj.text().to_string());
87 self.map_offset_up(range.start(), true), 57
88 self.map_offset_up(range.end(), false), 58 for mut hl_range in analysis.highlight(tmp_file_id).unwrap() {
89 ) 59 for range in inj.map_range_up(hl_range.range) {
90 } 60 if let Some(range) = literal.map_range_up(range) {
91 fn map_offset_up(&self, mut offset: TextSize, start: bool) -> TextSize { 61 hl_range.range = range;
92 for r in &self.markers { 62 hl.add(hl_range.clone());
93 if r.start() < offset || (start && r.start() == offset) {
94 offset += r.len()
95 } 63 }
96 } 64 }
97 offset
98 } 65 }
66
67 if let Some(range) = literal.close_quote_text_range() {
68 hl.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None })
69 }
70
71 Some(())
99} 72}
100 73
101const RUSTDOC_FENCE: &'static str = "```"; 74const RUSTDOC_FENCE: &'static str = "```";
@@ -116,7 +89,7 @@ const RUSTDOC_FENCE_TOKENS: &[&'static str] = &[
116/// Lastly, a vector of new comment highlight ranges (spanning only the 89/// Lastly, a vector of new comment highlight ranges (spanning only the
117/// comment prefix) is returned which is used in the syntax highlighting 90/// comment prefix) is returned which is used in the syntax highlighting
118/// injection to replace the previous (line-spanning) comment ranges. 91/// injection to replace the previous (line-spanning) comment ranges.
119pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec<HighlightedRange>, Injector)> { 92pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec<HlRange>, Injector)> {
120 let mut inj = Injector::default(); 93 let mut inj = Injector::default();
121 // wrap the doctest into function body to get correct syntax highlighting 94 // wrap the doctest into function body to get correct syntax highlighting
122 let prefix = "fn doctest() {\n"; 95 let prefix = "fn doctest() {\n";
@@ -166,12 +139,12 @@ pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec<Highlighted
166 pos 139 pos
167 }; 140 };
168 141
169 new_comments.push(HighlightedRange { 142 new_comments.push(HlRange {
170 range: TextRange::new( 143 range: TextRange::new(
171 range.start(), 144 range.start(),
172 range.start() + TextSize::try_from(pos).unwrap(), 145 range.start() + TextSize::try_from(pos).unwrap(),
173 ), 146 ),
174 highlight: HighlightTag::Comment | HighlightModifier::Documentation, 147 highlight: HlTag::Comment | HlMod::Documentation,
175 binding_hash: None, 148 binding_hash: None,
176 }); 149 });
177 line_start += range.len() - TextSize::try_from(pos).unwrap(); 150 line_start += range.len() - TextSize::try_from(pos).unwrap();
@@ -196,7 +169,7 @@ pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec<Highlighted
196 169
197/// Injection of syntax highlighting of doctests. 170/// Injection of syntax highlighting of doctests.
198pub(super) fn highlight_doc_comment( 171pub(super) fn highlight_doc_comment(
199 new_comments: Vec<HighlightedRange>, 172 new_comments: Vec<HlRange>,
200 inj: Injector, 173 inj: Injector,
201 stack: &mut Highlights, 174 stack: &mut Highlights,
202) { 175) {
@@ -207,9 +180,9 @@ pub(super) fn highlight_doc_comment(
207 180
208 for h in analysis.with_db(|db| super::highlight(db, tmp_file_id, None, true)).unwrap() { 181 for h in analysis.with_db(|db| super::highlight(db, tmp_file_id, None, true)).unwrap() {
209 for r in inj.map_range_up(h.range) { 182 for r in inj.map_range_up(h.range) {
210 stack.add(HighlightedRange { 183 stack.add(HlRange {
211 range: r, 184 range: r,
212 highlight: h.highlight | HighlightModifier::Injected, 185 highlight: h.highlight | HlMod::Injected,
213 binding_hash: h.binding_hash, 186 binding_hash: h.binding_hash,
214 }); 187 });
215 } 188 }
diff --git a/crates/ide/src/syntax_highlighting/injector.rs b/crates/ide/src/syntax_highlighting/injector.rs
index 0513a9fd6..e8f17eb69 100644
--- a/crates/ide/src/syntax_highlighting/injector.rs
+++ b/crates/ide/src/syntax_highlighting/injector.rs
@@ -17,17 +17,15 @@ impl Injector {
17 pub(super) fn add(&mut self, text: &str, source_range: TextRange) { 17 pub(super) fn add(&mut self, text: &str, source_range: TextRange) {
18 let len = TextSize::of(text); 18 let len = TextSize::of(text);
19 assert_eq!(len, source_range.len()); 19 assert_eq!(len, source_range.len());
20 20 self.add_impl(text, Some(source_range.start()));
21 let target_range = TextRange::at(TextSize::of(&self.buf), len);
22 self.ranges
23 .push((target_range, Some(Delta::new(target_range.start(), source_range.start()))));
24 self.buf.push_str(text);
25 } 21 }
26 pub(super) fn add_unmapped(&mut self, text: &str) { 22 pub(super) fn add_unmapped(&mut self, text: &str) {
23 self.add_impl(text, None);
24 }
25 fn add_impl(&mut self, text: &str, source: Option<TextSize>) {
27 let len = TextSize::of(text); 26 let len = TextSize::of(text);
28
29 let target_range = TextRange::at(TextSize::of(&self.buf), len); 27 let target_range = TextRange::at(TextSize::of(&self.buf), len);
30 self.ranges.push((target_range, None)); 28 self.ranges.push((target_range, source.map(|it| Delta::new(target_range.start(), it))));
31 self.buf.push_str(text); 29 self.buf.push_str(text);
32 } 30 }
33 31
diff --git a/crates/ide/src/syntax_highlighting/macro_rules.rs b/crates/ide/src/syntax_highlighting/macro_rules.rs
index 4462af47e..21d8a9835 100644
--- a/crates/ide/src/syntax_highlighting/macro_rules.rs
+++ b/crates/ide/src/syntax_highlighting/macro_rules.rs
@@ -1,7 +1,7 @@
1//! Syntax highlighting for macro_rules!. 1//! Syntax highlighting for macro_rules!.
2use syntax::{SyntaxElement, SyntaxKind, SyntaxToken, TextRange, T}; 2use syntax::{SyntaxElement, SyntaxKind, SyntaxToken, TextRange, T};
3 3
4use crate::{HighlightTag, HighlightedRange}; 4use crate::{HlRange, HlTag};
5 5
6#[derive(Default)] 6#[derive(Default)]
7pub(super) struct MacroRulesHighlighter { 7pub(super) struct MacroRulesHighlighter {
@@ -19,13 +19,13 @@ impl MacroRulesHighlighter {
19 } 19 }
20 } 20 }
21 21
22 pub(super) fn highlight(&self, element: SyntaxElement) -> Option<HighlightedRange> { 22 pub(super) fn highlight(&self, element: SyntaxElement) -> Option<HlRange> {
23 if let Some(state) = self.state.as_ref() { 23 if let Some(state) = self.state.as_ref() {
24 if matches!(state.rule_state, RuleState::Matcher | RuleState::Expander) { 24 if matches!(state.rule_state, RuleState::Matcher | RuleState::Expander) {
25 if let Some(range) = is_metavariable(element) { 25 if let Some(range) = is_metavariable(element) {
26 return Some(HighlightedRange { 26 return Some(HlRange {
27 range, 27 range,
28 highlight: HighlightTag::UnresolvedReference.into(), 28 highlight: HlTag::UnresolvedReference.into(),
29 binding_hash: None, 29 binding_hash: None,
30 }); 30 });
31 } 31 }
diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs
index a0286b72d..2f39bcc8e 100644
--- a/crates/ide/src/syntax_highlighting/tags.rs
+++ b/crates/ide/src/syntax_highlighting/tags.rs
@@ -7,15 +7,15 @@ use crate::SymbolKind;
7 7
8#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 8#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
9pub struct Highlight { 9pub struct Highlight {
10 pub tag: HighlightTag, 10 pub tag: HlTag,
11 pub modifiers: HighlightModifiers, 11 pub mods: HlMods,
12} 12}
13 13
14#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 14#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
15pub struct HighlightModifiers(u32); 15pub struct HlMods(u32);
16 16
17#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 17#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
18pub enum HighlightTag { 18pub enum HlTag {
19 Symbol(SymbolKind), 19 Symbol(SymbolKind),
20 20
21 BoolLiteral, 21 BoolLiteral,
@@ -33,13 +33,13 @@ pub enum HighlightTag {
33 Operator, 33 Operator,
34 UnresolvedReference, 34 UnresolvedReference,
35 35
36 // For things which don't have proper Tag, but want to use modifiers. 36 // For things which don't have a specific highlight.
37 Dummy, 37 None,
38} 38}
39 39
40#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 40#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
41#[repr(u8)] 41#[repr(u8)]
42pub enum HighlightModifier { 42pub enum HlMod {
43 /// Used to differentiate individual elements within attributes. 43 /// Used to differentiate individual elements within attributes.
44 Attribute = 0, 44 Attribute = 0,
45 /// Used with keywords like `if` and `break`. 45 /// Used with keywords like `if` and `break`.
@@ -61,10 +61,10 @@ pub enum HighlightModifier {
61 Unsafe, 61 Unsafe,
62} 62}
63 63
64impl HighlightTag { 64impl HlTag {
65 fn as_str(self) -> &'static str { 65 fn as_str(self) -> &'static str {
66 match self { 66 match self {
67 HighlightTag::Symbol(symbol) => match symbol { 67 HlTag::Symbol(symbol) => match symbol {
68 SymbolKind::Const => "constant", 68 SymbolKind::Const => "constant",
69 SymbolKind::Static => "static", 69 SymbolKind::Static => "static",
70 SymbolKind::Enum => "enum", 70 SymbolKind::Enum => "enum",
@@ -86,59 +86,59 @@ impl HighlightTag {
86 SymbolKind::SelfParam => "self_keyword", 86 SymbolKind::SelfParam => "self_keyword",
87 SymbolKind::Impl => "self_type", 87 SymbolKind::Impl => "self_type",
88 }, 88 },
89 HighlightTag::Attribute => "attribute", 89 HlTag::Attribute => "attribute",
90 HighlightTag::BoolLiteral => "bool_literal", 90 HlTag::BoolLiteral => "bool_literal",
91 HighlightTag::BuiltinType => "builtin_type", 91 HlTag::BuiltinType => "builtin_type",
92 HighlightTag::ByteLiteral => "byte_literal", 92 HlTag::ByteLiteral => "byte_literal",
93 HighlightTag::CharLiteral => "char_literal", 93 HlTag::CharLiteral => "char_literal",
94 HighlightTag::Comment => "comment", 94 HlTag::Comment => "comment",
95 HighlightTag::EscapeSequence => "escape_sequence", 95 HlTag::EscapeSequence => "escape_sequence",
96 HighlightTag::FormatSpecifier => "format_specifier", 96 HlTag::FormatSpecifier => "format_specifier",
97 HighlightTag::Keyword => "keyword", 97 HlTag::Keyword => "keyword",
98 HighlightTag::Punctuation => "punctuation", 98 HlTag::Punctuation => "punctuation",
99 HighlightTag::NumericLiteral => "numeric_literal", 99 HlTag::NumericLiteral => "numeric_literal",
100 HighlightTag::Operator => "operator", 100 HlTag::Operator => "operator",
101 HighlightTag::StringLiteral => "string_literal", 101 HlTag::StringLiteral => "string_literal",
102 HighlightTag::UnresolvedReference => "unresolved_reference", 102 HlTag::UnresolvedReference => "unresolved_reference",
103 HighlightTag::Dummy => "dummy", 103 HlTag::None => "none",
104 } 104 }
105 } 105 }
106} 106}
107 107
108impl fmt::Display for HighlightTag { 108impl fmt::Display for HlTag {
109 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 109 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
110 fmt::Display::fmt(self.as_str(), f) 110 fmt::Display::fmt(self.as_str(), f)
111 } 111 }
112} 112}
113 113
114impl HighlightModifier { 114impl HlMod {
115 const ALL: &'static [HighlightModifier; HighlightModifier::Unsafe as u8 as usize + 1] = &[ 115 const ALL: &'static [HlMod; HlMod::Unsafe as u8 as usize + 1] = &[
116 HighlightModifier::Attribute, 116 HlMod::Attribute,
117 HighlightModifier::ControlFlow, 117 HlMod::ControlFlow,
118 HighlightModifier::Definition, 118 HlMod::Definition,
119 HighlightModifier::Documentation, 119 HlMod::Documentation,
120 HighlightModifier::Injected, 120 HlMod::Injected,
121 HighlightModifier::Mutable, 121 HlMod::Mutable,
122 HighlightModifier::Consuming, 122 HlMod::Consuming,
123 HighlightModifier::Callable, 123 HlMod::Callable,
124 HighlightModifier::Static, 124 HlMod::Static,
125 HighlightModifier::Associated, 125 HlMod::Associated,
126 HighlightModifier::Unsafe, 126 HlMod::Unsafe,
127 ]; 127 ];
128 128
129 fn as_str(self) -> &'static str { 129 fn as_str(self) -> &'static str {
130 match self { 130 match self {
131 HighlightModifier::Attribute => "attribute", 131 HlMod::Attribute => "attribute",
132 HighlightModifier::ControlFlow => "control", 132 HlMod::ControlFlow => "control",
133 HighlightModifier::Definition => "declaration", 133 HlMod::Definition => "declaration",
134 HighlightModifier::Documentation => "documentation", 134 HlMod::Documentation => "documentation",
135 HighlightModifier::Injected => "injected", 135 HlMod::Injected => "injected",
136 HighlightModifier::Mutable => "mutable", 136 HlMod::Mutable => "mutable",
137 HighlightModifier::Consuming => "consuming", 137 HlMod::Consuming => "consuming",
138 HighlightModifier::Unsafe => "unsafe", 138 HlMod::Unsafe => "unsafe",
139 HighlightModifier::Callable => "callable", 139 HlMod::Callable => "callable",
140 HighlightModifier::Static => "static", 140 HlMod::Static => "static",
141 HighlightModifier::Associated => "associated", 141 HlMod::Associated => "associated",
142 } 142 }
143 } 143 }
144 144
@@ -147,7 +147,7 @@ impl HighlightModifier {
147 } 147 }
148} 148}
149 149
150impl fmt::Display for HighlightModifier { 150impl fmt::Display for HlMod {
151 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 151 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
152 fmt::Display::fmt(self.as_str(), f) 152 fmt::Display::fmt(self.as_str(), f)
153 } 153 }
@@ -156,63 +156,63 @@ impl fmt::Display for HighlightModifier {
156impl fmt::Display for Highlight { 156impl fmt::Display for Highlight {
157 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 157 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
158 write!(f, "{}", self.tag)?; 158 write!(f, "{}", self.tag)?;
159 for modifier in self.modifiers.iter() { 159 for modifier in self.mods.iter() {
160 write!(f, ".{}", modifier)? 160 write!(f, ".{}", modifier)?
161 } 161 }
162 Ok(()) 162 Ok(())
163 } 163 }
164} 164}
165 165
166impl From<HighlightTag> for Highlight { 166impl From<HlTag> for Highlight {
167 fn from(tag: HighlightTag) -> Highlight { 167 fn from(tag: HlTag) -> Highlight {
168 Highlight::new(tag) 168 Highlight::new(tag)
169 } 169 }
170} 170}
171 171
172impl Highlight { 172impl Highlight {
173 pub(crate) fn new(tag: HighlightTag) -> Highlight { 173 pub(crate) fn new(tag: HlTag) -> Highlight {
174 Highlight { tag, modifiers: HighlightModifiers::default() } 174 Highlight { tag, mods: HlMods::default() }
175 } 175 }
176 pub fn is_empty(&self) -> bool { 176 pub fn is_empty(&self) -> bool {
177 self.tag == HighlightTag::Dummy && self.modifiers == HighlightModifiers::default() 177 self.tag == HlTag::None && self.mods == HlMods::default()
178 } 178 }
179} 179}
180 180
181impl ops::BitOr<HighlightModifier> for HighlightTag { 181impl ops::BitOr<HlMod> for HlTag {
182 type Output = Highlight; 182 type Output = Highlight;
183 183
184 fn bitor(self, rhs: HighlightModifier) -> Highlight { 184 fn bitor(self, rhs: HlMod) -> Highlight {
185 Highlight::new(self) | rhs 185 Highlight::new(self) | rhs
186 } 186 }
187} 187}
188 188
189impl ops::BitOrAssign<HighlightModifier> for HighlightModifiers { 189impl ops::BitOrAssign<HlMod> for HlMods {
190 fn bitor_assign(&mut self, rhs: HighlightModifier) { 190 fn bitor_assign(&mut self, rhs: HlMod) {
191 self.0 |= rhs.mask(); 191 self.0 |= rhs.mask();
192 } 192 }
193} 193}
194 194
195impl ops::BitOrAssign<HighlightModifier> for Highlight { 195impl ops::BitOrAssign<HlMod> for Highlight {
196 fn bitor_assign(&mut self, rhs: HighlightModifier) { 196 fn bitor_assign(&mut self, rhs: HlMod) {
197 self.modifiers |= rhs; 197 self.mods |= rhs;
198 } 198 }
199} 199}
200 200
201impl ops::BitOr<HighlightModifier> for Highlight { 201impl ops::BitOr<HlMod> for Highlight {
202 type Output = Highlight; 202 type Output = Highlight;
203 203
204 fn bitor(mut self, rhs: HighlightModifier) -> Highlight { 204 fn bitor(mut self, rhs: HlMod) -> Highlight {
205 self |= rhs; 205 self |= rhs;
206 self 206 self
207 } 207 }
208} 208}
209 209
210impl HighlightModifiers { 210impl HlMods {
211 pub fn contains(self, m: HighlightModifier) -> bool { 211 pub fn contains(self, m: HlMod) -> bool {
212 self.0 & m.mask() == m.mask() 212 self.0 & m.mask() == m.mask()
213 } 213 }
214 214
215 pub fn iter(self) -> impl Iterator<Item = HighlightModifier> { 215 pub fn iter(self) -> impl Iterator<Item = HlMod> {
216 HighlightModifier::ALL.iter().copied().filter(move |it| self.0 & it.mask() == it.mask()) 216 HlMod::ALL.iter().copied().filter(move |it| self.0 & it.mask() == it.mask())
217 } 217 }
218} 218}
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html
index 9d42b11c1..7d1d2a839 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html
@@ -37,7 +37,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
37.unresolved_reference { color: #FC5555; text-decoration: wavy underline; } 37.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
38</style> 38</style>
39<pre><code><span class="comment documentation">/// ```</span> 39<pre><code><span class="comment documentation">/// ```</span>
40<span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="dummy injected"> </span><span class="punctuation injected">_</span><span class="dummy injected"> </span><span class="operator injected">=</span><span class="dummy injected"> </span><span class="string_literal injected">"early doctests should not go boom"</span><span class="punctuation injected">;</span> 40<span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="punctuation injected">_</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="string_literal injected">"early doctests should not go boom"</span><span class="punctuation injected">;</span>
41<span class="comment documentation">/// ```</span> 41<span class="comment documentation">/// ```</span>
42<span class="keyword">struct</span> <span class="struct declaration">Foo</span> <span class="punctuation">{</span> 42<span class="keyword">struct</span> <span class="struct declaration">Foo</span> <span class="punctuation">{</span>
43 <span class="field declaration">bar</span><span class="punctuation">:</span> <span class="builtin_type">bool</span><span class="punctuation">,</span> 43 <span class="field declaration">bar</span><span class="punctuation">:</span> <span class="builtin_type">bool</span><span class="punctuation">,</span>
@@ -45,7 +45,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
45 45
46<span class="keyword">impl</span> <span class="struct">Foo</span> <span class="punctuation">{</span> 46<span class="keyword">impl</span> <span class="struct">Foo</span> <span class="punctuation">{</span>
47 <span class="comment documentation">/// ```</span> 47 <span class="comment documentation">/// ```</span>
48 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="dummy injected"> </span><span class="punctuation injected">_</span><span class="dummy injected"> </span><span class="operator injected">=</span><span class="dummy injected"> </span><span class="string_literal injected">"Call me</span> 48 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="punctuation injected">_</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="string_literal injected">"Call me</span>
49 <span class="comment">// KILLER WHALE</span> 49 <span class="comment">// KILLER WHALE</span>
50 <span class="comment documentation">/// </span><span class="string_literal injected"> Ishmael."</span><span class="punctuation injected">;</span> 50 <span class="comment documentation">/// </span><span class="string_literal injected"> Ishmael."</span><span class="punctuation injected">;</span>
51 <span class="comment documentation">/// ```</span> 51 <span class="comment documentation">/// ```</span>
@@ -56,8 +56,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
56 <span class="comment documentation">/// # Examples</span> 56 <span class="comment documentation">/// # Examples</span>
57 <span class="comment documentation">///</span> 57 <span class="comment documentation">///</span>
58 <span class="comment documentation">/// ```</span> 58 <span class="comment documentation">/// ```</span>
59 <span class="comment documentation">/// #</span><span class="dummy injected"> </span><span class="attribute attribute injected">#</span><span class="attribute attribute injected">!</span><span class="attribute attribute injected">[</span><span class="function attribute injected">allow</span><span class="punctuation attribute injected">(</span><span class="attribute attribute injected">unused_mut</span><span class="punctuation attribute injected">)</span><span class="attribute attribute injected">]</span> 59 <span class="comment documentation">/// #</span><span class="none injected"> </span><span class="attribute attribute injected">#</span><span class="attribute attribute injected">!</span><span class="attribute attribute injected">[</span><span class="function attribute injected">allow</span><span class="punctuation attribute injected">(</span><span class="attribute attribute injected">unused_mut</span><span class="punctuation attribute injected">)</span><span class="attribute attribute injected">]</span>
60 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="dummy injected"> </span><span class="keyword injected">mut</span><span class="dummy injected"> </span><span class="variable declaration injected mutable">foo</span><span class="punctuation injected">:</span><span class="dummy injected"> </span><span class="struct injected">Foo</span><span class="dummy injected"> </span><span class="operator injected">=</span><span class="dummy injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="function injected">new</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span> 60 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="keyword injected">mut</span><span class="none injected"> </span><span class="variable declaration injected mutable">foo</span><span class="punctuation injected">:</span><span class="none injected"> </span><span class="struct injected">Foo</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="function injected">new</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span>
61 <span class="comment documentation">/// ```</span> 61 <span class="comment documentation">/// ```</span>
62 <span class="keyword">pub</span> <span class="keyword">const</span> <span class="keyword">fn</span> <span class="function declaration static associated">new</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="operator">-&gt;</span> <span class="struct">Foo</span> <span class="punctuation">{</span> 62 <span class="keyword">pub</span> <span class="keyword">const</span> <span class="keyword">fn</span> <span class="function declaration static associated">new</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="operator">-&gt;</span> <span class="struct">Foo</span> <span class="punctuation">{</span>
63 <span class="struct">Foo</span> <span class="punctuation">{</span> <span class="field">bar</span><span class="punctuation">:</span> <span class="bool_literal">true</span> <span class="punctuation">}</span> 63 <span class="struct">Foo</span> <span class="punctuation">{</span> <span class="field">bar</span><span class="punctuation">:</span> <span class="bool_literal">true</span> <span class="punctuation">}</span>
@@ -68,26 +68,26 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
68 <span class="comment documentation">/// # Examples</span> 68 <span class="comment documentation">/// # Examples</span>
69 <span class="comment documentation">///</span> 69 <span class="comment documentation">///</span>
70 <span class="comment documentation">/// ```</span> 70 <span class="comment documentation">/// ```</span>
71 <span class="comment documentation">/// </span><span class="keyword injected">use</span><span class="dummy injected"> </span><span class="module injected">x</span><span class="operator injected">::</span><span class="module injected">y</span><span class="punctuation injected">;</span> 71 <span class="comment documentation">/// </span><span class="keyword injected">use</span><span class="none injected"> </span><span class="module injected">x</span><span class="operator injected">::</span><span class="module injected">y</span><span class="punctuation injected">;</span>
72 <span class="comment documentation">///</span> 72 <span class="comment documentation">///</span>
73 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="dummy injected"> </span><span class="variable declaration injected">foo</span><span class="dummy injected"> </span><span class="operator injected">=</span><span class="dummy injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="function injected">new</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span> 73 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="variable declaration injected">foo</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="function injected">new</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span>
74 <span class="comment documentation">///</span> 74 <span class="comment documentation">///</span>
75 <span class="comment documentation">/// </span><span class="comment injected">// calls bar on foo</span> 75 <span class="comment documentation">/// </span><span class="comment injected">// calls bar on foo</span>
76 <span class="comment documentation">/// </span><span class="macro injected">assert!</span><span class="punctuation injected">(</span><span class="dummy injected">foo</span><span class="operator injected">.</span><span class="dummy injected">bar</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span> 76 <span class="comment documentation">/// </span><span class="macro injected">assert!</span><span class="punctuation injected">(</span><span class="none injected">foo</span><span class="operator injected">.</span><span class="none injected">bar</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span>
77 <span class="comment documentation">///</span> 77 <span class="comment documentation">///</span>
78 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="dummy injected"> </span><span class="variable declaration injected">bar</span><span class="dummy injected"> </span><span class="operator injected">=</span><span class="dummy injected"> </span><span class="variable injected">foo</span><span class="operator injected">.</span><span class="field injected">bar</span><span class="dummy injected"> </span><span class="operator injected">||</span><span class="dummy injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="constant injected">bar</span><span class="punctuation injected">;</span> 78 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="variable declaration injected">bar</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="variable injected">foo</span><span class="operator injected">.</span><span class="field injected">bar</span><span class="none injected"> </span><span class="operator injected">||</span><span class="none injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="constant injected">bar</span><span class="punctuation injected">;</span>
79 <span class="comment documentation">///</span> 79 <span class="comment documentation">///</span>
80 <span class="comment documentation">/// </span><span class="comment injected">/* multi-line</span> 80 <span class="comment documentation">/// </span><span class="comment injected">/* multi-line</span>
81 <span class="comment documentation">/// </span><span class="comment injected"> comment */</span> 81 <span class="comment documentation">/// </span><span class="comment injected"> comment */</span>
82 <span class="comment documentation">///</span> 82 <span class="comment documentation">///</span>
83 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="dummy injected"> </span><span class="variable declaration injected">multi_line_string</span><span class="dummy injected"> </span><span class="operator injected">=</span><span class="dummy injected"> </span><span class="string_literal injected">"Foo</span> 83 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="variable declaration injected">multi_line_string</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="string_literal injected">"Foo</span>
84 <span class="comment documentation">/// </span><span class="string_literal injected"> bar</span> 84 <span class="comment documentation">/// </span><span class="string_literal injected"> bar</span>
85 <span class="comment documentation">/// </span><span class="string_literal injected"> "</span><span class="punctuation injected">;</span> 85 <span class="comment documentation">/// </span><span class="string_literal injected"> "</span><span class="punctuation injected">;</span>
86 <span class="comment documentation">///</span> 86 <span class="comment documentation">///</span>
87 <span class="comment documentation">/// ```</span> 87 <span class="comment documentation">/// ```</span>
88 <span class="comment documentation">///</span> 88 <span class="comment documentation">///</span>
89 <span class="comment documentation">/// ```rust,no_run</span> 89 <span class="comment documentation">/// ```rust,no_run</span>
90 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="dummy injected"> </span><span class="variable declaration injected">foobar</span><span class="dummy injected"> </span><span class="operator injected">=</span><span class="dummy injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="function injected">new</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="operator injected">.</span><span class="function injected">bar</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span> 90 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="variable declaration injected">foobar</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="function injected">new</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="operator injected">.</span><span class="function injected">bar</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span>
91 <span class="comment documentation">/// ```</span> 91 <span class="comment documentation">/// ```</span>
92 <span class="comment documentation">///</span> 92 <span class="comment documentation">///</span>
93 <span class="comment documentation">/// ```sh</span> 93 <span class="comment documentation">/// ```sh</span>
diff --git a/crates/ide/src/syntax_highlighting/test_data/injection.html b/crates/ide/src/syntax_highlighting/test_data/injection.html
index a54d303b4..6703a84e5 100644
--- a/crates/ide/src/syntax_highlighting/test_data/injection.html
+++ b/crates/ide/src/syntax_highlighting/test_data/injection.html
@@ -40,9 +40,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
40<span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> 40<span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span>
41 <span class="function">f</span><span class="punctuation">(</span><span class="string_literal">r"</span> 41 <span class="function">f</span><span class="punctuation">(</span><span class="string_literal">r"</span>
42<span class="keyword">fn</span> <span class="function declaration">foo</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> 42<span class="keyword">fn</span> <span class="function declaration">foo</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span>
43 <span class="function">foo</span><span class="punctuation">(</span>$0<span class="punctuation">{</span> 43 <span class="function">foo</span><span class="punctuation">(</span><span class="keyword">$0</span><span class="punctuation">{</span>
44 <span class="numeric_literal">92</span> 44 <span class="numeric_literal">92</span>
45 <span class="punctuation">}</span>$0<span class="punctuation">)</span> 45 <span class="punctuation">}</span><span class="keyword">$0</span><span class="punctuation">)</span>
46<span class="punctuation">}</span><span class="string_literal">"</span><span class="punctuation">)</span><span class="punctuation">;</span> 46<span class="punctuation">}</span><span class="string_literal">"</span><span class="punctuation">)</span><span class="punctuation">;</span>
47<span class="punctuation">}</span> 47<span class="punctuation">}</span>
48 </code></pre> \ No newline at end of file 48 </code></pre> \ No newline at end of file
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 204cae265..d6bf60cde 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -6,10 +6,9 @@ use std::{
6 6
7use ide::{ 7use ide::{
8 Assist, AssistKind, CallInfo, CompletionItem, CompletionItemKind, Documentation, FileId, 8 Assist, AssistKind, CallInfo, CompletionItem, CompletionItemKind, Documentation, FileId,
9 FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HighlightModifier, HighlightTag, 9 FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HlMod, HlRange, HlTag, Indel, InlayHint,
10 HighlightedRange, Indel, InlayHint, InlayKind, InsertTextFormat, LineIndex, Markup, 10 InlayKind, InsertTextFormat, LineIndex, Markup, NavigationTarget, ReferenceAccess, Runnable,
11 NavigationTarget, ReferenceAccess, Runnable, Severity, SourceChange, SourceFileEdit, 11 Severity, SourceChange, SourceFileEdit, SymbolKind, TextEdit, TextRange, TextSize,
12 SymbolKind, TextEdit, TextRange, TextSize,
13}; 12};
14use itertools::Itertools; 13use itertools::Itertools;
15 14
@@ -337,7 +336,7 @@ static TOKEN_RESULT_COUNTER: AtomicU32 = AtomicU32::new(1);
337pub(crate) fn semantic_tokens( 336pub(crate) fn semantic_tokens(
338 text: &str, 337 text: &str,
339 line_index: &LineIndex, 338 line_index: &LineIndex,
340 highlights: Vec<HighlightedRange>, 339 highlights: Vec<HlRange>,
341) -> lsp_types::SemanticTokens { 340) -> lsp_types::SemanticTokens {
342 let id = TOKEN_RESULT_COUNTER.fetch_add(1, Ordering::SeqCst).to_string(); 341 let id = TOKEN_RESULT_COUNTER.fetch_add(1, Ordering::SeqCst).to_string();
343 let mut builder = semantic_tokens::SemanticTokensBuilder::new(id); 342 let mut builder = semantic_tokens::SemanticTokensBuilder::new(id);
@@ -377,7 +376,7 @@ fn semantic_token_type_and_modifiers(
377) -> (lsp_types::SemanticTokenType, semantic_tokens::ModifierSet) { 376) -> (lsp_types::SemanticTokenType, semantic_tokens::ModifierSet) {
378 let mut mods = semantic_tokens::ModifierSet::default(); 377 let mut mods = semantic_tokens::ModifierSet::default();
379 let type_ = match highlight.tag { 378 let type_ = match highlight.tag {
380 HighlightTag::Symbol(symbol) => match symbol { 379 HlTag::Symbol(symbol) => match symbol {
381 SymbolKind::Module => lsp_types::SemanticTokenType::NAMESPACE, 380 SymbolKind::Module => lsp_types::SemanticTokenType::NAMESPACE,
382 SymbolKind::Impl => lsp_types::SemanticTokenType::TYPE, 381 SymbolKind::Impl => lsp_types::SemanticTokenType::TYPE,
383 SymbolKind::Field => lsp_types::SemanticTokenType::PROPERTY, 382 SymbolKind::Field => lsp_types::SemanticTokenType::PROPERTY,
@@ -389,7 +388,7 @@ fn semantic_token_type_and_modifiers(
389 SymbolKind::SelfParam => semantic_tokens::SELF_KEYWORD, 388 SymbolKind::SelfParam => semantic_tokens::SELF_KEYWORD,
390 SymbolKind::Local => lsp_types::SemanticTokenType::VARIABLE, 389 SymbolKind::Local => lsp_types::SemanticTokenType::VARIABLE,
391 SymbolKind::Function => { 390 SymbolKind::Function => {
392 if highlight.modifiers.contains(HighlightModifier::Associated) { 391 if highlight.mods.contains(HlMod::Associated) {
393 lsp_types::SemanticTokenType::METHOD 392 lsp_types::SemanticTokenType::METHOD
394 } else { 393 } else {
395 lsp_types::SemanticTokenType::FUNCTION 394 lsp_types::SemanticTokenType::FUNCTION
@@ -412,38 +411,34 @@ fn semantic_token_type_and_modifiers(
412 SymbolKind::Trait => lsp_types::SemanticTokenType::INTERFACE, 411 SymbolKind::Trait => lsp_types::SemanticTokenType::INTERFACE,
413 SymbolKind::Macro => lsp_types::SemanticTokenType::MACRO, 412 SymbolKind::Macro => lsp_types::SemanticTokenType::MACRO,
414 }, 413 },
415 HighlightTag::BuiltinType => semantic_tokens::BUILTIN_TYPE, 414 HlTag::BuiltinType => semantic_tokens::BUILTIN_TYPE,
416 HighlightTag::Dummy => semantic_tokens::GENERIC, 415 HlTag::None => semantic_tokens::GENERIC,
417 HighlightTag::ByteLiteral | HighlightTag::NumericLiteral => { 416 HlTag::ByteLiteral | HlTag::NumericLiteral => lsp_types::SemanticTokenType::NUMBER,
418 lsp_types::SemanticTokenType::NUMBER 417 HlTag::BoolLiteral => semantic_tokens::BOOLEAN,
419 } 418 HlTag::CharLiteral | HlTag::StringLiteral => lsp_types::SemanticTokenType::STRING,
420 HighlightTag::BoolLiteral => semantic_tokens::BOOLEAN, 419 HlTag::Comment => lsp_types::SemanticTokenType::COMMENT,
421 HighlightTag::CharLiteral | HighlightTag::StringLiteral => { 420 HlTag::Attribute => semantic_tokens::ATTRIBUTE,
422 lsp_types::SemanticTokenType::STRING 421 HlTag::Keyword => lsp_types::SemanticTokenType::KEYWORD,
423 } 422 HlTag::UnresolvedReference => semantic_tokens::UNRESOLVED_REFERENCE,
424 HighlightTag::Comment => lsp_types::SemanticTokenType::COMMENT, 423 HlTag::FormatSpecifier => semantic_tokens::FORMAT_SPECIFIER,
425 HighlightTag::Attribute => semantic_tokens::ATTRIBUTE, 424 HlTag::Operator => lsp_types::SemanticTokenType::OPERATOR,
426 HighlightTag::Keyword => lsp_types::SemanticTokenType::KEYWORD, 425 HlTag::EscapeSequence => semantic_tokens::ESCAPE_SEQUENCE,
427 HighlightTag::UnresolvedReference => semantic_tokens::UNRESOLVED_REFERENCE, 426 HlTag::Punctuation => semantic_tokens::PUNCTUATION,
428 HighlightTag::FormatSpecifier => semantic_tokens::FORMAT_SPECIFIER,
429 HighlightTag::Operator => lsp_types::SemanticTokenType::OPERATOR,
430 HighlightTag::EscapeSequence => semantic_tokens::ESCAPE_SEQUENCE,
431 HighlightTag::Punctuation => semantic_tokens::PUNCTUATION,
432 }; 427 };
433 428
434 for modifier in highlight.modifiers.iter() { 429 for modifier in highlight.mods.iter() {
435 let modifier = match modifier { 430 let modifier = match modifier {
436 HighlightModifier::Attribute => semantic_tokens::ATTRIBUTE_MODIFIER, 431 HlMod::Attribute => semantic_tokens::ATTRIBUTE_MODIFIER,
437 HighlightModifier::Definition => lsp_types::SemanticTokenModifier::DECLARATION, 432 HlMod::Definition => lsp_types::SemanticTokenModifier::DECLARATION,
438 HighlightModifier::Documentation => lsp_types::SemanticTokenModifier::DOCUMENTATION, 433 HlMod::Documentation => lsp_types::SemanticTokenModifier::DOCUMENTATION,
439 HighlightModifier::Injected => semantic_tokens::INJECTED, 434 HlMod::Injected => semantic_tokens::INJECTED,
440 HighlightModifier::ControlFlow => semantic_tokens::CONTROL_FLOW, 435 HlMod::ControlFlow => semantic_tokens::CONTROL_FLOW,
441 HighlightModifier::Mutable => semantic_tokens::MUTABLE, 436 HlMod::Mutable => semantic_tokens::MUTABLE,
442 HighlightModifier::Consuming => semantic_tokens::CONSUMING, 437 HlMod::Consuming => semantic_tokens::CONSUMING,
443 HighlightModifier::Unsafe => semantic_tokens::UNSAFE, 438 HlMod::Unsafe => semantic_tokens::UNSAFE,
444 HighlightModifier::Callable => semantic_tokens::CALLABLE, 439 HlMod::Callable => semantic_tokens::CALLABLE,
445 HighlightModifier::Static => lsp_types::SemanticTokenModifier::STATIC, 440 HlMod::Static => lsp_types::SemanticTokenModifier::STATIC,
446 HighlightModifier::Associated => continue, 441 HlMod::Associated => continue,
447 }; 442 };
448 mods |= modifier; 443 mods |= modifier;
449 } 444 }