diff options
-rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 7 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 7 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/to_proto.rs | 14 |
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 | ||
6 | use std::{ | 6 | use std::{sync::Arc, time::Instant}; |
7 | sync::{Arc, Mutex}, | ||
8 | time::Instant, | ||
9 | }; | ||
10 | 7 | ||
11 | use crossbeam_channel::{unbounded, Receiver, Sender}; | 8 | use crossbeam_channel::{unbounded, Receiver, Sender}; |
12 | use flycheck::FlycheckHandle; | 9 | use flycheck::FlycheckHandle; |
13 | use lsp_types::{SemanticTokens, Url}; | 10 | use lsp_types::{SemanticTokens, Url}; |
14 | use parking_lot::RwLock; | 11 | use parking_lot::{Mutex, RwLock}; |
15 | use ra_db::{CrateId, VfsPath}; | 12 | use ra_db::{CrateId, VfsPath}; |
16 | use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FileId}; | 13 | use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FileId}; |
17 | use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target}; | 14 | use 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(¶ms.text_document.uri); | 455 | this.semantic_tokens_cache.lock().remove(¶ms.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. |
2 | use std::path::{self, Path}; | 2 | use std::{ |
3 | use std::time::SystemTime; | 3 | path::{self, Path}, |
4 | sync::atomic::{AtomicU32, Ordering}, | ||
5 | }; | ||
4 | 6 | ||
5 | use itertools::Itertools; | 7 | use itertools::Itertools; |
6 | use ra_db::{FileId, FileRange}; | 8 | use 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 | ||
309 | static TOKEN_RESULT_COUNTER: AtomicU32 = AtomicU32::new(1); | ||
310 | |||
307 | pub(crate) fn semantic_tokens( | 311 | pub(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 { |