diff options
Diffstat (limited to 'crates/ide/src/syntax_highlighting')
-rw-r--r-- | crates/ide/src/syntax_highlighting/format.rs | 5 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/highlight.rs | 4 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/inject.rs | 2 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/tags.rs | 2 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/test_data/highlighting.html | 4 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/tests.rs | 55 |
6 files changed, 55 insertions, 17 deletions
diff --git a/crates/ide/src/syntax_highlighting/format.rs b/crates/ide/src/syntax_highlighting/format.rs index a74ca844b..8c67a0863 100644 --- a/crates/ide/src/syntax_highlighting/format.rs +++ b/crates/ide/src/syntax_highlighting/format.rs | |||
@@ -1,10 +1,11 @@ | |||
1 | //! Syntax highlighting for format macro strings. | 1 | //! Syntax highlighting for format macro strings. |
2 | use ide_db::SymbolKind; | ||
2 | use syntax::{ | 3 | use syntax::{ |
3 | ast::{self, FormatSpecifier, HasFormatSpecifier}, | 4 | ast::{self, FormatSpecifier, HasFormatSpecifier}, |
4 | AstNode, AstToken, TextRange, | 5 | AstNode, AstToken, TextRange, |
5 | }; | 6 | }; |
6 | 7 | ||
7 | use crate::{syntax_highlighting::highlights::Highlights, HlRange, HlTag, SymbolKind}; | 8 | use crate::{syntax_highlighting::highlights::Highlights, HlRange, HlTag}; |
8 | 9 | ||
9 | pub(super) fn highlight_format_string( | 10 | pub(super) fn highlight_format_string( |
10 | stack: &mut Highlights, | 11 | stack: &mut Highlights, |
@@ -30,7 +31,7 @@ fn is_format_string(string: &ast::String) -> Option<()> { | |||
30 | let parent = string.syntax().parent(); | 31 | let parent = string.syntax().parent(); |
31 | 32 | ||
32 | let name = parent.parent().and_then(ast::MacroCall::cast)?.path()?.segment()?.name_ref()?; | 33 | let name = parent.parent().and_then(ast::MacroCall::cast)?.path()?.segment()?.name_ref()?; |
33 | if !matches!(name.text().as_str(), "format_args" | "format_args_nl") { | 34 | if !matches!(name.text(), "format_args" | "format_args_nl") { |
34 | return None; | 35 | return None; |
35 | } | 36 | } |
36 | 37 | ||
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 8625ef5df..24fcbb584 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | use hir::{AsAssocItem, Semantics, VariantDef}; | 3 | use hir::{AsAssocItem, Semantics, VariantDef}; |
4 | use ide_db::{ | 4 | use ide_db::{ |
5 | defs::{Definition, NameClass, NameRefClass}, | 5 | defs::{Definition, NameClass, NameRefClass}, |
6 | RootDatabase, | 6 | RootDatabase, SymbolKind, |
7 | }; | 7 | }; |
8 | use rustc_hash::FxHashMap; | 8 | use rustc_hash::FxHashMap; |
9 | use syntax::{ | 9 | use syntax::{ |
@@ -12,7 +12,7 @@ use syntax::{ | |||
12 | SyntaxNode, SyntaxToken, T, | 12 | SyntaxNode, SyntaxToken, T, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | use crate::{syntax_highlighting::tags::HlPunct, Highlight, HlMod, HlTag, SymbolKind}; | 15 | use crate::{syntax_highlighting::tags::HlPunct, Highlight, HlMod, HlTag}; |
16 | 16 | ||
17 | pub(super) fn element( | 17 | pub(super) fn element( |
18 | sema: &Semantics<RootDatabase>, | 18 | sema: &Semantics<RootDatabase>, |
diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs index 281461493..8cdc3688f 100644 --- a/crates/ide/src/syntax_highlighting/inject.rs +++ b/crates/ide/src/syntax_highlighting/inject.rs | |||
@@ -116,7 +116,7 @@ pub(super) fn doc_comment(hl: &mut Highlights, node: &SyntaxNode) { | |||
116 | None => (), | 116 | None => (), |
117 | } | 117 | } |
118 | 118 | ||
119 | let line: &str = comment.text().as_str(); | 119 | let line: &str = comment.text(); |
120 | let range = comment.syntax().text_range(); | 120 | let range = comment.syntax().text_range(); |
121 | 121 | ||
122 | let mut pos = TextSize::of(comment.prefix()); | 122 | let mut pos = TextSize::of(comment.prefix()); |
diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index 8dd05ac52..3c02fdb11 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | 3 | ||
4 | use std::{fmt, ops}; | 4 | use std::{fmt, ops}; |
5 | 5 | ||
6 | use crate::SymbolKind; | 6 | use ide_db::SymbolKind; |
7 | 7 | ||
8 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | 8 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] |
9 | pub struct Highlight { | 9 | pub struct Highlight { |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html index 237149566..2f983c0b8 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html | |||
@@ -108,6 +108,10 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
108 | <span class="brace">}</span> | 108 | <span class="brace">}</span> |
109 | <span class="brace">}</span> | 109 | <span class="brace">}</span> |
110 | 110 | ||
111 | <span class="keyword">fn</span> <span class="function declaration">str</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span> | ||
112 | <span class="function">str</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> | ||
113 | <span class="brace">}</span> | ||
114 | |||
111 | <span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable unsafe">STATIC_MUT</span><span class="colon">:</span> <span class="builtin_type">i32</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span> | 115 | <span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable unsafe">STATIC_MUT</span><span class="colon">:</span> <span class="builtin_type">i32</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span> |
112 | 116 | ||
113 | <span class="keyword">fn</span> <span class="function declaration">foo</span><span class="angle"><</span><span class="lifetime declaration">'a</span><span class="comma">,</span> <span class="type_param declaration">T</span><span class="angle">></span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="type_param">T</span> <span class="brace">{</span> | 117 | <span class="keyword">fn</span> <span class="function declaration">foo</span><span class="angle"><</span><span class="lifetime declaration">'a</span><span class="comma">,</span> <span class="type_param declaration">T</span><span class="angle">></span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="type_param">T</span> <span class="brace">{</span> |
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index a62704c39..9d0cd1af5 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs | |||
@@ -1,9 +1,8 @@ | |||
1 | use std::fs; | ||
2 | |||
3 | use expect_test::{expect_file, ExpectFile}; | 1 | use expect_test::{expect_file, ExpectFile}; |
4 | use test_utils::project_dir; | 2 | use ide_db::SymbolKind; |
3 | use test_utils::{bench, bench_fixture, skip_slow_tests}; | ||
5 | 4 | ||
6 | use crate::{fixture, FileRange, TextRange}; | 5 | use crate::{fixture, FileRange, HlTag, TextRange}; |
7 | 6 | ||
8 | #[test] | 7 | #[test] |
9 | fn test_highlighting() { | 8 | fn test_highlighting() { |
@@ -81,6 +80,10 @@ impl FooCopy { | |||
81 | } | 80 | } |
82 | } | 81 | } |
83 | 82 | ||
83 | fn str() { | ||
84 | str(); | ||
85 | } | ||
86 | |||
84 | static mut STATIC_MUT: i32 = 0; | 87 | static mut STATIC_MUT: i32 = 0; |
85 | 88 | ||
86 | fn foo<'a, T>() -> T { | 89 | fn foo<'a, T>() -> T { |
@@ -224,15 +227,45 @@ fn bar() { | |||
224 | } | 227 | } |
225 | 228 | ||
226 | #[test] | 229 | #[test] |
227 | fn accidentally_quadratic() { | 230 | fn benchmark_syntax_highlighting_long_struct() { |
228 | let file = project_dir().join("crates/syntax/test_data/accidentally_quadratic"); | 231 | if skip_slow_tests() { |
229 | let src = fs::read_to_string(file).unwrap(); | 232 | return; |
233 | } | ||
230 | 234 | ||
231 | let (analysis, file_id) = fixture::file(&src); | 235 | let fixture = bench_fixture::big_struct(); |
236 | let (analysis, file_id) = fixture::file(&fixture); | ||
232 | 237 | ||
233 | // let t = std::time::Instant::now(); | 238 | let hash = { |
234 | let _ = analysis.highlight(file_id).unwrap(); | 239 | let _pt = bench("syntax highlighting long struct"); |
235 | // eprintln!("elapsed: {:?}", t.elapsed()); | 240 | analysis |
241 | .highlight(file_id) | ||
242 | .unwrap() | ||
243 | .iter() | ||
244 | .filter(|it| it.highlight.tag == HlTag::Symbol(SymbolKind::Struct)) | ||
245 | .count() | ||
246 | }; | ||
247 | assert_eq!(hash, 2001); | ||
248 | } | ||
249 | |||
250 | #[test] | ||
251 | fn benchmark_syntax_highlighting_parser() { | ||
252 | if skip_slow_tests() { | ||
253 | return; | ||
254 | } | ||
255 | |||
256 | let fixture = bench_fixture::glorious_old_parser(); | ||
257 | let (analysis, file_id) = fixture::file(&fixture); | ||
258 | |||
259 | let hash = { | ||
260 | let _pt = bench("syntax highlighting parser"); | ||
261 | analysis | ||
262 | .highlight(file_id) | ||
263 | .unwrap() | ||
264 | .iter() | ||
265 | .filter(|it| it.highlight.tag == HlTag::Symbol(SymbolKind::Function)) | ||
266 | .count() | ||
267 | }; | ||
268 | assert_eq!(hash, 1629); | ||
236 | } | 269 | } |
237 | 270 | ||
238 | #[test] | 271 | #[test] |