@@ -552,10 +552,11 @@ impl<'l> Runtime<'l> {
552552 pub ( super ) fn run_source < ' a > (
553553 & mut self ,
554554 allocator : & ' a oxc_allocator:: Allocator ,
555- ) -> Vec < MessageWithPosition < ' a > > {
556- use oxc_allocator:: CloneIn ;
555+ ) -> FxHashMap < PathBuf , Vec < MessageWithPosition < ' a > > > {
557556 use std:: sync:: Mutex ;
558557
558+ use oxc_allocator:: CloneIn ;
559+
559560 use crate :: {
560561 FixWithPosition ,
561562 fixer:: { Fix , PossibleFixesWithPosition } ,
@@ -576,22 +577,74 @@ impl<'l> Runtime<'l> {
576577 }
577578 }
578579
579- let messages = Mutex :: new ( Vec :: < MessageWithPosition < ' a > > :: new ( ) ) ;
580+ fn message_to_message_with_position < ' a > (
581+ message : & Message < ' a > ,
582+ source_text : & str ,
583+ section_offset : u32 ,
584+ ) -> MessageWithPosition < ' a > {
585+ let labels = & message. error . labels . clone ( ) . map ( |labels| {
586+ labels
587+ . into_iter ( )
588+ . map ( |labeled_span| {
589+ let offset = labeled_span. offset ( ) as u32 ;
590+ let start_position =
591+ offset_to_position ( offset + section_offset, source_text) ;
592+ let end_position = offset_to_position (
593+ section_offset + offset + labeled_span. len ( ) as u32 ,
594+ source_text,
595+ ) ;
596+ let message =
597+ labeled_span. label ( ) . map ( |label| Cow :: Owned ( label. to_string ( ) ) ) ;
598+
599+ SpanPositionMessage :: new ( start_position, end_position) . with_message ( message)
600+ } )
601+ . collect :: < Vec < _ > > ( )
602+ } ) ;
603+
604+ MessageWithPosition {
605+ message : message. error . message . clone ( ) ,
606+ severity : message. error . severity ,
607+ help : message. error . help . clone ( ) ,
608+ url : message. error . url . clone ( ) ,
609+ code : message. error . code . clone ( ) ,
610+ labels : labels. clone ( ) ,
611+ fixes : match & message. fixes {
612+ PossibleFixes :: None => PossibleFixesWithPosition :: None ,
613+ PossibleFixes :: Single ( fix) => PossibleFixesWithPosition :: Single (
614+ fix_to_fix_with_position ( fix, section_offset, source_text) ,
615+ ) ,
616+ PossibleFixes :: Multiple ( fixes) => PossibleFixesWithPosition :: Multiple (
617+ fixes
618+ . iter ( )
619+ . map ( |fix| fix_to_fix_with_position ( fix, section_offset, source_text) )
620+ . collect ( ) ,
621+ ) ,
622+ } ,
623+ }
624+ }
625+
626+ let messages = Mutex :: new ( FxHashMap :: < PathBuf , Vec < MessageWithPosition < ' a > > > :: with_hasher (
627+ FxBuildHasher ,
628+ ) ) ;
580629 let ( sender, _receiver) = mpsc:: channel ( ) ;
581630 rayon:: scope ( |scope| {
582631 self . resolve_modules ( scope, true , & sender, |me, mut module| {
583632 module. content . with_dependent_mut ( |owner, dependent| {
584633 assert_eq ! ( module. section_module_records. len( ) , dependent. len( ) ) ;
634+ let path = Path :: new ( & module. path ) ;
585635
586636 for ( record_result, section) in
587637 module. section_module_records . into_iter ( ) . zip ( dependent. drain ( ..) )
588638 {
589639 match record_result {
590640 Err ( diagnostics) => {
641+ let messages_with_position =
642+ diagnostics. into_iter ( ) . map ( std:: convert:: Into :: into) ;
643+
591644 messages
592645 . lock ( )
593646 . unwrap ( )
594- . extend ( diagnostics . into_iter ( ) . map ( std :: convert :: Into :: into ) ) ;
647+ . insert ( path . to_path_buf ( ) , messages_with_position . collect ( ) ) ;
595648 }
596649 Ok ( module_record) => {
597650 let section_message = me. linter . run (
@@ -600,76 +653,19 @@ impl<'l> Runtime<'l> {
600653 Arc :: clone ( & module_record) ,
601654 ) ;
602655
603- messages. lock ( ) . unwrap ( ) . extend ( section_message. iter ( ) . map (
604- |message| {
605- let message = message. clone_in ( allocator) ;
606-
607- let labels = & message. error . labels . clone ( ) . map ( |labels| {
608- labels
609- . into_iter ( )
610- . map ( |labeled_span| {
611- let offset = labeled_span. offset ( ) as u32 ;
612- let start_position = offset_to_position (
613- offset + section. source . start ,
614- & owner. source_text ,
615- ) ;
616- let end_position = offset_to_position (
617- offset
618- + section. source . start
619- + labeled_span. len ( ) as u32 ,
620- & owner. source_text ,
621- ) ;
622- let message = labeled_span
623- . label ( )
624- . map ( |label| Cow :: Owned ( label. to_string ( ) ) ) ;
625-
626- SpanPositionMessage :: new (
627- start_position,
628- end_position,
629- )
630- . with_message ( message)
631- } )
632- . collect :: < Vec < _ > > ( )
633- } ) ;
634-
635- MessageWithPosition {
636- message : message. error . message . clone ( ) ,
637- severity : message. error . severity ,
638- help : message. error . help . clone ( ) ,
639- url : message. error . url . clone ( ) ,
640- code : message. error . code . clone ( ) ,
641- labels : labels. clone ( ) ,
642- fixes : match & message. fixes {
643- PossibleFixes :: None => {
644- PossibleFixesWithPosition :: None
645- }
646- PossibleFixes :: Single ( fix) => {
647- PossibleFixesWithPosition :: Single (
648- fix_to_fix_with_position (
649- fix,
650- section. source . start ,
651- & owner. source_text ,
652- ) ,
653- )
654- }
655- PossibleFixes :: Multiple ( fixes) => {
656- PossibleFixesWithPosition :: Multiple (
657- fixes
658- . iter ( )
659- . map ( |fix| {
660- fix_to_fix_with_position (
661- fix,
662- section. source . start ,
663- & owner. source_text ,
664- )
665- } )
666- . collect ( ) ,
667- )
668- }
669- } ,
670- }
671- } ,
672- ) ) ;
656+ let messages_with_position =
657+ section_message. iter ( ) . map ( |message| {
658+ message_to_message_with_position (
659+ & message. clone_in ( allocator) ,
660+ & owner. source_text ,
661+ section. source . start ,
662+ )
663+ } ) ;
664+
665+ messages
666+ . lock ( )
667+ . unwrap ( )
668+ . insert ( path. to_path_buf ( ) , messages_with_position. collect ( ) ) ;
673669 }
674670 }
675671 }
0 commit comments