From a1c187eef3ba08076aedb5154929f7eda8d1b424 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 12 Aug 2020 18:26:51 +0200 Subject: Rename ra_syntax -> syntax --- crates/ra_ide/src/syntax_highlighting/html.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide/src/syntax_highlighting/html.rs') diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs index a5e7d2867..418122648 100644 --- a/crates/ra_ide/src/syntax_highlighting/html.rs +++ b/crates/ra_ide/src/syntax_highlighting/html.rs @@ -2,7 +2,7 @@ use oorandom::Rand32; use ra_db::SourceDatabase; -use ra_syntax::{AstNode, TextRange, TextSize}; +use syntax::{AstNode, TextRange, TextSize}; use crate::{syntax_highlighting::highlight, FileId, RootDatabase}; -- cgit v1.2.3 From ed20a857f485a471369cd99b843af19a4d875ad0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 16:25:38 +0200 Subject: Rename ra_db -> base_db --- crates/ra_ide/src/syntax_highlighting/html.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide/src/syntax_highlighting/html.rs') diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs index 418122648..249368ff8 100644 --- a/crates/ra_ide/src/syntax_highlighting/html.rs +++ b/crates/ra_ide/src/syntax_highlighting/html.rs @@ -1,7 +1,7 @@ //! Renders a bit of code as HTML. +use base_db::SourceDatabase; use oorandom::Rand32; -use ra_db::SourceDatabase; use syntax::{AstNode, TextRange, TextSize}; use crate::{syntax_highlighting::highlight, FileId, RootDatabase}; -- cgit v1.2.3 From 1b0c7701cc97cd7bef8bb9729011d4cf291a60c5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 17:42:52 +0200 Subject: Rename ra_ide -> ide --- crates/ra_ide/src/syntax_highlighting/html.rs | 97 --------------------------- 1 file changed, 97 deletions(-) delete mode 100644 crates/ra_ide/src/syntax_highlighting/html.rs (limited to 'crates/ra_ide/src/syntax_highlighting/html.rs') diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs deleted file mode 100644 index 249368ff8..000000000 --- a/crates/ra_ide/src/syntax_highlighting/html.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! Renders a bit of code as HTML. - -use base_db::SourceDatabase; -use oorandom::Rand32; -use syntax::{AstNode, TextRange, TextSize}; - -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); - - fn rainbowify(seed: u64) -> String { - let mut rng = Rand32::new(seed); - format!( - "hsl({h},{s}%,{l}%)", - h = rng.rand_range(0..361), - s = rng.rand_range(42..99), - l = rng.rand_range(40..91), - ) - } - - let ranges = highlight(db, file_id, None, false); - let text = parse.tree().syntax().to_string(); - let mut prev_pos = TextSize::from(0); - let mut buf = String::new(); - buf.push_str(&STYLE); - buf.push_str("
");
-    for range in &ranges {
-        if range.range.start() > prev_pos {
-            let curr = &text[TextRange::new(prev_pos, range.range.start())];
-            let text = html_escape(curr);
-            buf.push_str(&text);
-        }
-        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) {
-            (true, Some(hash)) => {
-                format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash))
-            }
-            _ => "".into(),
-        };
-        buf.push_str(&format!("{}", class, color, html_escape(curr)));
-
-        prev_pos = range.range.end();
-    }
-    // Add the remaining (non-highlighted) text
-    let curr = &text[TextRange::new(prev_pos, TextSize::of(&text))];
-    let text = html_escape(curr);
-    buf.push_str(&text);
-    buf.push_str("
"); - buf -} - -//FIXME: like, real html escaping -fn html_escape(text: &str) -> String { - text.replace("<", "<").replace(">", ">") -} - -const STYLE: &str = " - -"; -- cgit v1.2.3