aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/global_state.rs7
-rw-r--r--crates/rust-analyzer/src/handlers.rs7
-rw-r--r--crates/rust-analyzer/src/main_loop.rs2
-rw-r--r--crates/rust-analyzer/src/to_proto.rs14
4 files changed, 12 insertions, 18 deletions
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index 4b34c3ec5..0e592ac1b 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -3,15 +3,12 @@
3//! 3//!
4//! Each tick provides an immutable snapshot of the state as `WorldSnapshot`. 4//! Each tick provides an immutable snapshot of the state as `WorldSnapshot`.
5 5
6use std::{ 6use std::{sync::Arc, time::Instant};
7 sync::{Arc, Mutex},
8 time::Instant,
9};
10 7
11use crossbeam_channel::{unbounded, Receiver, Sender}; 8use crossbeam_channel::{unbounded, Receiver, Sender};
12use flycheck::FlycheckHandle; 9use flycheck::FlycheckHandle;
13use lsp_types::{SemanticTokens, Url}; 10use lsp_types::{SemanticTokens, Url};
14use parking_lot::RwLock; 11use parking_lot::{Mutex, RwLock};
15use ra_db::{CrateId, VfsPath}; 12use ra_db::{CrateId, VfsPath};
16use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FileId}; 13use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FileId};
17use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target}; 14use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target};
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 0b0ea23fd..52dc72aad 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -1187,10 +1187,7 @@ pub(crate) fn handle_semantic_tokens(
1187 let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights); 1187 let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
1188 1188
1189 // Unconditionally cache the tokens 1189 // Unconditionally cache the tokens
1190 snap.semantic_tokens_cache 1190 snap.semantic_tokens_cache.lock().insert(params.text_document.uri, semantic_tokens.clone());
1191 .lock()
1192 .unwrap()
1193 .insert(params.text_document.uri, semantic_tokens.clone());
1194 1191
1195 Ok(Some(semantic_tokens.into())) 1192 Ok(Some(semantic_tokens.into()))
1196} 1193}
@@ -1209,7 +1206,7 @@ pub(crate) fn handle_semantic_tokens_edits(
1209 1206
1210 let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights); 1207 let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
1211 1208
1212 let mut cache = snap.semantic_tokens_cache.lock().unwrap(); 1209 let mut cache = snap.semantic_tokens_cache.lock();
1213 let cached_tokens = cache.entry(params.text_document.uri).or_default(); 1210 let cached_tokens = cache.entry(params.text_document.uri).or_default();
1214 1211
1215 if let Some(prev_id) = &cached_tokens.result_id { 1212 if let Some(prev_id) = &cached_tokens.result_id {
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index eb2a86972..075abf45c 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -452,7 +452,7 @@ impl GlobalState {
452 None => log::error!("orphan DidCloseTextDocument: {}", path), 452 None => log::error!("orphan DidCloseTextDocument: {}", path),
453 } 453 }
454 454
455 this.semantic_tokens_cache.lock().unwrap().remove(&params.text_document.uri); 455 this.semantic_tokens_cache.lock().remove(&params.text_document.uri);
456 456
457 if let Some(path) = path.as_path() { 457 if let Some(path) = path.as_path() {
458 this.loader.handle.invalidate(path.to_path_buf()); 458 this.loader.handle.invalidate(path.to_path_buf());
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 8da883ae4..5eba1f155 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -1,6 +1,8 @@
1//! Conversion of rust-analyzer specific types to lsp_types equivalents. 1//! Conversion of rust-analyzer specific types to lsp_types equivalents.
2use std::path::{self, Path}; 2use std::{
3use std::time::SystemTime; 3 path::{self, Path},
4 sync::atomic::{AtomicU32, Ordering},
5};
4 6
5use itertools::Itertools; 7use itertools::Itertools;
6use ra_db::{FileId, FileRange}; 8use ra_db::{FileId, FileRange};
@@ -304,16 +306,14 @@ pub(crate) fn inlay_int(line_index: &LineIndex, inlay_hint: InlayHint) -> lsp_ex
304 } 306 }
305} 307}
306 308
309static TOKEN_RESULT_COUNTER: AtomicU32 = AtomicU32::new(1);
310
307pub(crate) fn semantic_tokens( 311pub(crate) fn semantic_tokens(
308 text: &str, 312 text: &str,
309 line_index: &LineIndex, 313 line_index: &LineIndex,
310 highlights: Vec<HighlightedRange>, 314 highlights: Vec<HighlightedRange>,
311) -> lsp_types::SemanticTokens { 315) -> lsp_types::SemanticTokens {
312 let id = match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) { 316 let id = TOKEN_RESULT_COUNTER.fetch_add(1, Ordering::SeqCst).to_string();
313 Ok(d) => d.as_millis().to_string(),
314 Err(_) => String::new(),
315 };
316
317 let mut builder = semantic_tokens::SemanticTokensBuilder::new(id); 317 let mut builder = semantic_tokens::SemanticTokensBuilder::new(id);
318 318
319 for highlight_range in highlights { 319 for highlight_range in highlights {