@@ -12,8 +12,8 @@ use tower_lsp_server::{
1212
1313use oxc_allocator:: { Allocator , AllocatorPool } ;
1414use oxc_linter:: {
15- LINTABLE_EXTENSIONS , LintService , LintServiceOptions , Linter , MessageWithPosition ,
16- loader:: Loader , read_to_arena_str,
15+ ConfigStore , LINTABLE_EXTENSIONS , LintOptions , LintService , LintServiceOptions , Linter ,
16+ MessageWithPosition , loader:: Loader , read_to_arena_str,
1717} ;
1818use oxc_linter:: { RuntimeFileSystem , read_to_string} ;
1919
@@ -29,8 +29,7 @@ pub struct IsolatedLintHandlerOptions {
2929}
3030
3131pub struct IsolatedLintHandler {
32- linter : Linter ,
33- options : IsolatedLintHandlerOptions ,
32+ service : LintService ,
3433}
3534
3635pub struct IsolatedLintHandlerFileSystem {
@@ -63,11 +62,25 @@ impl RuntimeFileSystem for IsolatedLintHandlerFileSystem {
6362}
6463
6564impl IsolatedLintHandler {
66- pub fn new ( linter : Linter , options : IsolatedLintHandlerOptions ) -> Self {
67- Self { linter, options }
65+ pub fn new (
66+ lint_options : LintOptions ,
67+ config_store : ConfigStore ,
68+ options : & IsolatedLintHandlerOptions ,
69+ ) -> Self {
70+ let linter = Linter :: new ( lint_options, config_store) ;
71+ let lint_service_options = LintServiceOptions :: new ( options. root_path . clone ( ) )
72+ . with_cross_module ( options. use_cross_module ) ;
73+
74+ let service = LintService :: new ( linter, AllocatorPool :: default ( ) , lint_service_options) ;
75+
76+ Self { service }
6877 }
6978
70- pub fn run_single ( & self , uri : & Uri , content : Option < String > ) -> Option < Vec < DiagnosticReport > > {
79+ pub fn run_single (
80+ & mut self ,
81+ uri : & Uri ,
82+ content : Option < String > ,
83+ ) -> Option < Vec < DiagnosticReport > > {
7184 let path = uri. to_file_path ( ) ?;
7285
7386 if !Self :: should_lint_path ( & path) {
@@ -124,7 +137,7 @@ impl IsolatedLintHandler {
124137 }
125138
126139 fn lint_path < ' a > (
127- & self ,
140+ & mut self ,
128141 allocator : & ' a Allocator ,
129142 path : & Path ,
130143 source_text : Option < String > ,
@@ -138,17 +151,14 @@ impl IsolatedLintHandler {
138151
139152 debug ! ( "lint {}" , path. display( ) ) ;
140153
141- let lint_service_options = LintServiceOptions :: new ( self . options . root_path . clone ( ) )
142- . with_cross_module ( self . options . use_cross_module ) ;
143-
144- let mut lint_service =
145- LintService :: new ( & self . linter , AllocatorPool :: default ( ) , lint_service_options)
146- . with_file_system ( Box :: new ( IsolatedLintHandlerFileSystem :: new (
147- path. to_path_buf ( ) ,
148- source_text,
149- ) ) )
150- . with_paths ( vec ! [ Arc :: from( path. as_os_str( ) ) ] ) ;
151- let result = lint_service. run_source ( allocator) ;
154+ let result = self
155+ . service
156+ . with_file_system ( Box :: new ( IsolatedLintHandlerFileSystem :: new (
157+ path. to_path_buf ( ) ,
158+ source_text,
159+ ) ) )
160+ . with_paths ( vec ! [ Arc :: from( path. as_os_str( ) ) ] )
161+ . run_source ( allocator) ;
152162
153163 Some ( result)
154164 }
0 commit comments