@defai.digital/ax-cli 3.8.30 → 3.8.33
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/README.md +22 -1
- package/dist/agent/llm-agent.d.ts +19 -1
- package/dist/agent/llm-agent.js +69 -2
- package/dist/agent/llm-agent.js.map +1 -1
- package/dist/analyzers/ast/index.d.ts +7 -1
- package/dist/analyzers/ast/index.js +9 -1
- package/dist/analyzers/ast/index.js.map +1 -1
- package/dist/analyzers/ast/language-parser.d.ts +58 -0
- package/dist/analyzers/ast/language-parser.js +80 -0
- package/dist/analyzers/ast/language-parser.js.map +1 -0
- package/dist/analyzers/ast/multi-language-parser.d.ts +97 -0
- package/dist/analyzers/ast/multi-language-parser.js +275 -0
- package/dist/analyzers/ast/multi-language-parser.js.map +1 -0
- package/dist/analyzers/ast/parser.d.ts +1 -0
- package/dist/analyzers/ast/parser.js +15 -3
- package/dist/analyzers/ast/parser.js.map +1 -1
- package/dist/analyzers/ast/tree-sitter-parser.d.ts +134 -0
- package/dist/analyzers/ast/tree-sitter-parser.js +730 -0
- package/dist/analyzers/ast/tree-sitter-parser.js.map +1 -0
- package/dist/analyzers/code-smells/base-smell-detector.d.ts +2 -2
- package/dist/analyzers/code-smells/base-smell-detector.js +2 -2
- package/dist/analyzers/code-smells/base-smell-detector.js.map +1 -1
- package/dist/analyzers/code-smells/detectors/data-clumps-detector.js +1 -1
- package/dist/analyzers/code-smells/detectors/data-clumps-detector.js.map +1 -1
- package/dist/analyzers/code-smells/detectors/dead-code-detector.js +6 -1
- package/dist/analyzers/code-smells/detectors/dead-code-detector.js.map +1 -1
- package/dist/analyzers/code-smells/detectors/duplicate-code-detector.js +1 -1
- package/dist/analyzers/code-smells/detectors/duplicate-code-detector.js.map +1 -1
- package/dist/analyzers/code-smells/detectors/feature-envy-detector.js +4 -1
- package/dist/analyzers/code-smells/detectors/feature-envy-detector.js.map +1 -1
- package/dist/analyzers/code-smells/detectors/inappropriate-intimacy-detector.js +3 -0
- package/dist/analyzers/code-smells/detectors/inappropriate-intimacy-detector.js.map +1 -1
- package/dist/analyzers/code-smells/detectors/large-class-detector.js +1 -1
- package/dist/analyzers/code-smells/detectors/large-class-detector.js.map +1 -1
- package/dist/analyzers/code-smells/detectors/long-method-detector.js +1 -1
- package/dist/analyzers/code-smells/detectors/long-method-detector.js.map +1 -1
- package/dist/analyzers/code-smells/detectors/long-parameter-list-detector.js +1 -1
- package/dist/analyzers/code-smells/detectors/long-parameter-list-detector.js.map +1 -1
- package/dist/analyzers/code-smells/detectors/magic-numbers-detector.js +3 -0
- package/dist/analyzers/code-smells/detectors/magic-numbers-detector.js.map +1 -1
- package/dist/analyzers/code-smells/detectors/nested-conditionals-detector.js +3 -0
- package/dist/analyzers/code-smells/detectors/nested-conditionals-detector.js.map +1 -1
- package/dist/analyzers/dependency/dependency-analyzer.d.ts +4 -0
- package/dist/analyzers/dependency/dependency-analyzer.js +7 -3
- package/dist/analyzers/dependency/dependency-analyzer.js.map +1 -1
- package/dist/analyzers/git/hotspot-detector.js +3 -3
- package/dist/analyzers/git/hotspot-detector.js.map +1 -1
- package/dist/analyzers/metrics/metrics-analyzer.js +7 -3
- package/dist/analyzers/metrics/metrics-analyzer.js.map +1 -1
- package/dist/commands/usage.js +12 -1
- package/dist/commands/usage.js.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-Language Parser Facade
|
|
3
|
+
*
|
|
4
|
+
* Unified interface for parsing multiple programming languages.
|
|
5
|
+
* Uses ts-morph for TypeScript/JavaScript (proven, mature)
|
|
6
|
+
* Uses tree-sitter for Python, Rust, Go (fast, universal)
|
|
7
|
+
*/
|
|
8
|
+
import { TreeSitterParser } from './tree-sitter-parser.js';
|
|
9
|
+
import { type SupportedLanguage } from './language-parser.js';
|
|
10
|
+
import type { FileASTInfo } from './types.js';
|
|
11
|
+
import type { SourceFile } from 'ts-morph';
|
|
12
|
+
export { TreeSitterParser };
|
|
13
|
+
/**
|
|
14
|
+
* Multi-language parser facade
|
|
15
|
+
*
|
|
16
|
+
* Automatically selects the best parser based on file extension:
|
|
17
|
+
* - TypeScript/JavaScript: ts-morph (mature, accurate type info)
|
|
18
|
+
* - Python/Rust/Go: tree-sitter (fast, universal)
|
|
19
|
+
*/
|
|
20
|
+
export declare class MultiLanguageParser {
|
|
21
|
+
/**
|
|
22
|
+
* Parse a file, automatically selecting the appropriate parser
|
|
23
|
+
*/
|
|
24
|
+
parseFile(filePath: string): Promise<FileASTInfo>;
|
|
25
|
+
/**
|
|
26
|
+
* Parse content directly with specified language
|
|
27
|
+
*/
|
|
28
|
+
parseContent(content: string, language: SupportedLanguage, filePath?: string): Promise<FileASTInfo>;
|
|
29
|
+
/**
|
|
30
|
+
* Parse TypeScript/JavaScript file using ts-morph
|
|
31
|
+
*/
|
|
32
|
+
private parseTypeScriptFile;
|
|
33
|
+
/**
|
|
34
|
+
* Parse TypeScript/JavaScript content using ts-morph
|
|
35
|
+
*/
|
|
36
|
+
private parseTypeScriptContent;
|
|
37
|
+
/**
|
|
38
|
+
* Parse file using tree-sitter
|
|
39
|
+
*/
|
|
40
|
+
private parseTreeSitterFile;
|
|
41
|
+
/**
|
|
42
|
+
* Parse content using tree-sitter
|
|
43
|
+
*/
|
|
44
|
+
private parseTreeSitterContent;
|
|
45
|
+
/**
|
|
46
|
+
* Try to use tree-sitter as fallback for unknown file types
|
|
47
|
+
*/
|
|
48
|
+
private tryTreeSitterFallback;
|
|
49
|
+
/**
|
|
50
|
+
* Check if a language is supported
|
|
51
|
+
*/
|
|
52
|
+
supports(filePath: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Check if tree-sitter has a grammar for this file type
|
|
55
|
+
*/
|
|
56
|
+
private hasTreeSitterFallback;
|
|
57
|
+
/**
|
|
58
|
+
* Get the language for a file path
|
|
59
|
+
*/
|
|
60
|
+
getLanguage(filePath: string): SupportedLanguage;
|
|
61
|
+
/**
|
|
62
|
+
* Get ts-morph SourceFile for TypeScript/JavaScript files
|
|
63
|
+
* Returns null for other languages (use parseFile instead for those)
|
|
64
|
+
*
|
|
65
|
+
* Note: This is useful for advanced analysis that requires semantic information
|
|
66
|
+
* like finding references, type checking, etc. For basic AST info, use parseFile.
|
|
67
|
+
*/
|
|
68
|
+
getSourceFile(filePath: string): SourceFile | null;
|
|
69
|
+
/**
|
|
70
|
+
* Check if file supports advanced semantic analysis (ts-morph only)
|
|
71
|
+
*/
|
|
72
|
+
supportsSemanticAnalysis(filePath: string): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Get list of fully supported languages
|
|
75
|
+
*/
|
|
76
|
+
getSupportedLanguages(): SupportedLanguage[];
|
|
77
|
+
/**
|
|
78
|
+
* Get list of all parseable languages (including tree-sitter fallbacks)
|
|
79
|
+
*/
|
|
80
|
+
getAllParseableLanguages(): string[];
|
|
81
|
+
/**
|
|
82
|
+
* Create empty AST info
|
|
83
|
+
*/
|
|
84
|
+
private createEmptyASTInfo;
|
|
85
|
+
/**
|
|
86
|
+
* Clear all cached parsers and free memory
|
|
87
|
+
*/
|
|
88
|
+
dispose(): void;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the singleton multi-language parser instance
|
|
92
|
+
*/
|
|
93
|
+
export declare function getMultiLanguageParser(): MultiLanguageParser;
|
|
94
|
+
/**
|
|
95
|
+
* Reset the singleton (for testing)
|
|
96
|
+
*/
|
|
97
|
+
export declare function resetMultiLanguageParser(): void;
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-Language Parser Facade
|
|
3
|
+
*
|
|
4
|
+
* Unified interface for parsing multiple programming languages.
|
|
5
|
+
* Uses ts-morph for TypeScript/JavaScript (proven, mature)
|
|
6
|
+
* Uses tree-sitter for Python, Rust, Go (fast, universal)
|
|
7
|
+
*/
|
|
8
|
+
import { ASTParser } from './parser.js';
|
|
9
|
+
import { TreeSitterParser, createTreeSitterParser, TREE_SITTER_LANGUAGES } from './tree-sitter-parser.js';
|
|
10
|
+
import { getLanguageFromPath } from './language-parser.js';
|
|
11
|
+
// Re-export for convenience
|
|
12
|
+
export { TreeSitterParser };
|
|
13
|
+
/**
|
|
14
|
+
* Parser cache for reuse
|
|
15
|
+
*/
|
|
16
|
+
const parserCache = new Map();
|
|
17
|
+
let tsMorphParser = null;
|
|
18
|
+
/**
|
|
19
|
+
* Get or create the ts-morph parser (singleton)
|
|
20
|
+
*/
|
|
21
|
+
function getTsMorphParser() {
|
|
22
|
+
if (!tsMorphParser) {
|
|
23
|
+
tsMorphParser = new ASTParser();
|
|
24
|
+
}
|
|
25
|
+
return tsMorphParser;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get or create a tree-sitter parser for a language
|
|
29
|
+
*/
|
|
30
|
+
function getTreeSitterParser(language) {
|
|
31
|
+
const cached = parserCache.get(language);
|
|
32
|
+
if (cached && cached instanceof TreeSitterParser) {
|
|
33
|
+
return cached;
|
|
34
|
+
}
|
|
35
|
+
const parser = createTreeSitterParser(language);
|
|
36
|
+
parserCache.set(language, parser);
|
|
37
|
+
return parser;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Multi-language parser facade
|
|
41
|
+
*
|
|
42
|
+
* Automatically selects the best parser based on file extension:
|
|
43
|
+
* - TypeScript/JavaScript: ts-morph (mature, accurate type info)
|
|
44
|
+
* - Python/Rust/Go: tree-sitter (fast, universal)
|
|
45
|
+
*/
|
|
46
|
+
export class MultiLanguageParser {
|
|
47
|
+
/**
|
|
48
|
+
* Parse a file, automatically selecting the appropriate parser
|
|
49
|
+
*/
|
|
50
|
+
async parseFile(filePath) {
|
|
51
|
+
const language = getLanguageFromPath(filePath);
|
|
52
|
+
switch (language) {
|
|
53
|
+
case 'typescript':
|
|
54
|
+
case 'javascript':
|
|
55
|
+
return this.parseTypeScriptFile(filePath);
|
|
56
|
+
case 'python':
|
|
57
|
+
case 'rust':
|
|
58
|
+
case 'go':
|
|
59
|
+
case 'c':
|
|
60
|
+
case 'cpp':
|
|
61
|
+
case 'swift':
|
|
62
|
+
case 'html':
|
|
63
|
+
case 'css':
|
|
64
|
+
return this.parseTreeSitterFile(filePath, language);
|
|
65
|
+
default:
|
|
66
|
+
// Try tree-sitter as fallback for unknown languages
|
|
67
|
+
return this.tryTreeSitterFallback(filePath);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Parse content directly with specified language
|
|
72
|
+
*/
|
|
73
|
+
async parseContent(content, language, filePath = 'temp') {
|
|
74
|
+
switch (language) {
|
|
75
|
+
case 'typescript':
|
|
76
|
+
case 'javascript':
|
|
77
|
+
return this.parseTypeScriptContent(content, filePath);
|
|
78
|
+
case 'python':
|
|
79
|
+
case 'rust':
|
|
80
|
+
case 'go':
|
|
81
|
+
case 'c':
|
|
82
|
+
case 'cpp':
|
|
83
|
+
case 'swift':
|
|
84
|
+
case 'html':
|
|
85
|
+
case 'css':
|
|
86
|
+
return this.parseTreeSitterContent(content, language, filePath);
|
|
87
|
+
default:
|
|
88
|
+
return this.createEmptyASTInfo(filePath);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Parse TypeScript/JavaScript file using ts-morph
|
|
93
|
+
*/
|
|
94
|
+
parseTypeScriptFile(filePath) {
|
|
95
|
+
const parser = getTsMorphParser();
|
|
96
|
+
return parser.parseFile(filePath);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Parse TypeScript/JavaScript content using ts-morph
|
|
100
|
+
*/
|
|
101
|
+
parseTypeScriptContent(content, filePath) {
|
|
102
|
+
const parser = getTsMorphParser();
|
|
103
|
+
return parser.parseContent(content, filePath);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Parse file using tree-sitter
|
|
107
|
+
*/
|
|
108
|
+
async parseTreeSitterFile(filePath, language) {
|
|
109
|
+
const parser = getTreeSitterParser(language);
|
|
110
|
+
return parser.parseFile(filePath);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Parse content using tree-sitter
|
|
114
|
+
*/
|
|
115
|
+
async parseTreeSitterContent(content, language, filePath) {
|
|
116
|
+
const parser = getTreeSitterParser(language);
|
|
117
|
+
return parser.parseContent(content, filePath);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Try to use tree-sitter as fallback for unknown file types
|
|
121
|
+
*/
|
|
122
|
+
async tryTreeSitterFallback(filePath) {
|
|
123
|
+
// Extract extension and check if tree-sitter supports it
|
|
124
|
+
const ext = filePath.slice(filePath.lastIndexOf('.') + 1).toLowerCase();
|
|
125
|
+
// Map common extensions to tree-sitter language names
|
|
126
|
+
const extToTreeSitter = {
|
|
127
|
+
'html': 'html',
|
|
128
|
+
'htm': 'html',
|
|
129
|
+
'css': 'css',
|
|
130
|
+
'scss': 'scss',
|
|
131
|
+
'json': 'json',
|
|
132
|
+
'yaml': 'yaml',
|
|
133
|
+
'yml': 'yaml',
|
|
134
|
+
'toml': 'toml',
|
|
135
|
+
'md': 'markdown',
|
|
136
|
+
'c': 'c',
|
|
137
|
+
'h': 'c',
|
|
138
|
+
'cpp': 'cpp',
|
|
139
|
+
'cc': 'cpp',
|
|
140
|
+
'cxx': 'cpp',
|
|
141
|
+
'hpp': 'cpp',
|
|
142
|
+
'java': 'java',
|
|
143
|
+
'kt': 'kotlin',
|
|
144
|
+
'kts': 'kotlin',
|
|
145
|
+
'swift': 'swift',
|
|
146
|
+
'rb': 'ruby',
|
|
147
|
+
'php': 'php',
|
|
148
|
+
'lua': 'lua',
|
|
149
|
+
'sh': 'bash',
|
|
150
|
+
'bash': 'bash',
|
|
151
|
+
'zsh': 'bash',
|
|
152
|
+
'sql': 'sql',
|
|
153
|
+
'vue': 'vue',
|
|
154
|
+
'svelte': 'svelte',
|
|
155
|
+
};
|
|
156
|
+
const treeSitterLang = extToTreeSitter[ext];
|
|
157
|
+
if (treeSitterLang && TREE_SITTER_LANGUAGES.includes(treeSitterLang)) {
|
|
158
|
+
try {
|
|
159
|
+
// Create a specialized tree-sitter parser
|
|
160
|
+
const parser = new TreeSitterParser('unknown', treeSitterLang);
|
|
161
|
+
return parser.parseFile(filePath);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
// Fallback to empty AST
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return this.createEmptyASTInfo(filePath);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Check if a language is supported
|
|
171
|
+
*/
|
|
172
|
+
supports(filePath) {
|
|
173
|
+
const language = getLanguageFromPath(filePath);
|
|
174
|
+
return language !== 'unknown' || this.hasTreeSitterFallback(filePath);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Check if tree-sitter has a grammar for this file type
|
|
178
|
+
*/
|
|
179
|
+
hasTreeSitterFallback(filePath) {
|
|
180
|
+
const ext = filePath.slice(filePath.lastIndexOf('.') + 1).toLowerCase();
|
|
181
|
+
const fallbackExts = ['html', 'css', 'json', 'yaml', 'yml', 'toml', 'c', 'cpp', 'java', 'kt', 'swift', 'rb', 'php', 'lua', 'sh', 'bash', 'sql', 'vue'];
|
|
182
|
+
return fallbackExts.includes(ext);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get the language for a file path
|
|
186
|
+
*/
|
|
187
|
+
getLanguage(filePath) {
|
|
188
|
+
return getLanguageFromPath(filePath);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Get ts-morph SourceFile for TypeScript/JavaScript files
|
|
192
|
+
* Returns null for other languages (use parseFile instead for those)
|
|
193
|
+
*
|
|
194
|
+
* Note: This is useful for advanced analysis that requires semantic information
|
|
195
|
+
* like finding references, type checking, etc. For basic AST info, use parseFile.
|
|
196
|
+
*/
|
|
197
|
+
getSourceFile(filePath) {
|
|
198
|
+
const language = getLanguageFromPath(filePath);
|
|
199
|
+
if (language === 'typescript' || language === 'javascript') {
|
|
200
|
+
return getTsMorphParser().getSourceFile(filePath);
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Check if file supports advanced semantic analysis (ts-morph only)
|
|
206
|
+
*/
|
|
207
|
+
supportsSemanticAnalysis(filePath) {
|
|
208
|
+
const language = getLanguageFromPath(filePath);
|
|
209
|
+
return language === 'typescript' || language === 'javascript';
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Get list of fully supported languages
|
|
213
|
+
*/
|
|
214
|
+
getSupportedLanguages() {
|
|
215
|
+
return ['typescript', 'javascript', 'python', 'rust', 'go', 'c', 'cpp', 'swift', 'html', 'css'];
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Get list of all parseable languages (including tree-sitter fallbacks)
|
|
219
|
+
*/
|
|
220
|
+
getAllParseableLanguages() {
|
|
221
|
+
return [
|
|
222
|
+
...this.getSupportedLanguages(),
|
|
223
|
+
'json', 'yaml', 'toml', 'java', 'kotlin', 'ruby', 'php', 'lua', 'bash', 'sql', 'vue',
|
|
224
|
+
];
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Create empty AST info
|
|
228
|
+
*/
|
|
229
|
+
createEmptyASTInfo(filePath) {
|
|
230
|
+
return Object.freeze({
|
|
231
|
+
filePath,
|
|
232
|
+
functions: Object.freeze([]),
|
|
233
|
+
classes: Object.freeze([]),
|
|
234
|
+
imports: Object.freeze([]),
|
|
235
|
+
exports: Object.freeze([]),
|
|
236
|
+
totalLines: 0,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Clear all cached parsers and free memory
|
|
241
|
+
*/
|
|
242
|
+
dispose() {
|
|
243
|
+
for (const parser of parserCache.values()) {
|
|
244
|
+
parser.dispose();
|
|
245
|
+
}
|
|
246
|
+
parserCache.clear();
|
|
247
|
+
if (tsMorphParser) {
|
|
248
|
+
tsMorphParser.clear();
|
|
249
|
+
tsMorphParser = null;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Singleton instance for convenience
|
|
255
|
+
*/
|
|
256
|
+
let multiLanguageParserInstance = null;
|
|
257
|
+
/**
|
|
258
|
+
* Get the singleton multi-language parser instance
|
|
259
|
+
*/
|
|
260
|
+
export function getMultiLanguageParser() {
|
|
261
|
+
if (!multiLanguageParserInstance) {
|
|
262
|
+
multiLanguageParserInstance = new MultiLanguageParser();
|
|
263
|
+
}
|
|
264
|
+
return multiLanguageParserInstance;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Reset the singleton (for testing)
|
|
268
|
+
*/
|
|
269
|
+
export function resetMultiLanguageParser() {
|
|
270
|
+
if (multiLanguageParserInstance) {
|
|
271
|
+
multiLanguageParserInstance.dispose();
|
|
272
|
+
multiLanguageParserInstance = null;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
//# sourceMappingURL=multi-language-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-language-parser.js","sourceRoot":"","sources":["../../../src/analyzers/ast/multi-language-parser.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAC1G,OAAO,EAAE,mBAAmB,EAA+C,MAAM,sBAAsB,CAAC;AAIxG,4BAA4B;AAC5B,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B;;GAEG;AACH,MAAM,WAAW,GAAG,IAAI,GAAG,EAA0B,CAAC;AACtD,IAAI,aAAa,GAAqB,IAAI,CAAC;AAE3C;;GAEG;AACH,SAAS,gBAAgB;IACvB,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,IAAI,SAAS,EAAE,CAAC;IAClC,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,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D,OAAO,2BAA2B,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,wBAAwB;IACtC,IAAI,2BAA2B,EAAE,CAAC;QAChC,2BAA2B,CAAC,OAAO,EAAE,CAAC;QACtC,2BAA2B,GAAG,IAAI,CAAC;IACrC,CAAC;AACH,CAAC"}
|
|
@@ -50,6 +50,7 @@ export declare class ASTParser {
|
|
|
50
50
|
private calculateCyclomaticComplexity;
|
|
51
51
|
/**
|
|
52
52
|
* Get raw source file for advanced operations
|
|
53
|
+
* Note: This keeps the file in the project for semantic analysis (findReferences, etc.)
|
|
53
54
|
*/
|
|
54
55
|
getSourceFile(filePath: string): SourceFile;
|
|
55
56
|
/**
|
|
@@ -21,7 +21,10 @@ export class ASTParser {
|
|
|
21
21
|
* Parse a TypeScript/JavaScript file
|
|
22
22
|
*/
|
|
23
23
|
parseFile(filePath) {
|
|
24
|
-
|
|
24
|
+
// Check if file was already added (by getSourceFile for semantic analysis)
|
|
25
|
+
const existingFile = this.project.getSourceFile(filePath);
|
|
26
|
+
const sourceFile = existingFile || this.project.addSourceFileAtPath(filePath);
|
|
27
|
+
const shouldRemove = !existingFile; // Only remove if we just added it
|
|
25
28
|
try {
|
|
26
29
|
const functions = this.extractFunctions(sourceFile);
|
|
27
30
|
const classes = this.extractClasses(sourceFile);
|
|
@@ -37,8 +40,10 @@ export class ASTParser {
|
|
|
37
40
|
});
|
|
38
41
|
}
|
|
39
42
|
finally {
|
|
40
|
-
// Clean up to prevent memory leaks
|
|
41
|
-
|
|
43
|
+
// Clean up to prevent memory leaks, but preserve files needed for semantic analysis
|
|
44
|
+
if (shouldRemove) {
|
|
45
|
+
this.project.removeSourceFile(sourceFile);
|
|
46
|
+
}
|
|
42
47
|
}
|
|
43
48
|
}
|
|
44
49
|
/**
|
|
@@ -276,8 +281,15 @@ export class ASTParser {
|
|
|
276
281
|
}
|
|
277
282
|
/**
|
|
278
283
|
* Get raw source file for advanced operations
|
|
284
|
+
* Note: This keeps the file in the project for semantic analysis (findReferences, etc.)
|
|
279
285
|
*/
|
|
280
286
|
getSourceFile(filePath) {
|
|
287
|
+
// Check if file is already in project
|
|
288
|
+
const existing = this.project.getSourceFile(filePath);
|
|
289
|
+
if (existing) {
|
|
290
|
+
return existing;
|
|
291
|
+
}
|
|
292
|
+
// Add new file and keep it in project for semantic operations
|
|
281
293
|
return this.project.addSourceFileAtPath(filePath);
|
|
282
294
|
}
|
|
283
295
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../src/analyzers/ast/parser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAc,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGrF,MAAM,OAAO,SAAS;IACZ,OAAO,CAAU;IAEzB;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC;YACzB,eAAe,EAAE;gBACf,MAAM,EAAE,YAAY,CAAC,MAAM;gBAC3B,MAAM,EAAE,UAAU,CAAC,QAAQ;gBAC3B,OAAO,EAAE,IAAI;gBACb,YAAY,EAAE,IAAI;aACnB;YACD,2BAA2B,EAAE,IAAI;SAClC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,QAAgB;QACxB,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../src/analyzers/ast/parser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAc,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGrF,MAAM,OAAO,SAAS;IACZ,OAAO,CAAU;IAEzB;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC;YACzB,eAAe,EAAE;gBACf,MAAM,EAAE,YAAY,CAA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
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter Parser
|
|
3
|
+
*
|
|
4
|
+
* Base class for tree-sitter based language parsers.
|
|
5
|
+
* Uses WebAssembly (WASM) for cross-platform compatibility.
|
|
6
|
+
*
|
|
7
|
+
* Supports: Python, Rust, Go, TypeScript, JavaScript, HTML, CSS, and 30+ more languages
|
|
8
|
+
*/
|
|
9
|
+
import { Tree } from 'web-tree-sitter';
|
|
10
|
+
import { BaseLanguageParser, type SupportedLanguage } from './language-parser.js';
|
|
11
|
+
import type { FileASTInfo } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Tree-sitter based language parser
|
|
14
|
+
*/
|
|
15
|
+
export declare class TreeSitterParser extends BaseLanguageParser {
|
|
16
|
+
readonly language: SupportedLanguage;
|
|
17
|
+
private treeSitterLanguage;
|
|
18
|
+
private parser;
|
|
19
|
+
private loadedLanguage;
|
|
20
|
+
constructor(language: SupportedLanguage, treeSitterLanguage?: string);
|
|
21
|
+
private mapLanguageToTreeSitter;
|
|
22
|
+
/**
|
|
23
|
+
* Ensure parser is initialized
|
|
24
|
+
*/
|
|
25
|
+
private ensureInitialized;
|
|
26
|
+
parseFile(filePath: string): Promise<FileASTInfo>;
|
|
27
|
+
parseContent(content: string, filePath?: string): Promise<FileASTInfo>;
|
|
28
|
+
/**
|
|
29
|
+
* Extract functions from AST
|
|
30
|
+
*/
|
|
31
|
+
private extractFunctions;
|
|
32
|
+
/**
|
|
33
|
+
* Get node types that represent functions for this language
|
|
34
|
+
*/
|
|
35
|
+
private getFunctionNodeTypes;
|
|
36
|
+
/**
|
|
37
|
+
* Extract function info from a function node
|
|
38
|
+
*/
|
|
39
|
+
private extractFunctionInfo;
|
|
40
|
+
/**
|
|
41
|
+
* Extract function name
|
|
42
|
+
*/
|
|
43
|
+
private extractFunctionName;
|
|
44
|
+
/**
|
|
45
|
+
* Extract parameters from function
|
|
46
|
+
*/
|
|
47
|
+
private extractParameters;
|
|
48
|
+
/**
|
|
49
|
+
* Check if node is a parameter
|
|
50
|
+
*/
|
|
51
|
+
private isParameterNode;
|
|
52
|
+
/**
|
|
53
|
+
* Extract parameter info
|
|
54
|
+
*/
|
|
55
|
+
private extractParameterInfo;
|
|
56
|
+
/**
|
|
57
|
+
* Extract return type
|
|
58
|
+
*/
|
|
59
|
+
private extractReturnType;
|
|
60
|
+
/**
|
|
61
|
+
* Check if function is async
|
|
62
|
+
*/
|
|
63
|
+
private isAsyncFunction;
|
|
64
|
+
/**
|
|
65
|
+
* Check if function is exported
|
|
66
|
+
*/
|
|
67
|
+
private isExportedFunction;
|
|
68
|
+
/**
|
|
69
|
+
* Calculate cyclomatic complexity
|
|
70
|
+
*/
|
|
71
|
+
private calculateComplexity;
|
|
72
|
+
/**
|
|
73
|
+
* Extract classes from AST
|
|
74
|
+
*/
|
|
75
|
+
private extractClasses;
|
|
76
|
+
/**
|
|
77
|
+
* Get node types that represent classes
|
|
78
|
+
*/
|
|
79
|
+
private getClassNodeTypes;
|
|
80
|
+
/**
|
|
81
|
+
* Extract class info
|
|
82
|
+
*/
|
|
83
|
+
private extractClassInfo;
|
|
84
|
+
/**
|
|
85
|
+
* Check if class is exported
|
|
86
|
+
*/
|
|
87
|
+
private isExportedClass;
|
|
88
|
+
/**
|
|
89
|
+
* Extract methods from class
|
|
90
|
+
*/
|
|
91
|
+
private extractMethods;
|
|
92
|
+
/**
|
|
93
|
+
* Get method visibility
|
|
94
|
+
*/
|
|
95
|
+
private getVisibility;
|
|
96
|
+
/**
|
|
97
|
+
* Check if method is static
|
|
98
|
+
*/
|
|
99
|
+
private isStatic;
|
|
100
|
+
/**
|
|
101
|
+
* Extract properties from class
|
|
102
|
+
*/
|
|
103
|
+
private extractProperties;
|
|
104
|
+
/**
|
|
105
|
+
* Extract imports from AST
|
|
106
|
+
*/
|
|
107
|
+
private extractImports;
|
|
108
|
+
/**
|
|
109
|
+
* Get import node types for this language
|
|
110
|
+
*/
|
|
111
|
+
private getImportNodeTypes;
|
|
112
|
+
/**
|
|
113
|
+
* Extract import info
|
|
114
|
+
*/
|
|
115
|
+
private extractImportInfo;
|
|
116
|
+
/**
|
|
117
|
+
* Extract exports from AST
|
|
118
|
+
*/
|
|
119
|
+
private extractExports;
|
|
120
|
+
/**
|
|
121
|
+
* Get the raw syntax tree (for advanced usage)
|
|
122
|
+
*/
|
|
123
|
+
getTree(content: string): Promise<Tree | null>;
|
|
124
|
+
dispose(): void;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Create a parser for a specific language
|
|
128
|
+
*/
|
|
129
|
+
export declare function createTreeSitterParser(language: SupportedLanguage): TreeSitterParser;
|
|
130
|
+
/**
|
|
131
|
+
* Supported tree-sitter languages (beyond our core 5)
|
|
132
|
+
*/
|
|
133
|
+
export declare const TREE_SITTER_LANGUAGES: readonly ["bash", "c", "cpp", "c_sharp", "css", "dart", "elixir", "elm", "go", "html", "java", "javascript", "json", "kotlin", "lua", "objc", "ocaml", "php", "python", "ruby", "rust", "scala", "solidity", "swift", "toml", "tsx", "typescript", "vue", "yaml", "zig"];
|
|
134
|
+
export type TreeSitterLanguage = typeof TREE_SITTER_LANGUAGES[number];
|