diff --git a/crates/ra_ide_api/src/snapshots/highlighting.html b/crates/ra_ide_api/src/snapshots/highlighting.html index 2a32b32413..d79d35bf31 100644 --- a/crates/ra_ide_api/src/snapshots/highlighting.html +++ b/crates/ra_ide_api/src/snapshots/highlighting.html @@ -19,13 +19,13 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4e
#[derive(Clone, Debug)]
struct Foo {
- pub x: i32,
- pub y: i32,
+ pub x: i32,
+ pub y: i32,
}
-fn foo<T>() -> T {
+fn foo<T>() -> T {
unimplemented!();
- foo::<i32>();
+ foo::<i32>();
}
// comment
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index bf4e9c9d14..4b24754a80 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -30,6 +30,14 @@ fn is_control_keyword(kind: SyntaxKind) -> bool {
}
}
+fn is_prim_type(node: &ast::NameRef) -> bool {
+ match node.text().as_str() {
+ "u8" | "i8" | "u16" | "i16" | "u32" | "i32" | "u64" | "i64" | "u128" | "i128" | "usize"
+ | "isize" | "f32" | "f64" | "bool" | "char" | "str" => true,
+ _ => false,
+ }
+}
+
pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec {
let _p = profile("highlight");
let source_file = db.parse(file_id).tree;
@@ -62,46 +70,52 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec "attribute",
NAME_REF => {
if let Some(name_ref) = node.as_node().and_then(ast::NameRef::cast) {
- use crate::name_ref_kind::{classify_name_ref, NameRefKind::*};
- use hir::{ModuleDef, ImplItem};
+ // FIXME: revisit this after #1340
+ if is_prim_type(name_ref) {
+ "type"
+ } else {
+ use crate::name_ref_kind::{classify_name_ref, NameRefKind::*};
+ use hir::{ModuleDef, ImplItem};
- // FIXME: try to reuse the SourceAnalyzers
- let analyzer = hir::SourceAnalyzer::new(db, file_id, name_ref.syntax(), None);
- match classify_name_ref(db, &analyzer, name_ref) {
- Some(Method(_)) => "function",
- Some(Macro(_)) => "macro",
- Some(FieldAccess(_)) => "field",
- Some(AssocItem(ImplItem::Method(_))) => "function",
- Some(AssocItem(ImplItem::Const(_))) => "constant",
- Some(AssocItem(ImplItem::TypeAlias(_))) => "type",
- Some(Def(ModuleDef::Module(_))) => "module",
- Some(Def(ModuleDef::Function(_))) => "function",
- Some(Def(ModuleDef::Struct(_))) => "type",
- Some(Def(ModuleDef::Union(_))) => "type",
- Some(Def(ModuleDef::Enum(_))) => "type",
- Some(Def(ModuleDef::EnumVariant(_))) => "constant",
- Some(Def(ModuleDef::Const(_))) => "constant",
- Some(Def(ModuleDef::Static(_))) => "constant",
- Some(Def(ModuleDef::Trait(_))) => "type",
- Some(Def(ModuleDef::TypeAlias(_))) => "type",
- Some(SelfType(_)) => "type",
- Some(Pat(ptr)) => {
- binding_hash = Some({
- let text = ptr
- .syntax_node_ptr()
- .to_node(&source_file.syntax())
- .text()
- .to_smol_string();
- let shadow_count =
- bindings_shadow_count.entry(text.clone()).or_default();
- calc_binding_hash(file_id, &text, *shadow_count)
- });
+ // FIXME: try to reuse the SourceAnalyzers
+ let analyzer =
+ hir::SourceAnalyzer::new(db, file_id, name_ref.syntax(), None);
+ match classify_name_ref(db, &analyzer, name_ref) {
+ Some(Method(_)) => "function",
+ Some(Macro(_)) => "macro",
+ Some(FieldAccess(_)) => "field",
+ Some(AssocItem(ImplItem::Method(_))) => "function",
+ Some(AssocItem(ImplItem::Const(_))) => "constant",
+ Some(AssocItem(ImplItem::TypeAlias(_))) => "type",
+ Some(Def(ModuleDef::Module(_))) => "module",
+ Some(Def(ModuleDef::Function(_))) => "function",
+ Some(Def(ModuleDef::Struct(_))) => "type",
+ Some(Def(ModuleDef::Union(_))) => "type",
+ Some(Def(ModuleDef::Enum(_))) => "type",
+ Some(Def(ModuleDef::EnumVariant(_))) => "constant",
+ Some(Def(ModuleDef::Const(_))) => "constant",
+ Some(Def(ModuleDef::Static(_))) => "constant",
+ Some(Def(ModuleDef::Trait(_))) => "type",
+ Some(Def(ModuleDef::TypeAlias(_))) => "type",
+ Some(SelfType(_)) => "type",
+ Some(Pat(ptr)) => {
+ binding_hash = Some({
+ let text = ptr
+ .syntax_node_ptr()
+ .to_node(&source_file.syntax())
+ .text()
+ .to_smol_string();
+ let shadow_count =
+ bindings_shadow_count.entry(text.clone()).or_default();
+ calc_binding_hash(file_id, &text, *shadow_count)
+ });
- "variable"
+ "variable"
+ }
+ Some(SelfParam(_)) => "type",
+ Some(GenericParam(_)) => "type",
+ None => "text",
}
- Some(SelfParam(_)) => "type",
- Some(GenericParam(_)) => "type",
- None => "text",
}
} else {
"text"
@@ -138,7 +152,6 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec "type",
INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal",
LIFETIME => "parameter",
T![unsafe] => "keyword.unsafe",