aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-24 23:17:50 +0100
committerAleksey Kladov <[email protected]>2020-04-25 10:59:18 +0100
commitdc2151085e9b117bc87307bf47edf3d17a170b49 (patch)
tree24a22cdd8e5fb3b11d7b95fc264e56a91bd206a9 /crates/ra_ide
parent8843588fca7a6022b86800d5d2539594c0de93cf (diff)
Cleanups
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/syntax_highlighting/html.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs
index 4f17d1040..010db4017 100644
--- a/crates/ra_ide/src/syntax_highlighting/html.rs
+++ b/crates/ra_ide/src/syntax_highlighting/html.rs
@@ -1,11 +1,9 @@
1//! Renders a bit of code as HTML. 1//! Renders a bit of code as HTML.
2 2
3use ra_db::SourceDatabase; 3use ra_db::SourceDatabase;
4use ra_syntax::{AstNode, TextSize}; 4use ra_syntax::{AstNode, TextRange, TextSize};
5 5
6use crate::{FileId, RootDatabase}; 6use crate::{syntax_highlighting::highlight, FileId, RootDatabase};
7
8use super::highlight;
9 7
10pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: bool) -> String { 8pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: bool) -> String {
11 let parse = db.parse(file_id); 9 let parse = db.parse(file_id);
@@ -27,14 +25,13 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
27 let mut buf = String::new(); 25 let mut buf = String::new();
28 buf.push_str(&STYLE); 26 buf.push_str(&STYLE);
29 buf.push_str("<pre><code>"); 27 buf.push_str("<pre><code>");
30 // TODO: unusize
31 for range in &ranges { 28 for range in &ranges {
32 if range.range.start() > prev_pos { 29 if range.range.start() > prev_pos {
33 let curr = &text[usize::from(prev_pos)..usize::from(range.range.start())]; 30 let curr = &text[TextRange::new(prev_pos, range.range.start())];
34 let text = html_escape(curr); 31 let text = html_escape(curr);
35 buf.push_str(&text); 32 buf.push_str(&text);
36 } 33 }
37 let curr = &text[usize::from(range.range.start())..usize::from(range.range.end())]; 34 let curr = &text[TextRange::new(range.range.start(), range.range.end())];
38 35
39 let class = range.highlight.to_string().replace('.', " "); 36 let class = range.highlight.to_string().replace('.', " ");
40 let color = match (rainbow, range.binding_hash) { 37 let color = match (rainbow, range.binding_hash) {
@@ -48,7 +45,7 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
48 prev_pos = range.range.end(); 45 prev_pos = range.range.end();
49 } 46 }
50 // Add the remaining (non-highlighted) text 47 // Add the remaining (non-highlighted) text
51 let curr = &text[usize::from(prev_pos)..]; 48 let curr = &text[TextRange::new(prev_pos, TextSize::of(&text))];
52 let text = html_escape(curr); 49 let text = html_escape(curr);
53 buf.push_str(&text); 50 buf.push_str(&text);
54 buf.push_str("</code></pre>"); 51 buf.push_str("</code></pre>");