@milo4jo/contextkit 0.5.0 → 0.5.6
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 +59 -1
- package/dist/commands/cache.d.ts +3 -0
- package/dist/commands/cache.d.ts.map +1 -0
- package/dist/commands/cache.js +50 -0
- package/dist/commands/cache.js.map +1 -0
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +254 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/graph.d.ts +10 -0
- package/dist/commands/graph.d.ts.map +1 -0
- package/dist/commands/graph.js +289 -0
- package/dist/commands/graph.js.map +1 -0
- package/dist/commands/select.d.ts.map +1 -1
- package/dist/commands/select.js +11 -0
- package/dist/commands/select.js.map +1 -1
- package/dist/commands/symbol.d.ts +9 -0
- package/dist/commands/symbol.d.ts.map +1 -0
- package/dist/commands/symbol.js +420 -0
- package/dist/commands/symbol.js.map +1 -0
- package/dist/db/index.d.ts +48 -0
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +99 -0
- package/dist/db/index.js.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/indexer/chunker.d.ts +25 -3
- package/dist/indexer/chunker.d.ts.map +1 -1
- package/dist/indexer/chunker.js +344 -4
- package/dist/indexer/chunker.js.map +1 -1
- package/dist/indexer/index.d.ts.map +1 -1
- package/dist/indexer/index.js +3 -2
- package/dist/indexer/index.js.map +1 -1
- package/dist/mcp-server.js +0 -0
- package/dist/parsers/index.d.ts +65 -0
- package/dist/parsers/index.d.ts.map +1 -0
- package/dist/parsers/index.js +130 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/parsers/markdown.d.ts +29 -0
- package/dist/parsers/markdown.d.ts.map +1 -0
- package/dist/parsers/markdown.js +142 -0
- package/dist/parsers/markdown.js.map +1 -0
- package/dist/parsers/tree-sitter.d.ts +32 -0
- package/dist/parsers/tree-sitter.d.ts.map +1 -0
- package/dist/parsers/tree-sitter.js +356 -0
- package/dist/parsers/tree-sitter.js.map +1 -0
- package/dist/parsers/typescript.d.ts +43 -0
- package/dist/parsers/typescript.d.ts.map +1 -0
- package/dist/parsers/typescript.js +306 -0
- package/dist/parsers/typescript.js.map +1 -0
- package/dist/selector/formatter.d.ts +4 -1
- package/dist/selector/formatter.d.ts.map +1 -1
- package/dist/selector/formatter.js +214 -6
- package/dist/selector/formatter.js.map +1 -1
- package/dist/selector/index.d.ts +8 -0
- package/dist/selector/index.d.ts.map +1 -1
- package/dist/selector/index.js +37 -2
- package/dist/selector/index.js.map +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parsers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAEL,wBAAwB,EACxB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAEL,sBAAsB,EAEtB,+BAA+B,EAC/B,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAEL,UAAU,EACV,qBAAqB,EACtB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,+BAA+B,EAAE,CAAC;AAE5D,wEAAwE;AACxE,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,WAAW,CAAC;AAC3E,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAoBxF;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAIhE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAIxD;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAIlD;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,WAAW,CAoBxE;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAkB5F;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI,CAExE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,EAAE,CAIjD;AAGD,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,UAAU,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser Registry
|
|
3
|
+
*
|
|
4
|
+
* Central registry for language-specific parsers.
|
|
5
|
+
* Determines which parser to use based on file extension.
|
|
6
|
+
*
|
|
7
|
+
* Supports:
|
|
8
|
+
* - TypeScript/JavaScript (via acorn)
|
|
9
|
+
* - Python, Go, Rust (via tree-sitter)
|
|
10
|
+
*/
|
|
11
|
+
import { parseTypeScript, isTypeScriptOrJavaScript, } from './typescript.js';
|
|
12
|
+
import { parseWithTreeSitter, canParseWithTreeSitter, getTreeSitterExtensions, getSupportedTreeSitterLanguages, generateRepoMap, } from './tree-sitter.js';
|
|
13
|
+
import { parseMarkdown, isMarkdown, getMarkdownExtensions, } from './markdown.js';
|
|
14
|
+
export { generateRepoMap, getSupportedTreeSitterLanguages };
|
|
15
|
+
/** Registered sync parsers mapped by extension */
|
|
16
|
+
const syncParsers = new Map();
|
|
17
|
+
/** Extensions that use async tree-sitter parsing */
|
|
18
|
+
const treeSitterExtensions = new Set(getTreeSitterExtensions());
|
|
19
|
+
// Register TypeScript/JavaScript parser for all supported extensions
|
|
20
|
+
const tsExtensions = ['ts', 'tsx', 'js', 'jsx', 'mjs', 'cjs', 'mts', 'cts'];
|
|
21
|
+
for (const ext of tsExtensions) {
|
|
22
|
+
syncParsers.set(ext, parseTypeScript);
|
|
23
|
+
}
|
|
24
|
+
// Register Markdown parser for all supported extensions
|
|
25
|
+
const mdExtensions = getMarkdownExtensions();
|
|
26
|
+
for (const ext of mdExtensions) {
|
|
27
|
+
syncParsers.set(ext, parseMarkdown);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the sync parser for a file based on its extension.
|
|
31
|
+
*
|
|
32
|
+
* @param filePath - Path to the file
|
|
33
|
+
* @returns Parser function or undefined if no parser is available
|
|
34
|
+
*/
|
|
35
|
+
export function getParser(filePath) {
|
|
36
|
+
const ext = filePath.toLowerCase().split('.').pop();
|
|
37
|
+
if (!ext)
|
|
38
|
+
return undefined;
|
|
39
|
+
return syncParsers.get(ext);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Check if a file uses tree-sitter (async) parsing.
|
|
43
|
+
*/
|
|
44
|
+
export function usesTreeSitter(filePath) {
|
|
45
|
+
const ext = filePath.toLowerCase().split('.').pop();
|
|
46
|
+
if (!ext)
|
|
47
|
+
return false;
|
|
48
|
+
return treeSitterExtensions.has(ext);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Check if a file can be parsed by any registered parser (sync or async).
|
|
52
|
+
*
|
|
53
|
+
* @param filePath - Path to the file
|
|
54
|
+
* @returns True if a parser is available for this file type
|
|
55
|
+
*/
|
|
56
|
+
export function canParse(filePath) {
|
|
57
|
+
const ext = filePath.toLowerCase().split('.').pop();
|
|
58
|
+
if (!ext)
|
|
59
|
+
return false;
|
|
60
|
+
return syncParsers.has(ext) || treeSitterExtensions.has(ext);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Parse a file and extract code boundaries (sync version for TS/JS).
|
|
64
|
+
*
|
|
65
|
+
* @param content - File content
|
|
66
|
+
* @param filePath - Path to the file (used to determine parser)
|
|
67
|
+
* @returns Parse result with boundaries, or failure result if no parser available
|
|
68
|
+
*/
|
|
69
|
+
export function parseFile(content, filePath) {
|
|
70
|
+
const parser = getParser(filePath);
|
|
71
|
+
if (!parser) {
|
|
72
|
+
// Check if this should use tree-sitter (async)
|
|
73
|
+
if (usesTreeSitter(filePath)) {
|
|
74
|
+
return {
|
|
75
|
+
success: false,
|
|
76
|
+
boundaries: [],
|
|
77
|
+
error: `File ${filePath} requires async parsing. Use parseFileAsync instead.`,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
success: false,
|
|
82
|
+
boundaries: [],
|
|
83
|
+
error: `No parser available for file type: ${filePath}`,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return parser(content, filePath);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Parse a file and extract code boundaries (async version, supports all languages).
|
|
90
|
+
*
|
|
91
|
+
* @param content - File content
|
|
92
|
+
* @param filePath - Path to the file (used to determine parser)
|
|
93
|
+
* @returns Parse result with boundaries, or failure result if no parser available
|
|
94
|
+
*/
|
|
95
|
+
export async function parseFileAsync(content, filePath) {
|
|
96
|
+
// Check if this uses tree-sitter
|
|
97
|
+
if (usesTreeSitter(filePath)) {
|
|
98
|
+
return parseWithTreeSitter(content, filePath);
|
|
99
|
+
}
|
|
100
|
+
// Fall back to sync parser
|
|
101
|
+
const parser = getParser(filePath);
|
|
102
|
+
if (!parser) {
|
|
103
|
+
return {
|
|
104
|
+
success: false,
|
|
105
|
+
boundaries: [],
|
|
106
|
+
error: `No parser available for file type: ${filePath}`,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return parser(content, filePath);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Register a custom parser for a file extension.
|
|
113
|
+
*
|
|
114
|
+
* @param extension - File extension (without dot)
|
|
115
|
+
* @param parser - Parser function
|
|
116
|
+
*/
|
|
117
|
+
export function registerParser(extension, parser) {
|
|
118
|
+
syncParsers.set(extension.toLowerCase(), parser);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get list of supported file extensions (all parsers).
|
|
122
|
+
*/
|
|
123
|
+
export function getSupportedExtensions() {
|
|
124
|
+
const syncExts = Array.from(syncParsers.keys());
|
|
125
|
+
const asyncExts = Array.from(treeSitterExtensions);
|
|
126
|
+
return [...new Set([...syncExts, ...asyncExts])];
|
|
127
|
+
}
|
|
128
|
+
// Re-export utility functions
|
|
129
|
+
export { isTypeScriptOrJavaScript, canParseWithTreeSitter, isMarkdown, getMarkdownExtensions };
|
|
130
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/parsers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,eAAe,EACf,wBAAwB,GAIzB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,+BAA+B,EAC/B,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,aAAa,EACb,UAAU,EACV,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,eAAe,EAAE,+BAA+B,EAAE,CAAC;AAM5D,kDAAkD;AAClD,MAAM,WAAW,GAA0B,IAAI,GAAG,EAAE,CAAC;AAErD,oDAAoD;AACpD,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,uBAAuB,EAAE,CAAC,CAAC;AAEhE,qEAAqE;AACrE,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK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AAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACnD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,QAAQ,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,8BAA8B;AAC9B,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,UAAU,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown Parser
|
|
3
|
+
*
|
|
4
|
+
* Structure-aware parsing for Markdown files.
|
|
5
|
+
* Extracts sections based on headers, keeps code blocks intact.
|
|
6
|
+
*
|
|
7
|
+
* Inspired by QMD (Quarto) structure:
|
|
8
|
+
* - YAML front matter extraction
|
|
9
|
+
* - Header-based sections
|
|
10
|
+
* - Code block preservation
|
|
11
|
+
*/
|
|
12
|
+
import type { ParseResult } from './typescript.js';
|
|
13
|
+
/**
|
|
14
|
+
* Parse a Markdown file and extract structural boundaries.
|
|
15
|
+
*
|
|
16
|
+
* @param content - Markdown file content
|
|
17
|
+
* @param _filePath - Optional file path for context (unused, for API consistency)
|
|
18
|
+
* @returns Parse result with section/code block boundaries
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseMarkdown(content: string, _filePath?: string): ParseResult;
|
|
21
|
+
/**
|
|
22
|
+
* Check if a file is a Markdown file.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isMarkdown(filePath: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Get supported Markdown extensions.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getMarkdownExtensions(): string[];
|
|
29
|
+
//# sourceMappingURL=markdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/parsers/markdown.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,iBAAiB,CAAC;AAEjE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CA6H9E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGpD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAEhD"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown Parser
|
|
3
|
+
*
|
|
4
|
+
* Structure-aware parsing for Markdown files.
|
|
5
|
+
* Extracts sections based on headers, keeps code blocks intact.
|
|
6
|
+
*
|
|
7
|
+
* Inspired by QMD (Quarto) structure:
|
|
8
|
+
* - YAML front matter extraction
|
|
9
|
+
* - Header-based sections
|
|
10
|
+
* - Code block preservation
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Parse a Markdown file and extract structural boundaries.
|
|
14
|
+
*
|
|
15
|
+
* @param content - Markdown file content
|
|
16
|
+
* @param _filePath - Optional file path for context (unused, for API consistency)
|
|
17
|
+
* @returns Parse result with section/code block boundaries
|
|
18
|
+
*/
|
|
19
|
+
export function parseMarkdown(content, _filePath) {
|
|
20
|
+
const lines = content.split('\n');
|
|
21
|
+
const boundaries = [];
|
|
22
|
+
let inFrontMatter = false;
|
|
23
|
+
let frontMatterStart = 0;
|
|
24
|
+
let inCodeBlock = false;
|
|
25
|
+
let codeBlockStart = 0;
|
|
26
|
+
let codeBlockLang = '';
|
|
27
|
+
let currentSection = null;
|
|
28
|
+
// Check for YAML front matter at the start
|
|
29
|
+
if (lines[0]?.trim() === '---') {
|
|
30
|
+
inFrontMatter = true;
|
|
31
|
+
frontMatterStart = 1;
|
|
32
|
+
}
|
|
33
|
+
for (let i = 0; i < lines.length; i++) {
|
|
34
|
+
const line = lines[i];
|
|
35
|
+
const lineNum = i + 1;
|
|
36
|
+
// Handle front matter
|
|
37
|
+
if (inFrontMatter) {
|
|
38
|
+
if (line.trim() === '---' && lineNum > frontMatterStart) {
|
|
39
|
+
// End of front matter
|
|
40
|
+
boundaries.push({
|
|
41
|
+
type: 'constant', // Use 'constant' for front matter (document metadata)
|
|
42
|
+
name: 'frontmatter',
|
|
43
|
+
startLine: frontMatterStart,
|
|
44
|
+
endLine: lineNum,
|
|
45
|
+
exported: false,
|
|
46
|
+
});
|
|
47
|
+
inFrontMatter = false;
|
|
48
|
+
}
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
// Handle code blocks
|
|
52
|
+
const codeBlockMatch = line.match(/^```(\w*)/);
|
|
53
|
+
if (codeBlockMatch) {
|
|
54
|
+
if (!inCodeBlock) {
|
|
55
|
+
// Start of code block
|
|
56
|
+
inCodeBlock = true;
|
|
57
|
+
codeBlockStart = lineNum;
|
|
58
|
+
codeBlockLang = codeBlockMatch[1] || 'text';
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// End of code block
|
|
62
|
+
const blockName = codeBlockLang ? `codeblock:${codeBlockLang}` : 'codeblock';
|
|
63
|
+
boundaries.push({
|
|
64
|
+
type: 'function', // Use 'function' for code blocks (executable content)
|
|
65
|
+
name: blockName,
|
|
66
|
+
startLine: codeBlockStart,
|
|
67
|
+
endLine: lineNum,
|
|
68
|
+
exported: false,
|
|
69
|
+
});
|
|
70
|
+
inCodeBlock = false;
|
|
71
|
+
}
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
// Skip content inside code blocks
|
|
75
|
+
if (inCodeBlock) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
// Handle headers
|
|
79
|
+
const headerMatch = line.match(/^(#{1,6})\s+(.+)$/);
|
|
80
|
+
if (headerMatch) {
|
|
81
|
+
const level = headerMatch[1].length;
|
|
82
|
+
const title = headerMatch[2].trim();
|
|
83
|
+
// Always close previous section when we encounter a new header
|
|
84
|
+
// Each header defines a new section
|
|
85
|
+
if (currentSection) {
|
|
86
|
+
boundaries.push({
|
|
87
|
+
type: 'class', // Use 'class' for sections (containers of content)
|
|
88
|
+
name: currentSection.name,
|
|
89
|
+
startLine: currentSection.startLine,
|
|
90
|
+
endLine: lineNum - 1,
|
|
91
|
+
exported: currentSection.level === 1, // Top-level headers are "exported"
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// Start new section
|
|
95
|
+
currentSection = {
|
|
96
|
+
name: title,
|
|
97
|
+
level,
|
|
98
|
+
startLine: lineNum,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Close final section
|
|
103
|
+
if (currentSection) {
|
|
104
|
+
boundaries.push({
|
|
105
|
+
type: 'class',
|
|
106
|
+
name: currentSection.name,
|
|
107
|
+
startLine: currentSection.startLine,
|
|
108
|
+
endLine: lines.length,
|
|
109
|
+
exported: currentSection.level === 1,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
// Handle unclosed code block
|
|
113
|
+
if (inCodeBlock) {
|
|
114
|
+
boundaries.push({
|
|
115
|
+
type: 'function',
|
|
116
|
+
name: codeBlockLang ? `codeblock:${codeBlockLang}` : 'codeblock',
|
|
117
|
+
startLine: codeBlockStart,
|
|
118
|
+
endLine: lines.length,
|
|
119
|
+
exported: false,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
// Sort boundaries by start line
|
|
123
|
+
boundaries.sort((a, b) => a.startLine - b.startLine);
|
|
124
|
+
return {
|
|
125
|
+
success: true,
|
|
126
|
+
boundaries,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Check if a file is a Markdown file.
|
|
131
|
+
*/
|
|
132
|
+
export function isMarkdown(filePath) {
|
|
133
|
+
const ext = filePath.toLowerCase().split('.').pop();
|
|
134
|
+
return ext === 'md' || ext === 'mdx' || ext === 'markdown' || ext === 'qmd';
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get supported Markdown extensions.
|
|
138
|
+
*/
|
|
139
|
+
export function getMarkdownExtensions() {
|
|
140
|
+
return ['md', 'mdx', 'markdown', 'qmd'];
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/parsers/markdown.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,SAAkB;IAC/D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,UAAU,GAAmB,EAAE,CAAC;IAEtC,IAAI,aAAa,GAAG,KAAK,CAAC;IAC1B,IAAI,gBAAgB,GAAG,CAAC,CAAC;IACzB,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,IAAI,cAAc,GAAG,CAAC,CAAC;IACvB,IAAI,aAAa,GAAG,EAAE,CAAC;IACvB,IAAI,cAAc,GAIP,IAAI,CAAC;IAEhB,2CAA2C;IAC3C,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,KAAK,EAAE,CAAC;QAC/B,aAAa,GAAG,IAAI,CAAC;QACrB,gBAAgB,GAAG,CAAC,CAAC;IACvB,CAAC;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,MAAM,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;QAEtB,sBAAsB;QACtB,IAAI,aAAa,EAAE,CAAC;YAClB,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,KAAK,IAAI,OAAO,GAAG,gBAAgB,EAAE,CAAC;gBACxD,sBAAsB;g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,IAAI;QACb,UAAU;KACX,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,QAAgB;IACzC,MAAM,GAAG,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IACpD,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,UAAU,IAAI,GAAG,KAAK,KAAK,CAAC;AAC9E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter Multi-Language Parser
|
|
3
|
+
*
|
|
4
|
+
* Universal AST parsing using tree-sitter WASM bindings.
|
|
5
|
+
* Supports: Python, Go, Rust (and more to come)
|
|
6
|
+
*/
|
|
7
|
+
import type { ParseResult } from './typescript.js';
|
|
8
|
+
/**
|
|
9
|
+
* Get language ID from file extension
|
|
10
|
+
*/
|
|
11
|
+
export declare function getLanguageForFile(filePath: string): string | null;
|
|
12
|
+
/**
|
|
13
|
+
* Check if tree-sitter can parse this file type
|
|
14
|
+
*/
|
|
15
|
+
export declare function canParseWithTreeSitter(filePath: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Parse a file using tree-sitter
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseWithTreeSitter(content: string, filePath: string): Promise<ParseResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Generate a repo map (signatures only) from a parsed file
|
|
22
|
+
*/
|
|
23
|
+
export declare function generateRepoMap(fileContent: string, filePath: string): Promise<{
|
|
24
|
+
success: boolean;
|
|
25
|
+
map: string;
|
|
26
|
+
error?: string;
|
|
27
|
+
}>;
|
|
28
|
+
/** Get list of supported languages */
|
|
29
|
+
export declare function getSupportedTreeSitterLanguages(): string[];
|
|
30
|
+
/** Get file extensions supported by tree-sitter */
|
|
31
|
+
export declare function getTreeSitterExtensions(): string[];
|
|
32
|
+
//# sourceMappingURL=tree-sitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-sitter.d.ts","sourceRoot":"","sources":["../../src/parsers/tree-sitter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,iBAAiB,CAAC;AA6LjE;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIlE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEhE;AA+DD;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,CAAC,CAuDtB;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAmF5D;AAED,sCAAsC;AACtC,wBAAgB,+BAA+B,IAAI,MAAM,EAAE,CAE1D;AAED,mDAAmD;AACnD,wBAAgB,uBAAuB,IAAI,MAAM,EAAE,CAElD"}
|