Skip to content

Commit

Permalink
refactor: simplify how LSP deals with config file specifier (denoland…
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jan 17, 2022
1 parent 49343c1 commit 3595f37
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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));
}
}

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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| {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3595f37

Please sign in to comment.