ast.d.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * AST-aware chunking support via web-tree-sitter.
  3. *
  4. * Provides language detection, AST break point extraction for supported
  5. * code file types, and a stub for future symbol extraction.
  6. *
  7. * All functions degrade gracefully: parse failures or unsupported languages
  8. * return empty arrays, falling back to regex-only chunking.
  9. *
  10. * ## Dependency Note
  11. *
  12. * Grammar packages (tree-sitter-typescript, etc.) are listed as
  13. * optionalDependencies with pinned versions. They ship native prebuilds
  14. * and source files (~72 MB total) but QMD only uses the .wasm files
  15. * (~5 MB). If install size becomes a concern, the .wasm files can be
  16. * bundled directly in the repo (e.g. assets/grammars/) and resolved
  17. * via import.meta.url instead of require.resolve(), eliminating the
  18. * grammar packages entirely.
  19. */
  20. import type { BreakPoint } from "./store.js";
  21. export type SupportedLanguage = "typescript" | "tsx" | "javascript" | "python" | "go" | "rust" | "java" | "kotlin";
  22. /**
  23. * Detect language from file path extension.
  24. * Returns null for unsupported or unknown extensions (including .md).
  25. */
  26. export declare function detectLanguage(filepath: string): SupportedLanguage | null;
  27. /**
  28. * Parse a source file and return break points at AST node boundaries.
  29. *
  30. * Returns an empty array for unsupported languages, parse failures,
  31. * or grammar loading failures. Never throws.
  32. *
  33. * @param content - The file content to parse.
  34. * @param filepath - The file path (used for language detection).
  35. * @returns Array of BreakPoint objects suitable for merging with regex break points.
  36. */
  37. export declare function getASTBreakPoints(content: string, filepath: string): Promise<BreakPoint[]>;
  38. /**
  39. * Check which tree-sitter grammars are available.
  40. * Returns a status object for each supported language.
  41. */
  42. export declare function getASTStatus(): Promise<{
  43. available: boolean;
  44. languages: {
  45. language: SupportedLanguage;
  46. available: boolean;
  47. error?: string;
  48. }[];
  49. }>;
  50. /**
  51. * Metadata about a code symbol within a chunk.
  52. * Stubbed for Phase 2 — always returns empty array in Phase 1.
  53. */
  54. export interface SymbolInfo {
  55. name: string;
  56. kind: string;
  57. signature?: string;
  58. line: number;
  59. }
  60. /**
  61. * Extract symbol metadata for code within a byte range.
  62. * Stubbed for Phase 2 — returns empty array.
  63. */
  64. export declare function extractSymbols(_content: string, _language: string, _startPos: number, _endPos: number): SymbolInfo[];