Skip to content

Commit 73da317

Browse files
committed
refactor(oxlint/lsp): use fs as param in TsGoLintState, instead of source text (#16667)
In the future, the language server wants to lint multiple files at the same time. Refactored the code to accept the RuntimeFS (like the CLI tool) for reading the source text.
1 parent 26da85e commit 73da317

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

crates/oxc_language_server/src/linter/isolated_lint_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl IsolatedLintHandler {
125125

126126
let mut messages: Vec<DiagnosticReport> = self
127127
.runner
128-
.run_source(&Arc::from(path.as_os_str()), source_text.to_string(), &fs)
128+
.run_source(&Arc::from(path.as_os_str()), &fs)
129129
.into_iter()
130130
.map(|message| message_to_lsp_diagnostic(message, uri, source_text, rope))
131131
.collect();

crates/oxc_linter/src/lint_runner.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,13 @@ impl LintRunner {
236236
pub fn run_source(
237237
&self,
238238
file: &Arc<OsStr>,
239-
source_text: String,
240239
file_system: &(dyn crate::RuntimeFileSystem + Sync + Send),
241240
) -> Vec<Message> {
242241
let mut messages = self.lint_service.run_source(file_system, vec![Arc::clone(file)]);
243242

244243
if let Some(type_aware_linter) = &self.type_aware_linter {
245244
let tsgo_messages =
246-
match type_aware_linter.lint_source(file, source_text, self.directives_store.map())
245+
match type_aware_linter.lint_source(file, file_system, self.directives_store.map())
247246
{
248247
Ok(msgs) => msgs,
249248
Err(err) => {

crates/oxc_linter/src/tsgolint.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{
66
sync::{Arc, Mutex},
77
};
88

9+
use oxc_allocator::Allocator;
910
use rustc_hash::FxHashMap;
1011
use serde::{Deserialize, Serialize};
1112

@@ -320,12 +321,20 @@ impl TsGoLintState {
320321
pub fn lint_source(
321322
&self,
322323
path: &Arc<OsStr>,
323-
source_text: String,
324+
file_system: &(dyn crate::RuntimeFileSystem + Sync + Send),
324325
disable_directives_map: Arc<Mutex<FxHashMap<PathBuf, DisableDirectives>>>,
325326
) -> Result<Vec<Message>, String> {
326327
let mut resolved_configs: FxHashMap<PathBuf, ResolvedLinterState> = FxHashMap::default();
327328
let mut source_overrides = FxHashMap::default();
328-
source_overrides.insert(path.to_string_lossy().to_string(), source_text.clone());
329+
let allocator = Allocator::default();
330+
let Ok(source_text) = file_system.read_to_arena_str(Path::new(path.as_ref()), &allocator)
331+
else {
332+
return Err(format!("Failed to read source text for file: {}", path.to_string_lossy()));
333+
};
334+
335+
// Clone source_text to own it for the spawned thread
336+
let source_text_owned = source_text.to_string();
337+
source_overrides.insert(path.to_string_lossy().to_string(), source_text_owned.clone());
329338

330339
let json_input = self.json_input(
331340
std::slice::from_ref(path),
@@ -383,7 +392,7 @@ impl TsGoLintState {
383392

384393
let mut message = Message::from_tsgo_lint_diagnostic(
385394
tsgolint_diagnostic,
386-
&source_text,
395+
&source_text_owned,
387396
);
388397

389398
message.error.severity = if severity == AllowWarnDeny::Deny {

0 commit comments

Comments
 (0)