aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/syntax_highlighting/html.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting/html.rs')
-rw-r--r--crates/ra_ide/src/syntax_highlighting/html.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs
index 4496529a1..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, TextUnit}; 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);
@@ -23,17 +21,17 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
23 21
24 let ranges = highlight(db, file_id, None); 22 let ranges = highlight(db, file_id, None);
25 let text = parse.tree().syntax().to_string(); 23 let text = parse.tree().syntax().to_string();
26 let mut prev_pos = TextUnit::from(0); 24 let mut prev_pos = TextSize::from(0);
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 for range in &ranges { 28 for range in &ranges {
31 if range.range.start() > prev_pos { 29 if range.range.start() > prev_pos {
32 let curr = &text[prev_pos.to_usize()..range.range.start().to_usize()]; 30 let curr = &text[TextRange::new(prev_pos, range.range.start())];
33 let text = html_escape(curr); 31 let text = html_escape(curr);
34 buf.push_str(&text); 32 buf.push_str(&text);
35 } 33 }
36 let curr = &text[range.range.start().to_usize()..range.range.end().to_usize()]; 34 let curr = &text[TextRange::new(range.range.start(), range.range.end())];
37 35
38 let class = range.highlight.to_string().replace('.', " "); 36 let class = range.highlight.to_string().replace('.', " ");
39 let color = match (rainbow, range.binding_hash) { 37 let color = match (rainbow, range.binding_hash) {
@@ -47,7 +45,7 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
47 prev_pos = range.range.end(); 45 prev_pos = range.range.end();
48 } 46 }
49 // Add the remaining (non-highlighted) text 47 // Add the remaining (non-highlighted) text
50 let curr = &text[prev_pos.to_usize()..]; 48 let curr = &text[TextRange::new(prev_pos, TextSize::of(&text))];
51 let text = html_escape(curr); 49 let text = html_escape(curr);
52 buf.push_str(&text); 50 buf.push_str(&text);
53 buf.push_str("</code></pre>"); 51 buf.push_str("</code></pre>");