summaryrefslogtreecommitdiff
path: root/cli/lsp/language_server.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2024-02-12 22:12:49 +0000
committerGitHub <noreply@github.com>2024-02-12 22:12:49 +0000
commit49d82e609f7da97f793900528e800019d502a2ff (patch)
tree9fd726bad9ba1d9f5bd416c2697eaab9321bfdbf /cli/lsp/language_server.rs
parentf60720090c7bd8cdf91d7aebd0c42e01c86b3b83 (diff)
feat(lsp): jsr support first pass (#22382)
This implementation heavily depends on there being a lockfile, meaning JSR specifiers will always diagnose as uncached unless it's there. In practice this affects cases where a `deno.json` isn't being used. Our NPM specifier support isn't subject to this. The reason for this is that the version constraint solving code is currently buried in `deno_graph` and not usable from the LSP, so the only way to reuse that logic is the solved-version map in the lockfile's `packages.specifiers`.
Diffstat (limited to 'cli/lsp/language_server.rs')
-rw-r--r--cli/lsp/language_server.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 573fb1eb4..e775790fe 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -362,9 +362,24 @@ impl LanguageServer {
.client
.show_message(MessageType::WARNING, err);
}
- // do npm resolution in a write—we should have everything
- // cached by this point anyway
- self.0.write().await.refresh_npm_specifiers().await;
+ let mut lockfile_content_changed = false;
+ if let Some(lockfile) = self.0.read().await.config.maybe_lockfile() {
+ let lockfile = lockfile.lock();
+ let path = lockfile.filename.clone();
+ if let Ok(new_lockfile) = Lockfile::new(path, false) {
+ lockfile_content_changed = FastInsecureHasher::hash(&*lockfile)
+ != FastInsecureHasher::hash(new_lockfile);
+ } else {
+ lockfile_content_changed = true;
+ }
+ }
+ if lockfile_content_changed {
+ // TODO(nayeemrmn): Remove this branch when the documents config no
+ // longer depends on the lockfile for JSR resolution.
+ self.0.write().await.refresh_documents_config().await;
+ } else {
+ self.0.write().await.refresh_npm_specifiers().await;
+ }
// now refresh the data in a read
self.0.read().await.post_cache(result.mark).await;
}
@@ -1330,6 +1345,7 @@ impl Inner {
maybe_import_map: self.maybe_import_map.clone(),
maybe_config_file: self.config.maybe_config_file(),
maybe_package_json: self.maybe_package_json.as_ref(),
+ maybe_lockfile: self.config.maybe_lockfile().cloned(),
node_resolver: self.npm.node_resolver.clone(),
npm_resolver: self.npm.resolver.clone(),
});
@@ -2010,6 +2026,8 @@ impl Inner {
if diagnostic.code
== Some(NumberOrString::String("no-cache".to_string()))
|| diagnostic.code
+ == Some(NumberOrString::String("no-cache-jsr".to_string()))
+ || diagnostic.code
== Some(NumberOrString::String("no-cache-npm".to_string()))
{
includes_no_cache = true;