Skip to content
Merged
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
12 changes: 2 additions & 10 deletions crates/oxc_language_server/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,7 @@ impl LanguageServer for Backend {
}

if let Some(diagnostics) = diagnostics {
for (uri, reports) in &diagnostics.pin() {
new_diagnostics.push((
uri.clone(),
reports.iter().map(|d| d.diagnostic.clone()).collect(),
));
}
new_diagnostics.extend(diagnostics);
}

if let Some(watchers) = watchers
Expand Down Expand Up @@ -412,10 +407,7 @@ impl LanguageServer for Backend {
continue;
};

for (uri, reports) in &diagnostics.pin() {
all_diagnostics
.push((uri.clone(), reports.iter().map(|d| d.diagnostic.clone()).collect()));
}
all_diagnostics.extend(diagnostics);
}

if !all_diagnostics.is_empty() {
Expand Down
20 changes: 11 additions & 9 deletions crates/oxc_language_server/src/linter/server_linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use log::{debug, warn};
use oxc_linter::{AllowWarnDeny, LintIgnoreMatcher};
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
use tokio::sync::Mutex;
use tower_lsp_server::lsp_types::Uri;
use tower_lsp_server::lsp_types::{Diagnostic, Uri};

use oxc_linter::{
Config, ConfigStore, ConfigStoreBuilder, ExternalPluginStore, LintOptions, Oxlintrc,
Expand Down Expand Up @@ -283,17 +283,19 @@ impl ServerLinter {
.collect()
}

pub async fn revalidate_diagnostics(
&self,
uris: Vec<Uri>,
) -> ConcurrentHashMap<String, Vec<DiagnosticReport>> {
let map = ConcurrentHashMap::default();
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(diagnostics) = self.run_single(&uri, None, ServerLinterRun::Always).await {
map.pin().insert(uri.to_string(), diagnostics);
if let Some(file_diagnostic) =
self.run_single(&uri, None, ServerLinterRun::Always).await
{
diagnostics.push((
uri.to_string(),
file_diagnostic.into_iter().map(|d| d.diagnostic).collect(),
));
}
}
map
diagnostics
}

fn is_ignored(&self, uri: &Uri) -> bool {
Expand Down
13 changes: 5 additions & 8 deletions crates/oxc_language_server/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tower_lsp_server::{
};

use crate::{
ConcurrentHashMap, FORMAT_CONFIG_FILE,
FORMAT_CONFIG_FILE,
code_actions::{apply_all_fix_code_action, apply_fix_code_actions, fix_all_text_edit},
formatter::{options::FormatOptions, server_formatter::ServerFormatter},
linter::{
Expand Down Expand Up @@ -215,12 +215,9 @@ impl WorkspaceWorker {

/// Revalidate diagnostics for the given URIs
/// This will re-lint all opened files and return the new diagnostics
async fn revalidate_diagnostics(
&self,
uris: Vec<Uri>,
) -> ConcurrentHashMap<String, Vec<DiagnosticReport>> {
async fn revalidate_diagnostics(&self, uris: Vec<Uri>) -> Vec<(String, Vec<Diagnostic>)> {
let Some(server_linter) = &*self.server_linter.read().await else {
return ConcurrentHashMap::default();
return Vec::new();
};

server_linter.revalidate_diagnostics(uris).await
Expand Down Expand Up @@ -319,7 +316,7 @@ impl WorkspaceWorker {
pub async fn did_change_watched_files(
&self,
_file_event: &FileEvent,
) -> Option<ConcurrentHashMap<String, Vec<DiagnosticReport>>> {
) -> Option<Vec<(String, Vec<Diagnostic>)>> {
// TODO: the tools should implement a helper function to detect if the changed file is relevant
let files = {
let server_linter_guard = self.server_linter.read().await;
Expand Down Expand Up @@ -348,7 +345,7 @@ impl WorkspaceWorker {
changed_options: &Options,
) -> (
// Diagnostic reports that need to be revalidated
Option<ConcurrentHashMap<String, Vec<DiagnosticReport>>>,
Option<Vec<(String, Vec<Diagnostic>)>>,
// File system watcher for lint/fmt config changes
// - `None` if no watcher changes are needed
// - empty vector if all watchers should be removed
Expand Down
Loading