diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2024-04-05 16:18:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-05 16:18:48 +0100 |
commit | 61f1b8e8dc20846093a8b24a8f511a09bbf09919 (patch) | |
tree | 15556a7212f9603616f046533385e6e130680ec3 /cli/lsp/config.rs | |
parent | 049e703331409db8c4b4e2cc7d969f471c229df3 (diff) |
fix(lsp): respect DENO_FUTURE for BYONM config (#23207)
Diffstat (limited to 'cli/lsp/config.rs')
-rw-r--r-- | cli/lsp/config.rs | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index 1a707c44c..362b029e9 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -1145,6 +1145,7 @@ pub struct ConfigData { pub lint_options: Arc<LintOptions>, pub lint_rules: Arc<ConfiguredRules>, pub ts_config: Arc<LspTsConfig>, + pub byonm: bool, pub node_modules_dir: Option<PathBuf>, pub vendor_dir: Option<PathBuf>, pub lockfile: Option<Arc<Mutex<Lockfile>>>, @@ -1267,8 +1268,6 @@ impl ConfigData { let lint_rules = get_configured_rules(lint_options.rules.clone(), config_file.as_ref()); let ts_config = LspTsConfig::new(config_file.as_ref()); - let node_modules_dir = - config_file.as_ref().and_then(resolve_node_modules_dir); let vendor_dir = config_file.as_ref().and_then(|c| c.vendor_dir_path()); // Load lockfile @@ -1327,6 +1326,23 @@ impl ConfigData { } } } + let byonm = std::env::var("DENO_UNSTABLE_BYONM").is_ok() + || config_file + .as_ref() + .map(|c| c.has_unstable("byonm")) + .unwrap_or(false) + || (std::env::var("DENO_FUTURE").is_ok() + && package_json.is_some() + && config_file + .as_ref() + .map(|c| c.json.node_modules_dir.is_none()) + .unwrap_or(true)); + if byonm { + lsp_log!(" Enabled 'bring your own node_modules'."); + } + let node_modules_dir = config_file + .as_ref() + .and_then(|c| resolve_node_modules_dir(c, byonm)); // Load import map let mut import_map = None; @@ -1427,6 +1443,7 @@ impl ConfigData { lint_options: Arc::new(lint_options), lint_rules: Arc::new(lint_rules), ts_config: Arc::new(ts_config), + byonm, node_modules_dir, vendor_dir, lockfile: lockfile.map(Mutex::new).map(Arc::new), @@ -1648,7 +1665,10 @@ fn resolve_lockfile_from_config(config_file: &ConfigFile) -> Option<Lockfile> { resolve_lockfile_from_path(lockfile_path) } -fn resolve_node_modules_dir(config_file: &ConfigFile) -> Option<PathBuf> { +fn resolve_node_modules_dir( + config_file: &ConfigFile, + byonm: bool, +) -> Option<PathBuf> { // For the language server, require an explicit opt-in via the // `nodeModulesDir: true` setting in the deno.json file. This is to // reduce the chance of modifying someone's node_modules directory @@ -1657,7 +1677,8 @@ fn resolve_node_modules_dir(config_file: &ConfigFile) -> Option<PathBuf> { if explicitly_disabled { return None; } - let enabled = config_file.json.node_modules_dir == Some(true) + let enabled = byonm + || config_file.json.node_modules_dir == Some(true) || config_file.json.vendor == Some(true); if !enabled { return None; |