aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/syntax_highlighting
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-06-18 14:23:14 +0100
committerGitHub <[email protected]>2020-06-18 14:23:14 +0100
commitf7f627d342e89585350e9c8b42764d207eb33352 (patch)
tree800d91a03a1ea7d1678c95a48f2888327f952122 /crates/ra_ide/src/syntax_highlighting
parent0262dba97ef114bd7664a4e32be21caef2d63f0a (diff)
parent66fc084a86e8f5d207d63e33173d1e203cb5ce5e (diff)
Merge #4903
4903: Add highlighting support for doc comments r=matklad a=Nashenas88 The language server protocol includes a semantic modifier for documentation. This change exports that modifier for doc comments so users can choose to highlight them differently compared to regular comments. Example: <img width="375" alt="Screen Shot 2020-06-16 at 10 34 14 AM" src="https://user-images.githubusercontent.com/1673130/84788271-f6599580-afbc-11ea-96e5-7a0215da620b.png"> CC @woody77 Co-authored-by: Paul Daniel Faria <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting')
-rw-r--r--crates/ra_ide/src/syntax_highlighting/injection.rs8
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tags.rs3
2 files changed, 9 insertions, 2 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting/injection.rs b/crates/ra_ide/src/syntax_highlighting/injection.rs
index 929a5cc5c..415f24a6d 100644
--- a/crates/ra_ide/src/syntax_highlighting/injection.rs
+++ b/crates/ra_ide/src/syntax_highlighting/injection.rs
@@ -7,7 +7,10 @@ use hir::Semantics;
7use ra_syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; 7use ra_syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize};
8use stdx::SepBy; 8use stdx::SepBy;
9 9
10use crate::{call_info::ActiveParameter, Analysis, HighlightTag, HighlightedRange, RootDatabase}; 10use crate::{
11 call_info::ActiveParameter, Analysis, HighlightModifier, HighlightTag, HighlightedRange,
12 RootDatabase,
13};
11 14
12use super::HighlightedRangeStack; 15use super::HighlightedRangeStack;
13 16
@@ -118,7 +121,7 @@ pub(super) fn extract_doc_comments(
118 range.start(), 121 range.start(),
119 range.start() + TextSize::try_from(pos).unwrap(), 122 range.start() + TextSize::try_from(pos).unwrap(),
120 ), 123 ),
121 highlight: HighlightTag::Comment.into(), 124 highlight: HighlightTag::Comment | HighlightModifier::Documentation,
122 binding_hash: None, 125 binding_hash: None,
123 }); 126 });
124 line_start += range.len() - TextSize::try_from(pos).unwrap(); 127 line_start += range.len() - TextSize::try_from(pos).unwrap();
@@ -164,6 +167,7 @@ pub(super) fn highlight_doc_comment(
164 h.range.start() + start_offset, 167 h.range.start() + start_offset,
165 h.range.end() + end_offset.unwrap_or(start_offset), 168 h.range.end() + end_offset.unwrap_or(start_offset),
166 ); 169 );
170
167 stack.add(h); 171 stack.add(h);
168 } 172 }
169 } 173 }
diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs
index 400d22fb6..93bbb4b4d 100644
--- a/crates/ra_ide/src/syntax_highlighting/tags.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tags.rs
@@ -56,6 +56,7 @@ pub enum HighlightModifier {
56 /// `foo` in `fn foo(x: i32)` is a definition, `foo` in `foo(90 + 2)` is 56 /// `foo` in `fn foo(x: i32)` is a definition, `foo` in `foo(90 + 2)` is
57 /// not. 57 /// not.
58 Definition, 58 Definition,
59 Documentation,
59 Mutable, 60 Mutable,
60 Unsafe, 61 Unsafe,
61} 62}
@@ -108,6 +109,7 @@ impl HighlightModifier {
108 HighlightModifier::Attribute, 109 HighlightModifier::Attribute,
109 HighlightModifier::ControlFlow, 110 HighlightModifier::ControlFlow,
110 HighlightModifier::Definition, 111 HighlightModifier::Definition,
112 HighlightModifier::Documentation,
111 HighlightModifier::Mutable, 113 HighlightModifier::Mutable,
112 HighlightModifier::Unsafe, 114 HighlightModifier::Unsafe,
113 ]; 115 ];
@@ -117,6 +119,7 @@ impl HighlightModifier {
117 HighlightModifier::Attribute => "attribute", 119 HighlightModifier::Attribute => "attribute",
118 HighlightModifier::ControlFlow => "control", 120 HighlightModifier::ControlFlow => "control",
119 HighlightModifier::Definition => "declaration", 121 HighlightModifier::Definition => "declaration",
122 HighlightModifier::Documentation => "documentation",
120 HighlightModifier::Mutable => "mutable", 123 HighlightModifier::Mutable => "mutable",
121 HighlightModifier::Unsafe => "unsafe", 124 HighlightModifier::Unsafe => "unsafe",
122 } 125 }