From 189aba794367979125a61b127c897cccb8ab721e Mon Sep 17 00:00:00 2001
From: Lukas Wirth <lukastw97@gmail.com>
Date: Sun, 14 Apr 2024 10:43:43 +0200
Subject: [PATCH] minor: Carry inlay hint resolve hash as a string

---
 crates/rust-analyzer/src/handlers/request.rs | 11 +++--------
 crates/rust-analyzer/src/lsp/ext.rs          |  3 ++-
 crates/rust-analyzer/src/lsp/to_proto.rs     |  8 +++++---
 docs/dev/lsp-extensions.md                   |  2 +-
 4 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs
index a9e84de8a41..15da88595fc 100644
--- a/crates/rust-analyzer/src/handlers/request.rs
+++ b/crates/rust-analyzer/src/handlers/request.rs
@@ -1490,12 +1490,9 @@ pub(crate) fn handle_inlay_hints_resolve(
 ) -> anyhow::Result<InlayHint> {
     let _p = tracing::span!(tracing::Level::INFO, "handle_inlay_hints_resolve").entered();
 
-    let data = match original_hint.data.take() {
-        Some(it) => it,
-        None => return Ok(original_hint),
-    };
-
+    let Some(data) = original_hint.data.take() else { return Ok(original_hint) };
     let resolve_data: lsp_ext::InlayHintResolveData = serde_json::from_value(data)?;
+    let Some(hash) = resolve_data.hash.parse().ok() else { return Ok(original_hint) };
     let file_id = FileId::from_raw(resolve_data.file_id);
     anyhow::ensure!(snap.file_exists(file_id), "Invalid LSP resolve data");
 
@@ -1507,14 +1504,12 @@ pub(crate) fn handle_inlay_hints_resolve(
         &forced_resolve_inlay_hints_config,
         file_id,
         hint_position,
-        resolve_data.hash,
+        hash,
         |hint| {
             std::hash::BuildHasher::hash_one(
                 &std::hash::BuildHasherDefault::<ide_db::FxHasher>::default(),
                 hint,
             )
-            // json only supports numbers up to 2^53 - 1 as integers, so mask the rest
-            & ((1 << 53) - 1)
         },
     )?;
 
diff --git a/crates/rust-analyzer/src/lsp/ext.rs b/crates/rust-analyzer/src/lsp/ext.rs
index 1ef49b5c111..12f8e71c981 100644
--- a/crates/rust-analyzer/src/lsp/ext.rs
+++ b/crates/rust-analyzer/src/lsp/ext.rs
@@ -794,7 +794,8 @@ pub struct CompletionResolveData {
 #[derive(Debug, Serialize, Deserialize)]
 pub struct InlayHintResolveData {
     pub file_id: u32,
-    pub hash: u64,
+    // This is a string instead of a u64 as javascript can't represent u64 fully
+    pub hash: String,
 }
 
 #[derive(Debug, Serialize, Deserialize)]
diff --git a/crates/rust-analyzer/src/lsp/to_proto.rs b/crates/rust-analyzer/src/lsp/to_proto.rs
index 04a5486e941..2688c8ce0db 100644
--- a/crates/rust-analyzer/src/lsp/to_proto.rs
+++ b/crates/rust-analyzer/src/lsp/to_proto.rs
@@ -453,8 +453,6 @@ pub(crate) fn inlay_hint(
             &std::hash::BuildHasherDefault::<FxHasher>::default(),
             &inlay_hint,
         )
-        // json only supports numbers up to 2^53 - 1 as integers, so mask the rest
-         & ((1 << 53) - 1)
     });
 
     let mut something_to_resolve = false;
@@ -481,7 +479,11 @@ pub(crate) fn inlay_hint(
 
     let data = match resolve_hash {
         Some(hash) if something_to_resolve => Some(
-            to_value(lsp_ext::InlayHintResolveData { file_id: file_id.index(), hash }).unwrap(),
+            to_value(lsp_ext::InlayHintResolveData {
+                file_id: file_id.index(),
+                hash: hash.to_string(),
+            })
+            .unwrap(),
         ),
         _ => None,
     };
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
index 1b7534a549f..f1815082e2e 100644
--- a/docs/dev/lsp-extensions.md
+++ b/docs/dev/lsp-extensions.md
@@ -1,5 +1,5 @@
 <!---
-lsp/ext.rs hash: 4aacf4cca1c9ff5e
+lsp/ext.rs hash: dd51139b0530147e
 
 If you need to change the above hash to make the test pass, please check if you
 need to adjust this doc as well and ping this issue: