Skip to content

Commit 816ff03

Browse files
committed
feat(linter): read source text into the arena (#11825)
1 parent b39d1fa commit 816ff03

File tree

5 files changed

+243
-180
lines changed

5 files changed

+243
-180
lines changed

crates/oxc_language_server/src/linter/isolated_lint_handler.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ use tower_lsp_server::{
1111
};
1212

1313
use oxc_allocator::{Allocator, AllocatorPool};
14-
use oxc_linter::RuntimeFileSystem;
1514
use oxc_linter::{
1615
LINTABLE_EXTENSIONS, LintService, LintServiceOptions, Linter, MessageWithPosition,
17-
loader::Loader, read_to_string,
16+
loader::Loader, read_to_arena_str,
1817
};
18+
use oxc_linter::{RuntimeFileSystem, read_to_string};
1919

2020
use super::error_with_position::{
2121
DiagnosticReport, PossibleFixContent, message_with_position_to_lsp_diagnostic_report,
@@ -45,12 +45,17 @@ impl IsolatedLintHandlerFileSystem {
4545
}
4646

4747
impl RuntimeFileSystem for IsolatedLintHandlerFileSystem {
48-
fn read_to_string(&self, path: &Path) -> Result<String, std::io::Error> {
48+
fn read_to_arena_str<'a>(
49+
&self,
50+
path: &Path,
51+
allocator: &'a Allocator,
52+
) -> Result<&'a str, std::io::Error> {
4953
if path == self.path_to_lint {
50-
return Ok(self.source_text.clone());
54+
// TODO: i think we can avoid allocating here.
55+
return Ok(allocator.alloc_str(&self.source_text));
5156
}
5257

53-
read_to_string(path)
58+
read_to_arena_str(path, allocator)
5459
}
5560

5661
fn write_file(&self, _path: &Path, _content: String) -> Result<(), std::io::Error> {
@@ -129,6 +134,7 @@ impl IsolatedLintHandler {
129134
debug!("extension not supported yet.");
130135
return None;
131136
}
137+
132138
let source_text = source_text.or_else(|| read_to_string(path).ok())?;
133139

134140
debug!("lint {}", path.display());

crates/oxc_linter/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub use crate::{
4040
options::{AllowWarnDeny, InvalidFilterKind, LintFilter, LintFilterKind},
4141
rule::{RuleCategory, RuleFixMeta, RuleMeta},
4242
service::{LintService, LintServiceOptions, RuntimeFileSystem},
43+
utils::read_to_arena_str,
4344
utils::read_to_string,
4445
};
4546
use crate::{

0 commit comments

Comments
 (0)