1
0

types.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * Reference Resolution Types
  3. *
  4. * Types for the reference resolution system.
  5. */
  6. import { EdgeKind, Language, Node } from '../types';
  7. /**
  8. * An unresolved reference from extraction
  9. */
  10. export interface UnresolvedRef {
  11. /** ID of the source node containing the reference */
  12. fromNodeId: string;
  13. /** The name being referenced */
  14. referenceName: string;
  15. /** Type of reference */
  16. referenceKind: EdgeKind;
  17. /** Line where reference occurs */
  18. line: number;
  19. /** Column where reference occurs */
  20. column: number;
  21. /** File path where reference occurs */
  22. filePath: string;
  23. /** Language of the source file */
  24. language: Language;
  25. /** Possible qualified names it might resolve to */
  26. candidates?: string[];
  27. }
  28. /**
  29. * A resolved reference
  30. */
  31. export interface ResolvedRef {
  32. /** Original unresolved reference */
  33. original: UnresolvedRef;
  34. /** ID of the target node */
  35. targetNodeId: string;
  36. /** Confidence score (0-1) */
  37. confidence: number;
  38. /** How it was resolved */
  39. resolvedBy: 'exact-match' | 'import' | 'qualified-name' | 'framework' | 'fuzzy' | 'instance-method';
  40. }
  41. /**
  42. * Result of resolution attempt
  43. */
  44. export interface ResolutionResult {
  45. /** Successfully resolved references */
  46. resolved: ResolvedRef[];
  47. /** References that couldn't be resolved */
  48. unresolved: UnresolvedRef[];
  49. /** Statistics */
  50. stats: {
  51. total: number;
  52. resolved: number;
  53. unresolved: number;
  54. byMethod: Record<string, number>;
  55. };
  56. }
  57. /**
  58. * Context for resolution - provides access to the graph
  59. */
  60. export interface ResolutionContext {
  61. /** Get all nodes in a file */
  62. getNodesInFile(filePath: string): Node[];
  63. /** Get all nodes by name */
  64. getNodesByName(name: string): Node[];
  65. /** Get all nodes by qualified name */
  66. getNodesByQualifiedName(qualifiedName: string): Node[];
  67. /** Get all nodes of a kind */
  68. getNodesByKind(kind: Node['kind']): Node[];
  69. /** Check if a file exists */
  70. fileExists(filePath: string): boolean;
  71. /** Read file content */
  72. readFile(filePath: string): string | null;
  73. /** Get project root */
  74. getProjectRoot(): string;
  75. /** Get all files */
  76. getAllFiles(): string[];
  77. /** Get nodes by lowercase name (O(1) lookup for fuzzy matching) */
  78. getNodesByLowerName(lowerName: string): Node[];
  79. /** Get cached import mappings for a file */
  80. getImportMappings(filePath: string, language: Language): ImportMapping[];
  81. }
  82. /**
  83. * Framework-specific resolver
  84. */
  85. export interface FrameworkResolver {
  86. /** Framework name */
  87. name: string;
  88. /** Detect if project uses this framework */
  89. detect(context: ResolutionContext): boolean;
  90. /** Resolve a reference using framework-specific patterns */
  91. resolve(ref: UnresolvedRef, context: ResolutionContext): ResolvedRef | null;
  92. /** Extract additional nodes specific to this framework */
  93. extractNodes?(filePath: string, content: string): Node[];
  94. }
  95. /**
  96. * Import mapping from a file
  97. */
  98. export interface ImportMapping {
  99. /** Local name used in the file */
  100. localName: string;
  101. /** Original exported name (may differ due to aliasing) */
  102. exportedName: string;
  103. /** Source module/path */
  104. source: string;
  105. /** Whether it's a default import */
  106. isDefault: boolean;
  107. /** Whether it's a namespace import (import * as X) */
  108. isNamespace: boolean;
  109. /** Resolved file path (if local) */
  110. resolvedPath?: string;
  111. }