Skip to content

Commit 2b4068c

Browse files
committed
fix: cleanup
1 parent 2647dde commit 2b4068c

File tree

6 files changed

+24
-16
lines changed

6 files changed

+24
-16
lines changed

crates/oxc_language_server/src/linter/isolated_lint_handler.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ use log::{debug, info};
77
use oxc_data_structures::rope::Rope;
88
use rustc_hash::FxHashSet;
99
use tower_lsp_server::{UriExt, lsp_types::Uri};
10+
use std::collections::HashMap;
11+
use oxc_linter::read_to_string;
1012

1113
use oxc_allocator::Allocator;
1214
use oxc_linter::{
1315
AllowWarnDeny, ConfigStore, DirectivesStore, DisableDirectives, Fix, LINTABLE_EXTENSIONS,
1416
LintOptions, LintService, LintServiceOptions, Linter, Message, PossibleFixes, RuleCommentType,
15-
RuntimeFileSystem, read_to_arena_str, read_to_string,
17+
RuntimeFileSystem, read_to_arena_str
1618
};
1719

1820
use super::error_with_position::{
@@ -142,9 +144,6 @@ impl IsolatedLintHandler {
142144
/// Batch lint multiple paths using the underlying parallel runtime.
143145
/// Returns a vector of (Uri, DiagnosticReport list). Ignores non-lintable paths silently.
144146
pub fn run_workspace(&mut self, paths: &[PathBuf]) -> Vec<(Uri, Vec<DiagnosticReport>)> {
145-
use oxc_data_structures::rope::Rope;
146-
use oxc_linter::read_to_string;
147-
use std::collections::HashMap;
148147

149148

150149
// Filter to lintable extensions first.

crates/oxc_language_server/src/log_bridge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl log::Log for LspForwardingLogger {
3434
log::Level::Info => MessageType::INFO,
3535
_ => MessageType::LOG,
3636
};
37-
let _ = client.log_message(level, format!("{}", record.args()));
37+
let _ = client.log_message(level, record.args().to_string());
3838
}
3939
// Always emit via fallback (stdout/stderr formatting, filtering, etc.).
4040
self.fallback.log(record);

crates/oxc_language_server/src/worker.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,10 @@ impl WorkspaceWorker {
586586
// Extract, sort deterministically.
587587
let mut files: Vec<Uri> = match collected.lock() {
588588
Ok(guard) => guard.clone(),
589-
Err(poisoned) => poisoned.into_inner().clone(),
589+
Err(poisoned) => {
590+
log::warn!("Poisoned mutex encountered while collecting workspace files. Recovering inner value.");
591+
poisoned.into_inner().clone()
592+
},
590593
};
591594
files.sort_unstable_by(|a, b| a.as_str().cmp(b.as_str()));
592595
debug!(

crates/oxc_linter/src/tsgolint.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,13 @@ impl TsGoLintState {
353353
} else if let Some(st) = source_text_cache.get(&path) {
354354
st
355355
} else {
356-
let st = read_to_string(&path).unwrap_or_default();
356+
let st = match read_to_string(&path) {
357+
Ok(content) => content,
358+
Err(e) => {
359+
eprintln!("Failed to read file '{}': {}", path.display(), e);
360+
String::new()
361+
}
362+
};
357363
source_text_cache.insert(path.clone(), st);
358364
source_text_cache.get(&path).unwrap()
359365
};

editors/vscode/client/extension.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
ExecuteCommandRequest,
1717
MessageType,
1818
ShowMessageNotification,
19+
State,
1920
} from 'vscode-languageclient';
2021

2122
import { Executable, LanguageClient, LanguageClientOptions, ServerOptions, StreamInfo } from 'vscode-languageclient/node';
@@ -29,6 +30,8 @@ const languageClientName = 'oxc';
2930
const outputChannelName = 'Oxc';
3031
const commandPrefix = 'oxc';
3132

33+
const RESTART_DELAY_MS = 50;
34+
3235
const enum OxcCommands {
3336
RestartServer = `${commandPrefix}.restartServer`,
3437
ApplyAllFixesFile = `${commandPrefix}.applyAllFixesFile`,
@@ -63,13 +66,9 @@ export async function activate(context: ExtensionContext) {
6366
}
6467

6568
try {
66-
// Guard against invoking restart while the client is in a transitional state.
67-
// The languageclient exposes isRunning(), but we can also infer starting/stopping
68-
// via internal state; here we only act if it is fully running or fully stopped.
69-
// If starting, we bail out with a message to avoid race with initialize.
70-
// Access internal _state (not part of public API) for finer grained restart guarding.
71-
const state: string | undefined = (client as any)._state;
72-
if (state === 'starting') {
69+
70+
const state = (client as LanguageClient)?.state;
71+
if (state === State.Starting) {
7372
window.showWarningMessage('oxc server is still starting; try restart again in a moment.');
7473
return;
7574
}
@@ -80,7 +79,7 @@ export async function activate(context: ExtensionContext) {
8079
if (externalSocketSpec) {
8180
// External socket: stop sends shutdown/exit internally; wait a tick for server loop.
8281
await client.stop();
83-
await new Promise(r => setTimeout(r, 50));
82+
await new Promise(r => setTimeout(r, RESTART_DELAY_MS));
8483
await client.start();
8584
} else {
8685
// Spawned process: restart() is sufficient, but guard against transitional state.
@@ -217,7 +216,7 @@ export async function activate(context: ExtensionContext) {
217216
socket.on('error', (err) => {
218217
socket.destroy();
219218
if (attempt < maxAttempts) {
220-
const delay = baseDelayMs * Math.pow(2, attempt - 1);
219+
const delay = baseDelayMs * (2 ** (attempt - 1));
221220
outputChannel.info(`Language server not ready (attempt ${attempt}/${maxAttempts}). Retrying in ${delay}ms...`);
222221
setTimeout(tryConnect, delay);
223222
} else {

external/tsgolint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 1a61b63a8b59d6f76269bc32d8a9254cf88751c1

0 commit comments

Comments
 (0)