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,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter Java Loader
|
|
3
|
+
*
|
|
4
|
+
* Handles loading tree-sitter and tree-sitter-java with graceful fallback.
|
|
5
|
+
* Provides functions to check availability and access the parser/language.
|
|
6
|
+
*
|
|
7
|
+
* @requirements Java/Spring Boot Language Support
|
|
8
|
+
*/
|
|
9
|
+
import type { TreeSitterParser, TreeSitterLanguage } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Check if tree-sitter-java is available.
|
|
12
|
+
*
|
|
13
|
+
* This function attempts to load tree-sitter and tree-sitter-java
|
|
14
|
+
* on first call and caches the result.
|
|
15
|
+
*
|
|
16
|
+
* @returns true if tree-sitter-java is available and working
|
|
17
|
+
*/
|
|
18
|
+
export declare function isJavaTreeSitterAvailable(): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Get the Java language for tree-sitter.
|
|
21
|
+
*
|
|
22
|
+
* @returns TreeSitter Java language
|
|
23
|
+
* @throws Error if tree-sitter-java is not available
|
|
24
|
+
*/
|
|
25
|
+
export declare function getJavaLanguage(): TreeSitterLanguage;
|
|
26
|
+
/**
|
|
27
|
+
* Get the tree-sitter Parser constructor for Java.
|
|
28
|
+
*
|
|
29
|
+
* @returns TreeSitter Parser constructor
|
|
30
|
+
* @throws Error if tree-sitter is not available
|
|
31
|
+
*/
|
|
32
|
+
export declare function getJavaTreeSitter(): new () => TreeSitterParser;
|
|
33
|
+
/**
|
|
34
|
+
* Create a new tree-sitter parser instance configured for Java.
|
|
35
|
+
*
|
|
36
|
+
* @returns Configured TreeSitter parser
|
|
37
|
+
* @throws Error if tree-sitter-java is not available
|
|
38
|
+
*/
|
|
39
|
+
export declare function createJavaParser(): TreeSitterParser;
|
|
40
|
+
/**
|
|
41
|
+
* Get the loading error message if tree-sitter-java failed to load.
|
|
42
|
+
*
|
|
43
|
+
* @returns Error message or null if no error
|
|
44
|
+
*/
|
|
45
|
+
export declare function getJavaLoadingError(): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* Reset the loader state (useful for testing).
|
|
48
|
+
*/
|
|
49
|
+
export declare function resetJavaLoader(): void;
|
|
50
|
+
//# sourceMappingURL=java-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"java-loader.d.ts","sourceRoot":"","sources":["../../../src/parsers/tree-sitter/java-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAyBvE;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,IAAI,OAAO,CAenD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,kBAAkB,CAUpD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,UAAU,gBAAgB,CAU9D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,gBAAgB,CAgBnD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,GAAG,IAAI,CAInD;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAKtC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter Java Loader
|
|
3
|
+
*
|
|
4
|
+
* Handles loading tree-sitter and tree-sitter-java with graceful fallback.
|
|
5
|
+
* Provides functions to check availability and access the parser/language.
|
|
6
|
+
*
|
|
7
|
+
* @requirements Java/Spring Boot Language Support
|
|
8
|
+
*/
|
|
9
|
+
import { createRequire } from 'node:module';
|
|
10
|
+
// Create require function for ESM compatibility
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
// ============================================
|
|
13
|
+
// Module State
|
|
14
|
+
// ============================================
|
|
15
|
+
/** Whether tree-sitter-java is available */
|
|
16
|
+
let javaAvailable = null;
|
|
17
|
+
/** Cached tree-sitter module */
|
|
18
|
+
let cachedTreeSitter = null;
|
|
19
|
+
/** Cached Java language */
|
|
20
|
+
let cachedJavaLanguage = null;
|
|
21
|
+
/** Loading error message if any */
|
|
22
|
+
let loadingError = null;
|
|
23
|
+
// ============================================
|
|
24
|
+
// Public API
|
|
25
|
+
// ============================================
|
|
26
|
+
/**
|
|
27
|
+
* Check if tree-sitter-java is available.
|
|
28
|
+
*
|
|
29
|
+
* This function attempts to load tree-sitter and tree-sitter-java
|
|
30
|
+
* on first call and caches the result.
|
|
31
|
+
*
|
|
32
|
+
* @returns true if tree-sitter-java is available and working
|
|
33
|
+
*/
|
|
34
|
+
export function isJavaTreeSitterAvailable() {
|
|
35
|
+
if (javaAvailable !== null) {
|
|
36
|
+
return javaAvailable;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
loadJavaTreeSitter();
|
|
40
|
+
javaAvailable = true;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
javaAvailable = false;
|
|
44
|
+
loadingError = error instanceof Error ? error.message : 'Unknown error loading tree-sitter-java';
|
|
45
|
+
logDebug(`tree-sitter-java not available: ${loadingError}`);
|
|
46
|
+
}
|
|
47
|
+
return javaAvailable;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get the Java language for tree-sitter.
|
|
51
|
+
*
|
|
52
|
+
* @returns TreeSitter Java language
|
|
53
|
+
* @throws Error if tree-sitter-java is not available
|
|
54
|
+
*/
|
|
55
|
+
export function getJavaLanguage() {
|
|
56
|
+
if (!isJavaTreeSitterAvailable()) {
|
|
57
|
+
throw new Error(`tree-sitter-java is not available: ${loadingError ?? 'unknown error'}`);
|
|
58
|
+
}
|
|
59
|
+
if (!cachedJavaLanguage) {
|
|
60
|
+
throw new Error('tree-sitter-java language not loaded');
|
|
61
|
+
}
|
|
62
|
+
return cachedJavaLanguage;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the tree-sitter Parser constructor for Java.
|
|
66
|
+
*
|
|
67
|
+
* @returns TreeSitter Parser constructor
|
|
68
|
+
* @throws Error if tree-sitter is not available
|
|
69
|
+
*/
|
|
70
|
+
export function getJavaTreeSitter() {
|
|
71
|
+
if (!isJavaTreeSitterAvailable()) {
|
|
72
|
+
throw new Error(`tree-sitter-java is not available: ${loadingError ?? 'unknown error'}`);
|
|
73
|
+
}
|
|
74
|
+
if (!cachedTreeSitter) {
|
|
75
|
+
throw new Error('tree-sitter module not loaded');
|
|
76
|
+
}
|
|
77
|
+
return cachedTreeSitter;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create a new tree-sitter parser instance configured for Java.
|
|
81
|
+
*
|
|
82
|
+
* @returns Configured TreeSitter parser
|
|
83
|
+
* @throws Error if tree-sitter-java is not available
|
|
84
|
+
*/
|
|
85
|
+
export function createJavaParser() {
|
|
86
|
+
if (!isJavaTreeSitterAvailable()) {
|
|
87
|
+
throw new Error(`tree-sitter-java is not available: ${loadingError ?? 'unknown error'}`);
|
|
88
|
+
}
|
|
89
|
+
if (!cachedTreeSitter) {
|
|
90
|
+
throw new Error('tree-sitter module not loaded');
|
|
91
|
+
}
|
|
92
|
+
const Parser = cachedTreeSitter;
|
|
93
|
+
const language = getJavaLanguage();
|
|
94
|
+
const parser = new Parser();
|
|
95
|
+
parser.setLanguage(language);
|
|
96
|
+
return parser;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get the loading error message if tree-sitter-java failed to load.
|
|
100
|
+
*
|
|
101
|
+
* @returns Error message or null if no error
|
|
102
|
+
*/
|
|
103
|
+
export function getJavaLoadingError() {
|
|
104
|
+
// Ensure we've attempted to load
|
|
105
|
+
isJavaTreeSitterAvailable();
|
|
106
|
+
return loadingError;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Reset the loader state (useful for testing).
|
|
110
|
+
*/
|
|
111
|
+
export function resetJavaLoader() {
|
|
112
|
+
javaAvailable = null;
|
|
113
|
+
cachedTreeSitter = null;
|
|
114
|
+
cachedJavaLanguage = null;
|
|
115
|
+
loadingError = null;
|
|
116
|
+
}
|
|
117
|
+
// ============================================
|
|
118
|
+
// Internal Functions
|
|
119
|
+
// ============================================
|
|
120
|
+
/**
|
|
121
|
+
* Attempt to load tree-sitter and tree-sitter-java.
|
|
122
|
+
*
|
|
123
|
+
* @throws Error if loading fails
|
|
124
|
+
*/
|
|
125
|
+
function loadJavaTreeSitter() {
|
|
126
|
+
// Skip if already loaded
|
|
127
|
+
if (cachedTreeSitter && cachedJavaLanguage) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
// Dynamic require for optional dependencies
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
133
|
+
cachedTreeSitter = require('tree-sitter');
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
throw new Error(`Failed to load tree-sitter: ${error instanceof Error ? error.message : 'unknown error'}. ` +
|
|
137
|
+
'Install with: pnpm add tree-sitter tree-sitter-java');
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
141
|
+
cachedJavaLanguage = require('tree-sitter-java');
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
// Clear tree-sitter cache since we can't use it without Java
|
|
145
|
+
cachedTreeSitter = null;
|
|
146
|
+
throw new Error(`Failed to load tree-sitter-java: ${error instanceof Error ? error.message : 'unknown error'}. ` +
|
|
147
|
+
'Install with: pnpm add tree-sitter-java');
|
|
148
|
+
}
|
|
149
|
+
logDebug('tree-sitter and tree-sitter-java loaded successfully');
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Log debug message if debug mode is enabled.
|
|
153
|
+
*
|
|
154
|
+
* @param message - Message to log
|
|
155
|
+
*/
|
|
156
|
+
function logDebug(message) {
|
|
157
|
+
if (process.env['DRIFT_PARSER_DEBUG'] === 'true') {
|
|
158
|
+
console.debug(`[java-loader] ${message}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=java-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"java-loader.js","sourceRoot":"","sources":["../../../src/parsers/tree-sitter/java-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,gDAAgD;AAChD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,+CAA+C;AAC/C,eAAe;AACf,+CAA+C;AAE/C,4CAA4C;AAC5C,IAAI,aAAa,GAAmB,IAAI,CAAC;AAEzC,gCAAgC;AAChC,IAAI,gBAAgB,GAAwC,IAAI,CAAC;AAEjE,2BAA2B;AAC3B,IAAI,kBAAkB,GAA8B,IAAI,CAAC;AAEzD,mCAAmC;AACnC,IAAI,YAAY,GAAkB,IAAI,CAAC;AAEvC,+CAA+C;AAC/C,aAAa;AACb,+CAA+C;AAE/C;;;;;;;GAOG;AACH,MAAM,UAAU,yBAAyB;IACvC,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;QAC3B,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,IAAI,CAAC;QACH,kBAAkB,EAAE,CAAC;QACrB,aAAa,GAAG,IAAI,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,aAAa,GAAG,KAAK,CAAC;QACtB,YAAY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IG;AACH,SAAS,QAAQ,CAAC,OAAe;IAC/B,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,KAAK,MAAM,EAAE,CAAC;QACjD,OAAO,CAAC,KAAK,CAAC,iBAAiB,OAAO,EAAE,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter Loader
|
|
3
|
+
*
|
|
4
|
+
* Handles loading tree-sitter and tree-sitter-python with graceful fallback.
|
|
5
|
+
* Provides functions to check availability and access the parser/language.
|
|
6
|
+
*
|
|
7
|
+
* @requirements 3.5 - Unified AST query interface
|
|
8
|
+
*/
|
|
9
|
+
import type { TreeSitterParser, TreeSitterLanguage } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Check if tree-sitter is available.
|
|
12
|
+
*
|
|
13
|
+
* This function attempts to load tree-sitter and tree-sitter-python
|
|
14
|
+
* on first call and caches the result.
|
|
15
|
+
*
|
|
16
|
+
* @returns true if tree-sitter is available and working
|
|
17
|
+
*/
|
|
18
|
+
export declare function isTreeSitterAvailable(): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Get the tree-sitter Parser constructor.
|
|
21
|
+
*
|
|
22
|
+
* @returns TreeSitter Parser constructor
|
|
23
|
+
* @throws Error if tree-sitter is not available
|
|
24
|
+
*/
|
|
25
|
+
export declare function getTreeSitter(): new () => TreeSitterParser;
|
|
26
|
+
/**
|
|
27
|
+
* Get the Python language for tree-sitter.
|
|
28
|
+
*
|
|
29
|
+
* @returns TreeSitter Python language
|
|
30
|
+
* @throws Error if tree-sitter-python is not available
|
|
31
|
+
*/
|
|
32
|
+
export declare function getPythonLanguage(): TreeSitterLanguage;
|
|
33
|
+
/**
|
|
34
|
+
* Create a new tree-sitter parser instance configured for Python.
|
|
35
|
+
*
|
|
36
|
+
* @returns Configured TreeSitter parser
|
|
37
|
+
* @throws Error if tree-sitter is not available
|
|
38
|
+
*/
|
|
39
|
+
export declare function createPythonParser(): TreeSitterParser;
|
|
40
|
+
/**
|
|
41
|
+
* Get the loading error message if tree-sitter failed to load.
|
|
42
|
+
*
|
|
43
|
+
* @returns Error message or null if no error
|
|
44
|
+
*/
|
|
45
|
+
export declare function getLoadingError(): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* Reset the loader state (useful for testing).
|
|
48
|
+
*/
|
|
49
|
+
export declare function resetLoader(): void;
|
|
50
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/parsers/tree-sitter/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAyBvE;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,CAe/C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,UAAU,gBAAgB,CAU1D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,kBAAkB,CAUtD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,gBAAgB,CAQrD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,MAAM,GAAG,IAAI,CAI/C;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAKlC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter Loader
|
|
3
|
+
*
|
|
4
|
+
* Handles loading tree-sitter and tree-sitter-python with graceful fallback.
|
|
5
|
+
* Provides functions to check availability and access the parser/language.
|
|
6
|
+
*
|
|
7
|
+
* @requirements 3.5 - Unified AST query interface
|
|
8
|
+
*/
|
|
9
|
+
import { createRequire } from 'node:module';
|
|
10
|
+
// Create require function for ESM compatibility
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
// ============================================
|
|
13
|
+
// Module State
|
|
14
|
+
// ============================================
|
|
15
|
+
/** Whether tree-sitter is available */
|
|
16
|
+
let treeSitterAvailable = null;
|
|
17
|
+
/** Cached tree-sitter Parser constructor */
|
|
18
|
+
let cachedTreeSitter = null;
|
|
19
|
+
/** Cached Python language */
|
|
20
|
+
let cachedPythonLanguage = null;
|
|
21
|
+
/** Loading error message if any */
|
|
22
|
+
let loadingError = null;
|
|
23
|
+
// ============================================
|
|
24
|
+
// Public API
|
|
25
|
+
// ============================================
|
|
26
|
+
/**
|
|
27
|
+
* Check if tree-sitter is available.
|
|
28
|
+
*
|
|
29
|
+
* This function attempts to load tree-sitter and tree-sitter-python
|
|
30
|
+
* on first call and caches the result.
|
|
31
|
+
*
|
|
32
|
+
* @returns true if tree-sitter is available and working
|
|
33
|
+
*/
|
|
34
|
+
export function isTreeSitterAvailable() {
|
|
35
|
+
if (treeSitterAvailable !== null) {
|
|
36
|
+
return treeSitterAvailable;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
loadTreeSitter();
|
|
40
|
+
treeSitterAvailable = true;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
treeSitterAvailable = false;
|
|
44
|
+
loadingError = error instanceof Error ? error.message : 'Unknown error loading tree-sitter';
|
|
45
|
+
logDebug(`tree-sitter not available: ${loadingError}`);
|
|
46
|
+
}
|
|
47
|
+
return treeSitterAvailable;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get the tree-sitter Parser constructor.
|
|
51
|
+
*
|
|
52
|
+
* @returns TreeSitter Parser constructor
|
|
53
|
+
* @throws Error if tree-sitter is not available
|
|
54
|
+
*/
|
|
55
|
+
export function getTreeSitter() {
|
|
56
|
+
if (!isTreeSitterAvailable()) {
|
|
57
|
+
throw new Error(`tree-sitter is not available: ${loadingError ?? 'unknown error'}`);
|
|
58
|
+
}
|
|
59
|
+
if (!cachedTreeSitter) {
|
|
60
|
+
throw new Error('tree-sitter module not loaded');
|
|
61
|
+
}
|
|
62
|
+
return cachedTreeSitter;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the Python language for tree-sitter.
|
|
66
|
+
*
|
|
67
|
+
* @returns TreeSitter Python language
|
|
68
|
+
* @throws Error if tree-sitter-python is not available
|
|
69
|
+
*/
|
|
70
|
+
export function getPythonLanguage() {
|
|
71
|
+
if (!isTreeSitterAvailable()) {
|
|
72
|
+
throw new Error(`tree-sitter-python is not available: ${loadingError ?? 'unknown error'}`);
|
|
73
|
+
}
|
|
74
|
+
if (!cachedPythonLanguage) {
|
|
75
|
+
throw new Error('tree-sitter-python language not loaded');
|
|
76
|
+
}
|
|
77
|
+
return cachedPythonLanguage;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create a new tree-sitter parser instance configured for Python.
|
|
81
|
+
*
|
|
82
|
+
* @returns Configured TreeSitter parser
|
|
83
|
+
* @throws Error if tree-sitter is not available
|
|
84
|
+
*/
|
|
85
|
+
export function createPythonParser() {
|
|
86
|
+
const Parser = getTreeSitter();
|
|
87
|
+
const language = getPythonLanguage();
|
|
88
|
+
const parser = new Parser();
|
|
89
|
+
parser.setLanguage(language);
|
|
90
|
+
return parser;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get the loading error message if tree-sitter failed to load.
|
|
94
|
+
*
|
|
95
|
+
* @returns Error message or null if no error
|
|
96
|
+
*/
|
|
97
|
+
export function getLoadingError() {
|
|
98
|
+
// Ensure we've attempted to load
|
|
99
|
+
isTreeSitterAvailable();
|
|
100
|
+
return loadingError;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Reset the loader state (useful for testing).
|
|
104
|
+
*/
|
|
105
|
+
export function resetLoader() {
|
|
106
|
+
treeSitterAvailable = null;
|
|
107
|
+
cachedTreeSitter = null;
|
|
108
|
+
cachedPythonLanguage = null;
|
|
109
|
+
loadingError = null;
|
|
110
|
+
}
|
|
111
|
+
// ============================================
|
|
112
|
+
// Internal Functions
|
|
113
|
+
// ============================================
|
|
114
|
+
/**
|
|
115
|
+
* Attempt to load tree-sitter and tree-sitter-python.
|
|
116
|
+
*
|
|
117
|
+
* @throws Error if loading fails
|
|
118
|
+
*/
|
|
119
|
+
function loadTreeSitter() {
|
|
120
|
+
// Skip if already loaded
|
|
121
|
+
if (cachedTreeSitter && cachedPythonLanguage) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
// Dynamic require for optional dependencies
|
|
126
|
+
// tree-sitter exports the Parser constructor directly
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
128
|
+
cachedTreeSitter = require('tree-sitter');
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
throw new Error(`Failed to load tree-sitter: ${error instanceof Error ? error.message : 'unknown error'}. ` +
|
|
132
|
+
'Install with: pnpm add tree-sitter tree-sitter-python');
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
136
|
+
cachedPythonLanguage = require('tree-sitter-python');
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
// Clear tree-sitter cache since we can't use it without Python
|
|
140
|
+
cachedTreeSitter = null;
|
|
141
|
+
throw new Error(`Failed to load tree-sitter-python: ${error instanceof Error ? error.message : 'unknown error'}. ` +
|
|
142
|
+
'Install with: pnpm add tree-sitter-python');
|
|
143
|
+
}
|
|
144
|
+
logDebug('tree-sitter and tree-sitter-python loaded successfully');
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Log debug message if debug mode is enabled.
|
|
148
|
+
*
|
|
149
|
+
* @param message - Message to log
|
|
150
|
+
*/
|
|
151
|
+
function logDebug(message) {
|
|
152
|
+
if (process.env['DRIFT_PARSER_DEBUG'] === 'true') {
|
|
153
|
+
console.debug(`[tree-sitter-loader] ${message}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=loader.js.map
|
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AiE;QACjE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAA+B,CAAC;IAC1E,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,+BAA+B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,IAAI;YACzF,uDAAuD,CAC1D,CAAC;IACJ,CAAC;IAED,IAAI,CAAC;QACH,iEAAiE;QACjE,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAuB,CAAC;IAC7E,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,+DAA+D;QAC/D,gBAAgB,GAAG,IAAI,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,sCAAsC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,IAAI;YAChG,2CAA2C,CAC9C,CAAC;IACJ,CAAC;IAED,QAAQ,CAAC,wDAAwD,CAAC,CAAC;AACrE,CAAC;AAED;;;;GAIG;AACH,SAAS,QAAQ,CAAC,OAAe;IAC/B,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,KAAK,MAAM,EAAE,CAAC;QACjD,OAAO,CAAC,KAAK,CAAC,wBAAwB,OAAO,EAAE,CAAC,CAAC;IACnD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter PHP Loader
|
|
3
|
+
*
|
|
4
|
+
* Handles loading tree-sitter and tree-sitter-php with graceful fallback.
|
|
5
|
+
* Provides functions to check availability and access the parser/language.
|
|
6
|
+
*
|
|
7
|
+
* @requirements PHP/Laravel Language Support
|
|
8
|
+
*/
|
|
9
|
+
import type { TreeSitterParser, TreeSitterLanguage } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Check if tree-sitter-php is available.
|
|
12
|
+
*
|
|
13
|
+
* This function attempts to load tree-sitter and tree-sitter-php
|
|
14
|
+
* on first call and caches the result.
|
|
15
|
+
*
|
|
16
|
+
* @returns true if tree-sitter-php is available and working
|
|
17
|
+
*/
|
|
18
|
+
export declare function isPhpTreeSitterAvailable(): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Get the PHP language for tree-sitter.
|
|
21
|
+
*
|
|
22
|
+
* @returns TreeSitter PHP language
|
|
23
|
+
* @throws Error if tree-sitter-php is not available
|
|
24
|
+
*/
|
|
25
|
+
export declare function getPhpLanguage(): TreeSitterLanguage;
|
|
26
|
+
/**
|
|
27
|
+
* Get the tree-sitter Parser constructor for PHP.
|
|
28
|
+
*
|
|
29
|
+
* @returns TreeSitter Parser constructor
|
|
30
|
+
* @throws Error if tree-sitter is not available
|
|
31
|
+
*/
|
|
32
|
+
export declare function getPhpTreeSitter(): new () => TreeSitterParser;
|
|
33
|
+
/**
|
|
34
|
+
* Create a new tree-sitter parser instance configured for PHP.
|
|
35
|
+
*
|
|
36
|
+
* @returns Configured TreeSitter parser
|
|
37
|
+
* @throws Error if tree-sitter-php is not available
|
|
38
|
+
*/
|
|
39
|
+
export declare function createPhpParser(): TreeSitterParser;
|
|
40
|
+
/**
|
|
41
|
+
* Get the loading error message if tree-sitter-php failed to load.
|
|
42
|
+
*
|
|
43
|
+
* @returns Error message or null if no error
|
|
44
|
+
*/
|
|
45
|
+
export declare function getPhpLoadingError(): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* Reset the loader state (useful for testing).
|
|
48
|
+
*/
|
|
49
|
+
export declare function resetPhpLoader(): void;
|
|
50
|
+
//# sourceMappingURL=php-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"php-loader.d.ts","sourceRoot":"","sources":["../../../src/parsers/tree-sitter/php-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAyBvE;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,IAAI,OAAO,CAelD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,kBAAkB,CAUnD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,UAAU,gBAAgB,CAU7D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,gBAAgB,CAgBlD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,GAAG,IAAI,CAIlD;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAKrC"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter PHP Loader
|
|
3
|
+
*
|
|
4
|
+
* Handles loading tree-sitter and tree-sitter-php with graceful fallback.
|
|
5
|
+
* Provides functions to check availability and access the parser/language.
|
|
6
|
+
*
|
|
7
|
+
* @requirements PHP/Laravel Language Support
|
|
8
|
+
*/
|
|
9
|
+
import { createRequire } from 'node:module';
|
|
10
|
+
// Create require function for ESM compatibility
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
// ============================================
|
|
13
|
+
// Module State
|
|
14
|
+
// ============================================
|
|
15
|
+
/** Whether tree-sitter-php is available */
|
|
16
|
+
let phpAvailable = null;
|
|
17
|
+
/** Cached tree-sitter module */
|
|
18
|
+
let cachedTreeSitter = null;
|
|
19
|
+
/** Cached PHP language */
|
|
20
|
+
let cachedPhpLanguage = null;
|
|
21
|
+
/** Loading error message if any */
|
|
22
|
+
let loadingError = null;
|
|
23
|
+
// ============================================
|
|
24
|
+
// Public API
|
|
25
|
+
// ============================================
|
|
26
|
+
/**
|
|
27
|
+
* Check if tree-sitter-php is available.
|
|
28
|
+
*
|
|
29
|
+
* This function attempts to load tree-sitter and tree-sitter-php
|
|
30
|
+
* on first call and caches the result.
|
|
31
|
+
*
|
|
32
|
+
* @returns true if tree-sitter-php is available and working
|
|
33
|
+
*/
|
|
34
|
+
export function isPhpTreeSitterAvailable() {
|
|
35
|
+
if (phpAvailable !== null) {
|
|
36
|
+
return phpAvailable;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
loadPhpTreeSitter();
|
|
40
|
+
phpAvailable = true;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
phpAvailable = false;
|
|
44
|
+
loadingError = error instanceof Error ? error.message : 'Unknown error loading tree-sitter-php';
|
|
45
|
+
logDebug(`tree-sitter-php not available: ${loadingError}`);
|
|
46
|
+
}
|
|
47
|
+
return phpAvailable;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get the PHP language for tree-sitter.
|
|
51
|
+
*
|
|
52
|
+
* @returns TreeSitter PHP language
|
|
53
|
+
* @throws Error if tree-sitter-php is not available
|
|
54
|
+
*/
|
|
55
|
+
export function getPhpLanguage() {
|
|
56
|
+
if (!isPhpTreeSitterAvailable()) {
|
|
57
|
+
throw new Error(`tree-sitter-php is not available: ${loadingError ?? 'unknown error'}`);
|
|
58
|
+
}
|
|
59
|
+
if (!cachedPhpLanguage) {
|
|
60
|
+
throw new Error('tree-sitter-php language not loaded');
|
|
61
|
+
}
|
|
62
|
+
return cachedPhpLanguage;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the tree-sitter Parser constructor for PHP.
|
|
66
|
+
*
|
|
67
|
+
* @returns TreeSitter Parser constructor
|
|
68
|
+
* @throws Error if tree-sitter is not available
|
|
69
|
+
*/
|
|
70
|
+
export function getPhpTreeSitter() {
|
|
71
|
+
if (!isPhpTreeSitterAvailable()) {
|
|
72
|
+
throw new Error(`tree-sitter-php is not available: ${loadingError ?? 'unknown error'}`);
|
|
73
|
+
}
|
|
74
|
+
if (!cachedTreeSitter) {
|
|
75
|
+
throw new Error('tree-sitter module not loaded');
|
|
76
|
+
}
|
|
77
|
+
return cachedTreeSitter;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create a new tree-sitter parser instance configured for PHP.
|
|
81
|
+
*
|
|
82
|
+
* @returns Configured TreeSitter parser
|
|
83
|
+
* @throws Error if tree-sitter-php is not available
|
|
84
|
+
*/
|
|
85
|
+
export function createPhpParser() {
|
|
86
|
+
if (!isPhpTreeSitterAvailable()) {
|
|
87
|
+
throw new Error(`tree-sitter-php is not available: ${loadingError ?? 'unknown error'}`);
|
|
88
|
+
}
|
|
89
|
+
if (!cachedTreeSitter) {
|
|
90
|
+
throw new Error('tree-sitter module not loaded');
|
|
91
|
+
}
|
|
92
|
+
const Parser = cachedTreeSitter;
|
|
93
|
+
const language = getPhpLanguage();
|
|
94
|
+
const parser = new Parser();
|
|
95
|
+
parser.setLanguage(language);
|
|
96
|
+
return parser;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get the loading error message if tree-sitter-php failed to load.
|
|
100
|
+
*
|
|
101
|
+
* @returns Error message or null if no error
|
|
102
|
+
*/
|
|
103
|
+
export function getPhpLoadingError() {
|
|
104
|
+
// Ensure we've attempted to load
|
|
105
|
+
isPhpTreeSitterAvailable();
|
|
106
|
+
return loadingError;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Reset the loader state (useful for testing).
|
|
110
|
+
*/
|
|
111
|
+
export function resetPhpLoader() {
|
|
112
|
+
phpAvailable = null;
|
|
113
|
+
cachedTreeSitter = null;
|
|
114
|
+
cachedPhpLanguage = null;
|
|
115
|
+
loadingError = null;
|
|
116
|
+
}
|
|
117
|
+
// ============================================
|
|
118
|
+
// Internal Functions
|
|
119
|
+
// ============================================
|
|
120
|
+
/**
|
|
121
|
+
* Attempt to load tree-sitter and tree-sitter-php.
|
|
122
|
+
*
|
|
123
|
+
* @throws Error if loading fails
|
|
124
|
+
*/
|
|
125
|
+
function loadPhpTreeSitter() {
|
|
126
|
+
// Skip if already loaded
|
|
127
|
+
if (cachedTreeSitter && cachedPhpLanguage) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
// Dynamic require for optional dependencies
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
133
|
+
cachedTreeSitter = require('tree-sitter');
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
throw new Error(`Failed to load tree-sitter: ${error instanceof Error ? error.message : 'unknown error'}. ` +
|
|
137
|
+
'Install with: pnpm add tree-sitter tree-sitter-php');
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
// tree-sitter-php exports an object with php and php_only languages
|
|
141
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
142
|
+
const phpModule = require('tree-sitter-php');
|
|
143
|
+
// Use the 'php' language which includes HTML support
|
|
144
|
+
cachedPhpLanguage = phpModule.php ?? phpModule;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
// Clear tree-sitter cache since we can't use it without PHP
|
|
148
|
+
cachedTreeSitter = null;
|
|
149
|
+
throw new Error(`Failed to load tree-sitter-php: ${error instanceof Error ? error.message : 'unknown error'}. ` +
|
|
150
|
+
'Install with: pnpm add tree-sitter-php');
|
|
151
|
+
}
|
|
152
|
+
logDebug('tree-sitter and tree-sitter-php loaded successfully');
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Log debug message if debug mode is enabled.
|
|
156
|
+
*
|
|
157
|
+
* @param message - Message to log
|
|
158
|
+
*/
|
|
159
|
+
function logDebug(message) {
|
|
160
|
+
if (process.env['DRIFT_PARSER_DEBUG'] === 'true') {
|
|
161
|
+
console.debug(`[php-loader] ${message}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=php-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"php-loader.js","sourceRoot":"","sources":["../../../src/parsers/tree-sitter/php-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,gDAAgD;AAChD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CA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