diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-15 09:00:11 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-15 09:00:11 +0000 |
commit | 3e8f9eb6c45b6bde294c79deea0e5bb02c084ae0 (patch) | |
tree | 91e2b4c2738c89f22209bdb5925f0ba50f02349c /crates/ra_ide/src/syntax_highlighting.rs | |
parent | d6223253b628b279f9ddae8f83f7173d01f6b32c (diff) | |
parent | feb5a4a8b8b0a30d71cf34c7927bd41cbae4e104 (diff) |
Merge #2559
2559: Add some granularity to syntax highlighting. r=matklad a=omerbenamram
Hi,
I wanted to start using `rust-analyzer` a bit more frequently - one of the main blockers for me so far was the highlighting.
I just discovered it's possible to override the default colors with `ralsp.<something>` setting without waiting for #2061!
However, the current implementation was lumping a bunch of different tokens into `type` and `literal`.
The golden standard IMO is what Clion is currently doing (and is my current daily driver for rust).
Clion allows users to control the coloring for specific literal kinds, and the default is to distinguish between them (numerics get a different color from strings, and special colors for bytestrings).
I've also splitted the builtin types, which are also allowed to be highlighted speratly.
My goal is to match the default experience I'm getting with clion.
The only blockers now I think is that `rust-analyzer` doesn't corrently infer types in some situations, so the highlighting information is incorrect in those cases.
This is what it looks like so far (with colors overriden to match clion's theme):
![image](https://user-images.githubusercontent.com/2467993/70848219-ccd97900-1e76-11ea-89e1-2e467cfcc9fb.png)
If there are any other changes you feel is necessary let me know.
I did leave the default colors to match the current behavior, since I'm not familiar with the colors for this theme, I added some random (different) colors in the test to check that it indeed was working.
Co-authored-by: Omer Ben-Amram <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting.rs')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 7ecb1a027..235e09ffc 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -108,14 +108,17 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa | |||
108 | match name_kind { | 108 | match name_kind { |
109 | Some(name_kind) => highlight_name(db, name_kind), | 109 | Some(name_kind) => highlight_name(db, name_kind), |
110 | None => name.syntax().parent().map_or("function", |x| match x.kind() { | 110 | None => name.syntax().parent().map_or("function", |x| match x.kind() { |
111 | TYPE_PARAM | STRUCT_DEF | ENUM_DEF | TRAIT_DEF | TYPE_ALIAS_DEF => "type", | 111 | STRUCT_DEF | ENUM_DEF | TRAIT_DEF | TYPE_ALIAS_DEF => "type", |
112 | TYPE_PARAM => "type.param", | ||
112 | RECORD_FIELD_DEF => "field", | 113 | RECORD_FIELD_DEF => "field", |
113 | _ => "function", | 114 | _ => "function", |
114 | }), | 115 | }), |
115 | } | 116 | } |
116 | } | 117 | } |
117 | INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal", | 118 | INT_NUMBER | FLOAT_NUMBER => "literal.numeric", |
118 | LIFETIME => "parameter", | 119 | BYTE => "literal.byte", |
120 | CHAR => "literal.char", | ||
121 | LIFETIME => "type.lifetime", | ||
119 | T![unsafe] => "keyword.unsafe", | 122 | T![unsafe] => "keyword.unsafe", |
120 | k if is_control_keyword(k) => "keyword.control", | 123 | k if is_control_keyword(k) => "keyword.control", |
121 | k if k.is_keyword() => "keyword", | 124 | k if k.is_keyword() => "keyword", |
@@ -224,8 +227,9 @@ fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str { | |||
224 | Def(hir::ModuleDef::Static(_)) => "constant", | 227 | Def(hir::ModuleDef::Static(_)) => "constant", |
225 | Def(hir::ModuleDef::Trait(_)) => "type", | 228 | Def(hir::ModuleDef::Trait(_)) => "type", |
226 | Def(hir::ModuleDef::TypeAlias(_)) => "type", | 229 | Def(hir::ModuleDef::TypeAlias(_)) => "type", |
227 | Def(hir::ModuleDef::BuiltinType(_)) => "type", | 230 | Def(hir::ModuleDef::BuiltinType(_)) => "type.builtin", |
228 | SelfType(_) | TypeParam(_) => "type", | 231 | SelfType(_) => "type.self", |
232 | TypeParam(_) => "type.param", | ||
229 | Local(local) => { | 233 | Local(local) => { |
230 | if local.is_mut(db) { | 234 | if local.is_mut(db) { |
231 | "variable.mut" | 235 | "variable.mut" |
@@ -255,8 +259,10 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
255 | .builtin { color: #DD6718; } | 259 | .builtin { color: #DD6718; } |
256 | .text { color: #DCDCCC; } | 260 | .text { color: #DCDCCC; } |
257 | .type { color: #7CB8BB; } | 261 | .type { color: #7CB8BB; } |
262 | .type\\.param { color: #20999D; } | ||
258 | .attribute { color: #94BFF3; } | 263 | .attribute { color: #94BFF3; } |
259 | .literal { color: #BFEBBF; } | 264 | .literal { color: #BFEBBF; } |
265 | .literal\\.numeric { color: #6A8759; } | ||
260 | .macro { color: #94BFF3; } | 266 | .macro { color: #94BFF3; } |
261 | .variable { color: #DCDCCC; } | 267 | .variable { color: #DCDCCC; } |
262 | .variable\\.mut { color: #DCDCCC; text-decoration: underline; } | 268 | .variable\\.mut { color: #DCDCCC; text-decoration: underline; } |