0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

refactor: simplify how LSP deals with config file specifier (#13401)

This commit is contained in:
Ryan Dahl 2022-01-17 14:45:05 -05:00 committed by GitHub
parent 49343c13e1
commit 3595f37b07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -79,7 +79,6 @@ pub(crate) struct StateSnapshot {
pub documents: Documents,
pub maybe_lint_config: Option<LintConfig>,
pub maybe_fmt_config: Option<FmtConfig>,
pub maybe_config_uri: Option<ModuleSpecifier>,
pub module_registries: registries::ModuleRegistry,
pub performance: Performance,
pub url_map: urls::LspUrlMap,
@ -114,9 +113,6 @@ pub(crate) struct Inner {
maybe_lint_config: Option<LintConfig>,
/// An optional configuration for formatter which has been taken from specified config file.
maybe_fmt_config: Option<FmtConfig>,
/// An optional URL which provides the location of a TypeScript configuration
/// file which will be used by the Deno LSP.
maybe_config_uri: Option<Url>,
/// An optional import map which is used to resolve modules.
pub(crate) maybe_import_map: Option<Arc<ImportMap>>,
/// The URL for the import map which is used to determine relative imports.
@ -161,7 +157,6 @@ impl Inner {
maybe_fmt_config: None,
maybe_cache_server: None,
maybe_config_file: None,
maybe_config_uri: None,
maybe_import_map: None,
maybe_import_map_uri: None,
module_registries,
@ -293,9 +288,7 @@ impl Inner {
/// Returns a tuple with parsed `ConfigFile` and `Url` pointing to that file.
/// If there's no config file specified in settings returns `None`.
fn get_config_file_and_url(
&self,
) -> Result<Option<(ConfigFile, Url)>, AnyError> {
fn get_config_file(&self) -> Result<Option<ConfigFile>, AnyError> {
let workspace_settings = self.config.get_workspace_settings();
let maybe_root_uri = self.config.root_uri.clone();
let maybe_config = workspace_settings.config;
@ -317,7 +310,7 @@ impl Inner {
lsp_log!(" Resolved configuration file: \"{}\"", config_url);
let config_file = ConfigFile::from_specifier(&config_url)?;
return Ok(Some((config_file, config_url)));
return Ok(Some(config_file));
}
}
@ -376,7 +369,6 @@ impl Inner {
documents: self.documents.clone(),
maybe_lint_config: self.maybe_lint_config.clone(),
maybe_fmt_config: self.maybe_fmt_config.clone(),
maybe_config_uri: self.maybe_config_uri.clone(),
module_registries: self.module_registries.clone(),
performance: self.performance.clone(),
url_map: self.url_map.clone(),
@ -521,13 +513,10 @@ impl Inner {
fn update_config_file(&mut self) -> Result<(), AnyError> {
self.maybe_config_file = None;
self.maybe_config_uri = None;
self.maybe_fmt_config = None;
self.maybe_lint_config = None;
let maybe_file_and_url = self.get_config_file_and_url()?;
if let Some((config_file, config_url)) = maybe_file_and_url {
if let Some(config_file) = self.get_config_file()? {
let lint_config = config_file
.to_lint_config()
.map_err(|err| {
@ -542,7 +531,6 @@ impl Inner {
.unwrap_or_default();
self.maybe_config_file = Some(config_file);
self.maybe_config_uri = Some(config_url);
self.maybe_lint_config = Some(lint_config);
self.maybe_fmt_config = Some(fmt_config);
}
@ -940,8 +928,8 @@ impl Inner {
}
}
// if the current tsconfig has changed, we need to reload it
if let Some(config_uri) = &self.maybe_config_uri {
if changes.iter().any(|uri| config_uri == uri) {
if let Some(config_file) = &self.maybe_config_file {
if changes.iter().any(|uri| config_file.specifier == *uri) {
if let Err(err) = self.update_config_file() {
self.client.show_message(MessageType::WARNING, err).await;
}