From 845c6de1c9424050f1eca830c39ab3d68ae8031a Mon Sep 17 00:00:00 2001 From: Sysix <3897725+Sysix@users.noreply.github.com> Date: Mon, 18 Aug 2025 20:11:19 +0000 Subject: [PATCH] refactor(linter): store `source_text` of already opened files for `TsGoLintState` (#13197) When a file has multiple `tsgolint` diagnostics, `TsGoLintState` will now cache the source text in memory, instead of accessing the file system again. --- crates/oxc_linter/src/tsgolint.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/oxc_linter/src/tsgolint.rs b/crates/oxc_linter/src/tsgolint.rs index d3f0efdc454df..2fd5ec950d5f5 100644 --- a/crates/oxc_linter/src/tsgolint.rs +++ b/crates/oxc_linter/src/tsgolint.rs @@ -92,6 +92,8 @@ impl TsGoLintState { let mut buffer = Vec::with_capacity(8192); let mut read_buf = [0u8; 8192]; + let mut source_text_map: FxHashMap = FxHashMap::default(); + loop { match stdout.read(&mut read_buf) { Ok(0) => break, // EOF @@ -145,11 +147,23 @@ impl TsGoLintState { }, ); + let source_text: &str = + if let Some(source_text) = source_text_map.get(&path) { + source_text.as_str() + } else { + let source_text = read_to_string(&path) + .unwrap_or_else(|_| String::new()); + // Insert and get a reference to the inserted string + let entry = source_text_map + .entry(path.clone()) + .or_insert(source_text); + entry.as_str() + }; + let diagnostics = DiagnosticService::wrap_diagnostics( cwd_clone.clone(), path.clone(), - &read_to_string(&path) - .unwrap_or_else(|_| String::new()), + source_text, vec![oxc_diagnostic], );