From 5bf3e949e8470a138a61c806769e1a329761cab6 Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Thu, 23 May 2019 19:42:42 +0200 Subject: Semantic highlighting spike Very simple approach: For each identifier, set the hash of the range where it's defined as its 'id' and use it in the VSCode extension to generate unique colors. Thus, the generated colors are per-file. They are also quite fragile, and I'm not entirely sure why. Looks like we need to make sure the same ranges aren't overwritten by a later request? --- .../src/snapshots/tests__highlighting.snap | 192 +++++++++++++++++++++ .../src/snapshots/tests__sematic_highlighting.snap | 87 ++++++++++ 2 files changed, 279 insertions(+) create mode 100644 crates/ra_ide_api/src/snapshots/tests__highlighting.snap create mode 100644 crates/ra_ide_api/src/snapshots/tests__sematic_highlighting.snap (limited to 'crates/ra_ide_api/src/snapshots') diff --git a/crates/ra_ide_api/src/snapshots/tests__highlighting.snap b/crates/ra_ide_api/src/snapshots/tests__highlighting.snap new file mode 100644 index 000000000..208681f10 --- /dev/null +++ b/crates/ra_ide_api/src/snapshots/tests__highlighting.snap @@ -0,0 +1,192 @@ +--- +created: "2019-05-25T10:53:54.439877Z" +creator: insta@0.8.1 +source: crates/ra_ide_api/src/syntax_highlighting.rs +expression: result +--- +Ok( + [ + HighlightedRange { + range: [1; 24), + tag: "attribute", + id: None, + }, + HighlightedRange { + range: [25; 31), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [32; 35), + tag: "variable", + id: Some( + 461893210254723387, + ), + }, + HighlightedRange { + range: [42; 45), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [46; 47), + tag: "variable", + id: Some( + 8312289520117458465, + ), + }, + HighlightedRange { + range: [49; 52), + tag: "text", + id: None, + }, + HighlightedRange { + range: [58; 61), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [62; 63), + tag: "variable", + id: Some( + 4497542318236667727, + ), + }, + HighlightedRange { + range: [65; 68), + tag: "text", + id: None, + }, + HighlightedRange { + range: [73; 75), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [76; 79), + tag: "variable", + id: Some( + 4506850079084802999, + ), + }, + HighlightedRange { + range: [80; 81), + tag: "type", + id: None, + }, + HighlightedRange { + range: [80; 81), + tag: "variable", + id: Some( + 16968185728268100018, + ), + }, + HighlightedRange { + range: [88; 89), + tag: "type", + id: None, + }, + HighlightedRange { + range: [96; 110), + tag: "macro", + id: None, + }, + HighlightedRange { + range: [117; 127), + tag: "comment", + id: None, + }, + HighlightedRange { + range: [128; 130), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [131; 135), + tag: "variable", + id: Some( + 14467718814232352107, + ), + }, + HighlightedRange { + range: [145; 153), + tag: "macro", + id: None, + }, + HighlightedRange { + range: [154; 166), + tag: "string", + id: None, + }, + HighlightedRange { + range: [168; 170), + tag: "literal", + id: None, + }, + HighlightedRange { + range: [178; 181), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [182; 185), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [186; 189), + tag: "macro", + id: None, + }, + HighlightedRange { + range: [197; 200), + tag: "macro", + id: None, + }, + HighlightedRange { + range: [192; 195), + tag: "text", + id: None, + }, + HighlightedRange { + range: [208; 211), + tag: "macro", + id: None, + }, + HighlightedRange { + range: [212; 216), + tag: "macro", + id: None, + }, + HighlightedRange { + range: [226; 227), + tag: "literal", + id: None, + }, + HighlightedRange { + range: [232; 233), + tag: "literal", + id: None, + }, + HighlightedRange { + range: [242; 248), + tag: "keyword.unsafe", + id: None, + }, + HighlightedRange { + range: [251; 254), + tag: "text", + id: None, + }, + HighlightedRange { + range: [255; 262), + tag: "text", + id: None, + }, + HighlightedRange { + range: [263; 264), + tag: "literal", + id: None, + }, + ], +) diff --git a/crates/ra_ide_api/src/snapshots/tests__sematic_highlighting.snap b/crates/ra_ide_api/src/snapshots/tests__sematic_highlighting.snap new file mode 100644 index 000000000..3b3fe32e9 --- /dev/null +++ b/crates/ra_ide_api/src/snapshots/tests__sematic_highlighting.snap @@ -0,0 +1,87 @@ +--- +created: "2019-05-25T10:25:13.898113Z" +creator: insta@0.8.1 +source: crates/ra_ide_api/src/syntax_highlighting.rs +expression: result +--- +Ok( + [ + HighlightedRange { + range: [1; 3), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [4; 8), + tag: "variable", + id: Some( + 17119830160611610240, + ), + }, + HighlightedRange { + range: [17; 20), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [21; 26), + tag: "variable", + id: Some( + 2744494144922727377, + ), + }, + HighlightedRange { + range: [29; 36), + tag: "string", + id: None, + }, + HighlightedRange { + range: [42; 45), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [46; 47), + tag: "variable", + id: Some( + 10375904121795371996, + ), + }, + HighlightedRange { + range: [50; 55), + tag: "variable", + id: Some( + 2744494144922727377, + ), + }, + HighlightedRange { + range: [56; 65), + tag: "text", + id: None, + }, + HighlightedRange { + range: [73; 76), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [77; 78), + tag: "variable", + id: Some( + 8228548264153724449, + ), + }, + HighlightedRange { + range: [81; 86), + tag: "variable", + id: Some( + 2744494144922727377, + ), + }, + HighlightedRange { + range: [87; 96), + tag: "text", + id: None, + }, + ], +) -- cgit v1.2.3 From ed89b0638b1dbf8f9a33d9a95e829e602142bb05 Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Sat, 25 May 2019 12:56:52 +0200 Subject: Hash based on binding name and shadow counter --- .../src/snapshots/tests__highlighting.snap | 14 +-- .../src/snapshots/tests__rainbow_highlighting.snap | 128 +++++++++++++++++++++ .../src/snapshots/tests__sematic_highlighting.snap | 87 -------------- 3 files changed, 135 insertions(+), 94 deletions(-) create mode 100644 crates/ra_ide_api/src/snapshots/tests__rainbow_highlighting.snap delete mode 100644 crates/ra_ide_api/src/snapshots/tests__sematic_highlighting.snap (limited to 'crates/ra_ide_api/src/snapshots') diff --git a/crates/ra_ide_api/src/snapshots/tests__highlighting.snap b/crates/ra_ide_api/src/snapshots/tests__highlighting.snap index 208681f10..e50003b3c 100644 --- a/crates/ra_ide_api/src/snapshots/tests__highlighting.snap +++ b/crates/ra_ide_api/src/snapshots/tests__highlighting.snap @@ -1,5 +1,5 @@ --- -created: "2019-05-25T10:53:54.439877Z" +created: "2019-05-25T11:24:53.486036Z" creator: insta@0.8.1 source: crates/ra_ide_api/src/syntax_highlighting.rs expression: result @@ -20,7 +20,7 @@ Ok( range: [32; 35), tag: "variable", id: Some( - 461893210254723387, + 8465336196764640996, ), }, HighlightedRange { @@ -32,7 +32,7 @@ Ok( range: [46; 47), tag: "variable", id: Some( - 8312289520117458465, + 176272420896316891, ), }, HighlightedRange { @@ -49,7 +49,7 @@ Ok( range: [62; 63), tag: "variable", id: Some( - 4497542318236667727, + 15061637676198917049, ), }, HighlightedRange { @@ -66,7 +66,7 @@ Ok( range: [76; 79), tag: "variable", id: Some( - 4506850079084802999, + 14077410872302487760, ), }, HighlightedRange { @@ -78,7 +78,7 @@ Ok( range: [80; 81), tag: "variable", id: Some( - 16968185728268100018, + 8379786015941272633, ), }, HighlightedRange { @@ -105,7 +105,7 @@ Ok( range: [131; 135), tag: "variable", id: Some( - 14467718814232352107, + 5766414492220109266, ), }, HighlightedRange { diff --git a/crates/ra_ide_api/src/snapshots/tests__rainbow_highlighting.snap b/crates/ra_ide_api/src/snapshots/tests__rainbow_highlighting.snap new file mode 100644 index 000000000..84cd521a2 --- /dev/null +++ b/crates/ra_ide_api/src/snapshots/tests__rainbow_highlighting.snap @@ -0,0 +1,128 @@ +--- +created: "2019-05-25T11:21:56.117898Z" +creator: insta@0.8.1 +source: crates/ra_ide_api/src/syntax_highlighting.rs +expression: result +--- +Ok( + [ + HighlightedRange { + range: [1; 3), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [4; 8), + tag: "variable", + id: Some( + 5766414492220109266, + ), + }, + HighlightedRange { + range: [17; 20), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [21; 26), + tag: "variable", + id: Some( + 15975256018338854530, + ), + }, + HighlightedRange { + range: [29; 36), + tag: "string", + id: None, + }, + HighlightedRange { + range: [42; 45), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [46; 47), + tag: "variable", + id: Some( + 176272420896316891, + ), + }, + HighlightedRange { + range: [50; 55), + tag: "variable", + id: Some( + 15975256018338854530, + ), + }, + HighlightedRange { + range: [56; 65), + tag: "text", + id: None, + }, + HighlightedRange { + range: [73; 76), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [77; 78), + tag: "variable", + id: Some( + 15061637676198917049, + ), + }, + HighlightedRange { + range: [81; 86), + tag: "variable", + id: Some( + 15975256018338854530, + ), + }, + HighlightedRange { + range: [87; 96), + tag: "text", + id: None, + }, + HighlightedRange { + range: [105; 108), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [109; 110), + tag: "variable", + id: Some( + 1714508680417729339, + ), + }, + HighlightedRange { + range: [113; 134), + tag: "string", + id: None, + }, + HighlightedRange { + range: [140; 143), + tag: "keyword", + id: None, + }, + HighlightedRange { + range: [144; 145), + tag: "variable", + id: Some( + 15953336624848413466, + ), + }, + HighlightedRange { + range: [148; 149), + tag: "variable", + id: Some( + 1714508680417729339, + ), + }, + HighlightedRange { + range: [150; 159), + tag: "text", + id: None, + }, + ], +) diff --git a/crates/ra_ide_api/src/snapshots/tests__sematic_highlighting.snap b/crates/ra_ide_api/src/snapshots/tests__sematic_highlighting.snap deleted file mode 100644 index 3b3fe32e9..000000000 --- a/crates/ra_ide_api/src/snapshots/tests__sematic_highlighting.snap +++ /dev/null @@ -1,87 +0,0 @@ ---- -created: "2019-05-25T10:25:13.898113Z" -creator: insta@0.8.1 -source: crates/ra_ide_api/src/syntax_highlighting.rs -expression: result ---- -Ok( - [ - HighlightedRange { - range: [1; 3), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [4; 8), - tag: "variable", - id: Some( - 17119830160611610240, - ), - }, - HighlightedRange { - range: [17; 20), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [21; 26), - tag: "variable", - id: Some( - 2744494144922727377, - ), - }, - HighlightedRange { - range: [29; 36), - tag: "string", - id: None, - }, - HighlightedRange { - range: [42; 45), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [46; 47), - tag: "variable", - id: Some( - 10375904121795371996, - ), - }, - HighlightedRange { - range: [50; 55), - tag: "variable", - id: Some( - 2744494144922727377, - ), - }, - HighlightedRange { - range: [56; 65), - tag: "text", - id: None, - }, - HighlightedRange { - range: [73; 76), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [77; 78), - tag: "variable", - id: Some( - 8228548264153724449, - ), - }, - HighlightedRange { - range: [81; 86), - tag: "variable", - id: Some( - 2744494144922727377, - ), - }, - HighlightedRange { - range: [87; 96), - tag: "text", - id: None, - }, - ], -) -- cgit v1.2.3 From 43d5a4965308ec4b594725c0bd02cb046bdb730c Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Sat, 25 May 2019 16:23:58 +0200 Subject: More clever highlighting, incl draft for structs --- crates/ra_ide_api/src/snapshots/highlighting.html | 24 +-- .../src/snapshots/rainbow_highlighting.html | 27 +++ .../src/snapshots/tests__highlighting.snap | 192 --------------------- .../src/snapshots/tests__rainbow_highlighting.snap | 128 -------------- 4 files changed, 36 insertions(+), 335 deletions(-) create mode 100644 crates/ra_ide_api/src/snapshots/rainbow_highlighting.html delete mode 100644 crates/ra_ide_api/src/snapshots/tests__highlighting.snap delete mode 100644 crates/ra_ide_api/src/snapshots/tests__rainbow_highlighting.snap (limited to 'crates/ra_ide_api/src/snapshots') diff --git a/crates/ra_ide_api/src/snapshots/highlighting.html b/crates/ra_ide_api/src/snapshots/highlighting.html index bfc0a67b1..4f4ed62a1 100644 --- a/crates/ra_ide_api/src/snapshots/highlighting.html +++ b/crates/ra_ide_api/src/snapshots/highlighting.html @@ -1,10 +1,7 @@ -

-#[derive(Clone, Debug)]
+
#[derive(Clone, Debug)]
 struct Foo {
-    pub x: i32,
-    pub y: i32,
+    pub x: i32,
+    pub y: i32,
 }
 
 fn foo<T>() -> T {
@@ -36,10 +31,9 @@ pre {
 fn main() {
     println!("Hello, {}!", 92);
 
-    let mut vec = Vec::new();
+    let mut vec = Vec::new();
     if true {
-        vec.push(Foo { x: 0, y: 1 });
+        vec.push(Foo { x: 0, y: 1 });
     }
-    unsafe { vec.set_len(0); }
-}
-
\ No newline at end of file + unsafe { vec.set_len(0); } +}
\ No newline at end of file diff --git a/crates/ra_ide_api/src/snapshots/rainbow_highlighting.html b/crates/ra_ide_api/src/snapshots/rainbow_highlighting.html new file mode 100644 index 000000000..729d129d0 --- /dev/null +++ b/crates/ra_ide_api/src/snapshots/rainbow_highlighting.html @@ -0,0 +1,27 @@ + + +
fn main() {
+    let hello = "hello";
+    let x = hello.to_string();
+    let y = hello.to_string();
+
+    let x = "other color please!";
+    let y = x.to_string();
+}
\ No newline at end of file diff --git a/crates/ra_ide_api/src/snapshots/tests__highlighting.snap b/crates/ra_ide_api/src/snapshots/tests__highlighting.snap deleted file mode 100644 index e50003b3c..000000000 --- a/crates/ra_ide_api/src/snapshots/tests__highlighting.snap +++ /dev/null @@ -1,192 +0,0 @@ ---- -created: "2019-05-25T11:24:53.486036Z" -creator: insta@0.8.1 -source: crates/ra_ide_api/src/syntax_highlighting.rs -expression: result ---- -Ok( - [ - HighlightedRange { - range: [1; 24), - tag: "attribute", - id: None, - }, - HighlightedRange { - range: [25; 31), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [32; 35), - tag: "variable", - id: Some( - 8465336196764640996, - ), - }, - HighlightedRange { - range: [42; 45), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [46; 47), - tag: "variable", - id: Some( - 176272420896316891, - ), - }, - HighlightedRange { - range: [49; 52), - tag: "text", - id: None, - }, - HighlightedRange { - range: [58; 61), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [62; 63), - tag: "variable", - id: Some( - 15061637676198917049, - ), - }, - HighlightedRange { - range: [65; 68), - tag: "text", - id: None, - }, - HighlightedRange { - range: [73; 75), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [76; 79), - tag: "variable", - id: Some( - 14077410872302487760, - ), - }, - HighlightedRange { - range: [80; 81), - tag: "type", - id: None, - }, - HighlightedRange { - range: [80; 81), - tag: "variable", - id: Some( - 8379786015941272633, - ), - }, - HighlightedRange { - range: [88; 89), - tag: "type", - id: None, - }, - HighlightedRange { - range: [96; 110), - tag: "macro", - id: None, - }, - HighlightedRange { - range: [117; 127), - tag: "comment", - id: None, - }, - HighlightedRange { - range: [128; 130), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [131; 135), - tag: "variable", - id: Some( - 5766414492220109266, - ), - }, - HighlightedRange { - range: [145; 153), - tag: "macro", - id: None, - }, - HighlightedRange { - range: [154; 166), - tag: "string", - id: None, - }, - HighlightedRange { - range: [168; 170), - tag: "literal", - id: None, - }, - HighlightedRange { - range: [178; 181), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [182; 185), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [186; 189), - tag: "macro", - id: None, - }, - HighlightedRange { - range: [197; 200), - tag: "macro", - id: None, - }, - HighlightedRange { - range: [192; 195), - tag: "text", - id: None, - }, - HighlightedRange { - range: [208; 211), - tag: "macro", - id: None, - }, - HighlightedRange { - range: [212; 216), - tag: "macro", - id: None, - }, - HighlightedRange { - range: [226; 227), - tag: "literal", - id: None, - }, - HighlightedRange { - range: [232; 233), - tag: "literal", - id: None, - }, - HighlightedRange { - range: [242; 248), - tag: "keyword.unsafe", - id: None, - }, - HighlightedRange { - range: [251; 254), - tag: "text", - id: None, - }, - HighlightedRange { - range: [255; 262), - tag: "text", - id: None, - }, - HighlightedRange { - range: [263; 264), - tag: "literal", - id: None, - }, - ], -) diff --git a/crates/ra_ide_api/src/snapshots/tests__rainbow_highlighting.snap b/crates/ra_ide_api/src/snapshots/tests__rainbow_highlighting.snap deleted file mode 100644 index 84cd521a2..000000000 --- a/crates/ra_ide_api/src/snapshots/tests__rainbow_highlighting.snap +++ /dev/null @@ -1,128 +0,0 @@ ---- -created: "2019-05-25T11:21:56.117898Z" -creator: insta@0.8.1 -source: crates/ra_ide_api/src/syntax_highlighting.rs -expression: result ---- -Ok( - [ - HighlightedRange { - range: [1; 3), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [4; 8), - tag: "variable", - id: Some( - 5766414492220109266, - ), - }, - HighlightedRange { - range: [17; 20), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [21; 26), - tag: "variable", - id: Some( - 15975256018338854530, - ), - }, - HighlightedRange { - range: [29; 36), - tag: "string", - id: None, - }, - HighlightedRange { - range: [42; 45), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [46; 47), - tag: "variable", - id: Some( - 176272420896316891, - ), - }, - HighlightedRange { - range: [50; 55), - tag: "variable", - id: Some( - 15975256018338854530, - ), - }, - HighlightedRange { - range: [56; 65), - tag: "text", - id: None, - }, - HighlightedRange { - range: [73; 76), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [77; 78), - tag: "variable", - id: Some( - 15061637676198917049, - ), - }, - HighlightedRange { - range: [81; 86), - tag: "variable", - id: Some( - 15975256018338854530, - ), - }, - HighlightedRange { - range: [87; 96), - tag: "text", - id: None, - }, - HighlightedRange { - range: [105; 108), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [109; 110), - tag: "variable", - id: Some( - 1714508680417729339, - ), - }, - HighlightedRange { - range: [113; 134), - tag: "string", - id: None, - }, - HighlightedRange { - range: [140; 143), - tag: "keyword", - id: None, - }, - HighlightedRange { - range: [144; 145), - tag: "variable", - id: Some( - 15953336624848413466, - ), - }, - HighlightedRange { - range: [148; 149), - tag: "variable", - id: Some( - 1714508680417729339, - ), - }, - HighlightedRange { - range: [150; 159), - tag: "text", - id: None, - }, - ], -) -- cgit v1.2.3 From 2b200f6e1a600e263f314efba5d8c3743095071b Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Sat, 25 May 2019 16:29:39 +0200 Subject: Disable broken struct field rainbowing --- crates/ra_ide_api/src/snapshots/highlighting.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide_api/src/snapshots') diff --git a/crates/ra_ide_api/src/snapshots/highlighting.html b/crates/ra_ide_api/src/snapshots/highlighting.html index 4f4ed62a1..ebd187a35 100644 --- a/crates/ra_ide_api/src/snapshots/highlighting.html +++ b/crates/ra_ide_api/src/snapshots/highlighting.html @@ -19,8 +19,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4e
#[derive(Clone, Debug)]
 struct Foo {
-    pub x: i32,
-    pub y: i32,
+    pub x: i32,
+    pub y: i32,
 }
 
 fn foo<T>() -> T {
@@ -33,7 +33,7 @@ pre        { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4e
 
     let mut vec = Vec::new();
     if true {
-        vec.push(Foo { x: 0, y: 1 });
+        vec.push(Foo { x: 0, y: 1 });
     }
     unsafe { vec.set_len(0); }
 }
\ No newline at end of file -- cgit v1.2.3