diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-08-09 09:50:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-09 09:50:37 +0200 |
commit | c21f42c825b19d7309d883513d21f62395996f78 (patch) | |
tree | 9b1e1f97a1499d51d4842c7baae285a07d326841 /cli/lsp/config.rs | |
parent | 33b2eec793a7eb2335649010fe7bbd1947a8fb10 (diff) |
fix(lsp): don't always use byonm resolver when DENO_FUTURE=1 (#24865)
Co-authored-by: Nayeem Rahman <nayeemrmn99@gmail.com>
Diffstat (limited to 'cli/lsp/config.rs')
-rw-r--r-- | cli/lsp/config.rs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index bbfe3a6df..1d6601933 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -1115,6 +1115,7 @@ pub enum ConfigWatchedFileType { #[derive(Debug, Clone)] pub struct ConfigData { pub scope: Arc<ModuleSpecifier>, + pub canonicalized_scope: Option<Arc<ModuleSpecifier>>, pub member_dir: Arc<WorkspaceDirectory>, pub fmt_config: Arc<FmtConfig>, pub lint_config: Arc<LintConfig>, @@ -1253,6 +1254,16 @@ impl ConfigData { watched_files.entry(specifier).or_insert(file_type); }; + let canonicalized_scope = (|| { + let path = scope.to_file_path().ok()?; + let path = canonicalize_path_maybe_not_exists(&path).ok()?; + let specifier = ModuleSpecifier::from_directory_path(path).ok()?; + if specifier == *scope { + return None; + } + Some(Arc::new(specifier)) + })(); + if let Some(deno_json) = member_dir.maybe_deno_json() { lsp_log!( " Resolved Deno configuration file: \"{}\"", @@ -1559,6 +1570,7 @@ impl ConfigData { ConfigData { scope, + canonicalized_scope, member_dir, resolver, sloppy_imports_resolver, @@ -1587,6 +1599,15 @@ impl ConfigData { pub fn maybe_pkg_json(&self) -> Option<&Arc<deno_package_json::PackageJson>> { self.member_dir.maybe_pkg_json() } + + pub fn scope_contains_specifier(&self, specifier: &ModuleSpecifier) -> bool { + specifier.as_str().starts_with(self.scope.as_str()) + || self + .canonicalized_scope + .as_ref() + .map(|s| specifier.as_str().starts_with(s.as_str())) + .unwrap_or(false) + } } #[derive(Clone, Debug, Default)] @@ -1601,8 +1622,9 @@ impl ConfigTree { ) -> Option<&ModuleSpecifier> { self .scopes - .keys() - .rfind(|s| specifier.as_str().starts_with(s.as_str())) + .iter() + .rfind(|(_, d)| d.scope_contains_specifier(specifier)) + .map(|(s, _)| s) } pub fn data_for_specifier( |