Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions crates/ra_ide/src/snapshots/highlighting.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
<span class="keyword">pub</span> <span class="field declaration">y</span>: <span class="builtin_type">i32</span>,
}

<span class="keyword">trait</span> <span class="trait declaration">Bar</span> {
<span class="keyword">fn</span> <span class="function declaration">bar</span>(&<span class="keyword">self</span>) -&gt; <span class="builtin_type">i32</span>;
}

<span class="keyword">impl</span> <span class="trait">Bar</span> <span class="keyword">for</span> <span class="struct">Foo</span> {
<span class="keyword">fn</span> <span class="function declaration">bar</span>(&<span class="keyword">self</span>) -&gt; <span class="builtin_type">i32</span> {
<span class="keyword">self</span>.<span class="field">x</span>
}
}

<span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable">STATIC_MUT</span>: <span class="builtin_type">i32</span> = <span class="numeric_literal">0</span>;

<span class="keyword">fn</span> <span class="function declaration">foo</span>&lt;<span class="lifetime declaration">'a</span>, <span class="type_param declaration">T</span>&gt;() -&gt; <span class="type_param">T</span> {
Expand Down Expand Up @@ -63,6 +73,10 @@
<span class="static mutable">STATIC_MUT</span> = <span class="numeric_literal">1</span>;
}

<span class="keyword control">for</span> <span class="variable declaration">e</span> <span class="keyword control">in</span> <span class="variable mutable">vec</span> {
<span class="comment">// Do nothing</span>
}

<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">x</span> = <span class="numeric_literal">42</span>;
<span class="keyword">let</span> <span class="variable declaration mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>;
<span class="keyword">let</span> <span class="variable declaration">z</span> = &<span class="variable mutable">y</span>;
Expand Down
12 changes: 10 additions & 2 deletions crates/ra_ide/src/syntax_highlighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,13 @@ fn highlight_element(
T![break]
| T![continue]
| T![else]
| T![for]
| T![if]
| T![loop]
| T![match]
| T![return]
| T![while] => h | HighlightModifier::ControlFlow,
| T![while]
| T![in] => h | HighlightModifier::ControlFlow,
T![for] if !is_child_of_impl(element) => h | HighlightModifier::ControlFlow,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

T![unsafe] => h | HighlightModifier::Unsafe,
_ => h,
}
Expand All @@ -432,6 +433,13 @@ fn highlight_element(
}
}

fn is_child_of_impl(element: SyntaxElement) -> bool {
match element.parent() {
Some(e) => e.kind() == IMPL_DEF,
_ => false,
}
}

fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight {
match def {
Definition::Macro(_) => HighlightTag::Macro,
Expand Down
14 changes: 14 additions & 0 deletions crates/ra_ide/src/syntax_highlighting/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ struct Foo {
pub y: i32,
}

trait Bar {
fn bar(&self) -> i32;
}

impl Bar for Foo {
fn bar(&self) -> i32 {
self.x
}
}

static mut STATIC_MUT: i32 = 0;

fn foo<'a, T>() -> T {
Expand Down Expand Up @@ -47,6 +57,10 @@ fn main() {
STATIC_MUT = 1;
}

for e in vec {
// Do nothing
}

let mut x = 42;
let y = &mut x;
let z = &y;
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ fn semantic_token_type_and_modifiers(
HighlightTag::Trait => lsp_types::SemanticTokenType::INTERFACE,
HighlightTag::BuiltinType => semantic_tokens::BUILTIN_TYPE,
HighlightTag::SelfType => lsp_types::SemanticTokenType::TYPE,
HighlightTag::Field => lsp_types::SemanticTokenType::MEMBER,
HighlightTag::Field => lsp_types::SemanticTokenType::PROPERTY,
HighlightTag::Function => lsp_types::SemanticTokenType::FUNCTION,
HighlightTag::Module => lsp_types::SemanticTokenType::NAMESPACE,
HighlightTag::Constant => {
Expand Down
1 change: 1 addition & 0 deletions editors/code/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
!package.json
!package-lock.json
!ra_syntax_tree.tmGrammar.json
!rust.tmGrammar.json
!icon.png
!README.md
21 changes: 13 additions & 8 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@
}
],
"grammars": [
{
"language": "rust",
"scopeName": "source.rust",
"path": "rust.tmGrammar.json"
},
{
"language": "ra_syntax_tree",
"scopeName": "source.ra_syntax_tree",
Expand Down Expand Up @@ -596,28 +601,28 @@
"support.type.primitive"
],
"lifetime": [
"entity.name.lifetime.rust"
"storage.modifier.lifetime.rust"
],
"typeAlias": [
"entity.name.typeAlias"
"entity.name.type.typeAlias"
],
"union": [
"entity.name.union"
"entity.name.type.union"
],
"struct": [
"entity.name.type.struct"
],
"keyword.unsafe": [
"keyword.other.unsafe"
],
"keyword": [
"keyword"
"keyword.other"
],
"keyword.controlFlow": [
"keyword.control"
],
"variable.constant": [
"entity.name.constant"
"variable.other.constant"
],
"formatSpecifier": [
"punctuation.section.embedded"
]
}
}
Expand Down
Loading