Repository: denoland/deno
Pull request: fix(lsp): don't always use byonm resolver when DENO_FUTURE=1

Probably fixes #24863

Caused by https://github.com/denoland/deno/commit/a49d0bd10ba2a4745c291f3f413d97396213e4ec#diff-763c48dc07339b6f9b7800e2024d25f6ecd185d243f46a4416abc55917ccf0fcR446

I'm not bothering to add a test because we're going to completely revamp this in the coming weeks when we start work on Deno 2.0.

Changed files:
filename: cli/lsp/config.rs
patch: @@ -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(

filename: cli/lsp/resolver.rs
patch: @@ -4,7 +4,6 @@ use crate::args::create_default_npmrc;
 use crate::args::CacheSetting;
 use crate::args::CliLockfile;
 use crate::args::PackageJsonInstallDepsProvider;
-use crate::args::DENO_FUTURE;
 use crate::graph_util::CliJsrUrlProvider;
 use crate::http_util::HttpClientProvider;
 use crate::lsp::config::Config;
@@ -421,9 +420,14 @@ impl LspResolver {
     };
     self
       .by_scope
-      .iter()
-      .rfind(|(s, _)| file_referrer.as_str().starts_with(s.as_str()))
-      .map(|(_, r)| r.as_ref())
+      .values()
+      .rfind(|r| {
+        r.config_data
+          .as_ref()
+          .map(|d| d.scope_contains_specifier(file_referrer))
+          .unwrap_or(false)
+      })
+      .map(|r| r.as_ref())
       .unwrap_or(self.unscoped.as_ref())
   }
 }
@@ -433,7 +437,7 @@ async fn create_npm_resolver(
   cache: &LspCache,
   http_client_provider: &Arc<HttpClientProvider>,
 ) -> Option<Arc<dyn CliNpmResolver>> {
-  let enable_byonm = config_data.map(|d| d.byonm).unwrap_or(*DENO_FUTURE);
+  let enable_byonm = config_data.map(|d| d.byonm).unwrap_or(false);
   let options = if enable_byonm {
     CliNpmResolverCreateOptions::Byonm(CliNpmResolverByonmCreateOptions {
       fs: Arc::new(deno_fs::RealFs),