Skip to content

Commit 195111d

Browse files
committed
Address PR comments
1 parent fcfd7cb commit 195111d

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

crates/rust-analyzer/src/global_state.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
//!
44
//! Each tick provides an immutable snapshot of the state as `WorldSnapshot`.
55
6-
use std::{
7-
sync::{Arc, Mutex},
8-
time::Instant,
9-
};
6+
use std::{sync::Arc, time::Instant};
107

118
use crossbeam_channel::{unbounded, Receiver, Sender};
129
use flycheck::FlycheckHandle;
1310
use lsp_types::{SemanticTokens, Url};
14-
use parking_lot::RwLock;
11+
use parking_lot::{Mutex, RwLock};
1512
use ra_db::{CrateId, VfsPath};
1613
use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FileId};
1714
use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target};

crates/rust-analyzer/src/handlers.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,10 +1187,7 @@ pub(crate) fn handle_semantic_tokens(
11871187
let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
11881188

11891189
// Unconditionally cache the tokens
1190-
snap.semantic_tokens_cache
1191-
.lock()
1192-
.unwrap()
1193-
.insert(params.text_document.uri, semantic_tokens.clone());
1190+
snap.semantic_tokens_cache.lock().insert(params.text_document.uri, semantic_tokens.clone());
11941191

11951192
Ok(Some(semantic_tokens.into()))
11961193
}
@@ -1209,7 +1206,7 @@ pub(crate) fn handle_semantic_tokens_edits(
12091206

12101207
let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
12111208

1212-
let mut cache = snap.semantic_tokens_cache.lock().unwrap();
1209+
let mut cache = snap.semantic_tokens_cache.lock();
12131210
let cached_tokens = cache.entry(params.text_document.uri).or_default();
12141211

12151212
if let Some(prev_id) = &cached_tokens.result_id {

crates/rust-analyzer/src/main_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ impl GlobalState {
452452
None => log::error!("orphan DidCloseTextDocument: {}", path),
453453
}
454454

455-
this.semantic_tokens_cache.lock().unwrap().remove(&params.text_document.uri);
455+
this.semantic_tokens_cache.lock().remove(&params.text_document.uri);
456456

457457
if let Some(path) = path.as_path() {
458458
this.loader.handle.invalidate(path.to_path_buf());

crates/rust-analyzer/src/to_proto.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Conversion of rust-analyzer specific types to lsp_types equivalents.
2-
use std::path::{self, Path};
3-
use std::time::SystemTime;
2+
use std::{
3+
path::{self, Path},
4+
sync::atomic::{AtomicU32, Ordering},
5+
};
46

57
use itertools::Itertools;
68
use ra_db::{FileId, FileRange};
@@ -304,16 +306,14 @@ pub(crate) fn inlay_int(line_index: &LineIndex, inlay_hint: InlayHint) -> lsp_ex
304306
}
305307
}
306308

309+
static TOKEN_RESULT_COUNTER: AtomicU32 = AtomicU32::new(1);
310+
307311
pub(crate) fn semantic_tokens(
308312
text: &str,
309313
line_index: &LineIndex,
310314
highlights: Vec<HighlightedRange>,
311315
) -> lsp_types::SemanticTokens {
312-
let id = match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
313-
Ok(d) => d.as_millis().to_string(),
314-
Err(_) => String::new(),
315-
};
316-
316+
let id = TOKEN_RESULT_COUNTER.fetch_add(1, Ordering::SeqCst).to_string();
317317
let mut builder = semantic_tokens::SemanticTokensBuilder::new(id);
318318

319319
for highlight_range in highlights {

0 commit comments

Comments
 (0)