summaryrefslogtreecommitdiff
path: root/cli/lsp/registries.rs
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2022-01-07 11:27:13 +1100
committerGitHub <noreply@github.com>2022-01-07 11:27:13 +1100
commit57bfa87b2c56809eedcc64bf63be9dcdd6c7400f (patch)
treea93fe2d056323754f8d45d64c5fbc7204b06ee12 /cli/lsp/registries.rs
parent2067820714fea49be1692fa678754488ace8228b (diff)
feat(lsp): provide registry details on hover if present (#13294)
Closes: #13272
Diffstat (limited to 'cli/lsp/registries.rs')
-rw-r--r--cli/lsp/registries.rs57
1 files changed, 56 insertions, 1 deletions
diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs
index 93333dd92..9b967c3c2 100644
--- a/cli/lsp/registries.rs
+++ b/cli/lsp/registries.rs
@@ -27,6 +27,7 @@ use deno_core::url::ParseError;
use deno_core::url::Position;
use deno_core::url::Url;
use deno_core::ModuleSpecifier;
+use deno_graph::Dependency;
use deno_runtime::deno_web::BlobStore;
use deno_runtime::permissions::Permissions;
use log::error;
@@ -565,6 +566,60 @@ impl ModuleRegistry {
Ok(())
}
+ pub(crate) async fn get_hover(
+ &self,
+ dependency: &Dependency,
+ ) -> Option<String> {
+ let maybe_code = dependency.get_code();
+ let maybe_type = dependency.get_type();
+ let specifier = match (maybe_code, maybe_type) {
+ (Some(specifier), _) => Some(specifier),
+ (_, Some(specifier)) => Some(specifier),
+ _ => None,
+ }?;
+ let origin = base_url(specifier);
+ let registries = self.origins.get(&origin)?;
+ let path = &specifier[Position::BeforePath..];
+ for registry in registries {
+ let tokens = parse(&registry.schema, None).ok()?;
+ let matcher = Matcher::new(&tokens, None).ok()?;
+ if let Some(match_result) = matcher.matches(path) {
+ let key = if let Some(Token::Key(key)) = tokens.iter().last() {
+ Some(key)
+ } else {
+ None
+ }?;
+ let url = registry.get_documentation_url_for_key(key)?;
+ let endpoint = get_endpoint_with_match(
+ key,
+ url,
+ specifier,
+ &tokens,
+ &match_result,
+ None,
+ )
+ .ok()?;
+ let file = self
+ .file_fetcher
+ .fetch(&endpoint, &mut Permissions::allow_all())
+ .await
+ .ok()?;
+ let documentation: lsp::Documentation =
+ serde_json::from_str(&file.source).ok()?;
+ return match documentation {
+ lsp::Documentation::String(doc) => Some(doc),
+ lsp::Documentation::MarkupContent(lsp::MarkupContent {
+ value,
+ ..
+ }) => Some(value),
+ _ => None,
+ };
+ }
+ }
+
+ None
+ }
+
/// For a string specifier from the client, provide a set of completions, if
/// any, for the specifier.
pub(crate) async fn get_completions(
@@ -858,7 +913,7 @@ impl ModuleRegistry {
self.get_origin_completions(current_specifier, range)
}
- pub async fn get_documentation(
+ pub(crate) async fn get_documentation(
&self,
url: &str,
) -> Option<lsp::Documentation> {