@typespec/emitter-framework 0.7.0 → 0.8.0-dev.1
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/src/testing/scenario-test/snippet-extractor.d.ts +5 -9
- package/dist/src/testing/scenario-test/snippet-extractor.d.ts.map +1 -1
- package/dist/src/testing/scenario-test/snippet-extractor.js +21 -13
- package/dist/test/testing/snippet-extractor-csharp.test.js +4 -4
- package/dist/test/testing/snippet-extractor-java.test.js +4 -4
- package/dist/test/testing/snippet-extractor-python.test.js +2 -2
- package/dist/test/testing/snippet-extractor-typescript.test.js +4 -4
- package/package.json +9 -8
- package/src/testing/scenario-test/snippet-extractor.ts +27 -26
- package/test/testing/snippet-extractor-csharp.test.ts +4 -4
- package/test/testing/snippet-extractor-java.test.ts +4 -4
- package/test/testing/snippet-extractor-python.test.ts +2 -2
- package/test/testing/snippet-extractor-typescript.test.ts +4 -4
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Language } from "web-tree-sitter";
|
|
1
2
|
export interface SnippetExtractor {
|
|
2
3
|
getClass(fileContent: string, name: string): string | null;
|
|
3
4
|
getFunction(fileContent: string, name: string): string | null;
|
|
@@ -5,15 +6,10 @@ export interface SnippetExtractor {
|
|
|
5
6
|
getTypeAlias(fileContent: string, name: string): string | null;
|
|
6
7
|
getEnum(fileContent: string, name: string): string | null;
|
|
7
8
|
}
|
|
8
|
-
export declare function createCSharpExtractorConfig(): LanguageConfiguration
|
|
9
|
-
export declare function createJavaExtractorConfig(): LanguageConfiguration
|
|
10
|
-
export declare function createPythonExtractorConfig(): LanguageConfiguration
|
|
11
|
-
export declare function createTypeScriptExtractorConfig(): LanguageConfiguration
|
|
12
|
-
export type Language = {
|
|
13
|
-
name: string;
|
|
14
|
-
language: any;
|
|
15
|
-
nodeTypeInfo: any[];
|
|
16
|
-
};
|
|
9
|
+
export declare function createCSharpExtractorConfig(): Promise<LanguageConfiguration>;
|
|
10
|
+
export declare function createJavaExtractorConfig(): Promise<LanguageConfiguration>;
|
|
11
|
+
export declare function createPythonExtractorConfig(): Promise<LanguageConfiguration>;
|
|
12
|
+
export declare function createTypeScriptExtractorConfig(): Promise<LanguageConfiguration>;
|
|
17
13
|
export interface LanguageConfiguration {
|
|
18
14
|
language: Language;
|
|
19
15
|
format: (content: string) => Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snippet-extractor.d.ts","sourceRoot":"","sources":["../../../../src/testing/scenario-test/snippet-extractor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"snippet-extractor.d.ts","sourceRoot":"","sources":["../../../../src/testing/scenario-test/snippet-extractor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAgB,MAAM,iBAAiB,CAAC;AAGzD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC3D,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC9D,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC/D,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC/D,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAC3D;AAcD,wBAAsB,2BAA2B,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAYlF;AAED,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAYhF;AAED,wBAAsB,2BAA2B,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAUlF;AAED,wBAAsB,+BAA+B,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAatF;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,eAAe,EAAE;QACf,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAID,wBAAgB,sBAAsB,CACpC,qBAAqB,EAAE,qBAAqB,GAC3C,gBAAgB,CAElB"}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { format } from "prettier";
|
|
2
|
-
import Parser from "tree-sitter";
|
|
3
|
-
import CSharpLanguage from "tree-sitter-c-sharp";
|
|
4
|
-
import JavaLanguage from "tree-sitter-java";
|
|
5
|
-
import PythonLanguage from "tree-sitter-python";
|
|
6
|
-
import TypeScriptLanguage from "tree-sitter-typescript";
|
|
2
|
+
import { Language, Parser } from "web-tree-sitter";
|
|
7
3
|
|
|
8
4
|
// Interface for SnippetExtractor
|
|
9
5
|
|
|
10
|
-
|
|
6
|
+
const wasmMap = {
|
|
7
|
+
"tree-sitter-c-sharp": "tree-sitter-c-sharp/tree-sitter-c_sharp.wasm",
|
|
8
|
+
"tree-sitter-java": "tree-sitter-java/tree-sitter-java.wasm",
|
|
9
|
+
"tree-sitter-python": "tree-sitter-python/tree-sitter-python.wasm",
|
|
10
|
+
"tree-sitter-typescript": "tree-sitter-typescript/tree-sitter-typescript.wasm"
|
|
11
|
+
};
|
|
12
|
+
function loadLanguage(name) {
|
|
13
|
+
const path = require.resolve(wasmMap[name]);
|
|
14
|
+
return Language.load(path);
|
|
15
|
+
}
|
|
16
|
+
export async function createCSharpExtractorConfig() {
|
|
11
17
|
return {
|
|
12
18
|
codeBlockTypes: ["cs", "csharp"],
|
|
13
19
|
format: async content => content,
|
|
14
|
-
language:
|
|
20
|
+
language: await loadLanguage("tree-sitter-c-sharp"),
|
|
15
21
|
nodeKindMapping: {
|
|
16
22
|
classNodeType: "class_declaration",
|
|
17
23
|
functionNodeType: "local_function_statement",
|
|
@@ -20,11 +26,11 @@ export function createCSharpExtractorConfig() {
|
|
|
20
26
|
}
|
|
21
27
|
};
|
|
22
28
|
}
|
|
23
|
-
export function createJavaExtractorConfig() {
|
|
29
|
+
export async function createJavaExtractorConfig() {
|
|
24
30
|
return {
|
|
25
31
|
codeBlockTypes: ["java"],
|
|
26
32
|
format: async content => content,
|
|
27
|
-
language:
|
|
33
|
+
language: await loadLanguage("tree-sitter-java"),
|
|
28
34
|
nodeKindMapping: {
|
|
29
35
|
classNodeType: "class_declaration",
|
|
30
36
|
functionNodeType: "method_declaration",
|
|
@@ -33,21 +39,21 @@ export function createJavaExtractorConfig() {
|
|
|
33
39
|
}
|
|
34
40
|
};
|
|
35
41
|
}
|
|
36
|
-
export function createPythonExtractorConfig() {
|
|
42
|
+
export async function createPythonExtractorConfig() {
|
|
37
43
|
return {
|
|
38
44
|
codeBlockTypes: ["py", "python"],
|
|
39
45
|
format: async content => content,
|
|
40
|
-
language:
|
|
46
|
+
language: await loadLanguage("tree-sitter-python"),
|
|
41
47
|
nodeKindMapping: {
|
|
42
48
|
classNodeType: "class_definition",
|
|
43
49
|
functionNodeType: "function_definition"
|
|
44
50
|
}
|
|
45
51
|
};
|
|
46
52
|
}
|
|
47
|
-
export function createTypeScriptExtractorConfig() {
|
|
53
|
+
export async function createTypeScriptExtractorConfig() {
|
|
48
54
|
return {
|
|
49
55
|
codeBlockTypes: ["ts", "typescript"],
|
|
50
|
-
language:
|
|
56
|
+
language: await loadLanguage("tree-sitter-typescript"),
|
|
51
57
|
format: async content => format(content, {
|
|
52
58
|
parser: "typescript"
|
|
53
59
|
}),
|
|
@@ -60,6 +66,7 @@ export function createTypeScriptExtractorConfig() {
|
|
|
60
66
|
}
|
|
61
67
|
};
|
|
62
68
|
}
|
|
69
|
+
await Parser.init();
|
|
63
70
|
export function createSnipperExtractor(languageConfiguration) {
|
|
64
71
|
return new SnippetExtractorImpl(languageConfiguration);
|
|
65
72
|
}
|
|
@@ -131,6 +138,7 @@ class SnippetExtractorImpl {
|
|
|
131
138
|
// Helper function to find a node by type and name in AST
|
|
132
139
|
findNodeByTypeAndName(fileContent, type, name) {
|
|
133
140
|
const tree = this.parser.parse(fileContent);
|
|
141
|
+
if (!tree) return null;
|
|
134
142
|
const rootNode = tree.rootNode; // Start from the root node
|
|
135
143
|
|
|
136
144
|
const traverse = node => {
|
|
@@ -3,8 +3,8 @@ import { beforeEach, describe, expect, it } from "vitest";
|
|
|
3
3
|
import { createCSharpExtractorConfig, createSnipperExtractor } from "../../src/testing/index.js";
|
|
4
4
|
describe("C# Snippet Extractor", () => {
|
|
5
5
|
let extractor;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
extractor = createSnipperExtractor(createCSharpExtractorConfig());
|
|
6
|
+
beforeEach(async () => {
|
|
7
|
+
extractor = createSnipperExtractor(await createCSharpExtractorConfig());
|
|
8
8
|
});
|
|
9
9
|
it("should extract a class", () => {
|
|
10
10
|
const content = d`
|
|
@@ -52,8 +52,8 @@ describe("C# Snippet Extractor", () => {
|
|
|
52
52
|
});
|
|
53
53
|
describe("C# Snippet Extractor - Enums", () => {
|
|
54
54
|
let extractor;
|
|
55
|
-
beforeEach(() => {
|
|
56
|
-
extractor = createSnipperExtractor(createCSharpExtractorConfig());
|
|
55
|
+
beforeEach(async () => {
|
|
56
|
+
extractor = createSnipperExtractor(await createCSharpExtractorConfig());
|
|
57
57
|
});
|
|
58
58
|
it("should extract a basic enum", async () => {
|
|
59
59
|
const content = d`
|
|
@@ -3,8 +3,8 @@ import { beforeEach, describe, expect, it } from "vitest";
|
|
|
3
3
|
import { createJavaExtractorConfig, createSnipperExtractor } from "../../src/testing/index.js";
|
|
4
4
|
describe("Java Snippet Extractor", () => {
|
|
5
5
|
let extractor;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
extractor = createSnipperExtractor(createJavaExtractorConfig());
|
|
6
|
+
beforeEach(async () => {
|
|
7
|
+
extractor = createSnipperExtractor(await createJavaExtractorConfig());
|
|
8
8
|
});
|
|
9
9
|
it("should extract a class", () => {
|
|
10
10
|
const content = d`
|
|
@@ -52,8 +52,8 @@ describe("Java Snippet Extractor", () => {
|
|
|
52
52
|
});
|
|
53
53
|
describe("Java Snippet Extractor - Enums", () => {
|
|
54
54
|
let extractor;
|
|
55
|
-
beforeEach(() => {
|
|
56
|
-
extractor = createSnipperExtractor(createJavaExtractorConfig());
|
|
55
|
+
beforeEach(async () => {
|
|
56
|
+
extractor = createSnipperExtractor(await createJavaExtractorConfig());
|
|
57
57
|
});
|
|
58
58
|
it("should extract a basic enum", async () => {
|
|
59
59
|
const content = d`
|
|
@@ -3,8 +3,8 @@ import { beforeEach, describe, expect, it } from "vitest";
|
|
|
3
3
|
import { createPythonExtractorConfig, createSnipperExtractor } from "../../src/testing/index.js";
|
|
4
4
|
describe("Python Snippet Extractor", () => {
|
|
5
5
|
let extractor;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
extractor = createSnipperExtractor(createPythonExtractorConfig());
|
|
6
|
+
beforeEach(async () => {
|
|
7
|
+
extractor = createSnipperExtractor(await createPythonExtractorConfig());
|
|
8
8
|
});
|
|
9
9
|
it("should extract a class", () => {
|
|
10
10
|
const content = d`
|
|
@@ -3,8 +3,8 @@ import { beforeEach, describe, expect, it } from "vitest";
|
|
|
3
3
|
import { createSnipperExtractor, createTypeScriptExtractorConfig } from "../../src/testing/index.js";
|
|
4
4
|
describe("TypeScript Snippet Extractor", () => {
|
|
5
5
|
let extractor;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
extractor = createSnipperExtractor(createTypeScriptExtractorConfig());
|
|
6
|
+
beforeEach(async () => {
|
|
7
|
+
extractor = createSnipperExtractor(await createTypeScriptExtractorConfig());
|
|
8
8
|
});
|
|
9
9
|
it("should extract a class", async () => {
|
|
10
10
|
const content = d`
|
|
@@ -121,8 +121,8 @@ describe("TypeScript Snippet Extractor", () => {
|
|
|
121
121
|
});
|
|
122
122
|
describe("TypeScript Snippet Extractor - Enums", () => {
|
|
123
123
|
let extractor;
|
|
124
|
-
beforeEach(() => {
|
|
125
|
-
extractor = createSnipperExtractor(createTypeScriptExtractorConfig());
|
|
124
|
+
beforeEach(async () => {
|
|
125
|
+
extractor = createSnipperExtractor(await createTypeScriptExtractorConfig());
|
|
126
126
|
});
|
|
127
127
|
it("should extract a basic enum", async () => {
|
|
128
128
|
const content = d`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/emitter-framework",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-dev.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"@alloy-js/core": "^0.15.0",
|
|
23
23
|
"@alloy-js/typescript": "^0.15.0",
|
|
24
24
|
"@typespec/compiler": "^1.0.0",
|
|
25
|
-
"@typespec/http": "^1.0.
|
|
26
|
-
"@typespec/rest": "^0.70.0"
|
|
25
|
+
"@typespec/http": "^1.0.1",
|
|
26
|
+
"@typespec/rest": "^0.70.0 || >=0.71.0-dev <0.71.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@alloy-js/cli": "^0.15.0",
|
|
@@ -31,21 +31,22 @@
|
|
|
31
31
|
"@alloy-js/core": "^0.15.0",
|
|
32
32
|
"@alloy-js/typescript": "^0.15.0",
|
|
33
33
|
"@types/minimist": "^1.2.5",
|
|
34
|
+
"@typespec/compiler": "^1.0.0",
|
|
35
|
+
"@typespec/http": "^1.0.1",
|
|
36
|
+
"@typespec/rest": "^0.70.0 || >=0.71.0-dev <0.71.0",
|
|
34
37
|
"concurrently": "^9.1.2",
|
|
35
38
|
"minimist": "^1.2.8",
|
|
36
39
|
"prettier": "~3.5.3",
|
|
37
|
-
"tree-sitter": "^0.
|
|
40
|
+
"web-tree-sitter": "^0.25.4",
|
|
38
41
|
"tree-sitter-c-sharp": "^0.23.0",
|
|
39
42
|
"tree-sitter-java": "^0.23.2",
|
|
40
43
|
"tree-sitter-javascript": "^0.23.0",
|
|
41
44
|
"tree-sitter-python": "^0.23.2",
|
|
42
45
|
"tree-sitter-typescript": "^0.23.0",
|
|
43
46
|
"typescript": "~5.8.2",
|
|
44
|
-
"vitest": "^3.1.2"
|
|
45
|
-
"@typespec/compiler": "^1.0.0",
|
|
46
|
-
"@typespec/http": "^1.0.0",
|
|
47
|
-
"@typespec/rest": "^0.70.0"
|
|
47
|
+
"vitest": "^3.1.2"
|
|
48
48
|
},
|
|
49
|
+
"dependencies": {},
|
|
49
50
|
"scripts": {
|
|
50
51
|
"build": "alloy build",
|
|
51
52
|
"clean": "rimraf ./dist",
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { format } from "prettier";
|
|
2
|
-
import Parser from "tree-sitter";
|
|
3
|
-
import CSharpLanguage from "tree-sitter-c-sharp";
|
|
4
|
-
import JavaLanguage from "tree-sitter-java";
|
|
5
|
-
import PythonLanguage from "tree-sitter-python";
|
|
6
|
-
import TypeScriptLanguage from "tree-sitter-typescript";
|
|
2
|
+
import { Language, Node, Parser } from "web-tree-sitter";
|
|
7
3
|
|
|
8
4
|
// Interface for SnippetExtractor
|
|
9
5
|
export interface SnippetExtractor {
|
|
@@ -14,11 +10,23 @@ export interface SnippetExtractor {
|
|
|
14
10
|
getEnum(fileContent: string, name: string): string | null;
|
|
15
11
|
}
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
const wasmMap = {
|
|
14
|
+
"tree-sitter-c-sharp": "tree-sitter-c-sharp/tree-sitter-c_sharp.wasm",
|
|
15
|
+
"tree-sitter-java": "tree-sitter-java/tree-sitter-java.wasm",
|
|
16
|
+
"tree-sitter-python": "tree-sitter-python/tree-sitter-python.wasm",
|
|
17
|
+
"tree-sitter-typescript": "tree-sitter-typescript/tree-sitter-typescript.wasm",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function loadLanguage(name: keyof typeof wasmMap): Promise<Language> {
|
|
21
|
+
const path = require.resolve(wasmMap[name]);
|
|
22
|
+
return Language.load(path);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function createCSharpExtractorConfig(): Promise<LanguageConfiguration> {
|
|
18
26
|
return {
|
|
19
27
|
codeBlockTypes: ["cs", "csharp"],
|
|
20
28
|
format: async (content: string) => content,
|
|
21
|
-
language:
|
|
29
|
+
language: await loadLanguage("tree-sitter-c-sharp"),
|
|
22
30
|
nodeKindMapping: {
|
|
23
31
|
classNodeType: "class_declaration",
|
|
24
32
|
functionNodeType: "local_function_statement",
|
|
@@ -28,11 +36,11 @@ export function createCSharpExtractorConfig(): LanguageConfiguration {
|
|
|
28
36
|
};
|
|
29
37
|
}
|
|
30
38
|
|
|
31
|
-
export function createJavaExtractorConfig(): LanguageConfiguration {
|
|
39
|
+
export async function createJavaExtractorConfig(): Promise<LanguageConfiguration> {
|
|
32
40
|
return {
|
|
33
41
|
codeBlockTypes: ["java"],
|
|
34
42
|
format: async (content: string) => content,
|
|
35
|
-
language:
|
|
43
|
+
language: await loadLanguage("tree-sitter-java"),
|
|
36
44
|
nodeKindMapping: {
|
|
37
45
|
classNodeType: "class_declaration",
|
|
38
46
|
functionNodeType: "method_declaration",
|
|
@@ -42,11 +50,11 @@ export function createJavaExtractorConfig(): LanguageConfiguration {
|
|
|
42
50
|
};
|
|
43
51
|
}
|
|
44
52
|
|
|
45
|
-
export function createPythonExtractorConfig(): LanguageConfiguration {
|
|
53
|
+
export async function createPythonExtractorConfig(): Promise<LanguageConfiguration> {
|
|
46
54
|
return {
|
|
47
55
|
codeBlockTypes: ["py", "python"],
|
|
48
56
|
format: async (content: string) => content,
|
|
49
|
-
language:
|
|
57
|
+
language: await loadLanguage("tree-sitter-python"),
|
|
50
58
|
nodeKindMapping: {
|
|
51
59
|
classNodeType: "class_definition",
|
|
52
60
|
functionNodeType: "function_definition",
|
|
@@ -54,10 +62,10 @@ export function createPythonExtractorConfig(): LanguageConfiguration {
|
|
|
54
62
|
};
|
|
55
63
|
}
|
|
56
64
|
|
|
57
|
-
export function createTypeScriptExtractorConfig(): LanguageConfiguration {
|
|
65
|
+
export async function createTypeScriptExtractorConfig(): Promise<LanguageConfiguration> {
|
|
58
66
|
return {
|
|
59
67
|
codeBlockTypes: ["ts", "typescript"],
|
|
60
|
-
language:
|
|
68
|
+
language: await loadLanguage("tree-sitter-typescript"),
|
|
61
69
|
format: async (content: string) => format(content, { parser: "typescript" }),
|
|
62
70
|
nodeKindMapping: {
|
|
63
71
|
classNodeType: "class_declaration",
|
|
@@ -69,12 +77,6 @@ export function createTypeScriptExtractorConfig(): LanguageConfiguration {
|
|
|
69
77
|
};
|
|
70
78
|
}
|
|
71
79
|
|
|
72
|
-
export type Language = {
|
|
73
|
-
name: string;
|
|
74
|
-
language: any;
|
|
75
|
-
nodeTypeInfo: any[];
|
|
76
|
-
};
|
|
77
|
-
|
|
78
80
|
export interface LanguageConfiguration {
|
|
79
81
|
language: Language;
|
|
80
82
|
format: (content: string) => Promise<string>;
|
|
@@ -88,6 +90,8 @@ export interface LanguageConfiguration {
|
|
|
88
90
|
};
|
|
89
91
|
}
|
|
90
92
|
|
|
93
|
+
await Parser.init();
|
|
94
|
+
|
|
91
95
|
export function createSnipperExtractor(
|
|
92
96
|
languageConfiguration: LanguageConfiguration,
|
|
93
97
|
): SnippetExtractor {
|
|
@@ -151,7 +155,7 @@ class SnippetExtractorImpl implements SnippetExtractor {
|
|
|
151
155
|
}
|
|
152
156
|
|
|
153
157
|
// Helper function to extract code from a node
|
|
154
|
-
private getCodeFromNode(node:
|
|
158
|
+
private getCodeFromNode(node: Node): string {
|
|
155
159
|
// Walk backward to include preceding nodes like 'export', 'public', etc.
|
|
156
160
|
let startIndex = node.startIndex;
|
|
157
161
|
let current = node.previousSibling;
|
|
@@ -171,15 +175,12 @@ class SnippetExtractorImpl implements SnippetExtractor {
|
|
|
171
175
|
}
|
|
172
176
|
|
|
173
177
|
// Helper function to find a node by type and name in AST
|
|
174
|
-
private findNodeByTypeAndName(
|
|
175
|
-
fileContent: string,
|
|
176
|
-
type: string,
|
|
177
|
-
name: string,
|
|
178
|
-
): Parser.SyntaxNode | null {
|
|
178
|
+
private findNodeByTypeAndName(fileContent: string, type: string, name: string): Node | null {
|
|
179
179
|
const tree = this.parser.parse(fileContent);
|
|
180
|
+
if (!tree) return null;
|
|
180
181
|
const rootNode = tree.rootNode; // Start from the root node
|
|
181
182
|
|
|
182
|
-
const traverse = (node:
|
|
183
|
+
const traverse = (node: Node): Node | null => {
|
|
183
184
|
if (node.type === type && node.childForFieldName("name")?.text === name) {
|
|
184
185
|
return node;
|
|
185
186
|
}
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
describe("C# Snippet Extractor", () => {
|
|
9
9
|
let extractor: SnippetExtractor;
|
|
10
10
|
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
extractor = createSnipperExtractor(createCSharpExtractorConfig());
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
extractor = createSnipperExtractor(await createCSharpExtractorConfig());
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
it("should extract a class", () => {
|
|
@@ -65,8 +65,8 @@ describe("C# Snippet Extractor", () => {
|
|
|
65
65
|
describe("C# Snippet Extractor - Enums", () => {
|
|
66
66
|
let extractor: SnippetExtractor;
|
|
67
67
|
|
|
68
|
-
beforeEach(() => {
|
|
69
|
-
extractor = createSnipperExtractor(createCSharpExtractorConfig());
|
|
68
|
+
beforeEach(async () => {
|
|
69
|
+
extractor = createSnipperExtractor(await createCSharpExtractorConfig());
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
it("should extract a basic enum", async () => {
|
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
describe("Java Snippet Extractor", () => {
|
|
10
10
|
let extractor: SnippetExtractor;
|
|
11
11
|
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
extractor = createSnipperExtractor(createJavaExtractorConfig());
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
extractor = createSnipperExtractor(await createJavaExtractorConfig());
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it("should extract a class", () => {
|
|
@@ -66,8 +66,8 @@ describe("Java Snippet Extractor", () => {
|
|
|
66
66
|
describe("Java Snippet Extractor - Enums", () => {
|
|
67
67
|
let extractor: SnippetExtractor;
|
|
68
68
|
|
|
69
|
-
beforeEach(() => {
|
|
70
|
-
extractor = createSnipperExtractor(createJavaExtractorConfig());
|
|
69
|
+
beforeEach(async () => {
|
|
70
|
+
extractor = createSnipperExtractor(await createJavaExtractorConfig());
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it("should extract a basic enum", async () => {
|
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
describe("Python Snippet Extractor", () => {
|
|
10
10
|
let extractor: SnippetExtractor;
|
|
11
11
|
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
extractor = createSnipperExtractor(createPythonExtractorConfig());
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
extractor = createSnipperExtractor(await createPythonExtractorConfig());
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it("should extract a class", () => {
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
|
|
9
9
|
describe("TypeScript Snippet Extractor", () => {
|
|
10
10
|
let extractor: SnippetExtractor;
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
extractor = createSnipperExtractor(createTypeScriptExtractorConfig());
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
extractor = createSnipperExtractor(await createTypeScriptExtractorConfig());
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
it("should extract a class", async () => {
|
|
@@ -137,8 +137,8 @@ describe("TypeScript Snippet Extractor", () => {
|
|
|
137
137
|
|
|
138
138
|
describe("TypeScript Snippet Extractor - Enums", () => {
|
|
139
139
|
let extractor: SnippetExtractor;
|
|
140
|
-
beforeEach(() => {
|
|
141
|
-
extractor = createSnipperExtractor(createTypeScriptExtractorConfig());
|
|
140
|
+
beforeEach(async () => {
|
|
141
|
+
extractor = createSnipperExtractor(await createTypeScriptExtractorConfig());
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
it("should extract a basic enum", async () => {
|