aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-11 13:52:20 +0100
committerGitHub <[email protected]>2020-07-11 13:52:20 +0100
commit607d99fa8435523121c442c45653f0a430567c62 (patch)
tree5b39f39acd93780faa5809dda2b11cec106ad182 /crates
parent87ddcba05fe1a80e293565cd09a61c83adc6bc7d (diff)
parente1d6b7f7c48d82c3c03550bc702e64cd7d079c99 (diff)
Merge #5314
5314: Use dedicated semantic highlight tag for parameters r=matklad a=matklad closes #5106 bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model.rs15
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs5
-rw-r--r--crates/ra_ide/src/syntax_highlighting/html.rs5
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tags.rs2
-rw-r--r--crates/ra_ide/test_data/highlight_doctest.html5
-rw-r--r--crates/ra_ide/test_data/highlight_injection.html7
-rw-r--r--crates/ra_ide/test_data/highlight_strings.html5
-rw-r--r--crates/ra_ide/test_data/highlight_unsafe.html5
-rw-r--r--crates/ra_ide/test_data/highlighting.html9
-rw-r--r--crates/ra_ide/test_data/rainbow_highlighting.html5
-rw-r--r--crates/rust-analyzer/src/to_proto.rs1
11 files changed, 44 insertions, 20 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 1b3525011..04fd335fe 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -33,7 +33,10 @@ use hir_ty::{
33}; 33};
34use ra_db::{CrateId, Edition, FileId}; 34use ra_db::{CrateId, Edition, FileId};
35use ra_prof::profile; 35use ra_prof::profile;
36use ra_syntax::ast::{self, AttrsOwner, NameOwner}; 36use ra_syntax::{
37 ast::{self, AttrsOwner, NameOwner},
38 AstNode,
39};
37use rustc_hash::FxHashSet; 40use rustc_hash::FxHashSet;
38 41
39use crate::{ 42use crate::{
@@ -955,6 +958,16 @@ pub struct Local {
955} 958}
956 959
957impl Local { 960impl Local {
961 pub fn is_param(self, db: &dyn HirDatabase) -> bool {
962 let src = self.source(db);
963 match src.value {
964 Either::Left(bind_pat) => {
965 bind_pat.syntax().ancestors().any(|it| ast::Param::can_cast(it.kind()))
966 }
967 Either::Right(_self_param) => true,
968 }
969 }
970
958 // FIXME: why is this an option? It shouldn't be? 971 // FIXME: why is this an option? It shouldn't be?
959 pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { 972 pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
960 let body = db.body(self.parent.into()); 973 let body = db.body(self.parent.into());
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 028b55902..5bb6f9642 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -630,9 +630,10 @@ fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight {
630 }, 630 },
631 Definition::SelfType(_) => HighlightTag::SelfType, 631 Definition::SelfType(_) => HighlightTag::SelfType,
632 Definition::TypeParam(_) => HighlightTag::TypeParam, 632 Definition::TypeParam(_) => HighlightTag::TypeParam,
633 // FIXME: distinguish between locals and parameters
634 Definition::Local(local) => { 633 Definition::Local(local) => {
635 let mut h = Highlight::new(HighlightTag::Local); 634 let tag =
635 if local.is_param(db) { HighlightTag::ValueParam } else { HighlightTag::Local };
636 let mut h = Highlight::new(tag);
636 if local.is_mut(db) || local.ty(db).is_mutable_reference() { 637 if local.is_mut(db) || local.ty(db).is_mutable_reference() {
637 h |= HighlightModifier::Mutable; 638 h |= HighlightModifier::Mutable;
638 } 639 }
diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs
index 0c74f7370..0be55bca9 100644
--- a/crates/ra_ide/src/syntax_highlighting/html.rs
+++ b/crates/ra_ide/src/syntax_highlighting/html.rs
@@ -83,14 +83,15 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
83.bool_literal { color: #BFE6EB; } 83.bool_literal { color: #BFE6EB; }
84.macro { color: #94BFF3; } 84.macro { color: #94BFF3; }
85.module { color: #AFD8AF; } 85.module { color: #AFD8AF; }
86.value_param { color: #DCDCCC; }
86.variable { color: #DCDCCC; } 87.variable { color: #DCDCCC; }
87.format_specifier { color: #CC696B; } 88.format_specifier { color: #CC696B; }
88.mutable { text-decoration: underline; } 89.mutable { text-decoration: underline; }
89.unresolved_reference { color: #FC5555; }
90.escape_sequence { color: #94BFF3; } 90.escape_sequence { color: #94BFF3; }
91
92.keyword { color: #F0DFAF; font-weight: bold; } 91.keyword { color: #F0DFAF; font-weight: bold; }
93.keyword.unsafe { color: #BC8383; font-weight: bold; } 92.keyword.unsafe { color: #BC8383; font-weight: bold; }
94.control { font-style: italic; } 93.control { font-style: italic; }
94
95.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
95</style> 96</style>
96"; 97";
diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs
index 13d9dd195..719c6ed3c 100644
--- a/crates/ra_ide/src/syntax_highlighting/tags.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tags.rs
@@ -41,6 +41,7 @@ pub enum HighlightTag {
41 TypeAlias, 41 TypeAlias,
42 TypeParam, 42 TypeParam,
43 Union, 43 Union,
44 ValueParam,
44 Local, 45 Local,
45 UnresolvedReference, 46 UnresolvedReference,
46 FormatSpecifier, 47 FormatSpecifier,
@@ -95,6 +96,7 @@ impl HighlightTag {
95 HighlightTag::TypeAlias => "type_alias", 96 HighlightTag::TypeAlias => "type_alias",
96 HighlightTag::TypeParam => "type_param", 97 HighlightTag::TypeParam => "type_param",
97 HighlightTag::Union => "union", 98 HighlightTag::Union => "union",
99 HighlightTag::ValueParam => "value_param",
98 HighlightTag::Local => "variable", 100 HighlightTag::Local => "variable",
99 HighlightTag::UnresolvedReference => "unresolved_reference", 101 HighlightTag::UnresolvedReference => "unresolved_reference",
100 } 102 }
diff --git a/crates/ra_ide/test_data/highlight_doctest.html b/crates/ra_ide/test_data/highlight_doctest.html
index e8155def7..a77fabb68 100644
--- a/crates/ra_ide/test_data/highlight_doctest.html
+++ b/crates/ra_ide/test_data/highlight_doctest.html
@@ -24,15 +24,16 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
24.bool_literal { color: #BFE6EB; } 24.bool_literal { color: #BFE6EB; }
25.macro { color: #94BFF3; } 25.macro { color: #94BFF3; }
26.module { color: #AFD8AF; } 26.module { color: #AFD8AF; }
27.value_param { color: #DCDCCC; }
27.variable { color: #DCDCCC; } 28.variable { color: #DCDCCC; }
28.format_specifier { color: #CC696B; } 29.format_specifier { color: #CC696B; }
29.mutable { text-decoration: underline; } 30.mutable { text-decoration: underline; }
30.unresolved_reference { color: #FC5555; }
31.escape_sequence { color: #94BFF3; } 31.escape_sequence { color: #94BFF3; }
32
33.keyword { color: #F0DFAF; font-weight: bold; } 32.keyword { color: #F0DFAF; font-weight: bold; }
34.keyword.unsafe { color: #BC8383; font-weight: bold; } 33.keyword.unsafe { color: #BC8383; font-weight: bold; }
35.control { font-style: italic; } 34.control { font-style: italic; }
35
36.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
36</style> 37</style>
37<pre><code><span class="comment documentation">/// ```</span> 38<pre><code><span class="comment documentation">/// ```</span>
38<span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="generic injected"> _ = </span><span class="string_literal injected">"early doctests should not go boom"</span><span class="generic injected">;</span> 39<span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="generic injected"> _ = </span><span class="string_literal injected">"early doctests should not go boom"</span><span class="generic injected">;</span>
diff --git a/crates/ra_ide/test_data/highlight_injection.html b/crates/ra_ide/test_data/highlight_injection.html
index 1b0349bae..e15234936 100644
--- a/crates/ra_ide/test_data/highlight_injection.html
+++ b/crates/ra_ide/test_data/highlight_injection.html
@@ -24,17 +24,18 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
24.bool_literal { color: #BFE6EB; } 24.bool_literal { color: #BFE6EB; }
25.macro { color: #94BFF3; } 25.macro { color: #94BFF3; }
26.module { color: #AFD8AF; } 26.module { color: #AFD8AF; }
27.value_param { color: #DCDCCC; }
27.variable { color: #DCDCCC; } 28.variable { color: #DCDCCC; }
28.format_specifier { color: #CC696B; } 29.format_specifier { color: #CC696B; }
29.mutable { text-decoration: underline; } 30.mutable { text-decoration: underline; }
30.unresolved_reference { color: #FC5555; }
31.escape_sequence { color: #94BFF3; } 31.escape_sequence { color: #94BFF3; }
32
33.keyword { color: #F0DFAF; font-weight: bold; } 32.keyword { color: #F0DFAF; font-weight: bold; }
34.keyword.unsafe { color: #BC8383; font-weight: bold; } 33.keyword.unsafe { color: #BC8383; font-weight: bold; }
35.control { font-style: italic; } 34.control { font-style: italic; }
35
36.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
36</style> 37</style>
37<pre><code><span class="keyword">fn</span> <span class="function declaration">fixture</span>(<span class="variable declaration">ra_fixture</span>: &<span class="builtin_type">str</span>) {} 38<pre><code><span class="keyword">fn</span> <span class="function declaration">fixture</span>(<span class="value_param declaration">ra_fixture</span>: &<span class="builtin_type">str</span>) {}
38 39
39<span class="keyword">fn</span> <span class="function declaration">main</span>() { 40<span class="keyword">fn</span> <span class="function declaration">main</span>() {
40 <span class="function">fixture</span>(<span class="string_literal">r#"</span> 41 <span class="function">fixture</span>(<span class="string_literal">r#"</span>
diff --git a/crates/ra_ide/test_data/highlight_strings.html b/crates/ra_ide/test_data/highlight_strings.html
index d184b5691..423813366 100644
--- a/crates/ra_ide/test_data/highlight_strings.html
+++ b/crates/ra_ide/test_data/highlight_strings.html
@@ -24,15 +24,16 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
24.bool_literal { color: #BFE6EB; } 24.bool_literal { color: #BFE6EB; }
25.macro { color: #94BFF3; } 25.macro { color: #94BFF3; }
26.module { color: #AFD8AF; } 26.module { color: #AFD8AF; }
27.value_param { color: #DCDCCC; }
27.variable { color: #DCDCCC; } 28.variable { color: #DCDCCC; }
28.format_specifier { color: #CC696B; } 29.format_specifier { color: #CC696B; }
29.mutable { text-decoration: underline; } 30.mutable { text-decoration: underline; }
30.unresolved_reference { color: #FC5555; }
31.escape_sequence { color: #94BFF3; } 31.escape_sequence { color: #94BFF3; }
32
33.keyword { color: #F0DFAF; font-weight: bold; } 32.keyword { color: #F0DFAF; font-weight: bold; }
34.keyword.unsafe { color: #BC8383; font-weight: bold; } 33.keyword.unsafe { color: #BC8383; font-weight: bold; }
35.control { font-style: italic; } 34.control { font-style: italic; }
35
36.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
36</style> 37</style>
37<pre><code><span class="macro">macro_rules!</span> <span class="macro declaration">println</span> { 38<pre><code><span class="macro">macro_rules!</span> <span class="macro declaration">println</span> {
38 ($($arg:tt)*) =&gt; ({ 39 ($($arg:tt)*) =&gt; ({
diff --git a/crates/ra_ide/test_data/highlight_unsafe.html b/crates/ra_ide/test_data/highlight_unsafe.html
index 6936e949f..7585fbb42 100644
--- a/crates/ra_ide/test_data/highlight_unsafe.html
+++ b/crates/ra_ide/test_data/highlight_unsafe.html
@@ -24,15 +24,16 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
24.bool_literal { color: #BFE6EB; } 24.bool_literal { color: #BFE6EB; }
25.macro { color: #94BFF3; } 25.macro { color: #94BFF3; }
26.module { color: #AFD8AF; } 26.module { color: #AFD8AF; }
27.value_param { color: #DCDCCC; }
27.variable { color: #DCDCCC; } 28.variable { color: #DCDCCC; }
28.format_specifier { color: #CC696B; } 29.format_specifier { color: #CC696B; }
29.mutable { text-decoration: underline; } 30.mutable { text-decoration: underline; }
30.unresolved_reference { color: #FC5555; }
31.escape_sequence { color: #94BFF3; } 31.escape_sequence { color: #94BFF3; }
32
33.keyword { color: #F0DFAF; font-weight: bold; } 32.keyword { color: #F0DFAF; font-weight: bold; }
34.keyword.unsafe { color: #BC8383; font-weight: bold; } 33.keyword.unsafe { color: #BC8383; font-weight: bold; }
35.control { font-style: italic; } 34.control { font-style: italic; }
35
36.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
36</style> 37</style>
37<pre><code><span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function declaration unsafe">unsafe_fn</span>() {} 38<pre><code><span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function declaration unsafe">unsafe_fn</span>() {}
38 39
diff --git a/crates/ra_ide/test_data/highlighting.html b/crates/ra_ide/test_data/highlighting.html
index 8d0b38f95..134743c72 100644
--- a/crates/ra_ide/test_data/highlighting.html
+++ b/crates/ra_ide/test_data/highlighting.html
@@ -24,15 +24,16 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
24.bool_literal { color: #BFE6EB; } 24.bool_literal { color: #BFE6EB; }
25.macro { color: #94BFF3; } 25.macro { color: #94BFF3; }
26.module { color: #AFD8AF; } 26.module { color: #AFD8AF; }
27.value_param { color: #DCDCCC; }
27.variable { color: #DCDCCC; } 28.variable { color: #DCDCCC; }
28.format_specifier { color: #CC696B; } 29.format_specifier { color: #CC696B; }
29.mutable { text-decoration: underline; } 30.mutable { text-decoration: underline; }
30.unresolved_reference { color: #FC5555; }
31.escape_sequence { color: #94BFF3; } 31.escape_sequence { color: #94BFF3; }
32
33.keyword { color: #F0DFAF; font-weight: bold; } 32.keyword { color: #F0DFAF; font-weight: bold; }
34.keyword.unsafe { color: #BC8383; font-weight: bold; } 33.keyword.unsafe { color: #BC8383; font-weight: bold; }
35.control { font-style: italic; } 34.control { font-style: italic; }
35
36.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
36</style> 37</style>
37<pre><code><span class="attribute">#[</span><span class="function attribute">derive</span><span class="attribute">(Clone, Debug)]</span> 38<pre><code><span class="attribute">#[</span><span class="function attribute">derive</span><span class="attribute">(Clone, Debug)]</span>
38<span class="keyword">struct</span> <span class="struct declaration">Foo</span> { 39<span class="keyword">struct</span> <span class="struct declaration">Foo</span> {
@@ -108,8 +109,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
108<span class="keyword">use</span> <span class="enum">Option</span>::*; 109<span class="keyword">use</span> <span class="enum">Option</span>::*;
109 110
110<span class="keyword">impl</span>&lt;<span class="type_param declaration">T</span>&gt; <span class="enum">Option</span>&lt;<span class="type_param">T</span>&gt; { 111<span class="keyword">impl</span>&lt;<span class="type_param declaration">T</span>&gt; <span class="enum">Option</span>&lt;<span class="type_param">T</span>&gt; {
111 <span class="keyword">fn</span> <span class="function declaration">and</span>&lt;<span class="type_param declaration">U</span>&gt;(<span class="self_keyword">self</span>, <span class="variable declaration">other</span>: <span class="enum">Option</span>&lt;<span class="type_param">U</span>&gt;) -&gt; <span class="enum">Option</span>&lt;(<span class="type_param">T</span>, <span class="type_param">U</span>)&gt; { 112 <span class="keyword">fn</span> <span class="function declaration">and</span>&lt;<span class="type_param declaration">U</span>&gt;(<span class="self_keyword">self</span>, <span class="value_param declaration">other</span>: <span class="enum">Option</span>&lt;<span class="type_param">U</span>&gt;) -&gt; <span class="enum">Option</span>&lt;(<span class="type_param">T</span>, <span class="type_param">U</span>)&gt; {
112 <span class="keyword control">match</span> <span class="variable">other</span> { 113 <span class="keyword control">match</span> <span class="value_param">other</span> {
113 <span class="enum_variant">None</span> =&gt; <span class="macro">unimplemented!</span>(), 114 <span class="enum_variant">None</span> =&gt; <span class="macro">unimplemented!</span>(),
114 <span class="variable declaration">Nope</span> =&gt; <span class="variable">Nope</span>, 115 <span class="variable declaration">Nope</span> =&gt; <span class="variable">Nope</span>,
115 } 116 }
diff --git a/crates/ra_ide/test_data/rainbow_highlighting.html b/crates/ra_ide/test_data/rainbow_highlighting.html
index 9516c7441..84a7686b2 100644
--- a/crates/ra_ide/test_data/rainbow_highlighting.html
+++ b/crates/ra_ide/test_data/rainbow_highlighting.html
@@ -24,15 +24,16 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
24.bool_literal { color: #BFE6EB; } 24.bool_literal { color: #BFE6EB; }
25.macro { color: #94BFF3; } 25.macro { color: #94BFF3; }
26.module { color: #AFD8AF; } 26.module { color: #AFD8AF; }
27.value_param { color: #DCDCCC; }
27.variable { color: #DCDCCC; } 28.variable { color: #DCDCCC; }
28.format_specifier { color: #CC696B; } 29.format_specifier { color: #CC696B; }
29.mutable { text-decoration: underline; } 30.mutable { text-decoration: underline; }
30.unresolved_reference { color: #FC5555; }
31.escape_sequence { color: #94BFF3; } 31.escape_sequence { color: #94BFF3; }
32
33.keyword { color: #F0DFAF; font-weight: bold; } 32.keyword { color: #F0DFAF; font-weight: bold; }
34.keyword.unsafe { color: #BC8383; font-weight: bold; } 33.keyword.unsafe { color: #BC8383; font-weight: bold; }
35.control { font-style: italic; } 34.control { font-style: italic; }
35
36.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
36</style> 37</style>
37<pre><code><span class="keyword">fn</span> <span class="function declaration">main</span>() { 38<pre><code><span class="keyword">fn</span> <span class="function declaration">main</span>() {
38 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>; 39 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>;
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index f6dff1684..f6d2f4fc4 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -309,6 +309,7 @@ fn semantic_token_type_and_modifiers(
309 } 309 }
310 HighlightTag::EnumVariant => semantic_tokens::ENUM_MEMBER, 310 HighlightTag::EnumVariant => semantic_tokens::ENUM_MEMBER,
311 HighlightTag::Macro => lsp_types::SemanticTokenType::MACRO, 311 HighlightTag::Macro => lsp_types::SemanticTokenType::MACRO,
312 HighlightTag::ValueParam => lsp_types::SemanticTokenType::PARAMETER,
312 HighlightTag::Local => lsp_types::SemanticTokenType::VARIABLE, 313 HighlightTag::Local => lsp_types::SemanticTokenType::VARIABLE,
313 HighlightTag::TypeParam => lsp_types::SemanticTokenType::TYPE_PARAMETER, 314 HighlightTag::TypeParam => lsp_types::SemanticTokenType::TYPE_PARAMETER,
314 HighlightTag::Lifetime => semantic_tokens::LIFETIME, 315 HighlightTag::Lifetime => semantic_tokens::LIFETIME,