Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #17064 - Veykril:inlay-hints-fix, r=Veykril
minor: Carry inlay hint resolve hash as a string
bors 2024-04-14
parent 7dad0a2 · parent 189aba7 · commit f3c7bd0
-rw-r--r--crates/rust-analyzer/src/handlers/request.rs11
-rw-r--r--crates/rust-analyzer/src/lsp/ext.rs3
-rw-r--r--crates/rust-analyzer/src/lsp/to_proto.rs8
-rw-r--r--docs/dev/lsp-extensions.md2
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 3439ae1d07..c99b22bb7d 100644
--- a/crates/rust-analyzer/src/handlers/request.rs
+++ b/crates/rust-analyzer/src/handlers/request.rs
@@ -1504,12 +1504,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");
@@ -1521,14 +1518,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 1ef49b5c11..12f8e71c98 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 04a5486e94..2688c8ce0d 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 1b7534a549..f1815082e2 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: