driftdetect-core 0.1.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/boundaries/boundary-store.d.ts +92 -0
- package/dist/boundaries/boundary-store.d.ts.map +1 -0
- package/dist/boundaries/boundary-store.js +458 -0
- package/dist/boundaries/boundary-store.js.map +1 -0
- package/dist/boundaries/index.d.ts +8 -0
- package/dist/boundaries/index.d.ts.map +1 -0
- package/dist/boundaries/index.js +8 -0
- package/dist/boundaries/index.js.map +1 -0
- package/dist/boundaries/types.d.ts +237 -0
- package/dist/boundaries/types.d.ts.map +1 -0
- package/dist/boundaries/types.js +8 -0
- package/dist/boundaries/types.js.map +1 -0
- package/dist/dna/ai-context.d.ts +10 -0
- package/dist/dna/ai-context.d.ts.map +1 -0
- package/dist/dna/ai-context.js +46 -0
- package/dist/dna/ai-context.js.map +1 -0
- package/dist/dna/dna-analyzer.d.ts +34 -0
- package/dist/dna/dna-analyzer.d.ts.map +1 -0
- package/dist/dna/dna-analyzer.js +110 -0
- package/dist/dna/dna-analyzer.js.map +1 -0
- package/dist/dna/dna-store.d.ts +13 -0
- package/dist/dna/dna-store.d.ts.map +1 -0
- package/dist/dna/dna-store.js +43 -0
- package/dist/dna/dna-store.js.map +1 -0
- package/dist/dna/gene-extractors/animation-approach.d.ts +15 -0
- package/dist/dna/gene-extractors/animation-approach.d.ts.map +1 -0
- package/dist/dna/gene-extractors/animation-approach.js +97 -0
- package/dist/dna/gene-extractors/animation-approach.js.map +1 -0
- package/dist/dna/gene-extractors/base-extractor.d.ts +53 -0
- package/dist/dna/gene-extractors/base-extractor.d.ts.map +1 -0
- package/dist/dna/gene-extractors/base-extractor.js +76 -0
- package/dist/dna/gene-extractors/base-extractor.js.map +1 -0
- package/dist/dna/gene-extractors/index.d.ts +16 -0
- package/dist/dna/gene-extractors/index.d.ts.map +1 -0
- package/dist/dna/gene-extractors/index.js +38 -0
- package/dist/dna/gene-extractors/index.js.map +1 -0
- package/dist/dna/gene-extractors/responsive-approach.d.ts +10 -0
- package/dist/dna/gene-extractors/responsive-approach.d.ts.map +1 -0
- package/dist/dna/gene-extractors/responsive-approach.js +30 -0
- package/dist/dna/gene-extractors/responsive-approach.js.map +1 -0
- package/dist/dna/gene-extractors/spacing-philosophy.d.ts +10 -0
- package/dist/dna/gene-extractors/spacing-philosophy.d.ts.map +1 -0
- package/dist/dna/gene-extractors/spacing-philosophy.js +30 -0
- package/dist/dna/gene-extractors/spacing-philosophy.js.map +1 -0
- package/dist/dna/gene-extractors/state-styling.d.ts +10 -0
- package/dist/dna/gene-extractors/state-styling.d.ts.map +1 -0
- package/dist/dna/gene-extractors/state-styling.js +29 -0
- package/dist/dna/gene-extractors/state-styling.js.map +1 -0
- package/dist/dna/gene-extractors/theming.d.ts +10 -0
- package/dist/dna/gene-extractors/theming.d.ts.map +1 -0
- package/dist/dna/gene-extractors/theming.js +30 -0
- package/dist/dna/gene-extractors/theming.js.map +1 -0
- package/dist/dna/gene-extractors/variant-handling.d.ts +13 -0
- package/dist/dna/gene-extractors/variant-handling.d.ts.map +1 -0
- package/dist/dna/gene-extractors/variant-handling.js +38 -0
- package/dist/dna/gene-extractors/variant-handling.js.map +1 -0
- package/dist/dna/health-calculator.d.ts +21 -0
- package/dist/dna/health-calculator.d.ts.map +1 -0
- package/dist/dna/health-calculator.js +113 -0
- package/dist/dna/health-calculator.js.map +1 -0
- package/dist/dna/index.d.ts +21 -0
- package/dist/dna/index.d.ts.map +1 -0
- package/dist/dna/index.js +19 -0
- package/dist/dna/index.js.map +1 -0
- package/dist/dna/mutation-detector.d.ts +10 -0
- package/dist/dna/mutation-detector.d.ts.map +1 -0
- package/dist/dna/mutation-detector.js +39 -0
- package/dist/dna/mutation-detector.js.map +1 -0
- package/dist/dna/playbook-generator.d.ts +6 -0
- package/dist/dna/playbook-generator.d.ts.map +1 -0
- package/dist/dna/playbook-generator.js +53 -0
- package/dist/dna/playbook-generator.js.map +1 -0
- package/dist/dna/types.d.ts +95 -0
- package/dist/dna/types.d.ts.map +1 -0
- package/dist/dna/types.js +8 -0
- package/dist/dna/types.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/parsers/parser-manager.d.ts.map +1 -1
- package/dist/parsers/parser-manager.js +2 -0
- package/dist/parsers/parser-manager.js.map +1 -1
- package/dist/parsers/tree-sitter/config.d.ts +82 -0
- package/dist/parsers/tree-sitter/config.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/config.js +200 -0
- package/dist/parsers/tree-sitter/config.js.map +1 -0
- package/dist/parsers/tree-sitter/csharp-ast-converter.d.ts +64 -0
- package/dist/parsers/tree-sitter/csharp-ast-converter.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/csharp-ast-converter.js +271 -0
- package/dist/parsers/tree-sitter/csharp-ast-converter.js.map +1 -0
- package/dist/parsers/tree-sitter/csharp-loader.d.ts +43 -0
- package/dist/parsers/tree-sitter/csharp-loader.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/csharp-loader.js +146 -0
- package/dist/parsers/tree-sitter/csharp-loader.js.map +1 -0
- package/dist/parsers/tree-sitter/index.d.ts +31 -0
- package/dist/parsers/tree-sitter/index.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/index.js +63 -0
- package/dist/parsers/tree-sitter/index.js.map +1 -0
- package/dist/parsers/tree-sitter/java/annotation-extractor.d.ts +79 -0
- package/dist/parsers/tree-sitter/java/annotation-extractor.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/java/annotation-extractor.js +540 -0
- package/dist/parsers/tree-sitter/java/annotation-extractor.js.map +1 -0
- package/dist/parsers/tree-sitter/java/class-extractor.d.ts +40 -0
- package/dist/parsers/tree-sitter/java/class-extractor.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/java/class-extractor.js +770 -0
- package/dist/parsers/tree-sitter/java/class-extractor.js.map +1 -0
- package/dist/parsers/tree-sitter/java/index.d.ts +14 -0
- package/dist/parsers/tree-sitter/java/index.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/java/index.js +25 -0
- package/dist/parsers/tree-sitter/java/index.js.map +1 -0
- package/dist/parsers/tree-sitter/java/method-extractor.d.ts +88 -0
- package/dist/parsers/tree-sitter/java/method-extractor.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/java/method-extractor.js +551 -0
- package/dist/parsers/tree-sitter/java/method-extractor.js.map +1 -0
- package/dist/parsers/tree-sitter/java/types.d.ts +545 -0
- package/dist/parsers/tree-sitter/java/types.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/java/types.js +81 -0
- package/dist/parsers/tree-sitter/java/types.js.map +1 -0
- package/dist/parsers/tree-sitter/java-loader.d.ts +50 -0
- package/dist/parsers/tree-sitter/java-loader.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/java-loader.js +161 -0
- package/dist/parsers/tree-sitter/java-loader.js.map +1 -0
- package/dist/parsers/tree-sitter/loader.d.ts +50 -0
- package/dist/parsers/tree-sitter/loader.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/loader.js +156 -0
- package/dist/parsers/tree-sitter/loader.js.map +1 -0
- package/dist/parsers/tree-sitter/php-loader.d.ts +50 -0
- package/dist/parsers/tree-sitter/php-loader.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/php-loader.js +164 -0
- package/dist/parsers/tree-sitter/php-loader.js.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/config-extractor.d.ts +78 -0
- package/dist/parsers/tree-sitter/pydantic/config-extractor.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/config-extractor.js +278 -0
- package/dist/parsers/tree-sitter/pydantic/config-extractor.js.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/constraint-parser.d.ts +84 -0
- package/dist/parsers/tree-sitter/pydantic/constraint-parser.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/constraint-parser.js +321 -0
- package/dist/parsers/tree-sitter/pydantic/constraint-parser.js.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/field-extractor.d.ts +74 -0
- package/dist/parsers/tree-sitter/pydantic/field-extractor.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/field-extractor.js +285 -0
- package/dist/parsers/tree-sitter/pydantic/field-extractor.js.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/index.d.ts +18 -0
- package/dist/parsers/tree-sitter/pydantic/index.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/index.js +23 -0
- package/dist/parsers/tree-sitter/pydantic/index.js.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/inheritance-resolver.d.ts +70 -0
- package/dist/parsers/tree-sitter/pydantic/inheritance-resolver.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/inheritance-resolver.js +251 -0
- package/dist/parsers/tree-sitter/pydantic/inheritance-resolver.js.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/pydantic-extractor.d.ts +102 -0
- package/dist/parsers/tree-sitter/pydantic/pydantic-extractor.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/pydantic-extractor.js +399 -0
- package/dist/parsers/tree-sitter/pydantic/pydantic-extractor.js.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/type-resolver.d.ts +89 -0
- package/dist/parsers/tree-sitter/pydantic/type-resolver.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/type-resolver.js +426 -0
- package/dist/parsers/tree-sitter/pydantic/type-resolver.js.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/types.d.ts +177 -0
- package/dist/parsers/tree-sitter/pydantic/types.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/types.js +139 -0
- package/dist/parsers/tree-sitter/pydantic/types.js.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/validator-extractor.d.ts +88 -0
- package/dist/parsers/tree-sitter/pydantic/validator-extractor.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/pydantic/validator-extractor.js +315 -0
- package/dist/parsers/tree-sitter/pydantic/validator-extractor.js.map +1 -0
- package/dist/parsers/tree-sitter/python-ast-converter.d.ts +140 -0
- package/dist/parsers/tree-sitter/python-ast-converter.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/python-ast-converter.js +360 -0
- package/dist/parsers/tree-sitter/python-ast-converter.js.map +1 -0
- package/dist/parsers/tree-sitter/tree-sitter-csharp-parser.d.ts +465 -0
- package/dist/parsers/tree-sitter/tree-sitter-csharp-parser.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/tree-sitter-csharp-parser.js +1146 -0
- package/dist/parsers/tree-sitter/tree-sitter-csharp-parser.js.map +1 -0
- package/dist/parsers/tree-sitter/tree-sitter-java-parser.d.ts +90 -0
- package/dist/parsers/tree-sitter/tree-sitter-java-parser.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/tree-sitter-java-parser.js +298 -0
- package/dist/parsers/tree-sitter/tree-sitter-java-parser.js.map +1 -0
- package/dist/parsers/tree-sitter/tree-sitter-php-parser.d.ts +177 -0
- package/dist/parsers/tree-sitter/tree-sitter-php-parser.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/tree-sitter-php-parser.js +585 -0
- package/dist/parsers/tree-sitter/tree-sitter-php-parser.js.map +1 -0
- package/dist/parsers/tree-sitter/tree-sitter-python-parser.d.ts +86 -0
- package/dist/parsers/tree-sitter/tree-sitter-python-parser.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/tree-sitter-python-parser.js +177 -0
- package/dist/parsers/tree-sitter/tree-sitter-python-parser.js.map +1 -0
- package/dist/parsers/tree-sitter/types.d.ts +399 -0
- package/dist/parsers/tree-sitter/types.d.ts.map +1 -0
- package/dist/parsers/tree-sitter/types.js +20 -0
- package/dist/parsers/tree-sitter/types.js.map +1 -0
- package/dist/parsers/types.d.ts +1 -1
- package/dist/parsers/types.d.ts.map +1 -1
- package/dist/scanner/file-walker.d.ts.map +1 -1
- package/dist/scanner/file-walker.js +5 -0
- package/dist/scanner/file-walker.js.map +1 -1
- package/dist/store/history-store.d.ts +85 -269
- package/dist/store/history-store.d.ts.map +1 -1
- package/dist/store/history-store.js +272 -624
- package/dist/store/history-store.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/java-type-mapping.d.ts +79 -0
- package/dist/types/java-type-mapping.d.ts.map +1 -0
- package/dist/types/java-type-mapping.js +290 -0
- package/dist/types/java-type-mapping.js.map +1 -0
- package/package.json +9 -2
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter Python Parser
|
|
3
|
+
*
|
|
4
|
+
* Main parser implementation using tree-sitter for Python parsing.
|
|
5
|
+
* Implements the BaseParser interface and provides enhanced AST
|
|
6
|
+
* extraction with Pydantic model support.
|
|
7
|
+
*
|
|
8
|
+
* @requirements 3.5 - Unified AST query interface
|
|
9
|
+
*/
|
|
10
|
+
import { BaseParser } from '../base-parser.js';
|
|
11
|
+
import type { AST, ASTNode, Language, ParseResult } from '../types.js';
|
|
12
|
+
import type { TreeSitterTree, PydanticModelInfo } from './types.js';
|
|
13
|
+
import type { PythonParserConfig } from './config.js';
|
|
14
|
+
/**
|
|
15
|
+
* Extended parse result with tree-sitter specific information.
|
|
16
|
+
*/
|
|
17
|
+
export interface TreeSitterPythonParseResult extends ParseResult {
|
|
18
|
+
/** The raw tree-sitter tree (if available) */
|
|
19
|
+
treeSitterTree: TreeSitterTree | null;
|
|
20
|
+
/** Whether tree-sitter was used for parsing */
|
|
21
|
+
usedTreeSitter: boolean;
|
|
22
|
+
/** Extracted Pydantic models (if enabled) */
|
|
23
|
+
pydanticModels: PydanticModelInfo[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Tree-sitter based Python parser.
|
|
27
|
+
*
|
|
28
|
+
* Provides AST parsing using tree-sitter with fallback to regex-based
|
|
29
|
+
* parsing when tree-sitter is not available.
|
|
30
|
+
*/
|
|
31
|
+
export declare class TreeSitterPythonParser extends BaseParser {
|
|
32
|
+
readonly language: Language;
|
|
33
|
+
readonly extensions: string[];
|
|
34
|
+
private readonly config;
|
|
35
|
+
private readonly converter;
|
|
36
|
+
private readonly pydanticExtractor;
|
|
37
|
+
private parser;
|
|
38
|
+
/**
|
|
39
|
+
* Create a new TreeSitterPythonParser.
|
|
40
|
+
*
|
|
41
|
+
* @param config - Parser configuration options
|
|
42
|
+
*/
|
|
43
|
+
constructor(config?: Partial<PythonParserConfig>);
|
|
44
|
+
/**
|
|
45
|
+
* Check if tree-sitter is available for Python parsing.
|
|
46
|
+
*
|
|
47
|
+
* @returns true if tree-sitter and tree-sitter-python are available
|
|
48
|
+
*/
|
|
49
|
+
static isAvailable(): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Parse Python source code into an AST.
|
|
52
|
+
*
|
|
53
|
+
* @param source - The source code to parse
|
|
54
|
+
* @param filePath - Optional file path for error reporting
|
|
55
|
+
* @returns TreeSitterPythonParseResult containing the AST
|
|
56
|
+
*/
|
|
57
|
+
parse(source: string, filePath?: string): TreeSitterPythonParseResult;
|
|
58
|
+
/**
|
|
59
|
+
* Query the AST for nodes matching a pattern.
|
|
60
|
+
*
|
|
61
|
+
* Supports tree-sitter query syntax when tree-sitter is available,
|
|
62
|
+
* otherwise falls back to simple node type matching.
|
|
63
|
+
*
|
|
64
|
+
* @param ast - The AST to query
|
|
65
|
+
* @param pattern - The query pattern (tree-sitter query or node type)
|
|
66
|
+
* @returns Array of matching AST nodes
|
|
67
|
+
*/
|
|
68
|
+
query(ast: AST, pattern: string): ASTNode[];
|
|
69
|
+
/**
|
|
70
|
+
* Create a fallback result when tree-sitter is not available.
|
|
71
|
+
*/
|
|
72
|
+
private createFallbackResult;
|
|
73
|
+
/**
|
|
74
|
+
* Extract Pydantic models from a tree-sitter tree.
|
|
75
|
+
*/
|
|
76
|
+
private extractPydanticModelsFromTree;
|
|
77
|
+
/**
|
|
78
|
+
* Execute a tree-sitter query on the AST.
|
|
79
|
+
*/
|
|
80
|
+
private executeTreeSitterQuery;
|
|
81
|
+
/**
|
|
82
|
+
* Extract a simple node type from a tree-sitter query pattern.
|
|
83
|
+
*/
|
|
84
|
+
private extractNodeTypeFromQuery;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=tree-sitter-python-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-sitter-python-parser.d.ts","sourceRoot":"","sources":["../../../src/parsers/tree-sitter/tree-sitter-python-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,KAAK,EAEV,cAAc,EACd,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAQtD;;GAEG;AACH,MAAM,WAAW,2BAA4B,SAAQ,WAAW;IAC9D,8CAA8C;IAC9C,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IACtC,+CAA+C;IAC/C,cAAc,EAAE,OAAO,CAAC;IACxB,6CAA6C;IAC7C,cAAc,EAAE,iBAAiB,EAAE,CAAC;CACrC;AAMD;;;;;GAKG;AACH,qBAAa,sBAAuB,SAAQ,UAAU;IACpD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAY;IACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,CAA2B;IAExD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqB;IAC/C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAoB;IACtD,OAAO,CAAC,MAAM,CAAiC;IAE/C;;;;OAIG;gBACS,MAAM,GAAE,OAAO,CAAC,kBAAkB,CAAM;IAWpD;;;;OAIG;IACH,MAAM,CAAC,WAAW,IAAI,OAAO;IAI7B;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,2BAA2B;IAqDrE;;;;;;;;;OASG;IACH,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,EAAE;IAoB3C;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAyB5B;;OAEG;IACH,OAAO,CAAC,6BAA6B;IAOrC;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAM9B;;OAEG;IACH,OAAO,CAAC,wBAAwB;CAMjC"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter Python Parser
|
|
3
|
+
*
|
|
4
|
+
* Main parser implementation using tree-sitter for Python parsing.
|
|
5
|
+
* Implements the BaseParser interface and provides enhanced AST
|
|
6
|
+
* extraction with Pydantic model support.
|
|
7
|
+
*
|
|
8
|
+
* @requirements 3.5 - Unified AST query interface
|
|
9
|
+
*/
|
|
10
|
+
import { BaseParser } from '../base-parser.js';
|
|
11
|
+
import { PythonASTConverter } from './python-ast-converter.js';
|
|
12
|
+
import { isTreeSitterAvailable, createPythonParser } from './loader.js';
|
|
13
|
+
import { mergeConfig } from './config.js';
|
|
14
|
+
import { PydanticExtractor } from './pydantic/pydantic-extractor.js';
|
|
15
|
+
// ============================================
|
|
16
|
+
// Main Parser Class
|
|
17
|
+
// ============================================
|
|
18
|
+
/**
|
|
19
|
+
* Tree-sitter based Python parser.
|
|
20
|
+
*
|
|
21
|
+
* Provides AST parsing using tree-sitter with fallback to regex-based
|
|
22
|
+
* parsing when tree-sitter is not available.
|
|
23
|
+
*/
|
|
24
|
+
export class TreeSitterPythonParser extends BaseParser {
|
|
25
|
+
language = 'python';
|
|
26
|
+
extensions = ['.py', '.pyw', '.pyi'];
|
|
27
|
+
config;
|
|
28
|
+
converter;
|
|
29
|
+
pydanticExtractor;
|
|
30
|
+
parser = null;
|
|
31
|
+
/**
|
|
32
|
+
* Create a new TreeSitterPythonParser.
|
|
33
|
+
*
|
|
34
|
+
* @param config - Parser configuration options
|
|
35
|
+
*/
|
|
36
|
+
constructor(config = {}) {
|
|
37
|
+
super();
|
|
38
|
+
this.config = mergeConfig(config);
|
|
39
|
+
this.converter = new PythonASTConverter({
|
|
40
|
+
includeComments: this.config.includeComments,
|
|
41
|
+
includeAnonymous: this.config.includeAnonymous,
|
|
42
|
+
maxDepth: 0, // No limit
|
|
43
|
+
});
|
|
44
|
+
this.pydanticExtractor = new PydanticExtractor();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Check if tree-sitter is available for Python parsing.
|
|
48
|
+
*
|
|
49
|
+
* @returns true if tree-sitter and tree-sitter-python are available
|
|
50
|
+
*/
|
|
51
|
+
static isAvailable() {
|
|
52
|
+
return isTreeSitterAvailable();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parse Python source code into an AST.
|
|
56
|
+
*
|
|
57
|
+
* @param source - The source code to parse
|
|
58
|
+
* @param filePath - Optional file path for error reporting
|
|
59
|
+
* @returns TreeSitterPythonParseResult containing the AST
|
|
60
|
+
*/
|
|
61
|
+
parse(source, filePath) {
|
|
62
|
+
// Check if tree-sitter should be used
|
|
63
|
+
if (!this.config.useTreeSitter || !isTreeSitterAvailable()) {
|
|
64
|
+
return this.createFallbackResult(source, filePath);
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
// Initialize parser if needed
|
|
68
|
+
if (!this.parser) {
|
|
69
|
+
this.parser = createPythonParser();
|
|
70
|
+
}
|
|
71
|
+
// Set timeout if configured
|
|
72
|
+
if (this.config.parseTimeout > 0) {
|
|
73
|
+
this.parser.setTimeoutMicros(this.config.parseTimeout * 1000);
|
|
74
|
+
}
|
|
75
|
+
// Parse the source
|
|
76
|
+
const tree = this.parser.parse(source);
|
|
77
|
+
// Check for parse errors
|
|
78
|
+
const hasErrors = tree.rootNode.hasError;
|
|
79
|
+
// Convert to drift AST
|
|
80
|
+
const ast = this.converter.convertTree(tree, source);
|
|
81
|
+
// Extract Pydantic models if enabled
|
|
82
|
+
const pydanticModels = this.config.extractPydanticModels
|
|
83
|
+
? this.extractPydanticModelsFromTree(tree, source)
|
|
84
|
+
: [];
|
|
85
|
+
return {
|
|
86
|
+
ast,
|
|
87
|
+
language: this.language,
|
|
88
|
+
errors: hasErrors ? [this.createError('Parse errors detected', { row: 0, column: 0 })] : [],
|
|
89
|
+
success: true,
|
|
90
|
+
treeSitterTree: tree,
|
|
91
|
+
usedTreeSitter: true,
|
|
92
|
+
pydanticModels,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown parse error';
|
|
97
|
+
return {
|
|
98
|
+
...this.createFailureResult([
|
|
99
|
+
this.createError(`Tree-sitter parse error: ${errorMessage}`, { row: 0, column: 0 }),
|
|
100
|
+
]),
|
|
101
|
+
treeSitterTree: null,
|
|
102
|
+
usedTreeSitter: true,
|
|
103
|
+
pydanticModels: [],
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Query the AST for nodes matching a pattern.
|
|
109
|
+
*
|
|
110
|
+
* Supports tree-sitter query syntax when tree-sitter is available,
|
|
111
|
+
* otherwise falls back to simple node type matching.
|
|
112
|
+
*
|
|
113
|
+
* @param ast - The AST to query
|
|
114
|
+
* @param pattern - The query pattern (tree-sitter query or node type)
|
|
115
|
+
* @returns Array of matching AST nodes
|
|
116
|
+
*/
|
|
117
|
+
query(ast, pattern) {
|
|
118
|
+
// Simple node type query (works without tree-sitter)
|
|
119
|
+
if (!pattern.includes('(') && !pattern.includes('@')) {
|
|
120
|
+
return this.findNodesByType(ast, pattern);
|
|
121
|
+
}
|
|
122
|
+
// Tree-sitter query syntax requires tree-sitter
|
|
123
|
+
if (!isTreeSitterAvailable()) {
|
|
124
|
+
// Fall back to simple type matching
|
|
125
|
+
return this.findNodesByType(ast, this.extractNodeTypeFromQuery(pattern));
|
|
126
|
+
}
|
|
127
|
+
// Execute tree-sitter query
|
|
128
|
+
return this.executeTreeSitterQuery(ast, pattern);
|
|
129
|
+
}
|
|
130
|
+
// ============================================
|
|
131
|
+
// Private Methods
|
|
132
|
+
// ============================================
|
|
133
|
+
/**
|
|
134
|
+
* Create a fallback result when tree-sitter is not available.
|
|
135
|
+
*/
|
|
136
|
+
createFallbackResult(source, _filePath) {
|
|
137
|
+
// Create a minimal AST structure
|
|
138
|
+
const lines = source.split('\n');
|
|
139
|
+
const endPosition = lines.length > 0
|
|
140
|
+
? { row: lines.length - 1, column: lines[lines.length - 1]?.length ?? 0 }
|
|
141
|
+
: { row: 0, column: 0 };
|
|
142
|
+
const rootNode = this.createNode('Module', source, { row: 0, column: 0 }, endPosition, []);
|
|
143
|
+
const ast = this.createAST(rootNode, source);
|
|
144
|
+
return {
|
|
145
|
+
...this.createSuccessResult(ast),
|
|
146
|
+
treeSitterTree: null,
|
|
147
|
+
usedTreeSitter: false,
|
|
148
|
+
pydanticModels: [],
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Extract Pydantic models from a tree-sitter tree.
|
|
153
|
+
*/
|
|
154
|
+
extractPydanticModelsFromTree(tree, source) {
|
|
155
|
+
return this.pydanticExtractor.extractModels(tree, source, {
|
|
156
|
+
maxTypeDepth: this.config.maxTypeDepth,
|
|
157
|
+
includePositions: this.config.includePositions,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Execute a tree-sitter query on the AST.
|
|
162
|
+
*/
|
|
163
|
+
executeTreeSitterQuery(ast, pattern) {
|
|
164
|
+
// This requires access to the original tree-sitter tree
|
|
165
|
+
// For now, fall back to simple matching
|
|
166
|
+
return this.findNodesByType(ast, this.extractNodeTypeFromQuery(pattern));
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Extract a simple node type from a tree-sitter query pattern.
|
|
170
|
+
*/
|
|
171
|
+
extractNodeTypeFromQuery(pattern) {
|
|
172
|
+
// Extract the first node type from patterns like "(class_definition ...)"
|
|
173
|
+
const match = pattern.match(/\((\w+)/);
|
|
174
|
+
return match?.[1] ?? pattern;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=tree-sitter-python-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-sitter-python-parser.js","sourceRoot":"","sources":["../../../src/parsers/tree-sitter/tree-sitter-python-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAO/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAExE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAkBrE,+CAA+C;AAC/C,oBAAoB;AACpB,+CAA+C;AAE/C;;;;;GAKG;AACH,MAAM,OAAO,sBAAuB,SAAQ,UAAU;IAC3C,QAAQ,GAAa,QAAQ,CAAC;IAC9B,UAAU,GAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAEvC,MAAM,CAAqB;IAC3B,SAAS,CAAqB;IAC9B,iBAAiB,CAAoB;IAC9C,MAAM,GAA4B,IAAI,CAAC;IAE/C;;;;OAIG;IACH,YAAY,SAAsC,EAAE;QAClD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,IAAI,kBAAkB,CAAC;YACtC,eAAe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Y;YACtC,gBAAgB,EAAE,IAAI,CAAC,MAAM,CAAC,gBAAgB;SAC/C,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACK,sBAAsB,CAAC,GAAQ,EAAE,OAAe;QACtD,wDAAwD;QACxD,wCAAwC;QACxC,OAAO,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED;;OAEG;IACK,wBAAwB,CAAC,OAAe;QAC9C,0EAA0E;QAC1E,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACvC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC;IAC/B,CAAC;CAEF"}
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* TypeScript types for tree-sitter integration, including
|
|
5
|
+
* tree-sitter core types and Pydantic-specific types for
|
|
6
|
+
* Python model extraction.
|
|
7
|
+
*
|
|
8
|
+
* @requirements 3.5 - Unified AST query interface
|
|
9
|
+
*/
|
|
10
|
+
import type { Position } from '../types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Represents a tree-sitter syntax node.
|
|
13
|
+
* This mirrors the tree-sitter Node interface.
|
|
14
|
+
*/
|
|
15
|
+
export interface TreeSitterNode {
|
|
16
|
+
/** The type of the node (e.g., 'function_definition', 'class_definition') */
|
|
17
|
+
type: string;
|
|
18
|
+
/** The text content of the node */
|
|
19
|
+
text: string;
|
|
20
|
+
/** Start position in the source */
|
|
21
|
+
startPosition: TreeSitterPoint;
|
|
22
|
+
/** End position in the source */
|
|
23
|
+
endPosition: TreeSitterPoint;
|
|
24
|
+
/** Start byte offset in the source */
|
|
25
|
+
startIndex: number;
|
|
26
|
+
/** End byte offset in the source */
|
|
27
|
+
endIndex: number;
|
|
28
|
+
/** Whether this is a named node (vs anonymous) */
|
|
29
|
+
isNamed: boolean;
|
|
30
|
+
/** Whether this node has any errors */
|
|
31
|
+
hasError: boolean;
|
|
32
|
+
/** Whether this node is missing (error recovery) */
|
|
33
|
+
isMissing: boolean;
|
|
34
|
+
/** Child nodes */
|
|
35
|
+
children: TreeSitterNode[];
|
|
36
|
+
/** Named child nodes only */
|
|
37
|
+
namedChildren: TreeSitterNode[];
|
|
38
|
+
/** Number of children */
|
|
39
|
+
childCount: number;
|
|
40
|
+
/** Number of named children */
|
|
41
|
+
namedChildCount: number;
|
|
42
|
+
/** Parent node, if any */
|
|
43
|
+
parent: TreeSitterNode | null;
|
|
44
|
+
/** Next sibling node */
|
|
45
|
+
nextSibling: TreeSitterNode | null;
|
|
46
|
+
/** Previous sibling node */
|
|
47
|
+
previousSibling: TreeSitterNode | null;
|
|
48
|
+
/** Next named sibling node */
|
|
49
|
+
nextNamedSibling: TreeSitterNode | null;
|
|
50
|
+
/** Previous named sibling node */
|
|
51
|
+
previousNamedSibling: TreeSitterNode | null;
|
|
52
|
+
/** Get child by field name */
|
|
53
|
+
childForFieldName(fieldName: string): TreeSitterNode | null;
|
|
54
|
+
/** Get children by field name */
|
|
55
|
+
childrenForFieldName(fieldName: string): TreeSitterNode[];
|
|
56
|
+
/** Get the first child of a specific type */
|
|
57
|
+
firstChildForType(type: string): TreeSitterNode | null;
|
|
58
|
+
/** Get descendant for a position range */
|
|
59
|
+
descendantForPosition(start: TreeSitterPoint, end?: TreeSitterPoint): TreeSitterNode;
|
|
60
|
+
/** Get named descendant for a position range */
|
|
61
|
+
namedDescendantForPosition(start: TreeSitterPoint, end?: TreeSitterPoint): TreeSitterNode;
|
|
62
|
+
/** Walk the tree */
|
|
63
|
+
walk(): TreeSitterTreeCursor;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Represents a point (position) in tree-sitter.
|
|
67
|
+
*/
|
|
68
|
+
export interface TreeSitterPoint {
|
|
69
|
+
/** Row (0-indexed line number) */
|
|
70
|
+
row: number;
|
|
71
|
+
/** Column (0-indexed character offset) */
|
|
72
|
+
column: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Represents a tree-sitter syntax tree.
|
|
76
|
+
*/
|
|
77
|
+
export interface TreeSitterTree {
|
|
78
|
+
/** The root node of the tree */
|
|
79
|
+
rootNode: TreeSitterNode;
|
|
80
|
+
/** The language of the tree */
|
|
81
|
+
language: TreeSitterLanguage;
|
|
82
|
+
/** Walk the tree */
|
|
83
|
+
walk(): TreeSitterTreeCursor;
|
|
84
|
+
/** Edit the tree for incremental parsing */
|
|
85
|
+
edit(edit: TreeSitterEdit): void;
|
|
86
|
+
/** Get changed ranges after an edit */
|
|
87
|
+
getChangedRanges(other: TreeSitterTree): TreeSitterRange[];
|
|
88
|
+
/** Copy the tree */
|
|
89
|
+
copy(): TreeSitterTree;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Represents a tree-sitter parser.
|
|
93
|
+
*/
|
|
94
|
+
export interface TreeSitterParser {
|
|
95
|
+
/** Set the language for parsing */
|
|
96
|
+
setLanguage(language: TreeSitterLanguage): void;
|
|
97
|
+
/** Get the current language */
|
|
98
|
+
getLanguage(): TreeSitterLanguage | null;
|
|
99
|
+
/** Parse source code */
|
|
100
|
+
parse(input: string | TreeSitterInput, oldTree?: TreeSitterTree): TreeSitterTree;
|
|
101
|
+
/** Reset the parser */
|
|
102
|
+
reset(): void;
|
|
103
|
+
/** Set timeout in microseconds */
|
|
104
|
+
setTimeoutMicros(timeout: number): void;
|
|
105
|
+
/** Get timeout in microseconds */
|
|
106
|
+
getTimeoutMicros(): number;
|
|
107
|
+
/** Set included ranges */
|
|
108
|
+
setIncludedRanges(ranges: TreeSitterRange[]): void;
|
|
109
|
+
/** Get included ranges */
|
|
110
|
+
getIncludedRanges(): TreeSitterRange[];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Represents a tree-sitter language.
|
|
114
|
+
*/
|
|
115
|
+
export interface TreeSitterLanguage {
|
|
116
|
+
/** Language version */
|
|
117
|
+
version: number;
|
|
118
|
+
/** Number of node types */
|
|
119
|
+
nodeTypeCount: number;
|
|
120
|
+
/** Get node type name by ID */
|
|
121
|
+
nodeTypeForId(id: number): string | null;
|
|
122
|
+
/** Get node type ID by name */
|
|
123
|
+
nodeTypeIdForName(name: string, isNamed: boolean): number | null;
|
|
124
|
+
/** Number of fields */
|
|
125
|
+
fieldCount: number;
|
|
126
|
+
/** Get field name by ID */
|
|
127
|
+
fieldNameForId(id: number): string | null;
|
|
128
|
+
/** Get field ID by name */
|
|
129
|
+
fieldIdForName(name: string): number | null;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Represents a tree-sitter tree cursor for efficient traversal.
|
|
133
|
+
*/
|
|
134
|
+
export interface TreeSitterTreeCursor {
|
|
135
|
+
/** Current node */
|
|
136
|
+
currentNode: TreeSitterNode;
|
|
137
|
+
/** Current field name */
|
|
138
|
+
currentFieldName: string | null;
|
|
139
|
+
/** Current field ID */
|
|
140
|
+
currentFieldId: number;
|
|
141
|
+
/** Go to parent */
|
|
142
|
+
gotoParent(): boolean;
|
|
143
|
+
/** Go to first child */
|
|
144
|
+
gotoFirstChild(): boolean;
|
|
145
|
+
/** Go to first child for a byte offset */
|
|
146
|
+
gotoFirstChildForIndex(index: number): boolean;
|
|
147
|
+
/** Go to next sibling */
|
|
148
|
+
gotoNextSibling(): boolean;
|
|
149
|
+
/** Reset to a node */
|
|
150
|
+
reset(node: TreeSitterNode): void;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Input function for incremental parsing.
|
|
154
|
+
*/
|
|
155
|
+
export type TreeSitterInput = (startIndex: number, startPoint: TreeSitterPoint | null, endIndex: number | null) => string | null;
|
|
156
|
+
/**
|
|
157
|
+
* Represents an edit for incremental parsing.
|
|
158
|
+
*/
|
|
159
|
+
export interface TreeSitterEdit {
|
|
160
|
+
/** Start byte offset */
|
|
161
|
+
startIndex: number;
|
|
162
|
+
/** Old end byte offset */
|
|
163
|
+
oldEndIndex: number;
|
|
164
|
+
/** New end byte offset */
|
|
165
|
+
newEndIndex: number;
|
|
166
|
+
/** Start position */
|
|
167
|
+
startPosition: TreeSitterPoint;
|
|
168
|
+
/** Old end position */
|
|
169
|
+
oldEndPosition: TreeSitterPoint;
|
|
170
|
+
/** New end position */
|
|
171
|
+
newEndPosition: TreeSitterPoint;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Represents a range in the source.
|
|
175
|
+
*/
|
|
176
|
+
export interface TreeSitterRange {
|
|
177
|
+
/** Start position */
|
|
178
|
+
startPosition: TreeSitterPoint;
|
|
179
|
+
/** End position */
|
|
180
|
+
endPosition: TreeSitterPoint;
|
|
181
|
+
/** Start byte offset */
|
|
182
|
+
startIndex: number;
|
|
183
|
+
/** End byte offset */
|
|
184
|
+
endIndex: number;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Represents a tree-sitter query.
|
|
188
|
+
*/
|
|
189
|
+
export interface TreeSitterQuery {
|
|
190
|
+
/** Execute the query on a node */
|
|
191
|
+
matches(node: TreeSitterNode, options?: TreeSitterQueryOptions): TreeSitterQueryMatch[];
|
|
192
|
+
/** Execute the query and get captures */
|
|
193
|
+
captures(node: TreeSitterNode, options?: TreeSitterQueryOptions): TreeSitterQueryCapture[];
|
|
194
|
+
/** Pattern count */
|
|
195
|
+
patternCount: number;
|
|
196
|
+
/** Capture names */
|
|
197
|
+
captureNames: string[];
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Options for query execution.
|
|
201
|
+
*/
|
|
202
|
+
export interface TreeSitterQueryOptions {
|
|
203
|
+
/** Start position */
|
|
204
|
+
startPosition?: TreeSitterPoint;
|
|
205
|
+
/** End position */
|
|
206
|
+
endPosition?: TreeSitterPoint;
|
|
207
|
+
/** Start byte offset */
|
|
208
|
+
startIndex?: number;
|
|
209
|
+
/** End byte offset */
|
|
210
|
+
endIndex?: number;
|
|
211
|
+
/** Match limit */
|
|
212
|
+
matchLimit?: number;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Represents a query match.
|
|
216
|
+
*/
|
|
217
|
+
export interface TreeSitterQueryMatch {
|
|
218
|
+
/** Pattern index */
|
|
219
|
+
pattern: number;
|
|
220
|
+
/** Captures in this match */
|
|
221
|
+
captures: TreeSitterQueryCapture[];
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Represents a query capture.
|
|
225
|
+
*/
|
|
226
|
+
export interface TreeSitterQueryCapture {
|
|
227
|
+
/** Capture name */
|
|
228
|
+
name: string;
|
|
229
|
+
/** Captured node */
|
|
230
|
+
node: TreeSitterNode;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Information about a Pydantic model.
|
|
234
|
+
*/
|
|
235
|
+
export interface PydanticModelInfo {
|
|
236
|
+
/** Model class name */
|
|
237
|
+
name: string;
|
|
238
|
+
/** Base classes (e.g., BaseModel, BaseSettings) */
|
|
239
|
+
bases: string[];
|
|
240
|
+
/** Model fields */
|
|
241
|
+
fields: PydanticFieldInfo[];
|
|
242
|
+
/** Model validators */
|
|
243
|
+
validators: PydanticValidatorInfo[];
|
|
244
|
+
/** Model configuration (Config class or model_config) */
|
|
245
|
+
config: PydanticConfigInfo | null;
|
|
246
|
+
/** Decorators applied to the model */
|
|
247
|
+
decorators: string[];
|
|
248
|
+
/** Docstring if present */
|
|
249
|
+
docstring: string | null;
|
|
250
|
+
/** Whether this is a Pydantic v1 or v2 model */
|
|
251
|
+
version: 1 | 2 | 'unknown';
|
|
252
|
+
/** Start position in source */
|
|
253
|
+
startPosition: Position;
|
|
254
|
+
/** End position in source */
|
|
255
|
+
endPosition: Position;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Information about a Pydantic field.
|
|
259
|
+
*/
|
|
260
|
+
export interface PydanticFieldInfo {
|
|
261
|
+
/** Field name */
|
|
262
|
+
name: string;
|
|
263
|
+
/** Field type information */
|
|
264
|
+
type: TypeInfo;
|
|
265
|
+
/** Default value if any */
|
|
266
|
+
defaultValue: string | null;
|
|
267
|
+
/** Whether the field has a default */
|
|
268
|
+
hasDefault: boolean;
|
|
269
|
+
/** Whether the field uses Field() */
|
|
270
|
+
usesField: boolean;
|
|
271
|
+
/** Field constraints from Field() */
|
|
272
|
+
constraints: FieldConstraints;
|
|
273
|
+
/** Field alias if specified */
|
|
274
|
+
alias: string | null;
|
|
275
|
+
/** Field description if specified */
|
|
276
|
+
description: string | null;
|
|
277
|
+
/** Whether the field is required */
|
|
278
|
+
required: boolean;
|
|
279
|
+
/** Start position in source */
|
|
280
|
+
startPosition: Position;
|
|
281
|
+
/** End position in source */
|
|
282
|
+
endPosition: Position;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Information about a type annotation.
|
|
286
|
+
*/
|
|
287
|
+
export interface TypeInfo {
|
|
288
|
+
/** Raw type string as written in source */
|
|
289
|
+
raw: string;
|
|
290
|
+
/** Base type name (e.g., 'str', 'int', 'List') */
|
|
291
|
+
base: string;
|
|
292
|
+
/** Type arguments for generic types (e.g., ['str'] for List[str]) */
|
|
293
|
+
args: TypeInfo[];
|
|
294
|
+
/** Whether the type is Optional */
|
|
295
|
+
isOptional: boolean;
|
|
296
|
+
/** Whether the type is a Union */
|
|
297
|
+
isUnion: boolean;
|
|
298
|
+
/** Whether the type is a List/Sequence */
|
|
299
|
+
isList: boolean;
|
|
300
|
+
/** Whether the type is a Dict/Mapping */
|
|
301
|
+
isDict: boolean;
|
|
302
|
+
/** Whether the type is a literal type */
|
|
303
|
+
isLiteral: boolean;
|
|
304
|
+
/** Literal values if isLiteral is true */
|
|
305
|
+
literalValues: string[];
|
|
306
|
+
/** Whether the type references another Pydantic model */
|
|
307
|
+
isPydanticModel: boolean;
|
|
308
|
+
/** Referenced model name if isPydanticModel is true */
|
|
309
|
+
referencedModel: string | null;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Constraints that can be applied to a Pydantic field.
|
|
313
|
+
*/
|
|
314
|
+
export interface FieldConstraints {
|
|
315
|
+
/** Minimum value for numeric types */
|
|
316
|
+
ge: number | null;
|
|
317
|
+
/** Maximum value for numeric types */
|
|
318
|
+
le: number | null;
|
|
319
|
+
/** Greater than (exclusive minimum) */
|
|
320
|
+
gt: number | null;
|
|
321
|
+
/** Less than (exclusive maximum) */
|
|
322
|
+
lt: number | null;
|
|
323
|
+
/** Minimum length for strings/sequences */
|
|
324
|
+
minLength: number | null;
|
|
325
|
+
/** Maximum length for strings/sequences */
|
|
326
|
+
maxLength: number | null;
|
|
327
|
+
/** Regex pattern for strings */
|
|
328
|
+
pattern: string | null;
|
|
329
|
+
/** Multiple of for numeric types */
|
|
330
|
+
multipleOf: number | null;
|
|
331
|
+
/** Whether the field is frozen (immutable) */
|
|
332
|
+
frozen: boolean;
|
|
333
|
+
/** Custom validation function names */
|
|
334
|
+
validators: string[];
|
|
335
|
+
/** JSON schema extra properties */
|
|
336
|
+
jsonSchemaExtra: Record<string, unknown> | null;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Information about a Pydantic validator.
|
|
340
|
+
*/
|
|
341
|
+
export interface PydanticValidatorInfo {
|
|
342
|
+
/** Validator function name */
|
|
343
|
+
name: string;
|
|
344
|
+
/** Fields this validator applies to */
|
|
345
|
+
fields: string[];
|
|
346
|
+
/** Validator mode (before, after, wrap, plain) */
|
|
347
|
+
mode: 'before' | 'after' | 'wrap' | 'plain' | 'unknown';
|
|
348
|
+
/** Whether this is a field validator or model validator */
|
|
349
|
+
type: 'field' | 'model' | 'root';
|
|
350
|
+
/** Whether the validator is a classmethod */
|
|
351
|
+
isClassmethod: boolean;
|
|
352
|
+
/** Start position in source */
|
|
353
|
+
startPosition: Position;
|
|
354
|
+
/** End position in source */
|
|
355
|
+
endPosition: Position;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Information about Pydantic model configuration.
|
|
359
|
+
*/
|
|
360
|
+
export interface PydanticConfigInfo {
|
|
361
|
+
/** Whether extra fields are allowed */
|
|
362
|
+
extra: 'allow' | 'forbid' | 'ignore' | null;
|
|
363
|
+
/** Whether the model is frozen (immutable) */
|
|
364
|
+
frozen: boolean | null;
|
|
365
|
+
/** Whether to validate assignment */
|
|
366
|
+
validateAssignment: boolean | null;
|
|
367
|
+
/** Whether to use enum values */
|
|
368
|
+
useEnumValues: boolean | null;
|
|
369
|
+
/** Whether to validate default values */
|
|
370
|
+
validateDefault: boolean | null;
|
|
371
|
+
/** Whether to populate by name */
|
|
372
|
+
populateByName: boolean | null;
|
|
373
|
+
/** Arbitrary types allowed */
|
|
374
|
+
arbitraryTypesAllowed: boolean | null;
|
|
375
|
+
/** JSON schema extra */
|
|
376
|
+
jsonSchemaExtra: Record<string, unknown> | null;
|
|
377
|
+
/** All raw config values */
|
|
378
|
+
raw: Record<string, unknown>;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Configuration options for the tree-sitter Python parser.
|
|
382
|
+
*/
|
|
383
|
+
export interface TreeSitterPythonParserConfig {
|
|
384
|
+
/** Whether to extract Pydantic model information */
|
|
385
|
+
extractPydanticModels: boolean;
|
|
386
|
+
/** Maximum depth for type resolution */
|
|
387
|
+
maxTypeDepth: number;
|
|
388
|
+
/** Whether to include position information in extracted data */
|
|
389
|
+
includePositions: boolean;
|
|
390
|
+
/** Timeout for parsing in milliseconds (0 = no timeout) */
|
|
391
|
+
parseTimeout: number;
|
|
392
|
+
/** Whether to use incremental parsing when possible */
|
|
393
|
+
useIncremental: boolean;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Default configuration for tree-sitter Python parser.
|
|
397
|
+
*/
|
|
398
|
+
export declare const DEFAULT_TREE_SITTER_PYTHON_CONFIG: TreeSitterPythonParserConfig;
|
|
399
|
+
//# sourceMappingURL=types.d.ts.map
|