Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

18 changes: 12 additions & 6 deletions crates/oxc_language_server/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
code_actions::CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC,
commands::{FIX_ALL_COMMAND_ID, FixAllCommandArgs},
file_system::LSPFileSystem,
linter::server_linter::ServerLinterRun,
linter::options::Run,
options::{Options, WorkspaceOption},
worker::WorkspaceWorker,
};
Expand Down Expand Up @@ -488,7 +488,11 @@ impl LanguageServer for Backend {
self.file_system.write().await.remove(uri);
}

if let Some(diagnostics) = worker.lint_file(uri, None, ServerLinterRun::OnSave).await {
if !worker.should_lint_on_run_type(Run::OnSave).await {
return;
}

if let Some(diagnostics) = worker.lint_file(uri, None).await {
self.client
.publish_diagnostics(
uri.clone(),
Expand Down Expand Up @@ -516,7 +520,11 @@ impl LanguageServer for Backend {
self.file_system.write().await.set(uri, content.to_string());
}

if let Some(diagnostics) = worker.lint_file(uri, content, ServerLinterRun::OnType).await {
if !worker.should_lint_on_run_type(Run::OnType).await {
return;
}

if let Some(diagnostics) = worker.lint_file(uri, content).await {
self.client
.publish_diagnostics(
uri.clone(),
Expand Down Expand Up @@ -544,9 +552,7 @@ impl LanguageServer for Backend {
self.file_system.write().await.set(uri, content.to_string());
}

if let Some(diagnostics) =
worker.lint_file(uri, Some(content), ServerLinterRun::Always).await
{
if let Some(diagnostics) = worker.lint_file(uri, Some(content)).await {
self.client
.publish_diagnostics(
uri.clone(),
Expand Down
99 changes: 2 additions & 97 deletions crates/oxc_language_server/src/linter/server_linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,17 @@ use crate::linter::options::UnusedDisableDirectives;
use crate::linter::{
error_with_position::DiagnosticReport,
isolated_lint_handler::{IsolatedLintHandler, IsolatedLintHandlerOptions},
options::{LintOptions as LSPLintOptions, Run},
options::LintOptions as LSPLintOptions,
};
use crate::utils::normalize_path;
use crate::{ConcurrentHashMap, LINT_CONFIG_FILE};

use super::config_walker::ConfigWalker;

#[derive(Debug, PartialEq, Eq)]
pub enum ServerLinterRun {
OnType,
OnSave,
Always,
}

impl ServerLinterRun {
fn matches(&self, run: Run) -> bool {
matches!(
(self, run),
(ServerLinterRun::OnType, Run::OnType)
| (ServerLinterRun::OnSave, Run::OnSave)
| (ServerLinterRun::Always, _)
)
}
}

pub struct ServerLinter {
isolated_linter: Arc<Mutex<IsolatedLintHandler>>,
ignore_matcher: LintIgnoreMatcher,
gitignore_glob: Vec<Gitignore>,
lint_on_run: Run,
diagnostics: ServerLinterDiagnostics,
extended_paths: FxHashSet<PathBuf>,
}
Expand Down Expand Up @@ -172,7 +153,6 @@ impl ServerLinter {
),
gitignore_glob: Self::create_ignore_glob(&root_path),
extended_paths,
lint_on_run: options.run,
diagnostics: ServerLinterDiagnostics::default(),
}
}
Expand Down Expand Up @@ -280,9 +260,7 @@ impl ServerLinter {
pub async fn revalidate_diagnostics(&self, uris: Vec<Uri>) -> Vec<(String, Vec<Diagnostic>)> {
let mut diagnostics = Vec::with_capacity(uris.len());
for uri in uris {
if let Some(file_diagnostic) =
self.run_single(&uri, None, ServerLinterRun::Always).await
{
if let Some(file_diagnostic) = self.run_single(&uri, None).await {
diagnostics.push((
uri.to_string(),
file_diagnostic.into_iter().map(|d| d.diagnostic).collect(),
Expand Down Expand Up @@ -318,15 +296,7 @@ impl ServerLinter {
&self,
uri: &Uri,
content: Option<String>,
run_type: ServerLinterRun,
) -> Option<Vec<DiagnosticReport>> {
let run = matches!(run_type, ServerLinterRun::Always) || run_type.matches(self.lint_on_run);

// return `None` when both tools do not want to be used
if !run {
return None;
}

if self.is_ignored(uri) {
return None;
}
Expand Down Expand Up @@ -461,71 +431,6 @@ mod test {
assert!(result_empty.is_none());
}

#[test]
#[cfg(not(target_endian = "big"))]
fn test_lint_on_run_on_type_on_type() {
Tester::new(
"fixtures/linter/lint_on_run/on_type",
Some(LintOptions {
type_aware: true,
run: Run::OnType,
fix_kind: LintFixKindFlag::All,
..Default::default()
}),
)
.test_and_snapshot_single_file_with_run_type("on-type.ts", Run::OnType);
}

#[test]
#[cfg(not(target_endian = "big"))]
fn test_lint_on_run_on_save_on_save() {
Tester::new(
"fixtures/linter/lint_on_run/on_save",
Some(LintOptions {
type_aware: true,
run: Run::OnType,
fix_kind: LintFixKindFlag::All,
..Default::default()
}),
)
.test_and_snapshot_single_file_with_run_type("on-save.ts", Run::OnSave);
}

#[test]
#[cfg(not(target_endian = "big"))]
fn test_lint_on_run_on_save_on_type() {
Tester::new(
"fixtures/linter/lint_on_run/on_save",
Some(LintOptions { type_aware: true, run: Run::OnSave, ..Default::default() }),
)
.test_and_snapshot_single_file_with_run_type("on-type.ts", Run::OnType);
}

#[test]
#[cfg(not(target_endian = "big"))]
fn test_lint_on_run_on_type_on_save() {
Tester::new(
"fixtures/linter/lint_on_run/on_save",
Some(LintOptions {
type_aware: true,
run: Run::OnType,
fix_kind: LintFixKindFlag::All,
..Default::default()
}),
)
.test_and_snapshot_single_file_with_run_type("on-save.ts", Run::OnSave);
}

#[test]
#[cfg(not(target_endian = "big"))]
fn test_lint_on_run_on_type_on_save_without_type_aware() {
Tester::new(
"fixtures/linter/lint_on_run/on_type",
Some(LintOptions { type_aware: false, run: Run::OnType, ..Default::default() }),
)
.test_and_snapshot_single_file_with_run_type("on-save-no-type-aware.ts", Run::OnSave);
}

#[test]
fn test_no_errors() {
Tester::new("fixtures/linter/no_errors", None)
Expand Down
7 changes: 0 additions & 7 deletions crates/oxc_language_server/src/snapshots/[email protected]

This file was deleted.

7 changes: 0 additions & 7 deletions crates/oxc_language_server/src/snapshots/[email protected]

This file was deleted.

This file was deleted.

Loading
Loading