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
4 changes: 2 additions & 2 deletions crates/oxc_language_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl LanguageServer for Backend {
let Some(worker) = workers.iter().find(|worker| worker.is_responsible_for_uri(uri)) else {
return;
};
worker.remove_diagnostics(&params.text_document.uri).await;
worker.remove_diagnostics(&params.text_document.uri);
}

async fn code_action(&self, params: CodeActionParams) -> Result<Option<CodeActionResponse>> {
Expand Down Expand Up @@ -448,7 +448,7 @@ impl Backend {
async fn clear_all_diagnostics(&self) {
let mut cleared_diagnostics = vec![];
for worker in self.workspace_workers.lock().await.iter() {
cleared_diagnostics.extend(worker.get_clear_diagnostics().await);
cleared_diagnostics.extend(worker.get_clear_diagnostics());
}
self.publish_all_diagnostics(&cleared_diagnostics).await;
}
Expand Down
40 changes: 17 additions & 23 deletions crates/oxc_language_server/src/worker.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{str::FromStr, vec};
use std::{str::FromStr, sync::Arc, vec};

use log::debug;
use rustc_hash::FxBuildHasher;
Expand All @@ -20,7 +20,7 @@ use crate::{
pub struct WorkspaceWorker {
root_uri: Uri,
server_linter: RwLock<Option<ServerLinter>>,
diagnostics_report_map: RwLock<ConcurrentHashMap<String, Vec<DiagnosticReport>>>,
diagnostics_report_map: Arc<ConcurrentHashMap<String, Vec<DiagnosticReport>>>,
options: Mutex<Options>,
}

Expand All @@ -29,7 +29,7 @@ impl WorkspaceWorker {
Self {
root_uri,
server_linter: RwLock::new(None),
diagnostics_report_map: RwLock::new(ConcurrentHashMap::default()),
diagnostics_report_map: Arc::new(ConcurrentHashMap::default()),
options: Mutex::new(Options::default()),
}
}
Expand All @@ -54,8 +54,8 @@ impl WorkspaceWorker {
self.server_linter.read().await.is_none()
}

pub async fn remove_diagnostics(&self, uri: &Uri) {
self.diagnostics_report_map.read().await.pin().remove(&uri.to_string());
pub fn remove_diagnostics(&self, uri: &Uri) {
self.diagnostics_report_map.pin().remove(&uri.to_string());
}

async fn refresh_server_linter(&self) {
Expand Down Expand Up @@ -85,7 +85,7 @@ impl WorkspaceWorker {
let diagnostics = self.lint_file_internal(uri, content).await;

if let Some(diagnostics) = &diagnostics {
self.update_diagnostics(uri, diagnostics).await;
self.update_diagnostics(uri, diagnostics);
}

diagnostics
Expand All @@ -103,40 +103,36 @@ impl WorkspaceWorker {
server_linter.run_single(uri, content)
}

async fn update_diagnostics(&self, uri: &Uri, diagnostics: &[DiagnosticReport]) {
self.diagnostics_report_map
.read()
.await
.pin()
.insert(uri.to_string(), diagnostics.to_owned());
fn update_diagnostics(&self, uri: &Uri, diagnostics: &[DiagnosticReport]) {
self.diagnostics_report_map.pin().insert(uri.to_string(), diagnostics.to_owned());
}

async fn revalidate_diagnostics(&self) -> ConcurrentHashMap<String, Vec<DiagnosticReport>> {
let diagnostics_map = ConcurrentHashMap::with_capacity_and_hasher(
self.diagnostics_report_map.read().await.len(),
self.diagnostics_report_map.len(),
FxBuildHasher,
);
let server_linter = self.server_linter.read().await;
let Some(server_linter) = &*server_linter else {
debug!("no server_linter initialized in the worker");
return diagnostics_map;
};
for uri in self.diagnostics_report_map.read().await.pin().keys() {

for uri in self.diagnostics_report_map.pin_owned().keys() {
if let Some(diagnostics) = server_linter.run_single(&Uri::from_str(uri).unwrap(), None)
{
self.diagnostics_report_map.pin().insert(uri.clone(), diagnostics.clone());
diagnostics_map.pin().insert(uri.clone(), diagnostics);
} else {
self.diagnostics_report_map.pin().remove(uri);
}
}

*self.diagnostics_report_map.write().await = diagnostics_map.clone();

diagnostics_map
}

pub async fn get_clear_diagnostics(&self) -> Vec<(String, Vec<Diagnostic>)> {
pub fn get_clear_diagnostics(&self) -> Vec<(String, Vec<Diagnostic>)> {
self.diagnostics_report_map
.read()
.await
.pin()
.keys()
.map(|uri| (uri.clone(), vec![]))
Expand All @@ -149,8 +145,7 @@ impl WorkspaceWorker {
range: &Range,
is_source_fix_all_oxc: bool,
) -> Vec<CodeActionOrCommand> {
let report_map = self.diagnostics_report_map.read().await;
let report_map_ref = report_map.pin_owned();
let report_map_ref = self.diagnostics_report_map.pin_owned();
let value = match report_map_ref.get(&uri.to_string()) {
Some(value) => value,
// code actions / commands can be requested without opening the file
Expand Down Expand Up @@ -190,8 +185,7 @@ impl WorkspaceWorker {
}

pub async fn get_diagnostic_text_edits(&self, uri: &Uri) -> Vec<TextEdit> {
let report_map = self.diagnostics_report_map.read().await;
let report_map_ref = report_map.pin_owned();
let report_map_ref = self.diagnostics_report_map.pin_owned();
let value = match report_map_ref.get(&uri.to_string()) {
Some(value) => value,
// code actions / commands can be requested without opening the file
Expand Down
Loading