diff options
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/html.rs | 13 |
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 | ||
3 | use ra_db::SourceDatabase; | 3 | use ra_db::SourceDatabase; |
4 | use ra_syntax::{AstNode, TextSize}; | 4 | use ra_syntax::{AstNode, TextRange, TextSize}; |
5 | 5 | ||
6 | use crate::{FileId, RootDatabase}; | 6 | use crate::{syntax_highlighting::highlight, FileId, RootDatabase}; |
7 | |||
8 | use super::highlight; | ||
9 | 7 | ||
10 | pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: bool) -> String { | 8 | pub(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>"); |