summaryrefslogtreecommitdiff
path: root/cli/lsp
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp')
-rw-r--r--cli/lsp/analysis.rs7
-rw-r--r--cli/lsp/diagnostics.rs37
-rw-r--r--cli/lsp/language_server.rs57
-rw-r--r--cli/lsp/testing/execution.rs9
4 files changed, 58 insertions, 52 deletions
diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs
index e436dc91a..ddad05ee3 100644
--- a/cli/lsp/analysis.rs
+++ b/cli/lsp/analysis.rs
@@ -5,9 +5,7 @@ use super::documents::Documents;
use super::language_server;
use super::tsc;
-use crate::args::LintConfig;
use crate::tools::lint::create_linter;
-use crate::tools::lint::get_configured_rules;
use deno_ast::SourceRange;
use deno_ast::SourceRangedForSpanned;
@@ -18,10 +16,12 @@ use deno_core::error::AnyError;
use deno_core::serde::Deserialize;
use deno_core::serde_json::json;
use deno_core::ModuleSpecifier;
+use deno_lint::rules::LintRule;
use once_cell::sync::Lazy;
use regex::Regex;
use std::cmp::Ordering;
use std::collections::HashMap;
+use std::sync::Arc;
use tower_lsp::lsp_types as lsp;
use tower_lsp::lsp_types::Position;
use tower_lsp::lsp_types::Range;
@@ -127,9 +127,8 @@ fn as_lsp_range(range: &deno_lint::diagnostic::Range) -> Range {
pub fn get_lint_references(
parsed_source: &deno_ast::ParsedSource,
- maybe_lint_config: Option<&LintConfig>,
+ lint_rules: Vec<Arc<dyn LintRule>>,
) -> Result<Vec<Reference>, AnyError> {
- let lint_rules = get_configured_rules(maybe_lint_config, None, None, None)?;
let linter = create_linter(parsed_source.media_type(), lint_rules);
let lint_diagnostics = linter.lint_with_ast(parsed_source);
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs
index c52bde790..605bd85ac 100644
--- a/cli/lsp/diagnostics.rs
+++ b/cli/lsp/diagnostics.rs
@@ -12,8 +12,9 @@ use super::performance::Performance;
use super::tsc;
use super::tsc::TsServer;
-use crate::args::LintConfig;
+use crate::args::LintOptions;
use crate::npm::NpmPackageReference;
+use crate::tools::lint::get_configured_rules;
use deno_ast::MediaType;
use deno_core::anyhow::anyhow;
@@ -24,6 +25,7 @@ use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::ModuleSpecifier;
use deno_graph::Resolved;
+use deno_lint::rules::LintRule;
use deno_runtime::tokio_util::create_basic_runtime;
use log::error;
use std::collections::HashMap;
@@ -36,7 +38,7 @@ use tokio_util::sync::CancellationToken;
use tower_lsp::lsp_types as lsp;
pub type SnapshotForDiagnostics =
- (Arc<StateSnapshot>, Arc<ConfigSnapshot>, Option<LintConfig>);
+ (Arc<StateSnapshot>, Arc<ConfigSnapshot>, LintOptions);
pub type DiagnosticRecord =
(ModuleSpecifier, Option<i32>, Vec<lsp::Diagnostic>);
pub type DiagnosticVec = Vec<DiagnosticRecord>;
@@ -198,7 +200,7 @@ impl DiagnosticsServer {
match rx.recv().await {
// channel has closed
None => break,
- Some((snapshot, config, maybe_lint_config)) => {
+ Some((snapshot, config, lint_options)) => {
// cancel the previous run
token.cancel();
token = CancellationToken::new();
@@ -300,7 +302,7 @@ impl DiagnosticsServer {
let diagnostics = generate_lint_diagnostics(
&snapshot,
&config,
- maybe_lint_config,
+ &lint_options,
token.clone(),
)
.await;
@@ -443,12 +445,12 @@ fn ts_json_to_diagnostics(
async fn generate_lint_diagnostics(
snapshot: &language_server::StateSnapshot,
config: &ConfigSnapshot,
- maybe_lint_config: Option<LintConfig>,
+ lint_options: &LintOptions,
token: CancellationToken,
) -> DiagnosticVec {
let documents = snapshot.documents.documents(true, true);
let workspace_settings = config.settings.workspace.clone();
-
+ let lint_rules = get_configured_rules(lint_options.rules.clone());
let mut diagnostics_vec = Vec::new();
if workspace_settings.lint {
for document in documents {
@@ -470,7 +472,8 @@ async fn generate_lint_diagnostics(
version,
generate_document_lint_diagnostics(
config,
- &maybe_lint_config,
+ lint_options,
+ lint_rules.clone(),
&document,
),
));
@@ -481,23 +484,21 @@ async fn generate_lint_diagnostics(
fn generate_document_lint_diagnostics(
config: &ConfigSnapshot,
- maybe_lint_config: &Option<LintConfig>,
+ lint_options: &LintOptions,
+ lint_rules: Vec<Arc<dyn LintRule>>,
document: &Document,
) -> Vec<lsp::Diagnostic> {
if !config.specifier_enabled(document.specifier()) {
return Vec::new();
}
- if let Some(lint_config) = &maybe_lint_config {
- if !lint_config.files.matches_specifier(document.specifier()) {
- return Vec::new();
- }
+ if !lint_options.files.matches_specifier(document.specifier()) {
+ return Vec::new();
}
match document.maybe_parsed_source() {
Some(Ok(parsed_source)) => {
- if let Ok(references) = analysis::get_lint_references(
- &parsed_source,
- maybe_lint_config.as_ref(),
- ) {
+ if let Ok(references) =
+ analysis::get_lint_references(&parsed_source, lint_rules)
+ {
references
.into_iter()
.map(|r| r.to_diagnostic())
@@ -1080,7 +1081,7 @@ let c: number = "a";
let diagnostics = generate_lint_diagnostics(
&snapshot,
&enabled_config,
- None,
+ &Default::default(),
Default::default(),
)
.await;
@@ -1121,7 +1122,7 @@ let c: number = "a";
let diagnostics = generate_lint_diagnostics(
&snapshot,
&disabled_config,
- None,
+ &Default::default(),
Default::default(),
)
.await;
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);
diff --git a/cli/lsp/testing/execution.rs b/cli/lsp/testing/execution.rs
index a498df857..28f15a7ce 100644
--- a/cli/lsp/testing/execution.rs
+++ b/cli/lsp/testing/execution.rs
@@ -35,6 +35,7 @@ use deno_runtime::tokio_util::run_local;
use indexmap::IndexMap;
use std::collections::HashMap;
use std::collections::HashSet;
+use std::num::NonZeroUsize;
use std::sync::Arc;
use std::time::Duration;
use std::time::Instant;
@@ -273,7 +274,13 @@ impl TestRun {
let (concurrent_jobs, fail_fast) =
if let DenoSubcommand::Test(test_flags) = ps.options.sub_command() {
- (test_flags.concurrent_jobs.into(), test_flags.fail_fast)
+ (
+ test_flags
+ .concurrent_jobs
+ .unwrap_or_else(|| NonZeroUsize::new(1).unwrap())
+ .into(),
+ test_flags.fail_fast,
+ )
} else {
unreachable!("Should always be Test subcommand.");
};