mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
fix(lsp): don't always use byonm resolver when DENO_FUTURE=1 (#24865)
Co-authored-by: Nayeem Rahman <nayeemrmn99@gmail.com>
This commit is contained in:
parent
33b2eec793
commit
c21f42c825
2 changed files with 33 additions and 7 deletions
|
@ -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(
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue