Skip to content

Commit

Permalink
Auto merge of #17064 - Veykril:inlay-hints-fix, r=Veykril
Browse files Browse the repository at this point in the history
minor: Carry inlay hint resolve hash as a string
  • Loading branch information
bors committed Apr 14, 2024
2 parents 7dad0a2 + 189aba7 commit f3c7bd0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
11 changes: 3 additions & 8 deletions crates/rust-analyzer/src/handlers/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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)
},
)?;

Expand Down
3 changes: 2 additions & 1 deletion crates/rust-analyzer/src/lsp/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 5 additions & 3 deletions crates/rust-analyzer/src/lsp/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/lsp-extensions.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit f3c7bd0

Please sign in to comment.