From 63fdaefb4b786854e78fe9453228a654b8b1ed78 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Wed, 8 Dec 2021 20:26:31 +1100 Subject: [PATCH] change details to documentation --- cli/lsp/completions.rs | 2 +- cli/lsp/language_server.rs | 7 ++--- cli/lsp/registries.rs | 37 ++++++++++++------------ cli/schemas/registry-completions.v2.json | 21 +++++--------- 4 files changed, 29 insertions(+), 38 deletions(-) diff --git a/cli/lsp/completions.rs b/cli/lsp/completions.rs index 62115985a0638e..50ab2660f04100 100644 --- a/cli/lsp/completions.rs +++ b/cli/lsp/completions.rs @@ -24,7 +24,7 @@ const LOCAL_PATHS: &[&str] = &[CURRENT_PATH, PARENT_PATH]; #[serde(rename_all = "camelCase")] pub struct CompletionItemData { #[serde(skip_serializing_if = "Option::is_none")] - pub docs: Option, + pub documentation: Option, #[serde(skip_serializing_if = "Option::is_none")] pub tsc: Option, } diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 2e1cecac0bb331..d665fdb7422c1c 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -1773,12 +1773,9 @@ impl Inner { ); params } - } else if let Some(docs_url) = data.docs { + } else if let Some(url) = data.documentation { CompletionItem { - documentation: self - .module_registries - .get_documentation(&docs_url) - .await, + documentation: self.module_registries.get_documentation(&url).await, data: None, ..params } diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs index 26c04e18f366a3..33eadc619e1aeb 100644 --- a/cli/lsp/registries.rs +++ b/cli/lsp/registries.rs @@ -147,10 +147,10 @@ fn get_data( variable: &Key, value: &str, ) -> Option { - let url = registry.get_details_url_for_key(variable)?; + let url = registry.get_documentation_url_for_key(variable)?; get_endpoint(url, base, variable, Some(value)) .ok() - .map(|specifier| json!({ "registry": specifier })) + .map(|specifier| json!({ "documentation": specifier })) } /// Convert a single variable templated string into a fully qualified URL which @@ -317,9 +317,9 @@ fn validate_config(config: &RegistryConfigurationJson) -> Result<(), AnyError> { pub(crate) struct RegistryConfigurationVariable { /// The name of the variable. key: String, - /// An optional URL/API endpoint that can provide optional details for a + /// An optional URL/API endpoint that can provide optional documentation for a /// completion item when requested by the language server. - details: Option, + documentation: Option, /// The URL with variable substitutions of the endpoint that will provide /// completions for the variable. url: String, @@ -344,10 +344,10 @@ impl RegistryConfiguration { }) } - fn get_details_url_for_key(&self, key: &Key) -> Option<&str> { + fn get_documentation_url_for_key(&self, key: &Key) -> Option<&str> { self.variables.iter().find_map(|v| { if key.name == StringOrNumber::String(v.key.clone()) { - v.details.as_deref() + v.documentation.as_deref() } else { None } @@ -779,8 +779,7 @@ 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, k, &path); + let data = get_data(registry, &specifier, k, &path); completions.insert( item.clone(), lsp::CompletionItem { @@ -959,12 +958,12 @@ mod tests { variables: vec![ RegistryConfigurationVariable { key: "module".to_string(), - details: None, + documentation: None, url: "https://api.deno.land/modules?short".to_string(), }, RegistryConfigurationVariable { key: "version".to_string(), - details: None, + documentation: None, url: "https://deno.land/_vsc1/module/${module}".to_string(), }, ], @@ -979,17 +978,17 @@ mod tests { variables: vec![ RegistryConfigurationVariable { key: "module".to_string(), - details: None, + documentation: None, url: "https://api.deno.land/modules?short".to_string(), }, RegistryConfigurationVariable { key: "version".to_string(), - details: None, + documentation: None, url: "https://deno.land/_vsc1/module/${module}/${path}".to_string(), }, RegistryConfigurationVariable { key: "path".to_string(), - details: None, + documentation: None, url: "https://deno.land/_vsc1/module/${module}/v/${{version}}" .to_string(), }, @@ -1005,18 +1004,18 @@ mod tests { variables: vec![ RegistryConfigurationVariable { key: "module".to_string(), - details: None, + documentation: None, url: "https://api.deno.land/modules?short".to_string(), }, RegistryConfigurationVariable { key: "version".to_string(), - details: None, + documentation: None, url: "https://deno.land/_vsc1/module/${module}/v/${{version}}" .to_string(), }, RegistryConfigurationVariable { key: "path".to_string(), - details: None, + documentation: None, url: "https://deno.land/_vsc1/module/${module}/v/${{version}}" .to_string(), }, @@ -1032,17 +1031,17 @@ mod tests { variables: vec![ RegistryConfigurationVariable { key: "module".to_string(), - details: None, + documentation: None, url: "https://api.deno.land/modules?short".to_string(), }, RegistryConfigurationVariable { key: "version".to_string(), - details: None, + documentation: None, url: "https://deno.land/_vsc1/module/${module}".to_string(), }, RegistryConfigurationVariable { key: "path".to_string(), - details: None, + documentation: None, url: "https://deno.land/_vsc1/module/${module}/v/${{version}}" .to_string(), }, diff --git a/cli/schemas/registry-completions.v2.json b/cli/schemas/registry-completions.v2.json index bc09a066a87cb5..528e3f43b63f50 100644 --- a/cli/schemas/registry-completions.v2.json +++ b/cli/schemas/registry-completions.v2.json @@ -67,27 +67,22 @@ "path" ] }, - "details": { + "documentation": { "type": "string", - "description": "An optional \"endpoint\" to call to provide details for specified variable, which can be displayed to the client in the response. This can provide description information about the item.", + "description": "An optional \"endpoint\" to call to provide documentation for specified variable, which can be displayed to the client in the response. This can provide description information about the item. The value should contain the variable name in the template. Baseless URLs can be supplied and the host for the configuration file will be used as the base.", "examples": [ - "https://example.com/api/modules/${module}/${{version}}/details/${path}" - ] - }, - "parts": { - "type": "string", - "description": "An optional \"endpoint\" to call to provide incremental results of a complex variable, delimited by a path separator of \"/\".", - "examples": [ - "https://example.com/api/modules/${module}/${{version}}/${path}" + "https://example.com/api/documentation/packages/${package}/${{version}}/${path}", + "/api/documentation/packages/${package}/${{version}}/${path}" ] }, "url": { "type": "string", - "description": "The \"endpoint\" to call to provide values to complete the specifier. This endpoint should return an array of strings. Parsed values can be substituted using ${key} syntax.", + "description": "The \"endpoint\" to call to provide values to complete the specifier. This endpoint should return an array of strings. Parsed values can be substituted using ${key} syntax. In order to support incremental completions, the value should contain the variable name in the template. Baseless URLs can be supplied and the host for the configuration file will be used as the base.", "examples": [ "https://example.com/api/packages", - "https://example.com/api/packages/{package}", - "https://example.com/api/packages/{package}/${{version}}" + "https://example.com/api/packages/${package}", + "https://example.com/api/packages/${package}/${{version}}", + "/api/packages/${package}/${{version}}/${path}" ] } }