From dc2151085e9b117bc87307bf47edf3d17a170b49 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Apr 2020 00:17:50 +0200 Subject: Cleanups --- crates/ra_ide/src/syntax_highlighting/html.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'crates/ra_ide/src') 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 @@ //! Renders a bit of code as HTML. use ra_db::SourceDatabase; -use ra_syntax::{AstNode, TextSize}; +use ra_syntax::{AstNode, TextRange, TextSize}; -use crate::{FileId, RootDatabase}; - -use super::highlight; +use crate::{syntax_highlighting::highlight, FileId, RootDatabase}; pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: bool) -> String { let parse = db.parse(file_id); @@ -27,14 +25,13 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo let mut buf = String::new(); buf.push_str(&STYLE); buf.push_str("
");
-    // TODO: unusize
     for range in &ranges {
         if range.range.start() > prev_pos {
-            let curr = &text[usize::from(prev_pos)..usize::from(range.range.start())];
+            let curr = &text[TextRange::new(prev_pos, range.range.start())];
             let text = html_escape(curr);
             buf.push_str(&text);
         }
-        let curr = &text[usize::from(range.range.start())..usize::from(range.range.end())];
+        let curr = &text[TextRange::new(range.range.start(), range.range.end())];
 
         let class = range.highlight.to_string().replace('.', " ");
         let color = match (rainbow, range.binding_hash) {
@@ -48,7 +45,7 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
         prev_pos = range.range.end();
     }
     // Add the remaining (non-highlighted) text
-    let curr = &text[usize::from(prev_pos)..];
+    let curr = &text[TextRange::new(prev_pos, TextSize::of(&text))];
     let text = html_escape(curr);
     buf.push_str(&text);
     buf.push_str("
"); -- cgit v1.2.3