summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/lsp/registries.rs42
-rw-r--r--cli/tests/testdata/lsp/registries/deno-import-intellisense.json1
2 files changed, 41 insertions, 2 deletions
diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs
index 912a6a9de..9b68b8850 100644
--- a/cli/lsp/registries.rs
+++ b/cli/lsp/registries.rs
@@ -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
diff --git a/cli/tests/testdata/lsp/registries/deno-import-intellisense.json b/cli/tests/testdata/lsp/registries/deno-import-intellisense.json
index cdd71a7cf..f2784d2f6 100644
--- a/cli/tests/testdata/lsp/registries/deno-import-intellisense.json
+++ b/cli/tests/testdata/lsp/registries/deno-import-intellisense.json
@@ -11,6 +11,7 @@
},
{
"key": "version",
+ "documentation": "/lsp/registries/doc_${module}_${{version}}.json",
"url": "/lsp/registries/${module}_versions.json"
},
{