mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 04:48:52 -05:00
fix(lsp): properly generate data URLs for completion items (#13246)
This commit is contained in:
parent
003534e883
commit
0ae46a975c
2 changed files with 41 additions and 2 deletions
|
@ -152,6 +152,31 @@ fn get_data(
|
|||
.map(|specifier| json!({ "documentation": specifier }))
|
||||
}
|
||||
|
||||
/// Generate a data value for a completion item that will instruct the client to
|
||||
/// resolve the completion item to obtain further information, in this case, the
|
||||
/// details/documentation endpoint for the item if it exists in the registry
|
||||
/// configuration when there is a match result that should be interpolated
|
||||
fn get_data_with_match(
|
||||
registry: &RegistryConfiguration,
|
||||
base: &ModuleSpecifier,
|
||||
tokens: &[Token],
|
||||
match_result: &MatchResult,
|
||||
variable: &Key,
|
||||
value: &str,
|
||||
) -> Option<Value> {
|
||||
let url = registry.get_documentation_url_for_key(variable)?;
|
||||
get_endpoint_with_match(
|
||||
variable,
|
||||
url,
|
||||
base,
|
||||
tokens,
|
||||
match_result,
|
||||
Some(value),
|
||||
)
|
||||
.ok()
|
||||
.map(|specifier| json!({ "documentation": specifier }))
|
||||
}
|
||||
|
||||
/// Convert a single variable templated string into a fully qualified URL which
|
||||
/// can be fetched to provide additional data.
|
||||
fn get_endpoint(
|
||||
|
@ -667,8 +692,14 @@ impl ModuleRegistry {
|
|||
let sort_text = Some(format!("{:0>10}", idx + 1));
|
||||
let preselect =
|
||||
get_preselect(item.clone(), preselect.clone());
|
||||
let data =
|
||||
get_data(registry, &specifier, &key, &item);
|
||||
let data = get_data_with_match(
|
||||
registry,
|
||||
&specifier,
|
||||
&tokens,
|
||||
&match_result,
|
||||
&key,
|
||||
&item,
|
||||
);
|
||||
completions.insert(
|
||||
item,
|
||||
lsp::CompletionItem {
|
||||
|
@ -1282,6 +1313,12 @@ mod tests {
|
|||
assert!(completions.is_some());
|
||||
let completions = completions.unwrap().items;
|
||||
assert_eq!(completions.len(), 3);
|
||||
assert_eq!(
|
||||
completions[0].data,
|
||||
Some(json!({
|
||||
"documentation": format!("http://localhost:4545/lsp/registries/doc_a_{}.json", completions[0].label),
|
||||
}))
|
||||
);
|
||||
let range = lsp::Range {
|
||||
start: lsp::Position {
|
||||
line: 0,
|
||||
|
@ -1292,6 +1329,7 @@ mod tests {
|
|||
character: 53,
|
||||
},
|
||||
};
|
||||
|
||||
let completions = module_registry
|
||||
.get_completions("http://localhost:4545/x/a@v1.0.0/", 33, &range, |_| {
|
||||
false
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
},
|
||||
{
|
||||
"key": "version",
|
||||
"documentation": "/lsp/registries/doc_${module}_${{version}}.json",
|
||||
"url": "/lsp/registries/${module}_versions.json"
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue