aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-12-18 20:05:20 +0000
committerGitHub <[email protected]>2020-12-18 20:05:20 +0000
commitc7b7c37ea5f25806d8c523e309b7ee9be27f2cde (patch)
tree7ea6a6b3c6796223f9acffa7b549a95b7661cef3 /crates
parent38b108c20e82d003938f34cfebbfd4cb964a8de8 (diff)
parentc45221907adde640208a9e52636f4845d4654994 (diff)
Merge #6937
6937: Deduplicate highlight tags and symbol kinds r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/display/navigation_target.rs6
-rw-r--r--crates/ide/src/references.rs4
-rw-r--r--crates/ide/src/syntax_highlighting.rs101
-rw-r--r--crates/ide/src/syntax_highlighting/format.rs6
-rw-r--r--crates/ide/src/syntax_highlighting/tags.rs76
-rw-r--r--crates/rust-analyzer/src/to_proto.rs59
6 files changed, 128 insertions, 124 deletions
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs
index cbdd4ecc2..7d0514105 100644
--- a/crates/ide/src/display/navigation_target.rs
+++ b/crates/ide/src/display/navigation_target.rs
@@ -18,13 +18,14 @@ use crate::FileSymbol;
18 18
19use super::short_label::ShortLabel; 19use super::short_label::ShortLabel;
20 20
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 21#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
22pub enum SymbolKind { 22pub enum SymbolKind {
23 Module, 23 Module,
24 Impl, 24 Impl,
25 Field, 25 Field,
26 TypeParam, 26 TypeParam,
27 LifetimeParam, 27 LifetimeParam,
28 ValueParam,
28 SelfParam, 29 SelfParam,
29 Local, 30 Local,
30 Function, 31 Function,
@@ -406,10 +407,11 @@ impl ToNav for hir::Local {
406 Some(it) => it.to_string().into(), 407 Some(it) => it.to_string().into(),
407 None => "".into(), 408 None => "".into(),
408 }; 409 };
410 let kind = if self.is_param(db) { SymbolKind::ValueParam } else { SymbolKind::Local };
409 NavigationTarget { 411 NavigationTarget {
410 file_id: full_range.file_id, 412 file_id: full_range.file_id,
411 name, 413 name,
412 kind: Some(SymbolKind::Local), 414 kind: Some(kind),
413 full_range: full_range.range, 415 full_range: full_range.range,
414 focus_range: None, 416 focus_range: None,
415 container_name: None, 417 container_name: None,
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index 8c00a7105..18ea19305 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -546,7 +546,7 @@ fn bar() {
546fn foo(i : u32) -> u32 { i<|> } 546fn foo(i : u32) -> u32 { i<|> }
547"#, 547"#,
548 expect![[r#" 548 expect![[r#"
549 i Local FileId(0) 7..8 Other 549 i ValueParam FileId(0) 7..8 Other
550 550
551 FileId(0) 25..26 Other Read 551 FileId(0) 25..26 Other Read
552 "#]], 552 "#]],
@@ -560,7 +560,7 @@ fn foo(i : u32) -> u32 { i<|> }
560fn foo(i<|> : u32) -> u32 { i } 560fn foo(i<|> : u32) -> u32 { i }
561"#, 561"#,
562 expect![[r#" 562 expect![[r#"
563 i Local FileId(0) 7..8 Other 563 i ValueParam FileId(0) 7..8 Other
564 564
565 FileId(0) 25..26 Other Read 565 FileId(0) 25..26 Other Read
566 "#]], 566 "#]],
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index 488969f1a..7f98aa316 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -23,7 +23,7 @@ use crate::{
23 syntax_highlighting::{ 23 syntax_highlighting::{
24 format::FormatStringHighlighter, macro_rules::MacroRulesHighlighter, tags::Highlight, 24 format::FormatStringHighlighter, macro_rules::MacroRulesHighlighter, tags::Highlight,
25 }, 25 },
26 FileId, HighlightModifier, HighlightTag, 26 FileId, HighlightModifier, HighlightTag, SymbolKind,
27}; 27};
28 28
29pub(crate) use html::highlight_as_html; 29pub(crate) use html::highlight_as_html;
@@ -103,7 +103,7 @@ pub(crate) fn highlight(
103 if let Some(range) = macro_call_range(&mc) { 103 if let Some(range) = macro_call_range(&mc) {
104 stack.add(HighlightedRange { 104 stack.add(HighlightedRange {
105 range, 105 range,
106 highlight: HighlightTag::Macro.into(), 106 highlight: HighlightTag::Symbol(SymbolKind::Macro).into(),
107 binding_hash: None, 107 binding_hash: None,
108 }); 108 });
109 } 109 }
@@ -470,13 +470,13 @@ fn highlight_element(
470 }; 470 };
471 471
472 match name_kind { 472 match name_kind {
473 Some(NameClass::ExternCrate(_)) => HighlightTag::Module.into(), 473 Some(NameClass::ExternCrate(_)) => HighlightTag::Symbol(SymbolKind::Module).into(),
474 Some(NameClass::Definition(def)) => { 474 Some(NameClass::Definition(def)) => {
475 highlight_def(db, def) | HighlightModifier::Definition 475 highlight_def(db, def) | HighlightModifier::Definition
476 } 476 }
477 Some(NameClass::ConstReference(def)) => highlight_def(db, def), 477 Some(NameClass::ConstReference(def)) => highlight_def(db, def),
478 Some(NameClass::PatFieldShorthand { field_ref, .. }) => { 478 Some(NameClass::PatFieldShorthand { field_ref, .. }) => {
479 let mut h = HighlightTag::Field.into(); 479 let mut h = HighlightTag::Symbol(SymbolKind::Field).into();
480 if let Definition::Field(field) = field_ref { 480 if let Definition::Field(field) = field_ref {
481 if let VariantDef::Union(_) = field.parent_def(db) { 481 if let VariantDef::Union(_) = field.parent_def(db) {
482 h |= HighlightModifier::Unsafe; 482 h |= HighlightModifier::Unsafe;
@@ -493,14 +493,16 @@ fn highlight_element(
493 NAME_REF if element.ancestors().any(|it| it.kind() == ATTR) => { 493 NAME_REF if element.ancestors().any(|it| it.kind() == ATTR) => {
494 // even though we track whether we are in an attribute or not we still need this special case 494 // even though we track whether we are in an attribute or not we still need this special case
495 // as otherwise we would emit unresolved references for name refs inside attributes 495 // as otherwise we would emit unresolved references for name refs inside attributes
496 Highlight::from(HighlightTag::Function) 496 Highlight::from(HighlightTag::Symbol(SymbolKind::Function))
497 } 497 }
498 NAME_REF => { 498 NAME_REF => {
499 let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap(); 499 let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap();
500 highlight_func_by_name_ref(sema, &name_ref).unwrap_or_else(|| { 500 highlight_func_by_name_ref(sema, &name_ref).unwrap_or_else(|| {
501 match NameRefClass::classify(sema, &name_ref) { 501 match NameRefClass::classify(sema, &name_ref) {
502 Some(name_kind) => match name_kind { 502 Some(name_kind) => match name_kind {
503 NameRefClass::ExternCrate(_) => HighlightTag::Module.into(), 503 NameRefClass::ExternCrate(_) => {
504 HighlightTag::Symbol(SymbolKind::Module).into()
505 }
504 NameRefClass::Definition(def) => { 506 NameRefClass::Definition(def) => {
505 if let Definition::Local(local) = &def { 507 if let Definition::Local(local) = &def {
506 if let Some(name) = local.name(db) { 508 if let Some(name) = local.name(db) {
@@ -530,7 +532,9 @@ fn highlight_element(
530 532
531 h 533 h
532 } 534 }
533 NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(), 535 NameRefClass::FieldShorthand { .. } => {
536 HighlightTag::Symbol(SymbolKind::Field).into()
537 }
534 }, 538 },
535 None if syntactic_name_ref_highlighting => { 539 None if syntactic_name_ref_highlighting => {
536 highlight_name_ref_by_syntax(name_ref, sema) 540 highlight_name_ref_by_syntax(name_ref, sema)
@@ -556,7 +560,7 @@ fn highlight_element(
556 CHAR => HighlightTag::CharLiteral.into(), 560 CHAR => HighlightTag::CharLiteral.into(),
557 QUESTION => Highlight::new(HighlightTag::Operator) | HighlightModifier::ControlFlow, 561 QUESTION => Highlight::new(HighlightTag::Operator) | HighlightModifier::ControlFlow,
558 LIFETIME => { 562 LIFETIME => {
559 let h = Highlight::new(HighlightTag::Lifetime); 563 let h = Highlight::new(HighlightTag::Symbol(SymbolKind::LifetimeParam));
560 match element.parent().map(|it| it.kind()) { 564 match element.parent().map(|it| it.kind()) {
561 Some(LIFETIME_PARAM) | Some(LABEL) => h | HighlightModifier::Definition, 565 Some(LIFETIME_PARAM) | Some(LABEL) => h | HighlightModifier::Definition,
562 _ => h, 566 _ => h,
@@ -580,7 +584,7 @@ fn highlight_element(
580 HighlightTag::Operator.into() 584 HighlightTag::Operator.into()
581 } 585 }
582 T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { 586 T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => {
583 HighlightTag::Macro.into() 587 HighlightTag::Symbol(SymbolKind::Macro).into()
584 } 588 }
585 T![!] if element.parent().and_then(ast::NeverType::cast).is_some() => { 589 T![!] if element.parent().and_then(ast::NeverType::cast).is_some() => {
586 HighlightTag::BuiltinType.into() 590 HighlightTag::BuiltinType.into()
@@ -659,7 +663,7 @@ fn highlight_element(
659 .and_then(SyntaxNode::parent) 663 .and_then(SyntaxNode::parent)
660 .and_then(ast::Path::cast) 664 .and_then(ast::Path::cast)
661 .and_then(|p| sema.resolve_path(&p)); 665 .and_then(|p| sema.resolve_path(&p));
662 let mut h = HighlightTag::SelfKeyword.into(); 666 let mut h = HighlightTag::Symbol(SymbolKind::SelfParam).into();
663 if self_param_is_mut 667 if self_param_is_mut
664 || matches!(self_path, 668 || matches!(self_path,
665 Some(hir::PathResolution::Local(local)) 669 Some(hir::PathResolution::Local(local))
@@ -756,10 +760,10 @@ fn highlight_method_call(
756 760
757fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { 761fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
758 match def { 762 match def {
759 Definition::Macro(_) => HighlightTag::Macro, 763 Definition::Macro(_) => HighlightTag::Symbol(SymbolKind::Macro),
760 Definition::Field(_) => HighlightTag::Field, 764 Definition::Field(_) => HighlightTag::Symbol(SymbolKind::Field),
761 Definition::ModuleDef(def) => match def { 765 Definition::ModuleDef(def) => match def {
762 hir::ModuleDef::Module(_) => HighlightTag::Module, 766 hir::ModuleDef::Module(_) => HighlightTag::Symbol(SymbolKind::Module),
763 hir::ModuleDef::Function(func) => { 767 hir::ModuleDef::Function(func) => {
764 let mut h = if func.as_assoc_item(db).is_some() { 768 let mut h = if func.as_assoc_item(db).is_some() {
765 if func.self_param(db).is_none() { 769 if func.self_param(db).is_none() {
@@ -768,23 +772,23 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
768 HighlightTag::Method.into() 772 HighlightTag::Method.into()
769 } 773 }
770 } else { 774 } else {
771 HighlightTag::Function.into() 775 HighlightTag::Symbol(SymbolKind::Function).into()
772 }; 776 };
773 if func.is_unsafe(db) { 777 if func.is_unsafe(db) {
774 h |= HighlightModifier::Unsafe; 778 h |= HighlightModifier::Unsafe;
775 } 779 }
776 return h; 780 return h;
777 } 781 }
778 hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct, 782 hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Symbol(SymbolKind::Struct),
779 hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Enum, 783 hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Symbol(SymbolKind::Enum),
780 hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union, 784 hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Symbol(SymbolKind::Union),
781 hir::ModuleDef::EnumVariant(_) => HighlightTag::EnumVariant, 785 hir::ModuleDef::EnumVariant(_) => HighlightTag::Symbol(SymbolKind::Variant),
782 hir::ModuleDef::Const(_) => HighlightTag::Constant, 786 hir::ModuleDef::Const(_) => HighlightTag::Symbol(SymbolKind::Const),
783 hir::ModuleDef::Trait(_) => HighlightTag::Trait, 787 hir::ModuleDef::Trait(_) => HighlightTag::Symbol(SymbolKind::Trait),
784 hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias, 788 hir::ModuleDef::TypeAlias(_) => HighlightTag::Symbol(SymbolKind::TypeAlias),
785 hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType, 789 hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType,
786 hir::ModuleDef::Static(s) => { 790 hir::ModuleDef::Static(s) => {
787 let mut h = Highlight::new(HighlightTag::Static); 791 let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::Static));
788 if s.is_mut(db) { 792 if s.is_mut(db) {
789 h |= HighlightModifier::Mutable; 793 h |= HighlightModifier::Mutable;
790 h |= HighlightModifier::Unsafe; 794 h |= HighlightModifier::Unsafe;
@@ -792,11 +796,14 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
792 return h; 796 return h;
793 } 797 }
794 }, 798 },
795 Definition::SelfType(_) => HighlightTag::SelfType, 799 Definition::SelfType(_) => HighlightTag::Symbol(SymbolKind::Impl),
796 Definition::TypeParam(_) => HighlightTag::TypeParam, 800 Definition::TypeParam(_) => HighlightTag::Symbol(SymbolKind::TypeParam),
797 Definition::Local(local) => { 801 Definition::Local(local) => {
798 let tag = 802 let tag = if local.is_param(db) {
799 if local.is_param(db) { HighlightTag::ValueParam } else { HighlightTag::Local }; 803 HighlightTag::Symbol(SymbolKind::ValueParam)
804 } else {
805 HighlightTag::Symbol(SymbolKind::Local)
806 };
800 let mut h = Highlight::new(tag); 807 let mut h = Highlight::new(tag);
801 if local.is_mut(db) || local.ty(db).is_mutable_reference() { 808 if local.is_mut(db) || local.ty(db).is_mutable_reference() {
802 h |= HighlightModifier::Mutable; 809 h |= HighlightModifier::Mutable;
@@ -806,7 +813,7 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
806 } 813 }
807 return h; 814 return h;
808 } 815 }
809 Definition::LifetimeParam(_) => HighlightTag::Lifetime, 816 Definition::LifetimeParam(_) => HighlightTag::Symbol(SymbolKind::LifetimeParam),
810 } 817 }
811 .into() 818 .into()
812} 819}
@@ -820,19 +827,19 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
820 }; 827 };
821 828
822 let tag = match parent.kind() { 829 let tag = match parent.kind() {
823 STRUCT => HighlightTag::Struct, 830 STRUCT => HighlightTag::Symbol(SymbolKind::Struct),
824 ENUM => HighlightTag::Enum, 831 ENUM => HighlightTag::Symbol(SymbolKind::Enum),
825 UNION => HighlightTag::Union, 832 VARIANT => HighlightTag::Symbol(SymbolKind::Variant),
826 TRAIT => HighlightTag::Trait, 833 UNION => HighlightTag::Symbol(SymbolKind::Union),
827 TYPE_ALIAS => HighlightTag::TypeAlias, 834 TRAIT => HighlightTag::Symbol(SymbolKind::Trait),
828 TYPE_PARAM => HighlightTag::TypeParam, 835 TYPE_ALIAS => HighlightTag::Symbol(SymbolKind::TypeAlias),
829 RECORD_FIELD => HighlightTag::Field, 836 TYPE_PARAM => HighlightTag::Symbol(SymbolKind::TypeParam),
830 MODULE => HighlightTag::Module, 837 RECORD_FIELD => HighlightTag::Symbol(SymbolKind::Field),
831 FN => HighlightTag::Function, 838 MODULE => HighlightTag::Symbol(SymbolKind::Module),
832 CONST => HighlightTag::Constant, 839 FN => HighlightTag::Symbol(SymbolKind::Function),
833 STATIC => HighlightTag::Static, 840 CONST => HighlightTag::Symbol(SymbolKind::Const),
834 VARIANT => HighlightTag::EnumVariant, 841 STATIC => HighlightTag::Symbol(SymbolKind::Static),
835 IDENT_PAT => HighlightTag::Local, 842 IDENT_PAT => HighlightTag::Symbol(SymbolKind::Local),
836 _ => default, 843 _ => default,
837 }; 844 };
838 845
@@ -851,10 +858,10 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas
851 METHOD_CALL_EXPR => { 858 METHOD_CALL_EXPR => {
852 return ast::MethodCallExpr::cast(parent) 859 return ast::MethodCallExpr::cast(parent)
853 .and_then(|method_call| highlight_method_call(sema, &method_call)) 860 .and_then(|method_call| highlight_method_call(sema, &method_call))
854 .unwrap_or_else(|| HighlightTag::Function.into()); 861 .unwrap_or_else(|| HighlightTag::Symbol(SymbolKind::Function).into());
855 } 862 }
856 FIELD_EXPR => { 863 FIELD_EXPR => {
857 let h = HighlightTag::Field; 864 let h = HighlightTag::Symbol(SymbolKind::Field);
858 let is_union = ast::FieldExpr::cast(parent) 865 let is_union = ast::FieldExpr::cast(parent)
859 .and_then(|field_expr| { 866 .and_then(|field_expr| {
860 let field = sema.resolve_field(&field_expr)?; 867 let field = sema.resolve_field(&field_expr)?;
@@ -881,9 +888,9 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas
881 _ => { 888 _ => {
882 // within path, decide whether it is module or adt by checking for uppercase name 889 // within path, decide whether it is module or adt by checking for uppercase name
883 return if name.text().chars().next().unwrap_or_default().is_uppercase() { 890 return if name.text().chars().next().unwrap_or_default().is_uppercase() {
884 HighlightTag::Struct 891 HighlightTag::Symbol(SymbolKind::Struct)
885 } else { 892 } else {
886 HighlightTag::Module 893 HighlightTag::Symbol(SymbolKind::Module)
887 } 894 }
888 .into(); 895 .into();
889 } 896 }
@@ -894,11 +901,11 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas
894 }; 901 };
895 902
896 match parent.kind() { 903 match parent.kind() {
897 CALL_EXPR => HighlightTag::Function.into(), 904 CALL_EXPR => HighlightTag::Symbol(SymbolKind::Function).into(),
898 _ => if name.text().chars().next().unwrap_or_default().is_uppercase() { 905 _ => if name.text().chars().next().unwrap_or_default().is_uppercase() {
899 HighlightTag::Struct.into() 906 HighlightTag::Symbol(SymbolKind::Struct)
900 } else { 907 } else {
901 HighlightTag::Constant 908 HighlightTag::Symbol(SymbolKind::Const)
902 } 909 }
903 .into(), 910 .into(),
904 } 911 }
diff --git a/crates/ide/src/syntax_highlighting/format.rs b/crates/ide/src/syntax_highlighting/format.rs
index 42f27df5d..26416022b 100644
--- a/crates/ide/src/syntax_highlighting/format.rs
+++ b/crates/ide/src/syntax_highlighting/format.rs
@@ -4,7 +4,9 @@ use syntax::{
4 AstNode, AstToken, SyntaxElement, SyntaxKind, SyntaxNode, TextRange, 4 AstNode, AstToken, SyntaxElement, SyntaxKind, SyntaxNode, TextRange,
5}; 5};
6 6
7use crate::{syntax_highlighting::HighlightedRangeStack, HighlightTag, HighlightedRange}; 7use crate::{
8 syntax_highlighting::HighlightedRangeStack, HighlightTag, HighlightedRange, SymbolKind,
9};
8 10
9#[derive(Default)] 11#[derive(Default)]
10pub(super) struct FormatStringHighlighter { 12pub(super) struct FormatStringHighlighter {
@@ -71,6 +73,6 @@ fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HighlightTag> {
71 | FormatSpecifier::Asterisk 73 | FormatSpecifier::Asterisk
72 | FormatSpecifier::QuestionMark => HighlightTag::FormatSpecifier, 74 | FormatSpecifier::QuestionMark => HighlightTag::FormatSpecifier,
73 FormatSpecifier::Integer | FormatSpecifier::Zero => HighlightTag::NumericLiteral, 75 FormatSpecifier::Integer | FormatSpecifier::Zero => HighlightTag::NumericLiteral,
74 FormatSpecifier::Identifier => HighlightTag::Local, 76 FormatSpecifier::Identifier => HighlightTag::Symbol(SymbolKind::Local),
75 }) 77 })
76} 78}
diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs
index ffd9588b8..e0117a6b2 100644
--- a/crates/ide/src/syntax_highlighting/tags.rs
+++ b/crates/ide/src/syntax_highlighting/tags.rs
@@ -3,6 +3,8 @@
3 3
4use std::{fmt, ops}; 4use std::{fmt, ops};
5 5
6use crate::SymbolKind;
7
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 8#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
7pub struct Highlight { 9pub struct Highlight {
8 pub tag: HighlightTag, 10 pub tag: HighlightTag,
@@ -14,40 +16,26 @@ pub struct HighlightModifiers(u32);
14 16
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 17#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub enum HighlightTag { 18pub enum HighlightTag {
17 Attribute, 19 Symbol(SymbolKind),
20
18 BoolLiteral, 21 BoolLiteral,
19 BuiltinType, 22 BuiltinType,
20 ByteLiteral, 23 ByteLiteral,
21 CharLiteral, 24 CharLiteral,
25 NumericLiteral,
26 StringLiteral,
27 Attribute,
22 Comment, 28 Comment,
23 Constant,
24 Enum,
25 EnumVariant,
26 EscapeSequence, 29 EscapeSequence,
27 Field, 30 FormatSpecifier,
28 Function,
29 Generic,
30 Keyword, 31 Keyword,
31 Lifetime,
32 Macro,
33 Method,
34 Module,
35 NumericLiteral,
36 Punctuation, 32 Punctuation,
37 SelfKeyword,
38 SelfType,
39 Static,
40 StringLiteral,
41 Struct,
42 Trait,
43 TypeAlias,
44 TypeParam,
45 Union,
46 ValueParam,
47 Local,
48 UnresolvedReference,
49 FormatSpecifier,
50 Operator, 33 Operator,
34 UnresolvedReference,
35
36 // FIXME: this two are random and don't fit with the others
37 Method,
38 Generic,
51} 39}
52 40
53#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 41#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
@@ -73,39 +61,41 @@ pub enum HighlightModifier {
73impl HighlightTag { 61impl HighlightTag {
74 fn as_str(self) -> &'static str { 62 fn as_str(self) -> &'static str {
75 match self { 63 match self {
64 HighlightTag::Symbol(symbol) => match symbol {
65 SymbolKind::Const => "constant",
66 SymbolKind::Static => "static",
67 SymbolKind::Enum => "enum",
68 SymbolKind::Variant => "enum_variant",
69 SymbolKind::Struct => "struct",
70 SymbolKind::Union => "union",
71 SymbolKind::Field => "field",
72 SymbolKind::Module => "module",
73 SymbolKind::Trait => "trait",
74 SymbolKind::Function => "function",
75 SymbolKind::TypeAlias => "type_alias",
76 SymbolKind::TypeParam => "type_param",
77 SymbolKind::LifetimeParam => "lifetime",
78 SymbolKind::Macro => "macro",
79 SymbolKind::Local => "variable",
80 SymbolKind::ValueParam => "value_param",
81 SymbolKind::SelfParam => "self_keyword",
82 SymbolKind::Impl => "self_type",
83 },
76 HighlightTag::Attribute => "attribute", 84 HighlightTag::Attribute => "attribute",
77 HighlightTag::BoolLiteral => "bool_literal", 85 HighlightTag::BoolLiteral => "bool_literal",
78 HighlightTag::BuiltinType => "builtin_type", 86 HighlightTag::BuiltinType => "builtin_type",
79 HighlightTag::ByteLiteral => "byte_literal", 87 HighlightTag::ByteLiteral => "byte_literal",
80 HighlightTag::CharLiteral => "char_literal", 88 HighlightTag::CharLiteral => "char_literal",
81 HighlightTag::Comment => "comment", 89 HighlightTag::Comment => "comment",
82 HighlightTag::Constant => "constant",
83 HighlightTag::Enum => "enum",
84 HighlightTag::EnumVariant => "enum_variant",
85 HighlightTag::EscapeSequence => "escape_sequence", 90 HighlightTag::EscapeSequence => "escape_sequence",
86 HighlightTag::Field => "field",
87 HighlightTag::FormatSpecifier => "format_specifier", 91 HighlightTag::FormatSpecifier => "format_specifier",
88 HighlightTag::Function => "function",
89 HighlightTag::Generic => "generic", 92 HighlightTag::Generic => "generic",
90 HighlightTag::Keyword => "keyword", 93 HighlightTag::Keyword => "keyword",
91 HighlightTag::Lifetime => "lifetime",
92 HighlightTag::Punctuation => "punctuation", 94 HighlightTag::Punctuation => "punctuation",
93 HighlightTag::Macro => "macro",
94 HighlightTag::Method => "method", 95 HighlightTag::Method => "method",
95 HighlightTag::Module => "module",
96 HighlightTag::NumericLiteral => "numeric_literal", 96 HighlightTag::NumericLiteral => "numeric_literal",
97 HighlightTag::Operator => "operator", 97 HighlightTag::Operator => "operator",
98 HighlightTag::SelfKeyword => "self_keyword",
99 HighlightTag::SelfType => "self_type",
100 HighlightTag::Static => "static",
101 HighlightTag::StringLiteral => "string_literal", 98 HighlightTag::StringLiteral => "string_literal",
102 HighlightTag::Struct => "struct",
103 HighlightTag::Trait => "trait",
104 HighlightTag::TypeAlias => "type_alias",
105 HighlightTag::TypeParam => "type_param",
106 HighlightTag::Union => "union",
107 HighlightTag::ValueParam => "value_param",
108 HighlightTag::Local => "variable",
109 HighlightTag::UnresolvedReference => "unresolved_reference", 99 HighlightTag::UnresolvedReference => "unresolved_reference",
110 } 100 }
111 } 101 }
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 6b2302803..229df47dc 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -43,9 +43,10 @@ pub(crate) fn symbol_kind(symbol_kind: SymbolKind) -> lsp_types::SymbolKind {
43 SymbolKind::Static => lsp_types::SymbolKind::Constant, 43 SymbolKind::Static => lsp_types::SymbolKind::Constant,
44 SymbolKind::Const => lsp_types::SymbolKind::Constant, 44 SymbolKind::Const => lsp_types::SymbolKind::Constant,
45 SymbolKind::Impl => lsp_types::SymbolKind::Object, 45 SymbolKind::Impl => lsp_types::SymbolKind::Object,
46 SymbolKind::Local | SymbolKind::SelfParam | SymbolKind::LifetimeParam => { 46 SymbolKind::Local
47 lsp_types::SymbolKind::Variable 47 | SymbolKind::SelfParam
48 } 48 | SymbolKind::LifetimeParam
49 | SymbolKind::ValueParam => lsp_types::SymbolKind::Variable,
49 SymbolKind::Union => lsp_types::SymbolKind::Struct, 50 SymbolKind::Union => lsp_types::SymbolKind::Struct,
50 } 51 }
51} 52}
@@ -371,34 +372,36 @@ fn semantic_token_type_and_modifiers(
371) -> (lsp_types::SemanticTokenType, semantic_tokens::ModifierSet) { 372) -> (lsp_types::SemanticTokenType, semantic_tokens::ModifierSet) {
372 let mut mods = semantic_tokens::ModifierSet::default(); 373 let mut mods = semantic_tokens::ModifierSet::default();
373 let type_ = match highlight.tag { 374 let type_ = match highlight.tag {
374 HighlightTag::Struct => lsp_types::SemanticTokenType::STRUCT, 375 HighlightTag::Symbol(symbol) => match symbol {
375 HighlightTag::Enum => lsp_types::SemanticTokenType::ENUM, 376 SymbolKind::Module => lsp_types::SemanticTokenType::NAMESPACE,
376 HighlightTag::Union => semantic_tokens::UNION, 377 SymbolKind::Impl => lsp_types::SemanticTokenType::TYPE,
377 HighlightTag::TypeAlias => semantic_tokens::TYPE_ALIAS, 378 SymbolKind::Field => lsp_types::SemanticTokenType::PROPERTY,
378 HighlightTag::Trait => lsp_types::SemanticTokenType::INTERFACE, 379 SymbolKind::TypeParam => lsp_types::SemanticTokenType::TYPE_PARAMETER,
380 SymbolKind::LifetimeParam => semantic_tokens::LIFETIME,
381 SymbolKind::ValueParam => lsp_types::SemanticTokenType::PARAMETER,
382 SymbolKind::SelfParam => semantic_tokens::SELF_KEYWORD,
383 SymbolKind::Local => lsp_types::SemanticTokenType::VARIABLE,
384 SymbolKind::Function => lsp_types::SemanticTokenType::FUNCTION,
385 SymbolKind::Const => {
386 mods |= semantic_tokens::CONSTANT;
387 mods |= lsp_types::SemanticTokenModifier::STATIC;
388 lsp_types::SemanticTokenType::VARIABLE
389 }
390 SymbolKind::Static => {
391 mods |= lsp_types::SemanticTokenModifier::STATIC;
392 lsp_types::SemanticTokenType::VARIABLE
393 }
394 SymbolKind::Struct => lsp_types::SemanticTokenType::STRUCT,
395 SymbolKind::Enum => lsp_types::SemanticTokenType::ENUM,
396 SymbolKind::Variant => lsp_types::SemanticTokenType::ENUM_MEMBER,
397 SymbolKind::Union => semantic_tokens::UNION,
398 SymbolKind::TypeAlias => semantic_tokens::TYPE_ALIAS,
399 SymbolKind::Trait => lsp_types::SemanticTokenType::INTERFACE,
400 SymbolKind::Macro => lsp_types::SemanticTokenType::MACRO,
401 },
379 HighlightTag::BuiltinType => semantic_tokens::BUILTIN_TYPE, 402 HighlightTag::BuiltinType => semantic_tokens::BUILTIN_TYPE,
380 HighlightTag::SelfKeyword => semantic_tokens::SELF_KEYWORD,
381 HighlightTag::SelfType => lsp_types::SemanticTokenType::TYPE,
382 HighlightTag::Field => lsp_types::SemanticTokenType::PROPERTY,
383 HighlightTag::Function => lsp_types::SemanticTokenType::FUNCTION,
384 HighlightTag::Generic => semantic_tokens::GENERIC, 403 HighlightTag::Generic => semantic_tokens::GENERIC,
385 HighlightTag::Module => lsp_types::SemanticTokenType::NAMESPACE,
386 HighlightTag::Method => lsp_types::SemanticTokenType::METHOD, 404 HighlightTag::Method => lsp_types::SemanticTokenType::METHOD,
387 HighlightTag::Constant => {
388 mods |= semantic_tokens::CONSTANT;
389 mods |= lsp_types::SemanticTokenModifier::STATIC;
390 lsp_types::SemanticTokenType::VARIABLE
391 }
392 HighlightTag::Static => {
393 mods |= lsp_types::SemanticTokenModifier::STATIC;
394 lsp_types::SemanticTokenType::VARIABLE
395 }
396 HighlightTag::EnumVariant => lsp_types::SemanticTokenType::ENUM_MEMBER,
397 HighlightTag::Macro => lsp_types::SemanticTokenType::MACRO,
398 HighlightTag::ValueParam => lsp_types::SemanticTokenType::PARAMETER,
399 HighlightTag::Local => lsp_types::SemanticTokenType::VARIABLE,
400 HighlightTag::TypeParam => lsp_types::SemanticTokenType::TYPE_PARAMETER,
401 HighlightTag::Lifetime => semantic_tokens::LIFETIME,
402 HighlightTag::ByteLiteral | HighlightTag::NumericLiteral => { 405 HighlightTag::ByteLiteral | HighlightTag::NumericLiteral => {
403 lsp_types::SemanticTokenType::NUMBER 406 lsp_types::SemanticTokenType::NUMBER
404 } 407 }