@fragments-sdk/context 0.1.0 → 0.1.2
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.
|
@@ -93,14 +93,18 @@ var NAME_FIELD_NODES = /* @__PURE__ */ new Set([
|
|
|
93
93
|
"method_declaration",
|
|
94
94
|
"constructor_declaration"
|
|
95
95
|
]);
|
|
96
|
-
var
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
var tsModule = null;
|
|
97
|
+
var initialized = false;
|
|
98
|
+
async function getTreeSitter() {
|
|
99
|
+
if (!tsModule) {
|
|
99
100
|
const mod = await import("web-tree-sitter");
|
|
100
|
-
|
|
101
|
-
await parserModule.init();
|
|
101
|
+
tsModule = mod;
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
if (!initialized) {
|
|
104
|
+
await tsModule.Parser.init();
|
|
105
|
+
initialized = true;
|
|
106
|
+
}
|
|
107
|
+
return tsModule;
|
|
104
108
|
}
|
|
105
109
|
var GRAMMAR_PACKAGES = {
|
|
106
110
|
typescript: "tree-sitter-typescript/tree-sitter-typescript.wasm",
|
|
@@ -115,7 +119,7 @@ var languageCache = /* @__PURE__ */ new Map();
|
|
|
115
119
|
async function loadLanguage(grammarName, wasmBasePath) {
|
|
116
120
|
const cached = languageCache.get(grammarName);
|
|
117
121
|
if (cached) return cached;
|
|
118
|
-
const
|
|
122
|
+
const { Language } = await getTreeSitter();
|
|
119
123
|
const grammarFile = GRAMMAR_PACKAGES[grammarName];
|
|
120
124
|
if (!grammarFile) {
|
|
121
125
|
throw new Error(`No grammar available for: ${grammarName}`);
|
|
@@ -128,7 +132,7 @@ async function loadLanguage(grammarName, wasmBasePath) {
|
|
|
128
132
|
const require2 = createRequire(import.meta.url);
|
|
129
133
|
wasmPath = require2.resolve(grammarFile);
|
|
130
134
|
}
|
|
131
|
-
const lang = await
|
|
135
|
+
const lang = await Language.load(wasmPath);
|
|
132
136
|
languageCache.set(grammarName, lang);
|
|
133
137
|
return lang;
|
|
134
138
|
}
|
|
@@ -206,8 +210,7 @@ async function chunkByAST(content, filePath, language, grammarName, options) {
|
|
|
206
210
|
const maxChars = options?.maxChunkChars ?? 1500;
|
|
207
211
|
const minChars = options?.minChunkChars ?? 100;
|
|
208
212
|
const lang = await loadLanguage(grammarName, options?.wasmBasePath);
|
|
209
|
-
const
|
|
210
|
-
const Parser = TreeSitter;
|
|
213
|
+
const { Parser } = await getTreeSitter();
|
|
211
214
|
const parser = new Parser();
|
|
212
215
|
parser.setLanguage(lang);
|
|
213
216
|
const tree = parser.parse(content);
|
package/dist/chunking/index.js
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fragments-sdk/context",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Code intelligence and RAG primitives for design system and codebase indexing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -43,7 +43,13 @@
|
|
|
43
43
|
"clean": "rm -rf dist"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"
|
|
46
|
+
"tree-sitter-go": "^0.25.0",
|
|
47
|
+
"tree-sitter-java": "^0.23.5",
|
|
48
|
+
"tree-sitter-javascript": "^0.25.0",
|
|
49
|
+
"tree-sitter-python": "^0.25.0",
|
|
50
|
+
"tree-sitter-rust": "^0.24.0",
|
|
51
|
+
"tree-sitter-typescript": "^0.23.2",
|
|
52
|
+
"web-tree-sitter": "^0.26.5"
|
|
47
53
|
},
|
|
48
54
|
"devDependencies": {
|
|
49
55
|
"@types/node": "^22.0.0",
|