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? --- crates/ra_lsp_server/src/main_loop/handlers.rs | 6 +++++- crates/ra_lsp_server/src/req.rs | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index a82ae696b..5dfd64ed4 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -872,7 +872,11 @@ fn highlight(world: &ServerWorld, file_id: FileId) -> Result> { .analysis() .highlight(file_id)? .into_iter() - .map(|h| Decoration { range: h.range.conv_with(&line_index), tag: h.tag }) + .map(|h| Decoration { + range: h.range.conv_with(&line_index), + tag: h.tag, + id: h.id.map(|x| x.to_string()), + }) .collect(); Ok(res) } diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index 6090eb7b9..cea0e6ce7 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs @@ -129,6 +129,7 @@ pub struct PublishDecorationsParams { pub struct Decoration { pub range: Range, pub tag: &'static str, + pub id: Option, } pub enum ParentModule {} -- cgit v1.2.3 From 5abcca516d3563416d3fba9f2e4b8b024d10f846 Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Sun, 26 May 2019 11:56:31 +0200 Subject: make it build again --- crates/ra_lsp_server/src/main_loop/handlers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 5dfd64ed4..1df8224ba 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -875,7 +875,7 @@ fn highlight(world: &ServerWorld, file_id: FileId) -> Result> { .map(|h| Decoration { range: h.range.conv_with(&line_index), tag: h.tag, - id: h.id.map(|x| x.to_string()), + id: h.binding_hash.map(|x| x.to_string()), }) .collect(); Ok(res) -- cgit v1.2.3 From 4ac338b608bb40c5126d019db63232e7834914c2 Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Sun, 26 May 2019 15:39:57 +0200 Subject: rename stray id field --- crates/ra_lsp_server/src/main_loop/handlers.rs | 2 +- crates/ra_lsp_server/src/req.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 1df8224ba..e36db12b3 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -875,7 +875,7 @@ fn highlight(world: &ServerWorld, file_id: FileId) -> Result> { .map(|h| Decoration { range: h.range.conv_with(&line_index), tag: h.tag, - id: h.binding_hash.map(|x| x.to_string()), + binding_hash: h.binding_hash.map(|x| x.to_string()), }) .collect(); Ok(res) diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index cea0e6ce7..992c24eac 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs @@ -129,7 +129,7 @@ pub struct PublishDecorationsParams { pub struct Decoration { pub range: Range, pub tag: &'static str, - pub id: Option, + pub binding_hash: Option, } pub enum ParentModule {} -- cgit v1.2.3