diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide_api/src/syntax_highlighting.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index a03b13839..2158291dc 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use rustc_hash::FxHashSet; | 1 | use rustc_hash::FxHashSet; |
2 | 2 | ||
3 | use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind::*, SyntaxElement, T}; | 3 | use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind, SyntaxKind::*, SyntaxElement, T}; |
4 | use ra_db::SourceDatabase; | 4 | use ra_db::SourceDatabase; |
5 | 5 | ||
6 | use crate::{FileId, db::RootDatabase}; | 6 | use crate::{FileId, db::RootDatabase}; |
@@ -11,6 +11,21 @@ pub struct HighlightedRange { | |||
11 | pub tag: &'static str, | 11 | pub tag: &'static str, |
12 | } | 12 | } |
13 | 13 | ||
14 | fn is_control_keyword(kind: SyntaxKind) -> bool { | ||
15 | match kind { | ||
16 | T![for] | ||
17 | | T![loop] | ||
18 | | T![while] | ||
19 | | T![continue] | ||
20 | | T![break] | ||
21 | | T![if] | ||
22 | | T![else] | ||
23 | | T![match] | ||
24 | | T![return] => true, | ||
25 | _ => false, | ||
26 | } | ||
27 | } | ||
28 | |||
14 | pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { | 29 | pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { |
15 | let source_file = db.parse(file_id); | 30 | let source_file = db.parse(file_id); |
16 | 31 | ||
@@ -29,6 +44,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa | |||
29 | NAME => "function", | 44 | NAME => "function", |
30 | INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal", | 45 | INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal", |
31 | LIFETIME => "parameter", | 46 | LIFETIME => "parameter", |
47 | T![unsafe] => "keyword.unsafe", | ||
48 | k if is_control_keyword(k) => "keyword.control", | ||
32 | k if k.is_keyword() => "keyword", | 49 | k if k.is_keyword() => "keyword", |
33 | _ => { | 50 | _ => { |
34 | if let Some(macro_call) = node.as_node().and_then(ast::MacroCall::cast) { | 51 | if let Some(macro_call) = node.as_node().and_then(ast::MacroCall::cast) { |