Skip to content

Commit

Permalink
change details to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Dec 8, 2021
1 parent 2d50f0d commit 63fdaef
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 38 deletions.
2 changes: 1 addition & 1 deletion cli/lsp/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub documentation: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tsc: Option<tsc::CompletionItemData>,
}
Expand Down
7 changes: 2 additions & 5 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
37 changes: 18 additions & 19 deletions cli/lsp/registries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ fn get_data(
variable: &Key,
value: &str,
) -> Option<Value> {
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
Expand Down Expand Up @@ -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<String>,
documentation: Option<String>,
/// The URL with variable substitutions of the endpoint that will provide
/// completions for the variable.
url: String,
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
},
],
Expand All @@ -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(),
},
Expand All @@ -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(),
},
Expand All @@ -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(),
},
Expand Down
21 changes: 8 additions & 13 deletions cli/schemas/registry-completions.v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
]
}
}
Expand Down

0 comments on commit 63fdaef

Please sign in to comment.