types.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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';
  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. }
  78. /**
  79. * Framework-specific resolver
  80. */
  81. export interface FrameworkResolver {
  82. /** Framework name */
  83. name: string;
  84. /** Detect if project uses this framework */
  85. detect(context: ResolutionContext): boolean;
  86. /** Resolve a reference using framework-specific patterns */
  87. resolve(ref: UnresolvedRef, context: ResolutionContext): ResolvedRef | null;
  88. /** Extract additional nodes specific to this framework */
  89. extractNodes?(filePath: string, content: string): Node[];
  90. }
  91. /**
  92. * Import mapping from a file
  93. */
  94. export interface ImportMapping {
  95. /** Local name used in the file */
  96. localName: string;
  97. /** Original exported name (may differ due to aliasing) */
  98. exportedName: string;
  99. /** Source module/path */
  100. source: string;
  101. /** Whether it's a default import */
  102. isDefault: boolean;
  103. /** Whether it's a namespace import (import * as X) */
  104. isNamespace: boolean;
  105. /** Resolved file path (if local) */
  106. resolvedPath?: string;
  107. }