@vibe-agent-toolkit/resource-compiler 0.1.11
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 +449 -0
- package/bin/vat-compile-resources +8 -0
- package/dist/cli/compile-command.d.ts +11 -0
- package/dist/cli/compile-command.d.ts.map +1 -0
- package/dist/cli/compile-command.js +34 -0
- package/dist/cli/compile-command.js.map +1 -0
- package/dist/cli/compile-utils.d.ts +41 -0
- package/dist/cli/compile-utils.d.ts.map +1 -0
- package/dist/cli/compile-utils.js +51 -0
- package/dist/cli/compile-utils.js.map +1 -0
- package/dist/cli/generate-types-command.d.ts +11 -0
- package/dist/cli/generate-types-command.d.ts.map +1 -0
- package/dist/cli/generate-types-command.js +107 -0
- package/dist/cli/generate-types-command.js.map +1 -0
- package/dist/cli/index.d.ts +17 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +34 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/watch-command.d.ts +11 -0
- package/dist/cli/watch-command.d.ts.map +1 -0
- package/dist/cli/watch-command.js +88 -0
- package/dist/cli/watch-command.js.map +1 -0
- package/dist/compiler/dts-generator.d.ts +29 -0
- package/dist/compiler/dts-generator.d.ts.map +1 -0
- package/dist/compiler/dts-generator.js +133 -0
- package/dist/compiler/dts-generator.js.map +1 -0
- package/dist/compiler/index.d.ts +9 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +9 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/javascript-generator.d.ts +22 -0
- package/dist/compiler/javascript-generator.d.ts.map +1 -0
- package/dist/compiler/javascript-generator.js +106 -0
- package/dist/compiler/javascript-generator.js.map +1 -0
- package/dist/compiler/markdown-compiler.d.ts +30 -0
- package/dist/compiler/markdown-compiler.d.ts.map +1 -0
- package/dist/compiler/markdown-compiler.js +125 -0
- package/dist/compiler/markdown-compiler.js.map +1 -0
- package/dist/compiler/markdown-parser.d.ts +32 -0
- package/dist/compiler/markdown-parser.d.ts.map +1 -0
- package/dist/compiler/markdown-parser.js +126 -0
- package/dist/compiler/markdown-parser.js.map +1 -0
- package/dist/compiler/types.d.ts +71 -0
- package/dist/compiler/types.d.ts.map +1 -0
- package/dist/compiler/types.js +5 -0
- package/dist/compiler/types.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/language-service/completions.d.ts +27 -0
- package/dist/language-service/completions.d.ts.map +1 -0
- package/dist/language-service/completions.js +147 -0
- package/dist/language-service/completions.js.map +1 -0
- package/dist/language-service/definitions.d.ts +14 -0
- package/dist/language-service/definitions.d.ts.map +1 -0
- package/dist/language-service/definitions.js +140 -0
- package/dist/language-service/definitions.js.map +1 -0
- package/dist/language-service/diagnostics.d.ts +13 -0
- package/dist/language-service/diagnostics.d.ts.map +1 -0
- package/dist/language-service/diagnostics.js +169 -0
- package/dist/language-service/diagnostics.js.map +1 -0
- package/dist/language-service/hover.d.ts +15 -0
- package/dist/language-service/hover.d.ts.map +1 -0
- package/dist/language-service/hover.js +125 -0
- package/dist/language-service/hover.js.map +1 -0
- package/dist/language-service/index.d.ts +26 -0
- package/dist/language-service/index.d.ts.map +1 -0
- package/dist/language-service/index.js +30 -0
- package/dist/language-service/index.js.map +1 -0
- package/dist/language-service/markdown-cache.d.ts +44 -0
- package/dist/language-service/markdown-cache.d.ts.map +1 -0
- package/dist/language-service/markdown-cache.js +77 -0
- package/dist/language-service/markdown-cache.js.map +1 -0
- package/dist/language-service/plugin.d.ts +15 -0
- package/dist/language-service/plugin.d.ts.map +1 -0
- package/dist/language-service/plugin.js +51 -0
- package/dist/language-service/plugin.js.map +1 -0
- package/dist/language-service/utils.d.ts +173 -0
- package/dist/language-service/utils.d.ts.map +1 -0
- package/dist/language-service/utils.js +341 -0
- package/dist/language-service/utils.js.map +1 -0
- package/dist/transformer/ast-helpers.d.ts +35 -0
- package/dist/transformer/ast-helpers.d.ts.map +1 -0
- package/dist/transformer/ast-helpers.js +153 -0
- package/dist/transformer/ast-helpers.js.map +1 -0
- package/dist/transformer/declaration-generator.d.ts +47 -0
- package/dist/transformer/declaration-generator.d.ts.map +1 -0
- package/dist/transformer/declaration-generator.js +53 -0
- package/dist/transformer/declaration-generator.js.map +1 -0
- package/dist/transformer/import-detector.d.ts +62 -0
- package/dist/transformer/import-detector.d.ts.map +1 -0
- package/dist/transformer/import-detector.js +115 -0
- package/dist/transformer/import-detector.js.map +1 -0
- package/dist/transformer/index.d.ts +11 -0
- package/dist/transformer/index.d.ts.map +1 -0
- package/dist/transformer/index.js +11 -0
- package/dist/transformer/index.js.map +1 -0
- package/dist/transformer/module-generator.d.ts +29 -0
- package/dist/transformer/module-generator.d.ts.map +1 -0
- package/dist/transformer/module-generator.js +48 -0
- package/dist/transformer/module-generator.js.map +1 -0
- package/dist/transformer/path-resolver.d.ts +32 -0
- package/dist/transformer/path-resolver.d.ts.map +1 -0
- package/dist/transformer/path-resolver.js +112 -0
- package/dist/transformer/path-resolver.js.map +1 -0
- package/dist/transformer/transformer.d.ts +46 -0
- package/dist/transformer/transformer.d.ts.map +1 -0
- package/dist/transformer/transformer.js +89 -0
- package/dist/transformer/transformer.js.map +1 -0
- package/dist/utils/copy-resources.d.ts +54 -0
- package/dist/utils/copy-resources.d.ts.map +1 -0
- package/dist/utils/copy-resources.js +77 -0
- package/dist/utils/copy-resources.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown compiler orchestrator - coordinates the compilation pipeline
|
|
3
|
+
*/
|
|
4
|
+
import type { CompileOptions, CompileResult } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Compile markdown resources to JavaScript and TypeScript declarations
|
|
7
|
+
*
|
|
8
|
+
* @param options - Compilation options
|
|
9
|
+
* @returns Array of compilation results for each file
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const results = await compileMarkdownResources({
|
|
14
|
+
* inputDir: './resources',
|
|
15
|
+
* outputDir: './dist/resources',
|
|
16
|
+
* pattern: '**\/*.md',
|
|
17
|
+
* verbose: true,
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* for (const result of results) {
|
|
21
|
+
* if (result.success) {
|
|
22
|
+
* console.log(`✓ Compiled ${result.sourcePath}`);
|
|
23
|
+
* } else {
|
|
24
|
+
* console.error(`✗ Failed ${result.sourcePath}: ${result.error}`);
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function compileMarkdownResources(options: CompileOptions): Promise<CompileResult[]>;
|
|
30
|
+
//# sourceMappingURL=markdown-compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-compiler.d.ts","sourceRoot":"","sources":["../../src/compiler/markdown-compiler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,aAAa,EAAE,CAAC,CA4B1B"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown compiler orchestrator - coordinates the compilation pipeline
|
|
3
|
+
*/
|
|
4
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { mkdirSyncReal, toForwardSlash } from '@vibe-agent-toolkit/utils';
|
|
7
|
+
import { glob } from 'glob';
|
|
8
|
+
import { generateTypeScriptDeclarations } from './dts-generator.js';
|
|
9
|
+
import { generateJavaScript } from './javascript-generator.js';
|
|
10
|
+
import { parseMarkdown } from './markdown-parser.js';
|
|
11
|
+
/**
|
|
12
|
+
* Compile markdown resources to JavaScript and TypeScript declarations
|
|
13
|
+
*
|
|
14
|
+
* @param options - Compilation options
|
|
15
|
+
* @returns Array of compilation results for each file
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const results = await compileMarkdownResources({
|
|
20
|
+
* inputDir: './resources',
|
|
21
|
+
* outputDir: './dist/resources',
|
|
22
|
+
* pattern: '**\/*.md',
|
|
23
|
+
* verbose: true,
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* for (const result of results) {
|
|
27
|
+
* if (result.success) {
|
|
28
|
+
* console.log(`✓ Compiled ${result.sourcePath}`);
|
|
29
|
+
* } else {
|
|
30
|
+
* console.error(`✗ Failed ${result.sourcePath}: ${result.error}`);
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export async function compileMarkdownResources(options) {
|
|
36
|
+
const { inputDir, outputDir, pattern = '**/*.md', verbose = false } = options;
|
|
37
|
+
if (verbose) {
|
|
38
|
+
console.log(`Compiling markdown resources from ${inputDir}`);
|
|
39
|
+
console.log(`Pattern: ${pattern}`);
|
|
40
|
+
console.log(`Output: ${outputDir}`);
|
|
41
|
+
}
|
|
42
|
+
// Find all markdown files matching pattern
|
|
43
|
+
const files = await glob(pattern, {
|
|
44
|
+
cwd: inputDir,
|
|
45
|
+
absolute: false,
|
|
46
|
+
nodir: true,
|
|
47
|
+
});
|
|
48
|
+
if (verbose) {
|
|
49
|
+
console.log(`Found ${files.length} markdown files`);
|
|
50
|
+
}
|
|
51
|
+
const results = [];
|
|
52
|
+
for (const file of files) {
|
|
53
|
+
const result = await compileSingleFile(file, inputDir, outputDir, verbose);
|
|
54
|
+
results.push(result);
|
|
55
|
+
}
|
|
56
|
+
return results;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Compile a single markdown file
|
|
60
|
+
*
|
|
61
|
+
* @param relativeFilePath - Path relative to inputDir
|
|
62
|
+
* @param inputDir - Input directory
|
|
63
|
+
* @param outputDir - Output directory
|
|
64
|
+
* @param verbose - Enable verbose logging
|
|
65
|
+
* @returns Compilation result
|
|
66
|
+
*/
|
|
67
|
+
async function compileSingleFile(relativeFilePath, inputDir, outputDir, verbose) {
|
|
68
|
+
const sourcePath = join(inputDir, relativeFilePath);
|
|
69
|
+
try {
|
|
70
|
+
// Read markdown file
|
|
71
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- Controlled input from glob
|
|
72
|
+
const markdownContent = readFileSync(sourcePath, 'utf-8');
|
|
73
|
+
if (verbose) {
|
|
74
|
+
console.log(` Processing ${relativeFilePath}...`);
|
|
75
|
+
}
|
|
76
|
+
// Parse markdown
|
|
77
|
+
const resource = parseMarkdown(markdownContent);
|
|
78
|
+
// Generate JavaScript code
|
|
79
|
+
const jsCode = generateJavaScript(resource);
|
|
80
|
+
// Generate TypeScript declarations
|
|
81
|
+
const dtsCode = generateTypeScriptDeclarations(resource);
|
|
82
|
+
// Calculate output paths (maintain directory structure)
|
|
83
|
+
const fileBaseName = relativeFilePath.replace(/\.md$/i, '');
|
|
84
|
+
const jsRelativePath = `${fileBaseName}.js`;
|
|
85
|
+
const dtsRelativePath = `${fileBaseName}.d.ts`;
|
|
86
|
+
const jsPath = join(outputDir, jsRelativePath);
|
|
87
|
+
const dtsPath = join(outputDir, dtsRelativePath);
|
|
88
|
+
// Ensure output directories exist
|
|
89
|
+
const jsDir = dirname(jsPath);
|
|
90
|
+
const dtsDir = dirname(dtsPath);
|
|
91
|
+
mkdirSyncReal(jsDir, { recursive: true });
|
|
92
|
+
if (jsDir !== dtsDir) {
|
|
93
|
+
mkdirSyncReal(dtsDir, { recursive: true });
|
|
94
|
+
}
|
|
95
|
+
// Write output files
|
|
96
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- Controlled output path
|
|
97
|
+
writeFileSync(jsPath, jsCode, 'utf-8');
|
|
98
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- Controlled output path
|
|
99
|
+
writeFileSync(dtsPath, dtsCode, 'utf-8');
|
|
100
|
+
if (verbose) {
|
|
101
|
+
console.log(` ✓ ${toForwardSlash(jsRelativePath)}`);
|
|
102
|
+
console.log(` ✓ ${toForwardSlash(dtsRelativePath)}`);
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
sourcePath,
|
|
106
|
+
jsPath,
|
|
107
|
+
dtsPath,
|
|
108
|
+
success: true,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
113
|
+
if (verbose) {
|
|
114
|
+
console.error(` ✗ Failed to compile ${relativeFilePath}: ${errorMessage}`);
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
sourcePath,
|
|
118
|
+
jsPath: '',
|
|
119
|
+
dtsPath: '',
|
|
120
|
+
success: false,
|
|
121
|
+
error: errorMessage,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=markdown-compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-compiler.js","sourceRoot":"","sources":["../../src/compiler/markdown-compiler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,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AAE,OAAO,CAAC,CAAC;QAEzC,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,SAAS,cAAc,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;YACvD,OAAO,CAAC,GAAG,CAAC,SAAS,cAAc,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;QAC1D,CAAC;QAED,OAAO;YACL,UAAU;YACV,MAAM;YACN,OAAO;YACP,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAE5E,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,CAAC,2BAA2B,gBAAgB,KAAK,YAAY,EAAE,CAAC,CAAC;QAChF,CAAC;QAED,OAAO;YACL,UAAU;YACV,MAAM,EAAE,EAAE;YACV,OAAO,EAAE,EAAE;YACX,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,YAAY;SACpB,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown parser for extracting frontmatter and H2 fragments
|
|
3
|
+
*/
|
|
4
|
+
import type { MarkdownResource } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Parse markdown file content into a MarkdownResource
|
|
7
|
+
*
|
|
8
|
+
* @param content - Raw markdown file content
|
|
9
|
+
* @returns Parsed resource with frontmatter and fragments
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const content = `---
|
|
14
|
+
* title: My Document
|
|
15
|
+
* ---
|
|
16
|
+
* # Main Title
|
|
17
|
+
*
|
|
18
|
+
* ## First Section
|
|
19
|
+
* Content here
|
|
20
|
+
*
|
|
21
|
+
* ## Second Section
|
|
22
|
+
* More content
|
|
23
|
+
* `;
|
|
24
|
+
*
|
|
25
|
+
* const resource = parseMarkdown(content);
|
|
26
|
+
* console.log(resource.frontmatter.title); // "My Document"
|
|
27
|
+
* console.log(resource.fragments.length); // 2
|
|
28
|
+
* console.log(resource.fragments[0].slug); // "first-section"
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseMarkdown(content: string): MarkdownResource;
|
|
32
|
+
//# sourceMappingURL=markdown-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-parser.d.ts","sourceRoot":"","sources":["../../src/compiler/markdown-parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAE,gBAAgB,EAAoB,MAAM,YAAY,CAAC;AAerE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAY/D"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown parser for extracting frontmatter and H2 fragments
|
|
3
|
+
*/
|
|
4
|
+
import matter from 'gray-matter';
|
|
5
|
+
import slugifyModule from 'slugify';
|
|
6
|
+
// Import slugify with type assertion to handle CJS module
|
|
7
|
+
const slugifyFn = slugifyModule;
|
|
8
|
+
/**
|
|
9
|
+
* Parse markdown file content into a MarkdownResource
|
|
10
|
+
*
|
|
11
|
+
* @param content - Raw markdown file content
|
|
12
|
+
* @returns Parsed resource with frontmatter and fragments
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const content = `---
|
|
17
|
+
* title: My Document
|
|
18
|
+
* ---
|
|
19
|
+
* # Main Title
|
|
20
|
+
*
|
|
21
|
+
* ## First Section
|
|
22
|
+
* Content here
|
|
23
|
+
*
|
|
24
|
+
* ## Second Section
|
|
25
|
+
* More content
|
|
26
|
+
* `;
|
|
27
|
+
*
|
|
28
|
+
* const resource = parseMarkdown(content);
|
|
29
|
+
* console.log(resource.frontmatter.title); // "My Document"
|
|
30
|
+
* console.log(resource.fragments.length); // 2
|
|
31
|
+
* console.log(resource.fragments[0].slug); // "first-section"
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function parseMarkdown(content) {
|
|
35
|
+
// Parse frontmatter
|
|
36
|
+
const { data: frontmatter, content: markdownContent } = matter(content);
|
|
37
|
+
// Extract H2 fragments
|
|
38
|
+
const fragments = extractH2Fragments(markdownContent);
|
|
39
|
+
return {
|
|
40
|
+
frontmatter,
|
|
41
|
+
content: markdownContent,
|
|
42
|
+
fragments,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Extract H2 heading fragments from markdown content
|
|
47
|
+
*
|
|
48
|
+
* @param content - Markdown content (without frontmatter)
|
|
49
|
+
* @returns Array of parsed fragments
|
|
50
|
+
*/
|
|
51
|
+
function extractH2Fragments(content) {
|
|
52
|
+
const fragments = [];
|
|
53
|
+
// Split by H2 headings (## at start of line)
|
|
54
|
+
const h2Regex = /^## (.+)$/gm;
|
|
55
|
+
const matches = [...content.matchAll(h2Regex)];
|
|
56
|
+
if (matches.length === 0) {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
for (let i = 0; i < matches.length; i++) {
|
|
60
|
+
const match = matches[i];
|
|
61
|
+
if (!match || typeof match.index !== 'number') {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const heading = match[1]?.trim() ?? '';
|
|
65
|
+
const startIndex = match.index;
|
|
66
|
+
// Find content between this heading and next (or end of file)
|
|
67
|
+
const nextMatch = matches[i + 1];
|
|
68
|
+
const endIndex = nextMatch?.index ?? content.length;
|
|
69
|
+
// Extract the full text (header + body)
|
|
70
|
+
const text = content.slice(startIndex, endIndex).trim();
|
|
71
|
+
// Extract just the body (everything after the header line)
|
|
72
|
+
const headerEndIndex = content.indexOf('\n', startIndex);
|
|
73
|
+
const bodyStartIndex = headerEndIndex === -1 ? content.length : headerEndIndex + 1;
|
|
74
|
+
const body = content.slice(bodyStartIndex, endIndex).trim();
|
|
75
|
+
// Generate slug and camelCase name
|
|
76
|
+
const slug = generateSlug(heading);
|
|
77
|
+
const camelCase = slugToCamelCase(slug);
|
|
78
|
+
fragments.push({
|
|
79
|
+
heading,
|
|
80
|
+
slug,
|
|
81
|
+
camelCase,
|
|
82
|
+
header: `## ${heading}`,
|
|
83
|
+
body,
|
|
84
|
+
text,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return fragments;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Generate a URL-safe slug from heading text
|
|
91
|
+
*
|
|
92
|
+
* @param heading - Original heading text
|
|
93
|
+
* @returns Kebab-case slug
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* generateSlug("Purpose Driven") // "purpose-driven"
|
|
98
|
+
* generateSlug("API v2.0") // "api-v2-0"
|
|
99
|
+
* generateSlug("Hello, World!") // "hello-world"
|
|
100
|
+
* generateSlug(" Spaces Everywhere ") // "spaces-everywhere"
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
function generateSlug(heading) {
|
|
104
|
+
return slugifyFn(heading, {
|
|
105
|
+
lower: true,
|
|
106
|
+
strict: true,
|
|
107
|
+
trim: true,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Convert kebab-case slug to camelCase
|
|
112
|
+
*
|
|
113
|
+
* @param slug - Kebab-case slug
|
|
114
|
+
* @returns camelCase property name
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* slugToCamelCase("purpose-driven") // "purposeDriven"
|
|
119
|
+
* slugToCamelCase("api-v2-0") // "apiV20"
|
|
120
|
+
* slugToCamelCase("single") // "single"
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
function slugToCamelCase(slug) {
|
|
124
|
+
return slug.replaceAll(/-([a-z0-9])/g, (_, char) => char.toUpperCase());
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=markdown-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-parser.js","sourceRoot":"","sources":["../../src/compiler/markdown-parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,aAAa,MAAM,SAAS,CAAC;AAIpC,0DAA0D;AAC1D,MAAM,SAAS,GAAG,aAUP,CAAC;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,oBAAoB;IACpB,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAExE,uBAAuB;IACvB,MAAM,SAAS,GAAG,kBAAkB,CAAC,eAAe,CAAC,CAAC;IAEtD,OAAO;QACL,WAAW;QACX,OAAO,EAAE,eAAe;QACxB,SAAS;KACV,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,OAAe;IACzC,MAAM,SAAS,GAAuB,EAAE,CAAC;IAEzC,6CAA6C;IAC7C,MAAM,OAAO,GAAG,aAAa,CAAC;IAC9B,MAAM,OAAO,GAAG,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IAE/C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACzB,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,CAAC,KAAK,KA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AI;KACX,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAS,eAAe,CAAC,IAAY;IACnC,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,CAAC,EAAE,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for the resource compiler
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Represents a parsed markdown resource with frontmatter and fragments
|
|
6
|
+
*/
|
|
7
|
+
export interface MarkdownResource {
|
|
8
|
+
/** Parsed YAML frontmatter as a key-value object */
|
|
9
|
+
frontmatter: Record<string, unknown>;
|
|
10
|
+
/** Full markdown content (excluding frontmatter) */
|
|
11
|
+
content: string;
|
|
12
|
+
/** Extracted H2 heading fragments */
|
|
13
|
+
fragments: MarkdownFragment[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Represents a single H2 heading section in markdown
|
|
17
|
+
*/
|
|
18
|
+
export interface MarkdownFragment {
|
|
19
|
+
/** Original heading text (e.g., "Purpose Driven") */
|
|
20
|
+
heading: string;
|
|
21
|
+
/** Slugified heading (e.g., "purpose-driven") */
|
|
22
|
+
slug: string;
|
|
23
|
+
/** camelCase property name (e.g., "purposeDriven") */
|
|
24
|
+
camelCase: string;
|
|
25
|
+
/** Heading with markdown prefix (e.g., "## Purpose Driven") */
|
|
26
|
+
header: string;
|
|
27
|
+
/** Content below the heading (excluding the heading itself) */
|
|
28
|
+
body: string;
|
|
29
|
+
/** Full text (header + body) */
|
|
30
|
+
text: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Options for compiling markdown resources
|
|
34
|
+
*/
|
|
35
|
+
export interface CompileOptions {
|
|
36
|
+
/** Input directory containing markdown files */
|
|
37
|
+
inputDir: string;
|
|
38
|
+
/** Output directory for compiled JavaScript/TypeScript */
|
|
39
|
+
outputDir: string;
|
|
40
|
+
/** Enable watch mode for automatic recompilation */
|
|
41
|
+
watch?: boolean;
|
|
42
|
+
/** Enable verbose logging */
|
|
43
|
+
verbose?: boolean;
|
|
44
|
+
/** File glob pattern (default: "**\/*.md") */
|
|
45
|
+
pattern?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Result of parsing a single markdown file
|
|
49
|
+
*/
|
|
50
|
+
export interface ParseResult {
|
|
51
|
+
/** Path to the markdown file */
|
|
52
|
+
filePath: string;
|
|
53
|
+
/** Parsed resource */
|
|
54
|
+
resource: MarkdownResource;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Result of compiling a single markdown file
|
|
58
|
+
*/
|
|
59
|
+
export interface CompileResult {
|
|
60
|
+
/** Path to the original markdown file */
|
|
61
|
+
sourcePath: string;
|
|
62
|
+
/** Path to the generated JavaScript file */
|
|
63
|
+
jsPath: string;
|
|
64
|
+
/** Path to the generated TypeScript declaration file */
|
|
65
|
+
dtsPath: string;
|
|
66
|
+
/** Whether compilation succeeded */
|
|
67
|
+
success: boolean;
|
|
68
|
+
/** Error message if compilation failed */
|
|
69
|
+
error?: string;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/compiler/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oDAAoD;IACpD,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,qCAAqC;IACrC,SAAS,EAAE,gBAAgB,EAAE,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,SAAS,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,6BAA6B;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,gCAAgC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,sBAAsB;IACtB,QAAQ,EAAE,gBAAgB,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/compiler/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhance autocomplete with markdown fragment suggestions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Enhance completion items with markdown fragment suggestions
|
|
6
|
+
*
|
|
7
|
+
* @param ts - TypeScript module
|
|
8
|
+
* @param info - Plugin create info
|
|
9
|
+
* @param prior - Original completion results from TypeScript
|
|
10
|
+
* @param fileName - File being edited
|
|
11
|
+
* @param position - Cursor position
|
|
12
|
+
* @returns Enhanced completion results, or original if no enhancements needed
|
|
13
|
+
*/
|
|
14
|
+
export declare function enhanceCompletions(ts: any, info: any, prior: any, fileName: string, position: number): any;
|
|
15
|
+
/**
|
|
16
|
+
* Get detailed information for a completion entry
|
|
17
|
+
* Called when user hovers over a completion item
|
|
18
|
+
*
|
|
19
|
+
* @param ts - TypeScript module
|
|
20
|
+
* @param info - Plugin create info
|
|
21
|
+
* @param fileName - File being edited
|
|
22
|
+
* @param position - Cursor position
|
|
23
|
+
* @param entryName - Name of the completion entry
|
|
24
|
+
* @returns Detailed completion entry info, or undefined
|
|
25
|
+
*/
|
|
26
|
+
export declare function getCompletionEntryDetails(ts: any, info: any, fileName: string, position: number, entryName: string): any;
|
|
27
|
+
//# sourceMappingURL=completions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completions.d.ts","sourceRoot":"","sources":["../../src/language-service/completions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,GAAG,EACP,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,GAAG,EACV,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,GAAG,CA0CL;AAiDD;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CACvC,EAAE,EAAE,GAAG,EACP,IAAI,EAAE,GAAG,EACT,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,GAAG,CAoDL"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhance autocomplete with markdown fragment suggestions
|
|
3
|
+
*/
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types, max-depth, sonarjs/cognitive-complexity -- TypeScript Language Service plugin API requires any and complex AST traversal */
|
|
5
|
+
import { getSourceFileAndNode, getMarkdownPathFromExpression, resolveAndLoadMarkdown, } from './utils.js';
|
|
6
|
+
/**
|
|
7
|
+
* Enhance completion items with markdown fragment suggestions
|
|
8
|
+
*
|
|
9
|
+
* @param ts - TypeScript module
|
|
10
|
+
* @param info - Plugin create info
|
|
11
|
+
* @param prior - Original completion results from TypeScript
|
|
12
|
+
* @param fileName - File being edited
|
|
13
|
+
* @param position - Cursor position
|
|
14
|
+
* @returns Enhanced completion results, or original if no enhancements needed
|
|
15
|
+
*/
|
|
16
|
+
export function enhanceCompletions(ts, info, prior, fileName, position) {
|
|
17
|
+
// If no prior completions, return undefined
|
|
18
|
+
if (!prior) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
// Get the source file and find the node at cursor
|
|
23
|
+
const context = getSourceFileAndNode(ts, info, fileName, position);
|
|
24
|
+
if (!context) {
|
|
25
|
+
return prior;
|
|
26
|
+
}
|
|
27
|
+
// Check if we're in a markdown fragment access context
|
|
28
|
+
// Look for patterns like: Core.fragments.<cursor>
|
|
29
|
+
let parent = context.node.parent;
|
|
30
|
+
while (parent) {
|
|
31
|
+
if (ts.isPropertyAccessExpression(parent)) {
|
|
32
|
+
const expressionInfo = getMarkdownPathFromExpression(ts, parent, context.sourceFile);
|
|
33
|
+
if (expressionInfo) {
|
|
34
|
+
// Found markdown fragment access - add completions
|
|
35
|
+
return addMarkdownFragmentCompletions(ts, info, prior, expressionInfo.markdownPath, fileName);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
parent = parent.parent;
|
|
39
|
+
}
|
|
40
|
+
// Not in a markdown context - return original completions
|
|
41
|
+
return prior;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
// Log error and return original completions
|
|
45
|
+
info.project.projectService.logger.info(`markdown-import-plugin: Error enhancing completions: ${String(error)}`);
|
|
46
|
+
return prior;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Add markdown fragment completions to the completion list
|
|
51
|
+
*
|
|
52
|
+
* @param ts - TypeScript module
|
|
53
|
+
* @param info - Plugin create info
|
|
54
|
+
* @param prior - Original completion results
|
|
55
|
+
* @param markdownPath - Import path to markdown file
|
|
56
|
+
* @param containingFile - File containing the completion request
|
|
57
|
+
* @returns Enhanced completion results with markdown fragments
|
|
58
|
+
*/
|
|
59
|
+
function addMarkdownFragmentCompletions(ts, info, prior, markdownPath, containingFile) {
|
|
60
|
+
try {
|
|
61
|
+
// Resolve markdown path and load resource
|
|
62
|
+
const result = resolveAndLoadMarkdown(info, markdownPath, containingFile);
|
|
63
|
+
if (!result) {
|
|
64
|
+
return prior;
|
|
65
|
+
}
|
|
66
|
+
// Create completion entries for each fragment
|
|
67
|
+
const fragmentEntries = result.resource.fragments.map((fragment) => ({
|
|
68
|
+
name: fragment.camelCase,
|
|
69
|
+
kind: ts.ScriptElementKind.propertyElement,
|
|
70
|
+
sortText: '0', // Sort before other completions
|
|
71
|
+
insertText: fragment.camelCase,
|
|
72
|
+
kindModifiers: 'declare',
|
|
73
|
+
}));
|
|
74
|
+
// Merge with original completions
|
|
75
|
+
return {
|
|
76
|
+
...prior,
|
|
77
|
+
entries: [...fragmentEntries, ...prior.entries],
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
// Log error and return original completions
|
|
82
|
+
info.project.projectService.logger.info(`markdown-import-plugin: Error loading markdown for completions: ${String(error)}`);
|
|
83
|
+
return prior;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get detailed information for a completion entry
|
|
88
|
+
* Called when user hovers over a completion item
|
|
89
|
+
*
|
|
90
|
+
* @param ts - TypeScript module
|
|
91
|
+
* @param info - Plugin create info
|
|
92
|
+
* @param fileName - File being edited
|
|
93
|
+
* @param position - Cursor position
|
|
94
|
+
* @param entryName - Name of the completion entry
|
|
95
|
+
* @returns Detailed completion entry info, or undefined
|
|
96
|
+
*/
|
|
97
|
+
export function getCompletionEntryDetails(ts, info, fileName, position, entryName) {
|
|
98
|
+
try {
|
|
99
|
+
// Get the source file and node
|
|
100
|
+
const context = getSourceFileAndNode(ts, info, fileName, position);
|
|
101
|
+
if (!context) {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
// Find markdown context
|
|
105
|
+
let parent = context.node.parent;
|
|
106
|
+
while (parent) {
|
|
107
|
+
if (ts.isPropertyAccessExpression(parent)) {
|
|
108
|
+
const expressionInfo = getMarkdownPathFromExpression(ts, parent, context.sourceFile);
|
|
109
|
+
if (expressionInfo) {
|
|
110
|
+
// Resolve and load the markdown file
|
|
111
|
+
const result = resolveAndLoadMarkdown(info, expressionInfo.markdownPath, fileName);
|
|
112
|
+
if (!result) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
// Find the fragment matching this entry
|
|
116
|
+
const fragment = result.resource.fragments.find((f) => f.camelCase === entryName);
|
|
117
|
+
if (!fragment) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
// Return detailed info with fragment heading
|
|
121
|
+
return {
|
|
122
|
+
name: entryName,
|
|
123
|
+
kind: ts.ScriptElementKind.propertyElement,
|
|
124
|
+
kindModifiers: 'declare',
|
|
125
|
+
displayParts: [
|
|
126
|
+
{ text: 'fragment', kind: 'keyword' },
|
|
127
|
+
{ text: ' ', kind: 'space' },
|
|
128
|
+
{ text: entryName, kind: 'propertyName' },
|
|
129
|
+
],
|
|
130
|
+
documentation: [
|
|
131
|
+
{
|
|
132
|
+
text: `Markdown fragment: ${fragment.heading}`,
|
|
133
|
+
kind: 'text',
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
parent = parent.parent;
|
|
140
|
+
}
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=completions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completions.js","sourceRoot":"","sources":["../../src/language-service/completions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oOAAoO;AAEpO,OAAO,EACL,oBAAoB,EACpB,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAChC,EAAO,EACP,IAAS,EACT,KAAU,EACV,QAAgB,EAChB,QAAgB;IAEhB,4CAA4C;IAC5C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC;QACH,kDAAkD;QAClD,MAAM,OAAO,GAAG,oBAAoB,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACnE,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,KAAK,CAAC;QACf,CAAC;QAED,uDAAuD;QACvD,kDAAkD;QAClD,IAAI,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;QACjC,OAAO,MAAM,EAAE,CAAC;YACd,IAAI,EAAE,CAAC,0BAA0B,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC1C,MAAM,cAAc,GAAG,6BAA6B,CAAC,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,IAAI,CAAC,QAAQ,EAAE,CAAC;wBACd,OAAO,SAAS,CAAC;oBACnB,CAAC;oBAED,6CAA6C;oBAC7C,OAAO;wBACL,IAAI,EAAE,SAAS;wBACf,IAAI,EAAE,EAAE,CAAC,iBAAiB,CAAC,eAAe;wBAC1C,aAAa,EAAE,SAAS;wBACxB,YAAY,EAAE;4BACZ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;4BACrC,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE;4BAC5B,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,cAAc,EAAE;yBAC1C;wBACD,aAAa,EAAE;4BACb;gCACE,IAAI,EAAE,sBAAsB,QAAQ,CAAC,OAAO,EAAE;gCAC9C,IAAI,EAAE,MAAM;6BACb;yBACF;qBACF,CAAC;gBACJ,CAAC;YACH,CAAC;YACD,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QACzB,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhance go-to-definition for markdown imports and fragments
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Enhance definition results with markdown file and fragment locations
|
|
6
|
+
*
|
|
7
|
+
* @param ts - TypeScript module
|
|
8
|
+
* @param info - Plugin create info
|
|
9
|
+
* @param fileName - File being edited
|
|
10
|
+
* @param position - Cursor position
|
|
11
|
+
* @returns Enhanced definition info, or original if no enhancements needed
|
|
12
|
+
*/
|
|
13
|
+
export declare function enhanceDefinitions(ts: any, info: any, fileName: string, position: number): readonly any[] | undefined;
|
|
14
|
+
//# sourceMappingURL=definitions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../src/language-service/definitions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAeH;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,GAAG,EACP,IAAI,EAAE,GAAG,EACT,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,SAAS,GAAG,EAAE,GAAG,SAAS,CA4C5B"}
|