Skip to content

Commit 189aba7

Browse files
committed
minor: Carry inlay hint resolve hash as a string
1 parent 2c5c12a commit 189aba7

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

crates/rust-analyzer/src/handlers/request.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,12 +1490,9 @@ pub(crate) fn handle_inlay_hints_resolve(
14901490
) -> anyhow::Result<InlayHint> {
14911491
let _p = tracing::span!(tracing::Level::INFO, "handle_inlay_hints_resolve").entered();
14921492

1493-
let data = match original_hint.data.take() {
1494-
Some(it) => it,
1495-
None => return Ok(original_hint),
1496-
};
1497-
1493+
let Some(data) = original_hint.data.take() else { return Ok(original_hint) };
14981494
let resolve_data: lsp_ext::InlayHintResolveData = serde_json::from_value(data)?;
1495+
let Some(hash) = resolve_data.hash.parse().ok() else { return Ok(original_hint) };
14991496
let file_id = FileId::from_raw(resolve_data.file_id);
15001497
anyhow::ensure!(snap.file_exists(file_id), "Invalid LSP resolve data");
15011498

@@ -1507,14 +1504,12 @@ pub(crate) fn handle_inlay_hints_resolve(
15071504
&forced_resolve_inlay_hints_config,
15081505
file_id,
15091506
hint_position,
1510-
resolve_data.hash,
1507+
hash,
15111508
|hint| {
15121509
std::hash::BuildHasher::hash_one(
15131510
&std::hash::BuildHasherDefault::<ide_db::FxHasher>::default(),
15141511
hint,
15151512
)
1516-
// json only supports numbers up to 2^53 - 1 as integers, so mask the rest
1517-
& ((1 << 53) - 1)
15181513
},
15191514
)?;
15201515

crates/rust-analyzer/src/lsp/ext.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,8 @@ pub struct CompletionResolveData {
794794
#[derive(Debug, Serialize, Deserialize)]
795795
pub struct InlayHintResolveData {
796796
pub file_id: u32,
797-
pub hash: u64,
797+
// This is a string instead of a u64 as javascript can't represent u64 fully
798+
pub hash: String,
798799
}
799800

800801
#[derive(Debug, Serialize, Deserialize)]

crates/rust-analyzer/src/lsp/to_proto.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,6 @@ pub(crate) fn inlay_hint(
453453
&std::hash::BuildHasherDefault::<FxHasher>::default(),
454454
&inlay_hint,
455455
)
456-
// json only supports numbers up to 2^53 - 1 as integers, so mask the rest
457-
& ((1 << 53) - 1)
458456
});
459457

460458
let mut something_to_resolve = false;
@@ -481,7 +479,11 @@ pub(crate) fn inlay_hint(
481479

482480
let data = match resolve_hash {
483481
Some(hash) if something_to_resolve => Some(
484-
to_value(lsp_ext::InlayHintResolveData { file_id: file_id.index(), hash }).unwrap(),
482+
to_value(lsp_ext::InlayHintResolveData {
483+
file_id: file_id.index(),
484+
hash: hash.to_string(),
485+
})
486+
.unwrap(),
485487
),
486488
_ => None,
487489
};

docs/dev/lsp-extensions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!---
2-
lsp/ext.rs hash: 4aacf4cca1c9ff5e
2+
lsp/ext.rs hash: dd51139b0530147e
33
44
If you need to change the above hash to make the test pass, please check if you
55
need to adjust this doc as well and ping this issue:

0 commit comments

Comments
 (0)