* Formats LSP result based on operation type and extracts summary counts
( operation: Input['operation'], result: unknown, cwd: string, )
| 634 | * Formats LSP result based on operation type and extracts summary counts |
| 635 | */ |
| 636 | function formatResult( |
| 637 | operation: Input['operation'], |
| 638 | result: unknown, |
| 639 | cwd: string, |
| 640 | ): { formatted: string; resultCount: number; fileCount: number } { |
| 641 | switch (operation) { |
| 642 | case 'goToDefinition': { |
| 643 | // Handle both Location and LocationLink formats |
| 644 | const rawResults = Array.isArray(result) |
| 645 | ? result |
| 646 | : result |
| 647 | ? [result as Location | LocationLink] |
| 648 | : [] |
| 649 | |
| 650 | // Convert LocationLinks to Locations for uniform handling |
| 651 | const locations = rawResults.map(toLocation) |
| 652 | |
| 653 | // Log and filter out locations with undefined uris |
| 654 | const invalidLocations = locations.filter(loc => !loc || !loc.uri) |
| 655 | if (invalidLocations.length > 0) { |
| 656 | logError( |
| 657 | new Error( |
| 658 | `LSP server returned ${invalidLocations.length} location(s) with undefined URI for goToDefinition on ${cwd}. ` + |
| 659 | `This indicates malformed data from the LSP server.`, |
| 660 | ), |
| 661 | ) |
| 662 | } |
| 663 | |
| 664 | const validLocations = locations.filter(loc => loc && loc.uri) |
| 665 | return { |
| 666 | formatted: formatGoToDefinitionResult( |
| 667 | result as |
| 668 | | Location |
| 669 | | Location[] |
| 670 | | LocationLink |
| 671 | | LocationLink[] |
| 672 | | null, |
| 673 | cwd, |
| 674 | ), |
| 675 | resultCount: validLocations.length, |
| 676 | fileCount: countUniqueFiles(validLocations), |
| 677 | } |
| 678 | } |
| 679 | case 'findReferences': { |
| 680 | const locations = (result as Location[]) || [] |
| 681 | |
| 682 | // Log and filter out locations with undefined uris |
| 683 | const invalidLocations = locations.filter(loc => !loc || !loc.uri) |
| 684 | if (invalidLocations.length > 0) { |
| 685 | logError( |
| 686 | new Error( |
| 687 | `LSP server returned ${invalidLocations.length} location(s) with undefined URI for findReferences on ${cwd}. ` + |
| 688 | `This indicates malformed data from the LSP server.`, |
| 689 | ), |
| 690 | ) |
| 691 | } |
| 692 | |
| 693 | const validLocations = locations.filter(loc => loc && loc.uri) |
no test coverage detected