summaryrefslogtreecommitdiff
path: root/cli/lsp/language_server.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp/language_server.rs')
-rw-r--r--cli/lsp/language_server.rs57
1 files changed, 28 insertions, 29 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index f44f8e071..ec31fea4c 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -62,8 +62,8 @@ use crate::args::CacheSetting;
use crate::args::CliOptions;
use crate::args::ConfigFile;
use crate::args::Flags;
-use crate::args::FmtConfig;
-use crate::args::LintConfig;
+use crate::args::FmtOptions;
+use crate::args::LintOptions;
use crate::args::TsConfig;
use crate::cache::DenoDir;
use crate::file_fetcher::get_source_from_data_url;
@@ -122,14 +122,14 @@ pub struct Inner {
/// An optional configuration file which has been specified in the client
/// options.
maybe_config_file: Option<ConfigFile>,
- /// An optional configuration for formatter which has been taken from specified config file.
- maybe_fmt_config: Option<FmtConfig>,
/// An optional import map which is used to resolve modules.
pub maybe_import_map: Option<Arc<ImportMap>>,
/// The URL for the import map which is used to determine relative imports.
maybe_import_map_uri: Option<Url>,
+ /// Configuration for formatter which has been taken from specified config file.
+ fmt_options: FmtOptions,
/// An optional configuration for linter which has been taken from specified config file.
- pub maybe_lint_config: Option<LintConfig>,
+ lint_options: LintOptions,
/// A lazily create "server" for handling test run requests.
maybe_testing_server: Option<testing::TestServer>,
/// Resolver for npm packages.
@@ -347,8 +347,8 @@ impl Inner {
maybe_config_file: None,
maybe_import_map: None,
maybe_import_map_uri: None,
- maybe_lint_config: None,
- maybe_fmt_config: None,
+ fmt_options: Default::default(),
+ lint_options: Default::default(),
maybe_testing_server: None,
module_registries,
module_registries_location,
@@ -713,26 +713,30 @@ impl Inner {
fn update_config_file(&mut self) -> Result<(), AnyError> {
self.maybe_config_file = None;
- self.maybe_fmt_config = None;
- self.maybe_lint_config = None;
+ self.fmt_options = Default::default();
+ self.lint_options = Default::default();
if let Some(config_file) = self.get_config_file()? {
- let lint_config = config_file
+ let lint_options = config_file
.to_lint_config()
+ .and_then(|maybe_lint_config| {
+ LintOptions::resolve(maybe_lint_config, None)
+ })
.map_err(|err| {
anyhow!("Unable to update lint configuration: {:?}", err)
- })?
- .unwrap_or_default();
- let fmt_config = config_file
+ })?;
+ let fmt_options = config_file
.to_fmt_config()
+ .and_then(|maybe_fmt_config| {
+ FmtOptions::resolve(maybe_fmt_config, None)
+ })
.map_err(|err| {
anyhow!("Unable to update formatter configuration: {:?}", err)
- })?
- .unwrap_or_default();
+ })?;
self.maybe_config_file = Some(config_file);
- self.maybe_lint_config = Some(lint_config);
- self.maybe_fmt_config = Some(fmt_config);
+ self.lint_options = lint_options;
+ self.fmt_options = fmt_options;
}
Ok(())
@@ -1196,19 +1200,14 @@ impl Inner {
LspError::invalid_request()
})?;
- let fmt_options = if let Some(fmt_config) = self.maybe_fmt_config.as_ref() {
- // skip formatting any files ignored by the config file
- if !fmt_config.files.matches_specifier(&specifier) {
- return Ok(None);
- }
- fmt_config.options.clone()
- } else {
- Default::default()
- };
+ // skip formatting any files ignored by the config file
+ if !self.fmt_options.files.matches_specifier(&specifier) {
+ return Ok(None);
+ }
let format_result = match document.maybe_parsed_source() {
Some(Ok(parsed_source)) => {
- format_parsed_source(&parsed_source, fmt_options)
+ format_parsed_source(&parsed_source, &self.fmt_options.options)
}
Some(Err(err)) => Err(anyhow!("{}", err)),
None => {
@@ -1221,7 +1220,7 @@ impl Inner {
.map(|ext| file_path.with_extension(ext))
.unwrap_or(file_path);
// it's not a js/ts file, so attempt to format its contents
- format_file(&file_path, &document.content(), &fmt_options)
+ format_file(&file_path, &document.content(), &self.fmt_options.options)
}
};
@@ -2521,7 +2520,7 @@ impl Inner {
let snapshot = (
self.snapshot(),
self.config.snapshot(),
- self.maybe_lint_config.clone(),
+ self.lint_options.clone(),
);
if let Err(err) = self.diagnostics_server.update(snapshot) {
error!("Cannot update diagnostics: {}", err);