aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/syntax_highlighting
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting')
-rw-r--r--crates/ra_ide/src/syntax_highlighting/html.rs15
-rw-r--r--crates/ra_ide/src/syntax_highlighting/injection.rs2
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tags.rs4
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs32
4 files changed, 33 insertions, 20 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs
index 0c74f7370..a5e7d2867 100644
--- a/crates/ra_ide/src/syntax_highlighting/html.rs
+++ b/crates/ra_ide/src/syntax_highlighting/html.rs
@@ -1,5 +1,6 @@
1//! Renders a bit of code as HTML. 1//! Renders a bit of code as HTML.
2 2
3use oorandom::Rand32;
3use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
4use ra_syntax::{AstNode, TextRange, TextSize}; 5use ra_syntax::{AstNode, TextRange, TextSize};
5 6
@@ -9,13 +10,12 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
9 let parse = db.parse(file_id); 10 let parse = db.parse(file_id);
10 11
11 fn rainbowify(seed: u64) -> String { 12 fn rainbowify(seed: u64) -> String {
12 use rand::prelude::*; 13 let mut rng = Rand32::new(seed);
13 let mut rng = SmallRng::seed_from_u64(seed);
14 format!( 14 format!(
15 "hsl({h},{s}%,{l}%)", 15 "hsl({h},{s}%,{l}%)",
16 h = rng.gen_range::<u16, _, _>(0, 361), 16 h = rng.rand_range(0..361),
17 s = rng.gen_range::<u16, _, _>(42, 99), 17 s = rng.rand_range(42..99),
18 l = rng.gen_range::<u16, _, _>(40, 91), 18 l = rng.rand_range(40..91),
19 ) 19 )
20 } 20 }
21 21
@@ -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/injection.rs b/crates/ra_ide/src/syntax_highlighting/injection.rs
index 181c21256..8665b480f 100644
--- a/crates/ra_ide/src/syntax_highlighting/injection.rs
+++ b/crates/ra_ide/src/syntax_highlighting/injection.rs
@@ -25,7 +25,7 @@ pub(super) fn highlight_injection(
25 return None; 25 return None;
26 } 26 }
27 let value = literal.value()?; 27 let value = literal.value()?;
28 let (analysis, tmp_file_id) = Analysis::from_single_file(value); 28 let (analysis, tmp_file_id) = Analysis::from_single_file(value.into_owned());
29 29
30 if let Some(range) = literal.open_quote_text_range() { 30 if let Some(range) = literal.open_quote_text_range() {
31 acc.add(HighlightedRange { 31 acc.add(HighlightedRange {
diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs
index 13d9dd195..49ec94bdc 100644
--- a/crates/ra_ide/src/syntax_highlighting/tags.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tags.rs
@@ -32,6 +32,7 @@ pub enum HighlightTag {
32 Macro, 32 Macro,
33 Module, 33 Module,
34 NumericLiteral, 34 NumericLiteral,
35 Punctuation,
35 SelfKeyword, 36 SelfKeyword,
36 SelfType, 37 SelfType,
37 Static, 38 Static,
@@ -41,6 +42,7 @@ pub enum HighlightTag {
41 TypeAlias, 42 TypeAlias,
42 TypeParam, 43 TypeParam,
43 Union, 44 Union,
45 ValueParam,
44 Local, 46 Local,
45 UnresolvedReference, 47 UnresolvedReference,
46 FormatSpecifier, 48 FormatSpecifier,
@@ -82,6 +84,7 @@ impl HighlightTag {
82 HighlightTag::Generic => "generic", 84 HighlightTag::Generic => "generic",
83 HighlightTag::Keyword => "keyword", 85 HighlightTag::Keyword => "keyword",
84 HighlightTag::Lifetime => "lifetime", 86 HighlightTag::Lifetime => "lifetime",
87 HighlightTag::Punctuation => "punctuation",
85 HighlightTag::Macro => "macro", 88 HighlightTag::Macro => "macro",
86 HighlightTag::Module => "module", 89 HighlightTag::Module => "module",
87 HighlightTag::NumericLiteral => "numeric_literal", 90 HighlightTag::NumericLiteral => "numeric_literal",
@@ -95,6 +98,7 @@ impl HighlightTag {
95 HighlightTag::TypeAlias => "type_alias", 98 HighlightTag::TypeAlias => "type_alias",
96 HighlightTag::TypeParam => "type_param", 99 HighlightTag::TypeParam => "type_param",
97 HighlightTag::Union => "union", 100 HighlightTag::Union => "union",
101 HighlightTag::ValueParam => "value_param",
98 HighlightTag::Local => "variable", 102 HighlightTag::Local => "variable",
99 HighlightTag::UnresolvedReference => "unresolved_reference", 103 HighlightTag::UnresolvedReference => "unresolved_reference",
100 } 104 }
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index b7fad9719..87a6e2523 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -1,6 +1,7 @@
1use std::fs; 1use std::fs;
2 2
3use test_utils::{assert_eq_text, project_dir, read_text}; 3use expect::{expect_file, ExpectFile};
4use test_utils::project_dir;
4 5
5use crate::{mock_analysis::single_file, FileRange, TextRange}; 6use crate::{mock_analysis::single_file, FileRange, TextRange};
6 7
@@ -24,6 +25,16 @@ impl Bar for Foo {
24 } 25 }
25} 26}
26 27
28impl Foo {
29 fn baz(mut self) -> i32 {
30 self.x
31 }
32
33 fn qux(&mut self) {
34 self.x = 0;
35 }
36}
37
27static mut STATIC_MUT: i32 = 0; 38static mut STATIC_MUT: i32 = 0;
28 39
29fn foo<'a, T>() -> T { 40fn foo<'a, T>() -> T {
@@ -91,7 +102,7 @@ impl<T> Option<T> {
91} 102}
92"# 103"#
93 .trim(), 104 .trim(),
94 "crates/ra_ide/src/snapshots/highlighting.html", 105 expect_file!["crates/ra_ide/test_data/highlighting.html"],
95 false, 106 false,
96 ); 107 );
97} 108}
@@ -114,7 +125,7 @@ fn bar() {
114} 125}
115"# 126"#
116 .trim(), 127 .trim(),
117 "crates/ra_ide/src/snapshots/rainbow_highlighting.html", 128 expect_file!["crates/ra_ide/test_data/rainbow_highlighting.html"],
118 true, 129 true,
119 ); 130 );
120} 131}
@@ -167,7 +178,7 @@ fn main() {
167 ); 178 );
168}"## 179}"##
169 .trim(), 180 .trim(),
170 "crates/ra_ide/src/snapshots/highlight_injection.html", 181 expect_file!["crates/ra_ide/test_data/highlight_injection.html"],
171 false, 182 false,
172 ); 183 );
173} 184}
@@ -250,7 +261,7 @@ fn main() {
250 println!("{ничоси}", ничоси = 92); 261 println!("{ничоси}", ничоси = 92);
251}"# 262}"#
252 .trim(), 263 .trim(),
253 "crates/ra_ide/src/snapshots/highlight_strings.html", 264 expect_file!["crates/ra_ide/test_data/highlight_strings.html"],
254 false, 265 false,
255 ); 266 );
256} 267}
@@ -278,7 +289,7 @@ fn main() {
278} 289}
279"# 290"#
280 .trim(), 291 .trim(),
281 "crates/ra_ide/src/snapshots/highlight_unsafe.html", 292 expect_file!["crates/ra_ide/test_data/highlight_unsafe.html"],
282 false, 293 false,
283 ); 294 );
284} 295}
@@ -354,7 +365,7 @@ macro_rules! noop {
354} 365}
355"# 366"#
356 .trim(), 367 .trim(),
357 "crates/ra_ide/src/snapshots/highlight_doctest.html", 368 expect_file!["crates/ra_ide/test_data/highlight_doctest.html"],
358 false, 369 false,
359 ); 370 );
360} 371}
@@ -362,11 +373,8 @@ macro_rules! noop {
362/// Highlights the code given by the `ra_fixture` argument, renders the 373/// Highlights the code given by the `ra_fixture` argument, renders the
363/// result as HTML, and compares it with the HTML file given as `snapshot`. 374/// result as HTML, and compares it with the HTML file given as `snapshot`.
364/// Note that the `snapshot` file is overwritten by the rendered HTML. 375/// Note that the `snapshot` file is overwritten by the rendered HTML.
365fn check_highlighting(ra_fixture: &str, snapshot: &str, rainbow: bool) { 376fn check_highlighting(ra_fixture: &str, expect: ExpectFile, rainbow: bool) {
366 let (analysis, file_id) = single_file(ra_fixture); 377 let (analysis, file_id) = single_file(ra_fixture);
367 let dst_file = project_dir().join(snapshot);
368 let actual_html = &analysis.highlight_as_html(file_id, rainbow).unwrap(); 378 let actual_html = &analysis.highlight_as_html(file_id, rainbow).unwrap();
369 let expected_html = &read_text(&dst_file); 379 expect.assert_eq(actual_html)
370 fs::write(dst_file, &actual_html).unwrap();
371 assert_eq_text!(expected_html, actual_html);
372} 380}