diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-07-18 18:16:35 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-18 18:16:35 -0400 |
commit | 3bda8eb4fe059fd79a522c9277a5a872f75dc270 (patch) | |
tree | 172d04d91223694c494b754d39c44ac5851575ac /cli/lsp/language_server.rs | |
parent | 1722e0aebfd830b7cbc0824ace5de0517072d0dc (diff) |
fix(lsp): support npm workspaces and fix some resolution issues (#24627)
Makes the lsp use the same code as the rest of the cli.
Diffstat (limited to 'cli/lsp/language_server.rs')
-rw-r--r-- | cli/lsp/language_server.rs | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 093ea1dab..5b6ff79f2 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -89,6 +89,7 @@ use super::tsc::TsServer; use super::urls; use crate::args::create_default_npmrc; use crate::args::get_root_cert_store; +use crate::args::has_flag_env_var; use crate::args::CaData; use crate::args::CacheSetting; use crate::args::CliOptions; @@ -1322,7 +1323,7 @@ impl Inner { if !self .config .tree - .fmt_options_for_specifier(&specifier) + .fmt_config_for_specifier(&specifier) .files .matches_specifier(&specifier) { @@ -1352,7 +1353,7 @@ impl Inner { let mut fmt_options = self .config .tree - .fmt_options_for_specifier(&specifier) + .fmt_config_for_specifier(&specifier) .options .clone(); fmt_options.use_tabs = Some(!params.options.insert_spaces); @@ -1606,7 +1607,7 @@ impl Inner { (&self .config .tree - .fmt_options_for_specifier(&specifier) + .fmt_config_for_specifier(&specifier) .options) .into(), tsc::UserPreferences::from_config_for_specifier( @@ -1771,7 +1772,7 @@ impl Inner { (&self .config .tree - .fmt_options_for_specifier(&code_action_data.specifier) + .fmt_config_for_specifier(&code_action_data.specifier) .options) .into(), tsc::UserPreferences::from_config_for_specifier( @@ -1822,7 +1823,7 @@ impl Inner { (&self .config .tree - .fmt_options_for_specifier(&action_data.specifier) + .fmt_config_for_specifier(&action_data.specifier) .options) .into(), line_index.offset_tsc(action_data.range.start)? @@ -1857,7 +1858,9 @@ impl Inner { .config .tree .data_for_specifier(file_referrer) - .and_then(|d| d.import_map.as_ref().map(|i| i.as_ref())), + // todo(dsherret): this should probably just take the resolver itself + // as the import map is an implementation detail + .and_then(|d| d.resolver.maybe_import_map()), self.resolver.as_ref(), ) } @@ -2178,7 +2181,9 @@ impl Inner { .config .tree .data_for_specifier(file_referrer) - .and_then(|d| d.import_map.as_ref().map(|i| i.as_ref())), + // todo(dsherret): this should probably just take the resolver itself + // as the import map is an implementation detail + .and_then(|d| d.resolver.maybe_import_map()), ) .await; } @@ -2213,7 +2218,7 @@ impl Inner { (&self .config .tree - .fmt_options_for_specifier(&specifier) + .fmt_config_for_specifier(&specifier) .options) .into(), scope.cloned(), @@ -2268,11 +2273,7 @@ impl Inner { self.snapshot(), GetCompletionDetailsArgs { format_code_settings: Some( - (&self - .config - .tree - .fmt_options_for_specifier(specifier) - .options) + (&self.config.tree.fmt_config_for_specifier(specifier).options) .into(), ), preferences: Some( @@ -2846,7 +2847,7 @@ impl Inner { let format_code_settings = (&self .config .tree - .fmt_options_for_specifier(&old_specifier) + .fmt_config_for_specifier(&old_specifier) .options) .into(); changes.extend( @@ -3056,7 +3057,7 @@ impl tower_lsp::LanguageServer for LanguageServer { let mut config_events = vec![]; for (scope_uri, config_data) in inner.config.tree.data_by_scope().iter() { - if let Some(config_file) = &config_data.config_file { + if let Some(config_file) = config_data.maybe_deno_json() { config_events.push(lsp_custom::DenoConfigurationChangeEvent { scope_uri: scope_uri.clone(), file_uri: config_file.specifier.clone(), @@ -3064,7 +3065,7 @@ impl tower_lsp::LanguageServer for LanguageServer { configuration_type: lsp_custom::DenoConfigurationType::DenoJson, }); } - if let Some(package_json) = &config_data.package_json { + if let Some(package_json) = config_data.maybe_pkg_json() { config_events.push(lsp_custom::DenoConfigurationChangeEvent { scope_uri: scope_uri.clone(), file_uri: package_json.specifier(), @@ -3542,7 +3543,7 @@ impl Inner { if let Some(npm_reqs) = self .documents .npm_reqs_by_scope() - .get(&config_data.map(|d| d.scope.clone())) + .get(&config_data.map(|d| d.scope.as_ref().clone())) { roots.extend( npm_reqs @@ -3562,12 +3563,13 @@ impl Inner { ]), &WorkspaceDiscoverOptions { fs: &DenoConfigFsAdapter::new(&deno_runtime::deno_fs::RealFs), + deno_json_cache: None, pkg_json_cache: None, config_parse_options: deno_config::ConfigParseOptions { include_task_comments: false, }, additional_config_file_names: &[], - discover_pkg_json: true, + discover_pkg_json: !has_flag_env_var("DENO_NO_PACKAGE_JSON"), maybe_vendor_override: if force_global_cache { Some(deno_config::workspace::VendorEnablement::Disable) } else { @@ -3584,10 +3586,9 @@ impl Inner { .unsafely_ignore_certificate_errors .clone(), import_map_path: config_data.and_then(|d| { - if d.import_map_from_settings { - return Some(d.import_map.as_ref()?.base_url().to_string()); - } - None + d.import_map_from_settings + .as_ref() + .map(|url| url.to_string()) }), node_modules_dir: Some( config_data |