mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Address the feedback from pascalkuthe
* Use Base64 to minify the hash representation in the JSON data * Do hash checks only for items with similar labels
This commit is contained in:
parent
2529e9e1e1
commit
4169926b3f
6 changed files with 21 additions and 6 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -84,6 +84,12 @@ dependencies = [
|
||||||
"vfs",
|
"vfs",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.22.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
|
@ -1649,6 +1655,7 @@ version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"always-assert",
|
"always-assert",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"base64",
|
||||||
"cargo_metadata",
|
"cargo_metadata",
|
||||||
"cfg",
|
"cfg",
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
|
|
|
@ -21,6 +21,7 @@ path = "src/bin/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
|
base64 = "0.22"
|
||||||
crossbeam-channel.workspace = true
|
crossbeam-channel.workspace = true
|
||||||
dirs = "5.0.1"
|
dirs = "5.0.1"
|
||||||
dissimilar.workspace = true
|
dissimilar.workspace = true
|
||||||
|
|
|
@ -10,6 +10,7 @@ use std::{
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
|
||||||
|
use base64::{prelude::BASE64_STANDARD, Engine};
|
||||||
use ide::{
|
use ide::{
|
||||||
AnnotationConfig, AssistKind, AssistResolveStrategy, Cancellable, CompletionFieldsToResolve,
|
AnnotationConfig, AssistKind, AssistResolveStrategy, Cancellable, CompletionFieldsToResolve,
|
||||||
FilePosition, FileRange, HoverAction, HoverGotoTypeData, InlayFieldsToResolve, Query,
|
FilePosition, FileRange, HoverAction, HoverGotoTypeData, InlayFieldsToResolve, Query,
|
||||||
|
@ -1136,10 +1137,15 @@ pub(crate) fn handle_completion_resolve(
|
||||||
else {
|
else {
|
||||||
return Ok(original_completion);
|
return Ok(original_completion);
|
||||||
};
|
};
|
||||||
|
let Ok(resolve_data_hash) = BASE64_STANDARD.decode(resolve_data.hash) else {
|
||||||
|
return Ok(original_completion);
|
||||||
|
};
|
||||||
|
|
||||||
let Some(corresponding_completion) = completions.into_iter().find(|completion_item| {
|
let Some(corresponding_completion) = completions.into_iter().find(|completion_item| {
|
||||||
let hash = completion_item_hash(completion_item, resolve_data.for_ref);
|
// Avoid computing hashes for items that obviously do not match
|
||||||
hash == resolve_data.hash
|
// r-a might append a detail-based suffix to the label, so we cannot check for equality
|
||||||
|
original_completion.label.starts_with(completion_item.label.as_str())
|
||||||
|
&& resolve_data_hash == completion_item_hash(completion_item, resolve_data.for_ref)
|
||||||
}) else {
|
}) else {
|
||||||
return Ok(original_completion);
|
return Ok(original_completion);
|
||||||
};
|
};
|
||||||
|
|
|
@ -827,7 +827,7 @@ pub struct CompletionResolveData {
|
||||||
pub version: Option<i32>,
|
pub version: Option<i32>,
|
||||||
pub trigger_character: Option<char>,
|
pub trigger_character: Option<char>,
|
||||||
pub for_ref: bool,
|
pub for_ref: bool,
|
||||||
pub hash: [u8; 20],
|
pub hash: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::{
|
||||||
sync::atomic::{AtomicU32, Ordering},
|
sync::atomic::{AtomicU32, Ordering},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use base64::{prelude::BASE64_STANDARD, Engine};
|
||||||
use ide::{
|
use ide::{
|
||||||
Annotation, AnnotationKind, Assist, AssistKind, Cancellable, CompletionFieldsToResolve,
|
Annotation, AnnotationKind, Assist, AssistKind, Cancellable, CompletionFieldsToResolve,
|
||||||
CompletionItem, CompletionItemKind, CompletionRelevance, Documentation, FileId, FileRange,
|
CompletionItem, CompletionItemKind, CompletionRelevance, Documentation, FileId, FileRange,
|
||||||
|
@ -402,7 +403,7 @@ fn completion_item(
|
||||||
version,
|
version,
|
||||||
trigger_character: completion_trigger_character,
|
trigger_character: completion_trigger_character,
|
||||||
for_ref: true,
|
for_ref: true,
|
||||||
hash: completion_item_hash(&item, true),
|
hash: BASE64_STANDARD.encode(completion_item_hash(&item, true)),
|
||||||
};
|
};
|
||||||
Some(to_value(ref_resolve_data).unwrap())
|
Some(to_value(ref_resolve_data).unwrap())
|
||||||
} else {
|
} else {
|
||||||
|
@ -414,7 +415,7 @@ fn completion_item(
|
||||||
version,
|
version,
|
||||||
trigger_character: completion_trigger_character,
|
trigger_character: completion_trigger_character,
|
||||||
for_ref: false,
|
for_ref: false,
|
||||||
hash: completion_item_hash(&item, false),
|
hash: BASE64_STANDARD.encode(completion_item_hash(&item, false)),
|
||||||
};
|
};
|
||||||
(ref_resolve_data, Some(to_value(resolve_data).unwrap()))
|
(ref_resolve_data, Some(to_value(resolve_data).unwrap()))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!---
|
<!---
|
||||||
lsp/ext.rs hash: c4c37ab0bcf7ccb0
|
lsp/ext.rs hash: 14b7fb1309f5bb00
|
||||||
|
|
||||||
If you need to change the above hash to make the test pass, please check if you
|
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:
|
need to adjust this doc as well and ping this issue:
|
||||||
|
|
Loading…
Reference in a new issue