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
59 changes: 38 additions & 21 deletions crates/oxc_language_server/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,33 @@ impl WorkspaceWorker {
uri: &Uri,
content: Option<String>,
) -> Option<Vec<DiagnosticReport>> {
if self.is_ignored(uri).await {
return None;
let diagnostics = self.lint_file_internal(uri, content).await;

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

Some(self.update_diagnostics(uri, content).await)
diagnostics
}

async fn update_diagnostics(
async fn lint_file_internal(
&self,
uri: &Uri,
content: Option<String>,
) -> Vec<DiagnosticReport> {
let diagnostics = self.server_linter.read().await.run_single(uri, content);
if let Some(diagnostics) = diagnostics {
self.diagnostics_report_map
.read()
.await
.pin()
.insert(uri.to_string(), diagnostics.clone());

return diagnostics;
) -> Option<Vec<DiagnosticReport>> {
if self.is_ignored(uri).await {
return None;
}

vec![]
self.server_linter.read().await.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());
}

async fn revalidate_diagnostics(&self) -> ConcurrentHashMap<String, Vec<DiagnosticReport>> {
Expand Down Expand Up @@ -160,11 +163,18 @@ impl WorkspaceWorker {
is_source_fix_all_oxc: bool,
) -> Vec<CodeActionOrCommand> {
let report_map = self.diagnostics_report_map.read().await;
let report_map_ref = report_map.pin();
let Some(value) = report_map_ref.get(&uri.to_string()) else {
return vec![];
let report_map_ref = 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
// we just internally lint and provide the code actions / commands without refreshing the diagnostic map.
None => &self.lint_file_internal(uri, None).await.unwrap_or_default(),
};

if value.is_empty() {
return vec![];
}

let reports = value
.iter()
.filter(|r| r.diagnostic.range == *range || range_overlaps(*range, r.diagnostic.range));
Expand Down Expand Up @@ -194,11 +204,18 @@ 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();
let Some(value) = report_map_ref.get(&uri.to_string()) else {
return vec![];
let report_map_ref = 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
// we just internally lint and provide the code actions / commands without refreshing the diagnostic map.
None => &self.lint_file_internal(uri, None).await.unwrap_or_default(),
};

if value.is_empty() {
return vec![];
}

let mut text_edits = vec![];

for report in value {
Expand Down
2 changes: 1 addition & 1 deletion editors/vscode/client/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ suite('code actions', () => {
});

await workspace.applyEdit(edit);
await window.showTextDocument(fileUri);
// await window.showTextDocument(fileUri); -- should also work without opening the file

const codeActions: ProviderResult<Array<CodeAction>> = await commands.executeCommand(
'vscode.executeCodeActionProvider',
Expand Down
Loading