aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs12
1 files changed, 11 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..ab69a4374 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -1,6 +1,6 @@
1use rustc_hash::FxHashSet; 1use rustc_hash::FxHashSet;
2 2
3use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind::*, SyntaxElement, T}; 3use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind, SyntaxKind::*, SyntaxElement, T};
4use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
5 5
6use crate::{FileId, db::RootDatabase}; 6use crate::{FileId, db::RootDatabase};
@@ -11,6 +11,14 @@ pub struct HighlightedRange {
11 pub tag: &'static str, 11 pub tag: &'static str,
12} 12}
13 13
14fn is_control_keyword(kind: SyntaxKind) -> bool {
15 match kind {
16 FOR_KW | LOOP_KW | WHILE_KW | CONTINUE_KW | BREAK_KW | IF_KW | ELSE_KW | MATCH_KW
17 | RETURN_KW => true,
18 _ => false,
19 }
20}
21
14pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { 22pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> {
15 let source_file = db.parse(file_id); 23 let source_file = db.parse(file_id);
16 24
@@ -29,6 +37,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
29 NAME => "function", 37 NAME => "function",
30 INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal", 38 INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal",
31 LIFETIME => "parameter", 39 LIFETIME => "parameter",
40 UNSAFE_KW => "unsafe",
41 k if is_control_keyword(k) => "control",
32 k if k.is_keyword() => "keyword", 42 k if k.is_keyword() => "keyword",
33 _ => { 43 _ => {
34 if let Some(macro_call) = node.as_node().and_then(ast::MacroCall::cast) { 44 if let Some(macro_call) = node.as_node().and_then(ast::MacroCall::cast) {