@@ -19,7 +19,6 @@ use crate::linter::{
1919 error_with_position:: DiagnosticReport ,
2020 isolated_lint_handler:: { IsolatedLintHandler , IsolatedLintHandlerOptions } ,
2121 options:: { LintOptions as LSPLintOptions , Run } ,
22- tsgo_linter:: TsgoLinter ,
2322} ;
2423use crate :: utils:: normalize_path;
2524use crate :: { ConcurrentHashMap , LINT_CONFIG_FILE } ;
@@ -35,7 +34,6 @@ pub enum ServerLinterRun {
3534
3635pub struct ServerLinter {
3736 isolated_linter : Arc < Mutex < IsolatedLintHandler > > ,
38- tsgo_linter : Arc < Option < TsgoLinter > > ,
3937 ignore_matcher : LintIgnoreMatcher ,
4038 gitignore_glob : Vec < Gitignore > ,
4139 lint_on_run : Run ,
@@ -46,7 +44,6 @@ pub struct ServerLinter {
4644#[ derive( Debug , Default ) ]
4745struct ServerLinterDiagnostics {
4846 isolated_linter : Arc < ConcurrentHashMap < String , Option < Vec < DiagnosticReport > > > > ,
49- tsgo_linter : Arc < ConcurrentHashMap < String , Option < Vec < DiagnosticReport > > > > ,
5047}
5148
5249impl ServerLinterDiagnostics {
@@ -59,29 +56,15 @@ impl ServerLinterDiagnostics {
5956 reports. extend ( diagnostics. clone ( ) ) ;
6057 }
6158 }
62- if let Some ( entry) = self . tsgo_linter . pin ( ) . get ( path) {
63- found = true ;
64- if let Some ( diagnostics) = entry {
65- reports. extend ( diagnostics. clone ( ) ) ;
66- }
67- }
6859 if found { Some ( reports) } else { None }
6960 }
7061
7162 pub fn remove_diagnostics ( & self , path : & str ) {
7263 self . isolated_linter . pin ( ) . remove ( path) ;
73- self . tsgo_linter . pin ( ) . remove ( path) ;
7464 }
7565
7666 pub fn get_cached_files_of_diagnostics ( & self ) -> Vec < String > {
77- let isolated_files = self . isolated_linter . pin ( ) . keys ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ;
78- let tsgo_files = self . tsgo_linter . pin ( ) . keys ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ;
79-
80- let mut files = Vec :: with_capacity ( isolated_files. len ( ) + tsgo_files. len ( ) ) ;
81- files. extend ( isolated_files) ;
82- files. extend ( tsgo_files) ;
83- files. dedup ( ) ;
84- files
67+ self . isolated_linter . pin ( ) . keys ( ) . cloned ( ) . collect :: < Vec < _ > > ( )
8568 }
8669}
8770
@@ -153,9 +136,10 @@ impl ServerLinter {
153136
154137 let isolated_linter = IsolatedLintHandler :: new (
155138 lint_options,
156- config_store. clone ( ) , // clone because tsgo linter needs it
139+ config_store,
157140 & IsolatedLintHandlerOptions {
158141 use_cross_module,
142+ type_aware : options. type_aware ,
159143 root_path : root_path. to_path_buf ( ) ,
160144 tsconfig_path : options. ts_config_path . as_ref ( ) . map ( |path| {
161145 let path = Path :: new ( path) . to_path_buf ( ) ;
@@ -175,11 +159,6 @@ impl ServerLinter {
175159 extended_paths,
176160 lint_on_run : options. run ,
177161 diagnostics : ServerLinterDiagnostics :: default ( ) ,
178- tsgo_linter : if options. type_aware {
179- Arc :: new ( Some ( TsgoLinter :: new ( & root_path, config_store) ) )
180- } else {
181- Arc :: new ( None )
182- } ,
183162 }
184163 }
185164
@@ -326,45 +305,26 @@ impl ServerLinter {
326305 content : Option < String > ,
327306 run_type : ServerLinterRun ,
328307 ) -> Option < Vec < DiagnosticReport > > {
329- let ( oxlint, tsgolint) = match ( run_type, self . lint_on_run ) {
330- // run everything on save, or when it is forced
331- ( ServerLinterRun :: Always , _) | ( ServerLinterRun :: OnSave , Run :: OnSave ) => ( true , true ) ,
332- // run only oxlint on type
333- // tsgolint does not support memory source_text
334- ( ServerLinterRun :: OnType , Run :: OnType ) => ( true , false ) ,
335- // it does not match, run nothing
336- ( ServerLinterRun :: OnType , Run :: OnSave ) => ( false , false ) ,
337- // In onType mode, only TypeScript type checking runs on save
338- // If type_aware is disabled (tsgo_linter is None), skip everything to preserve diagnostics
339- ( ServerLinterRun :: OnSave , Run :: OnType ) => {
340- let should_run_tsgo = self . tsgo_linter . as_ref ( ) . is_some ( ) ;
341- ( false , should_run_tsgo)
342- }
343- } ;
308+ let run = !matches ! (
309+ ( run_type, self . lint_on_run) ,
310+ ( ServerLinterRun :: OnType , Run :: OnSave ) | ( ServerLinterRun :: OnSave , Run :: OnType )
311+ ) ;
344312
345313 // return `None` when both tools do not want to be used
346- if !oxlint && !tsgolint {
314+ if !run {
347315 return None ;
348316 }
349317
350318 if self . is_ignored ( uri) {
351319 return None ;
352320 }
353321
354- if oxlint {
355- let diagnostics = {
356- let mut isolated_linter = self . isolated_linter . lock ( ) . await ;
357- isolated_linter. run_single ( uri, content. clone ( ) )
358- } ;
359- self . diagnostics . isolated_linter . pin ( ) . insert ( uri. to_string ( ) , diagnostics) ;
360- }
322+ let diagnostics = {
323+ let mut isolated_linter = self . isolated_linter . lock ( ) . await ;
324+ isolated_linter. run_single ( uri, content. clone ( ) )
325+ } ;
361326
362- if tsgolint && let Some ( tsgo_linter) = self . tsgo_linter . as_ref ( ) {
363- self . diagnostics
364- . tsgo_linter
365- . pin ( )
366- . insert ( uri. to_string ( ) , tsgo_linter. lint_file ( uri, content. clone ( ) ) ) ;
367- }
327+ self . diagnostics . isolated_linter . pin ( ) . insert ( uri. to_string ( ) , diagnostics) ;
368328
369329 self . diagnostics . get_diagnostics ( & uri. to_string ( ) )
370330 }
@@ -466,31 +426,23 @@ mod test {
466426 fn test_get_diagnostics_found_and_none_entries ( ) {
467427 let key = "file:///test.js" . to_string ( ) ;
468428
469- // Case 1: Both entries present, Some diagnostics
429+ // Case 1: Entry present, Some diagnostics
470430 let diag = DiagnosticReport :: default ( ) ;
471431 let diag_map = ConcurrentHashMap :: default ( ) ;
472- diag_map. pin ( ) . insert ( key. clone ( ) , Some ( vec ! [ diag. clone( ) ] ) ) ;
473- let tsgo_map = ConcurrentHashMap :: default ( ) ;
474- tsgo_map. pin ( ) . insert ( key. clone ( ) , Some ( vec ! [ diag] ) ) ;
432+ diag_map. pin ( ) . insert ( key. clone ( ) , Some ( vec ! [ diag] ) ) ;
475433
476- let server_diag = super :: ServerLinterDiagnostics {
477- isolated_linter : std:: sync:: Arc :: new ( diag_map) ,
478- tsgo_linter : std:: sync:: Arc :: new ( tsgo_map) ,
479- } ;
434+ let server_diag =
435+ super :: ServerLinterDiagnostics { isolated_linter : std:: sync:: Arc :: new ( diag_map) } ;
480436 let result = server_diag. get_diagnostics ( & key) ;
481437 assert ! ( result. is_some( ) ) ;
482- assert_eq ! ( result. unwrap( ) . len( ) , 2 ) ;
438+ assert_eq ! ( result. unwrap( ) . len( ) , 1 ) ;
483439
484440 // Case 2: Entry present, but value is None
485441 let diag_map_none = ConcurrentHashMap :: default ( ) ;
486442 diag_map_none. pin ( ) . insert ( key. clone ( ) , None ) ;
487- let tsgo_map_none = ConcurrentHashMap :: default ( ) ;
488- tsgo_map_none. pin ( ) . insert ( key. clone ( ) , None ) ;
489443
490- let server_diag_none = ServerLinterDiagnostics {
491- isolated_linter : std:: sync:: Arc :: new ( diag_map_none) ,
492- tsgo_linter : std:: sync:: Arc :: new ( tsgo_map_none) ,
493- } ;
444+ let server_diag_none =
445+ ServerLinterDiagnostics { isolated_linter : std:: sync:: Arc :: new ( diag_map_none) } ;
494446 let result_none = server_diag_none. get_diagnostics ( & key) ;
495447 assert ! ( result_none. is_some( ) ) ;
496448 assert_eq ! ( result_none. unwrap( ) . len( ) , 0 ) ;
@@ -535,7 +487,7 @@ mod test {
535487 #[ cfg( not( target_endian = "big" ) ) ]
536488 fn test_lint_on_run_on_save_on_save ( ) {
537489 Tester :: new (
538- "fixtures/linter/lint_on_run/on_type " ,
490+ "fixtures/linter/lint_on_run/on_save " ,
539491 Some ( LintOptions { type_aware : true , run : Run :: OnSave , ..Default :: default ( ) } ) ,
540492 )
541493 . test_and_snapshot_single_file_with_run_type ( "on-save.ts" , Run :: OnSave ) ;
0 commit comments