@@ -28,6 +28,7 @@ const (
2828 findAllReferencesCmd baselineCommand = "findAllReferences"
2929 goToDefinitionCmd baselineCommand = "goToDefinition"
3030 goToImplementationCmd baselineCommand = "goToImplementation"
31+ goToSourceDefinitionCmd baselineCommand = "goToSourceDefinition"
3132 goToTypeDefinitionCmd baselineCommand = "goToType"
3233 inlayHintsCmd baselineCommand = "Inlay Hints"
3334 nonSuggestionDiagnosticsCmd baselineCommand = "Syntax and Semantic Diagnostics"
@@ -274,7 +275,7 @@ func (f *FourslashTest) getBaselineOptions(command baselineCommand, testPath str
274275 return strings .Join (fixedLines , "\n " )
275276 },
276277 }
277- case goToDefinitionCmd , goToTypeDefinitionCmd , goToImplementationCmd :
278+ case goToDefinitionCmd , goToTypeDefinitionCmd , goToImplementationCmd , goToSourceDefinitionCmd :
278279 return baseline.Options {
279280 Subfolder : subfolder ,
280281 IsSubmodule : true ,
@@ -515,7 +516,9 @@ type baselineFourslashLocationsOptions struct {
515516 endMarkerSuffix func (span documentSpan ) * string
516517 getLocationData func (span documentSpan ) string
517518
518- additionalSpan * documentSpan
519+ additionalSpan * documentSpan
520+ preserveResultOrder bool
521+ orderedFiles []lsproto.DocumentUri
519522}
520523
521524func locationToSpan (loc lsproto.Location ) documentSpan {
@@ -534,6 +537,9 @@ func (f *FourslashTest) getBaselineForLocationsWithFileContents(locations []lspr
534537
535538func (f * FourslashTest ) getBaselineForSpansWithFileContents (spans []documentSpan , options baselineFourslashLocationsOptions ) string {
536539 spansByFile := collections .GroupBy (spans , func (span documentSpan ) lsproto.DocumentUri { return span .uri })
540+ if options .preserveResultOrder {
541+ options .orderedFiles = uniqueFilesInSpanOrder (spans )
542+ }
537543 return f .getBaselineForGroupedSpansWithFileContents (
538544 spansByFile ,
539545 options ,
@@ -549,25 +555,16 @@ func (f *FourslashTest) getBaselineForGroupedSpansWithFileContents(groupedRanges
549555 spanToContextId := map [documentSpan ]int {}
550556
551557 baselineEntries := []string {}
552- walkDirFn := func (path string , d vfs.DirEntry , e error ) error {
553- if e != nil {
554- return e
555- }
556-
557- if ! d .Type ().IsRegular () {
558- return nil
559- }
560-
558+ addFileEntry := func (path string ) {
561559 fileName := lsconv .FileNameToDocumentURI (path )
562560 ranges := groupedRanges .Get (fileName )
563561 if len (ranges ) == 0 {
564- return nil
562+ return
565563 }
566564
567565 content , ok := f .textOfFile (path )
568566 if ! ok {
569- // !!! error?
570- return nil
567+ return
571568 }
572569
573570 if options .marker != nil && options .marker .FileName () == path {
@@ -579,17 +576,34 @@ func (f *FourslashTest) getBaselineForGroupedSpansWithFileContents(groupedRanges
579576 }
580577
581578 baselineEntries = append (baselineEntries , f .getBaselineContentForFile (path , content , ranges , spanToContextId , options ))
582- return nil
583579 }
580+ walkDirFn := func (path string , d vfs.DirEntry , e error ) error {
581+ if e != nil {
582+ return e
583+ }
584+
585+ if ! d .Type ().IsRegular () {
586+ return nil
587+ }
584588
585- err := f .vfs .WalkDir ("/" , walkDirFn )
586- if err != nil && ! errors .Is (err , fs .ErrNotExist ) {
587- panic ("walkdir error during fourslash baseline: " + err .Error ())
589+ addFileEntry (path )
590+ return nil
588591 }
589592
590- err = f .vfs .WalkDir ("bundled:///" , walkDirFn )
591- if err != nil && ! errors .Is (err , fs .ErrNotExist ) {
592- panic ("walkdir error during fourslash baseline: " + err .Error ())
593+ if options .preserveResultOrder {
594+ for _ , uri := range options .orderedFiles {
595+ addFileEntry (uri .FileName ())
596+ }
597+ } else {
598+ err := f .vfs .WalkDir ("/" , walkDirFn )
599+ if err != nil && ! errors .Is (err , fs .ErrNotExist ) {
600+ panic ("walkdir error during fourslash baseline: " + err .Error ())
601+ }
602+
603+ err = f .vfs .WalkDir ("bundled:///" , walkDirFn )
604+ if err != nil && ! errors .Is (err , fs .ErrNotExist ) {
605+ panic ("walkdir error during fourslash baseline: " + err .Error ())
606+ }
593607 }
594608
595609 // In Strada, there is a bug where we only ever add additional spans to baselines if we haven't
@@ -620,6 +634,22 @@ func (f *FourslashTest) getBaselineForGroupedSpansWithFileContents(groupedRanges
620634 return strings .Join (baselineEntries , "\n \n " )
621635}
622636
637+ func uniqueFilesInSpanOrder (spans []documentSpan ) []lsproto.DocumentUri {
638+ if len (spans ) == 0 {
639+ return nil
640+ }
641+ seen := map [lsproto.DocumentUri ]struct {}{}
642+ result := make ([]lsproto.DocumentUri , 0 , len (spans ))
643+ for _ , span := range spans {
644+ if _ , ok := seen [span .uri ]; ok {
645+ continue
646+ }
647+ seen [span .uri ] = struct {}{}
648+ result = append (result , span .uri )
649+ }
650+ return result
651+ }
652+
623653func (f * FourslashTest ) textOfFile (fileName string ) (string , bool ) {
624654 if _ , ok := f .openFiles [fileName ]; ok {
625655 return f .getScriptInfo (fileName ).content , true
0 commit comments