@ksm0709/context 0.0.29 → 0.0.30
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/cli/index.js +1598 -27
- package/dist/index.js +4 -4
- package/dist/omc/session-start-hook.js +514 -0
- package/dist/omc/stop-hook.js +40 -0
- package/dist/omx/index.mjs +81 -51
- package/package.json +4 -4
package/dist/cli/index.js
CHANGED
|
@@ -27,7 +27,7 @@ function resolveContextDir(projectDir) {
|
|
|
27
27
|
// package.json
|
|
28
28
|
var package_default = {
|
|
29
29
|
name: "@ksm0709/context",
|
|
30
|
-
version: "0.0.
|
|
30
|
+
version: "0.0.30",
|
|
31
31
|
author: {
|
|
32
32
|
name: "TaehoKang",
|
|
33
33
|
email: "ksm07091@gmail.com"
|
|
@@ -57,10 +57,10 @@ var package_default = {
|
|
|
57
57
|
access: "public"
|
|
58
58
|
},
|
|
59
59
|
scripts: {
|
|
60
|
-
build: "bun build ./src/index.ts --outdir dist --target bun && bun build ./src/mcp.ts --outdir dist --target bun && bun build ./src/cli/index.ts --outdir dist/cli --target bun && bun build ./src/omx/index.ts --outdir dist/omx --target node --format esm --external jsonc-parser && mv dist/omx/index.js dist/omx/index.mjs",
|
|
60
|
+
build: "bun build ./src/index.ts --outdir dist --target bun && bun build ./src/mcp.ts --outdir dist --target bun && bun build ./src/cli/index.ts --outdir dist/cli --target bun && bun build ./src/omx/index.ts --outdir dist/omx --target node --format esm --external jsonc-parser && mv dist/omx/index.js dist/omx/index.mjs && bun build ./src/omc/session-start-hook.ts --outdir dist/omc --target bun && bun build ./src/omc/stop-hook.ts --outdir dist/omc --target bun",
|
|
61
61
|
test: "vitest run",
|
|
62
62
|
lint: "eslint src --ext .ts",
|
|
63
|
-
prepublishOnly: "bun build ./src/index.ts --outdir dist --target bun && bun build ./src/mcp.ts --outdir dist --target bun && bun build ./src/cli/index.ts --outdir dist/cli --target bun && bun build ./src/omx/index.ts --outdir dist/omx --target node --format esm --external jsonc-parser && mv dist/omx/index.js dist/omx/index.mjs"
|
|
63
|
+
prepublishOnly: "bun build ./src/index.ts --outdir dist --target bun && bun build ./src/mcp.ts --outdir dist --target bun && bun build ./src/cli/index.ts --outdir dist/cli --target bun && bun build ./src/omx/index.ts --outdir dist/omx --target node --format esm --external jsonc-parser && mv dist/omx/index.js dist/omx/index.mjs && bun build ./src/omc/session-start-hook.ts --outdir dist/omc --target bun && bun build ./src/omc/stop-hook.ts --outdir dist/omc --target bun"
|
|
64
64
|
},
|
|
65
65
|
files: [
|
|
66
66
|
"dist"
|
|
@@ -69,7 +69,7 @@ var package_default = {
|
|
|
69
69
|
"@opencode-ai/plugin": ">=1.0.0"
|
|
70
70
|
},
|
|
71
71
|
dependencies: {
|
|
72
|
-
"@ksm0709/context": "^0.0.
|
|
72
|
+
"@ksm0709/context": "^0.0.29",
|
|
73
73
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
74
74
|
"jsonc-parser": "^3.0.0"
|
|
75
75
|
},
|
|
@@ -397,6 +397,29 @@ var TEMPLATE_FILES = {
|
|
|
397
397
|
"index.md": DEFAULT_INDEX_TEMPLATE,
|
|
398
398
|
"work-complete.txt": DEFAULT_WORK_COMPLETE_TEMPLATE
|
|
399
399
|
};
|
|
400
|
+
function scaffoldIfNeeded(projectDir) {
|
|
401
|
+
const contextDir = join2(projectDir, resolveContextDir(projectDir));
|
|
402
|
+
if (existsSync2(contextDir)) {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
const templatesDir = join2(contextDir, "templates");
|
|
407
|
+
mkdirSync(templatesDir, { recursive: true });
|
|
408
|
+
const guidesDir = join2(contextDir, "guides");
|
|
409
|
+
mkdirSync(guidesDir, { recursive: true });
|
|
410
|
+
writeFileSync(join2(contextDir, "config.jsonc"), DEFAULT_CONFIG, "utf-8");
|
|
411
|
+
for (const [filename, content] of Object.entries(TEMPLATE_FILES)) {
|
|
412
|
+
writeFileSync(join2(templatesDir, filename), content, "utf-8");
|
|
413
|
+
}
|
|
414
|
+
for (const [filename, content] of Object.entries(GUIDE_FILES)) {
|
|
415
|
+
writeFileSync(join2(guidesDir, filename), content, "utf-8");
|
|
416
|
+
}
|
|
417
|
+
writeVersion(contextDir, PLUGIN_VERSION);
|
|
418
|
+
return true;
|
|
419
|
+
} catch {
|
|
420
|
+
return false;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
400
423
|
function updateScaffold(projectDir) {
|
|
401
424
|
const contextDir = join2(projectDir, resolveContextDir(projectDir));
|
|
402
425
|
mkdirSync(join2(contextDir, "templates"), { recursive: true });
|
|
@@ -577,46 +600,60 @@ function updateConfigPaths(contextDir) {
|
|
|
577
600
|
}
|
|
578
601
|
|
|
579
602
|
// src/cli/commands/install.ts
|
|
580
|
-
import { join as
|
|
581
|
-
import { existsSync as
|
|
603
|
+
import { join as join8, resolve as resolve4, dirname as dirname5 } from "path";
|
|
604
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync5, copyFileSync } from "fs";
|
|
582
605
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
583
|
-
import { createRequire } from "module";
|
|
606
|
+
import { createRequire as createRequire2 } from "module";
|
|
607
|
+
import { execSync } from "child_process";
|
|
584
608
|
|
|
585
609
|
// src/omx/registry.ts
|
|
610
|
+
import { join as join6, dirname as dirname2 } from "path";
|
|
611
|
+
import { existsSync as existsSync6, readFileSync as readFileSync3, writeFileSync as writeFileSync3, mkdirSync as mkdirSync2 } from "fs";
|
|
612
|
+
import { homedir as homedir2 } from "os";
|
|
613
|
+
|
|
614
|
+
// src/shared/mcp-path.ts
|
|
586
615
|
import { fileURLToPath } from "url";
|
|
587
616
|
import { dirname, join as join5, resolve as resolve3 } from "path";
|
|
588
|
-
import { existsSync as existsSync5
|
|
589
|
-
import {
|
|
617
|
+
import { existsSync as existsSync5 } from "fs";
|
|
618
|
+
import { createRequire } from "module";
|
|
590
619
|
function resolveMcpPath() {
|
|
620
|
+
try {
|
|
621
|
+
const req = createRequire(import.meta.url);
|
|
622
|
+
const pkgJsonPath = req.resolve("@ksm0709/context/package.json");
|
|
623
|
+
const pkgRoot = dirname(pkgJsonPath);
|
|
624
|
+
const distMcp = join5(pkgRoot, "dist", "mcp.js");
|
|
625
|
+
if (existsSync5(distMcp))
|
|
626
|
+
return distMcp;
|
|
627
|
+
} catch {}
|
|
591
628
|
const currentFile = fileURLToPath(import.meta.url);
|
|
592
629
|
const currentDir = dirname(currentFile);
|
|
593
630
|
const distMcpPath = resolve3(currentDir, "..", "mcp.js");
|
|
594
|
-
if (existsSync5(distMcpPath))
|
|
631
|
+
if (existsSync5(distMcpPath))
|
|
595
632
|
return distMcpPath;
|
|
596
|
-
}
|
|
597
633
|
const srcMcpPath = resolve3(currentDir, "..", "mcp.ts");
|
|
598
|
-
if (existsSync5(srcMcpPath))
|
|
634
|
+
if (existsSync5(srcMcpPath))
|
|
599
635
|
return srcMcpPath;
|
|
600
|
-
}
|
|
601
636
|
return distMcpPath;
|
|
602
637
|
}
|
|
638
|
+
|
|
639
|
+
// src/omx/registry.ts
|
|
603
640
|
function getRegistryPaths() {
|
|
604
641
|
return [
|
|
605
|
-
|
|
606
|
-
|
|
642
|
+
join6(homedir2(), ".omx", "mcp-registry.json"),
|
|
643
|
+
join6(homedir2(), ".omc", "mcp-registry.json")
|
|
607
644
|
];
|
|
608
645
|
}
|
|
609
646
|
function ensureMcpRegistered(sdkLog) {
|
|
610
647
|
const registryPaths = getRegistryPaths();
|
|
611
648
|
let targetPath = registryPaths[0];
|
|
612
649
|
for (const p of registryPaths) {
|
|
613
|
-
if (
|
|
650
|
+
if (existsSync6(p)) {
|
|
614
651
|
targetPath = p;
|
|
615
652
|
break;
|
|
616
653
|
}
|
|
617
654
|
}
|
|
618
655
|
let registry = {};
|
|
619
|
-
if (
|
|
656
|
+
if (existsSync6(targetPath)) {
|
|
620
657
|
try {
|
|
621
658
|
const content = readFileSync3(targetPath, "utf-8");
|
|
622
659
|
registry = JSON.parse(content);
|
|
@@ -644,7 +681,7 @@ function ensureMcpRegistered(sdkLog) {
|
|
|
644
681
|
}
|
|
645
682
|
if (changed) {
|
|
646
683
|
try {
|
|
647
|
-
mkdirSync2(
|
|
684
|
+
mkdirSync2(dirname2(targetPath), { recursive: true });
|
|
648
685
|
writeFileSync3(targetPath, JSON.stringify(registry, null, 2), "utf-8");
|
|
649
686
|
if (sdkLog) {
|
|
650
687
|
sdkLog(`[INFO] Registered context_mcp in ${targetPath}`);
|
|
@@ -660,32 +697,1527 @@ function ensureMcpRegistered(sdkLog) {
|
|
|
660
697
|
return false;
|
|
661
698
|
}
|
|
662
699
|
|
|
700
|
+
// src/shared/agents-md.ts
|
|
701
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync, writeFileSync as writeFileSync4 } from "fs";
|
|
702
|
+
import { dirname as dirname3 } from "path";
|
|
703
|
+
var START_MARKER = "<!-- context:start -->";
|
|
704
|
+
var END_MARKER = "<!-- context:end -->";
|
|
705
|
+
function renderMarkerBlock(content, trailingNewline) {
|
|
706
|
+
const block = `${START_MARKER}
|
|
707
|
+
${content}
|
|
708
|
+
${END_MARKER}`;
|
|
709
|
+
if (trailingNewline) {
|
|
710
|
+
return `${block}
|
|
711
|
+
`;
|
|
712
|
+
}
|
|
713
|
+
return block;
|
|
714
|
+
}
|
|
715
|
+
function appendMarkerBlock(existingContent, content) {
|
|
716
|
+
if (existingContent.length === 0) {
|
|
717
|
+
return renderMarkerBlock(content, true);
|
|
718
|
+
}
|
|
719
|
+
const separator = existingContent.endsWith(`
|
|
720
|
+
`) ? `
|
|
721
|
+
` : `
|
|
722
|
+
|
|
723
|
+
`;
|
|
724
|
+
return `${existingContent}${separator}${renderMarkerBlock(content, true)}`;
|
|
725
|
+
}
|
|
726
|
+
function replaceMarkerBlock(existingContent, content) {
|
|
727
|
+
const startIndex = existingContent.indexOf(START_MARKER);
|
|
728
|
+
const endIndex = existingContent.indexOf(END_MARKER, startIndex + START_MARKER.length);
|
|
729
|
+
if (startIndex === -1 || endIndex === -1 || endIndex < startIndex) {
|
|
730
|
+
return appendMarkerBlock(existingContent, content);
|
|
731
|
+
}
|
|
732
|
+
const before = existingContent.slice(0, startIndex);
|
|
733
|
+
const after = existingContent.slice(endIndex + END_MARKER.length);
|
|
734
|
+
const replacement = renderMarkerBlock(content, false);
|
|
735
|
+
return `${before}${replacement}${after}`;
|
|
736
|
+
}
|
|
737
|
+
function writeFileAtomically(filePath, content) {
|
|
738
|
+
const tempPath = `${filePath}.tmp`;
|
|
739
|
+
writeFileSync4(tempPath, content, "utf-8");
|
|
740
|
+
renameSync(tempPath, filePath);
|
|
741
|
+
}
|
|
742
|
+
function injectIntoAgentsMd(agentsMdPath, content) {
|
|
743
|
+
mkdirSync3(dirname3(agentsMdPath), { recursive: true });
|
|
744
|
+
if (!existsSync7(agentsMdPath)) {
|
|
745
|
+
writeFileAtomically(agentsMdPath, renderMarkerBlock(content, true));
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
const existingContent = readFileSync4(agentsMdPath, "utf-8");
|
|
749
|
+
const nextContent = existingContent.includes(START_MARKER) && existingContent.includes(END_MARKER) ? replaceMarkerBlock(existingContent, content) : appendMarkerBlock(existingContent, content);
|
|
750
|
+
writeFileAtomically(agentsMdPath, nextContent);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// src/shared/knowledge-context.ts
|
|
754
|
+
var STATIC_KNOWLEDGE_CONTEXT = `## Knowledge Context
|
|
755
|
+
|
|
756
|
+
\uC774 \uD504\uB85C\uC81D\uD2B8\uB294 **\uC81C\uD154\uCE74\uC2A4\uD150(Zettelkasten)** \uBC29\uC2DD\uC73C\uB85C \uC9C0\uC2DD\uC744 \uAD00\uB9AC\uD569\uB2C8\uB2E4.
|
|
757
|
+
\uC138\uC158 \uAC04 \uCEE8\uD14D\uC2A4\uD2B8\uB97C \uBCF4\uC874\uD558\uC5EC, \uC774\uC804 \uC138\uC158\uC758 \uACB0\uC815/\uD328\uD134/\uC2E4\uC218\uAC00 \uB2E4\uC74C \uC138\uC158\uC5D0\uC11C \uC7AC\uD65C\uC6A9\uB429\uB2C8\uB2E4.
|
|
758
|
+
|
|
759
|
+
### \uC81C\uD154\uCE74\uC2A4\uD150 \uD575\uC2EC \uC6D0\uCE59
|
|
760
|
+
1. **\uC6D0\uC790\uC131** -- \uD558\uB098\uC758 \uB178\uD2B8 = \uD558\uB098\uC758 \uC8FC\uC81C. \uC5EC\uB7EC \uC8FC\uC81C\uB97C \uC11E\uC9C0 \uB9C8\uC138\uC694.
|
|
761
|
+
2. **\uC5F0\uACB0** -- \uBAA8\uB4E0 \uB178\uD2B8\uB294 [[wikilink]]\uB85C \uAD00\uB828 \uB178\uD2B8\uC5D0 \uC5F0\uACB0. \uACE0\uB9BD\uB41C \uB178\uD2B8\uB294 \uBC1C\uACAC\uB418\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.
|
|
762
|
+
3. **\uC790\uAE30 \uC5B8\uC5B4** -- \uBCF5\uC0AC-\uBD99\uC5EC\uB123\uAE30\uAC00 \uC544\uB2CC, \uD575\uC2EC\uC744 \uC774\uD574\uD558\uACE0 \uAC04\uACB0\uD558\uAC8C \uC11C\uC220\uD558\uC138\uC694.
|
|
763
|
+
|
|
764
|
+
### MCP Tools
|
|
765
|
+
- **\uC9C0\uC2DD \uAD00\uB9AC**: \`context_mcp_search_knowledge\`, \`context_mcp_read_knowledge\`, \`context_mcp_create_knowledge_note\`, \`context_mcp_update_knowledge_note\`
|
|
766
|
+
- **\uB370\uC77C\uB9AC \uB178\uD2B8**: \`context_mcp_read_daily_note\`, \`context_mcp_append_daily_note\`
|
|
767
|
+
- **\uC791\uC5C5 \uC644\uB8CC**: \`context_mcp_submit_turn_complete\` (\uC791\uC5C5 \uC885\uB8CC \uC2DC \uD544\uC218 \uD638\uCD9C)
|
|
768
|
+
|
|
769
|
+
### \uC791\uC5C5 \uC804 \uD544\uC218
|
|
770
|
+
- **\uB370\uC77C\uB9AC \uB178\uD2B8 \uD655\uC778**: \uAC00\uC7A5 \uCD5C\uADFC\uC758 \uB370\uC77C\uB9AC \uB178\uD2B8\uB97C \uC77D\uACE0 \uC774\uC804 \uC138\uC158\uC758 \uCEE8\uD14D\uC2A4\uD2B8\uC640 \uBBF8\uD574\uACB0 \uC774\uC288\uB97C \uD30C\uC545\uD558\uC138\uC694.
|
|
771
|
+
- **\uC791\uC5C5 \uC758\uB3C4 \uC120\uC5B8**: \uC791\uC5C5 \uC2DC\uC791 \uC804, \uD604\uC7AC \uC138\uC158\uC758 \uBAA9\uD45C\uC640 \uC791\uC5C5 \uC758\uB3C4\uB97C \uBA85\uD655\uD788 \uD30C\uC545\uD558\uACE0 \uC120\uC5B8\uD558\uC138\uC694.
|
|
772
|
+
- **\uC9C0\uC2DD \uAC80\uC0C9**: \uC791\uC5C5\uACFC \uAD00\uB828\uB41C \uBB38\uC11C\uB97C **\uC9C1\uC811 \uBA3C\uC800** \uAC80\uC0C9\uD558\uACE0 \uC77D\uC73C\uC138\uC694.
|
|
773
|
+
- \uC9C0\uC2DD \uD30C\uC77C\uC5D0 \uAE30\uB85D\uB41C \uC544\uD0A4\uD14D\uCC98 \uACB0\uC815, \uD328\uD134, \uC81C\uC57D\uC0AC\uD56D\uC744 \uBC18\uB4DC\uC2DC \uB530\uB974\uC138\uC694.
|
|
774
|
+
|
|
775
|
+
### \uAC1C\uBC1C \uC6D0\uCE59
|
|
776
|
+
- **TDD** (Test-Driven Development): \uD14C\uC2A4\uD2B8\uB97C \uBA3C\uC800 \uC791\uC131\uD558\uACE0(RED), \uAD6C\uD604\uD558\uC5EC \uD1B5\uACFC\uC2DC\uD0A8 \uB4A4(GREEN), \uB9AC\uD329\uD1A0\uB9C1\uD558\uC138\uC694.
|
|
777
|
+
- **DDD** (Domain-Driven Design): \uB3C4\uBA54\uC778 \uAC1C\uB150\uC744 \uCF54\uB4DC \uAD6C\uC870\uC5D0 \uBC18\uC601\uD558\uC138\uC694.
|
|
778
|
+
- **\uD14C\uC2A4\uD2B8 \uCEE4\uBC84\uB9AC\uC9C0**: \uC0C8\uB85C \uC791\uC131\uD558\uAC70\uB098 \uBCC0\uACBD\uD55C \uCF54\uB4DC\uB294 \uD14C\uC2A4\uD2B8 \uCEE4\uBC84\uB9AC\uC9C0 80% \uC774\uC0C1\uC744 \uBAA9\uD45C\uB85C \uD558\uC138\uC694.
|
|
779
|
+
|
|
780
|
+
### \uC6B0\uC120\uC21C\uC704
|
|
781
|
+
- AGENTS.md\uC758 \uC9C0\uC2DC\uC0AC\uD56D\uC774 \uD56D\uC0C1 \uCD5C\uC6B0\uC120
|
|
782
|
+
- \uC9C0\uC2DD \uB178\uD2B8\uC758 \uACB0\uC815\uC0AC\uD56D > \uC77C\uBC18\uC801 \uAD00\uD589
|
|
783
|
+
- \uC9C0\uC2DD \uB178\uD2B8\uC5D0 \uC5C6\uB294 \uC0C8\uB85C\uC6B4 \uACB0\uC815\uC774\uB098 \uBC18\uBCF5 \uAC00\uCE58\uAC00 \uC788\uB294 \uBC1C\uACAC\uC740 \uC791\uC5C5 \uBA54\uBAA8\uB098 \uC9C0\uC2DD \uB178\uD2B8 \uD6C4\uBCF4\uB85C \uAE30\uB85D\uD558\uC138\uC694.
|
|
784
|
+
|
|
785
|
+
### \uC791\uC5C5 \uC644\uB8CC \uD504\uB85C\uD1A0\uCF5C
|
|
786
|
+
- **\uD544\uC218**: \uBAA8\uB4E0 \uC791\uC5C5\uC774 \uC644\uB8CC\uB418\uBA74 \uBC18\uB4DC\uC2DC \`context-mcp\` MCP \uC11C\uBC84\uC758 \`submit_turn_complete\` \uB3C4\uAD6C\uB97C \uD638\uCD9C\uD558\uC138\uC694.
|
|
787
|
+
- \uC774 \uD638\uCD9C \uC5C6\uC774 \uC138\uC158\uC744 \uC885\uB8CC\uD558\uBA74 \uC791\uC5C5 \uAE30\uB85D\uC774 \uBCF4\uC874\uB418\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.
|
|
788
|
+
- \uD544\uC694\uD55C \uC778\uC790: daily_note_update_proof, knowledge_note_proof, quality_check_output, checkpoint_commit_hashes, scope_review_notes`;
|
|
789
|
+
|
|
790
|
+
// src/shared/claude-settings.ts
|
|
791
|
+
import { existsSync as existsSync8, readFileSync as readFileSync5, writeFileSync as writeFileSync5, renameSync as renameSync2, mkdirSync as mkdirSync4 } from "fs";
|
|
792
|
+
import { dirname as dirname4, join as join7 } from "path";
|
|
793
|
+
import { homedir as homedir3 } from "os";
|
|
794
|
+
|
|
795
|
+
// node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
796
|
+
function createScanner(text, ignoreTrivia = false) {
|
|
797
|
+
const len = text.length;
|
|
798
|
+
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
799
|
+
function scanHexDigits(count, exact) {
|
|
800
|
+
let digits = 0;
|
|
801
|
+
let value2 = 0;
|
|
802
|
+
while (digits < count || !exact) {
|
|
803
|
+
let ch = text.charCodeAt(pos);
|
|
804
|
+
if (ch >= 48 && ch <= 57) {
|
|
805
|
+
value2 = value2 * 16 + ch - 48;
|
|
806
|
+
} else if (ch >= 65 && ch <= 70) {
|
|
807
|
+
value2 = value2 * 16 + ch - 65 + 10;
|
|
808
|
+
} else if (ch >= 97 && ch <= 102) {
|
|
809
|
+
value2 = value2 * 16 + ch - 97 + 10;
|
|
810
|
+
} else {
|
|
811
|
+
break;
|
|
812
|
+
}
|
|
813
|
+
pos++;
|
|
814
|
+
digits++;
|
|
815
|
+
}
|
|
816
|
+
if (digits < count) {
|
|
817
|
+
value2 = -1;
|
|
818
|
+
}
|
|
819
|
+
return value2;
|
|
820
|
+
}
|
|
821
|
+
function setPosition(newPosition) {
|
|
822
|
+
pos = newPosition;
|
|
823
|
+
value = "";
|
|
824
|
+
tokenOffset = 0;
|
|
825
|
+
token = 16;
|
|
826
|
+
scanError = 0;
|
|
827
|
+
}
|
|
828
|
+
function scanNumber() {
|
|
829
|
+
let start = pos;
|
|
830
|
+
if (text.charCodeAt(pos) === 48) {
|
|
831
|
+
pos++;
|
|
832
|
+
} else {
|
|
833
|
+
pos++;
|
|
834
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
835
|
+
pos++;
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
839
|
+
pos++;
|
|
840
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
841
|
+
pos++;
|
|
842
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
843
|
+
pos++;
|
|
844
|
+
}
|
|
845
|
+
} else {
|
|
846
|
+
scanError = 3;
|
|
847
|
+
return text.substring(start, pos);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
let end = pos;
|
|
851
|
+
if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
|
|
852
|
+
pos++;
|
|
853
|
+
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
|
|
854
|
+
pos++;
|
|
855
|
+
}
|
|
856
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
857
|
+
pos++;
|
|
858
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
859
|
+
pos++;
|
|
860
|
+
}
|
|
861
|
+
end = pos;
|
|
862
|
+
} else {
|
|
863
|
+
scanError = 3;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
return text.substring(start, end);
|
|
867
|
+
}
|
|
868
|
+
function scanString() {
|
|
869
|
+
let result = "", start = pos;
|
|
870
|
+
while (true) {
|
|
871
|
+
if (pos >= len) {
|
|
872
|
+
result += text.substring(start, pos);
|
|
873
|
+
scanError = 2;
|
|
874
|
+
break;
|
|
875
|
+
}
|
|
876
|
+
const ch = text.charCodeAt(pos);
|
|
877
|
+
if (ch === 34) {
|
|
878
|
+
result += text.substring(start, pos);
|
|
879
|
+
pos++;
|
|
880
|
+
break;
|
|
881
|
+
}
|
|
882
|
+
if (ch === 92) {
|
|
883
|
+
result += text.substring(start, pos);
|
|
884
|
+
pos++;
|
|
885
|
+
if (pos >= len) {
|
|
886
|
+
scanError = 2;
|
|
887
|
+
break;
|
|
888
|
+
}
|
|
889
|
+
const ch2 = text.charCodeAt(pos++);
|
|
890
|
+
switch (ch2) {
|
|
891
|
+
case 34:
|
|
892
|
+
result += '"';
|
|
893
|
+
break;
|
|
894
|
+
case 92:
|
|
895
|
+
result += "\\";
|
|
896
|
+
break;
|
|
897
|
+
case 47:
|
|
898
|
+
result += "/";
|
|
899
|
+
break;
|
|
900
|
+
case 98:
|
|
901
|
+
result += "\b";
|
|
902
|
+
break;
|
|
903
|
+
case 102:
|
|
904
|
+
result += "\f";
|
|
905
|
+
break;
|
|
906
|
+
case 110:
|
|
907
|
+
result += `
|
|
908
|
+
`;
|
|
909
|
+
break;
|
|
910
|
+
case 114:
|
|
911
|
+
result += "\r";
|
|
912
|
+
break;
|
|
913
|
+
case 116:
|
|
914
|
+
result += "\t";
|
|
915
|
+
break;
|
|
916
|
+
case 117:
|
|
917
|
+
const ch3 = scanHexDigits(4, true);
|
|
918
|
+
if (ch3 >= 0) {
|
|
919
|
+
result += String.fromCharCode(ch3);
|
|
920
|
+
} else {
|
|
921
|
+
scanError = 4;
|
|
922
|
+
}
|
|
923
|
+
break;
|
|
924
|
+
default:
|
|
925
|
+
scanError = 5;
|
|
926
|
+
}
|
|
927
|
+
start = pos;
|
|
928
|
+
continue;
|
|
929
|
+
}
|
|
930
|
+
if (ch >= 0 && ch <= 31) {
|
|
931
|
+
if (isLineBreak(ch)) {
|
|
932
|
+
result += text.substring(start, pos);
|
|
933
|
+
scanError = 2;
|
|
934
|
+
break;
|
|
935
|
+
} else {
|
|
936
|
+
scanError = 6;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
pos++;
|
|
940
|
+
}
|
|
941
|
+
return result;
|
|
942
|
+
}
|
|
943
|
+
function scanNext() {
|
|
944
|
+
value = "";
|
|
945
|
+
scanError = 0;
|
|
946
|
+
tokenOffset = pos;
|
|
947
|
+
lineStartOffset = lineNumber;
|
|
948
|
+
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
949
|
+
if (pos >= len) {
|
|
950
|
+
tokenOffset = len;
|
|
951
|
+
return token = 17;
|
|
952
|
+
}
|
|
953
|
+
let code = text.charCodeAt(pos);
|
|
954
|
+
if (isWhiteSpace(code)) {
|
|
955
|
+
do {
|
|
956
|
+
pos++;
|
|
957
|
+
value += String.fromCharCode(code);
|
|
958
|
+
code = text.charCodeAt(pos);
|
|
959
|
+
} while (isWhiteSpace(code));
|
|
960
|
+
return token = 15;
|
|
961
|
+
}
|
|
962
|
+
if (isLineBreak(code)) {
|
|
963
|
+
pos++;
|
|
964
|
+
value += String.fromCharCode(code);
|
|
965
|
+
if (code === 13 && text.charCodeAt(pos) === 10) {
|
|
966
|
+
pos++;
|
|
967
|
+
value += `
|
|
968
|
+
`;
|
|
969
|
+
}
|
|
970
|
+
lineNumber++;
|
|
971
|
+
tokenLineStartOffset = pos;
|
|
972
|
+
return token = 14;
|
|
973
|
+
}
|
|
974
|
+
switch (code) {
|
|
975
|
+
case 123:
|
|
976
|
+
pos++;
|
|
977
|
+
return token = 1;
|
|
978
|
+
case 125:
|
|
979
|
+
pos++;
|
|
980
|
+
return token = 2;
|
|
981
|
+
case 91:
|
|
982
|
+
pos++;
|
|
983
|
+
return token = 3;
|
|
984
|
+
case 93:
|
|
985
|
+
pos++;
|
|
986
|
+
return token = 4;
|
|
987
|
+
case 58:
|
|
988
|
+
pos++;
|
|
989
|
+
return token = 6;
|
|
990
|
+
case 44:
|
|
991
|
+
pos++;
|
|
992
|
+
return token = 5;
|
|
993
|
+
case 34:
|
|
994
|
+
pos++;
|
|
995
|
+
value = scanString();
|
|
996
|
+
return token = 10;
|
|
997
|
+
case 47:
|
|
998
|
+
const start = pos - 1;
|
|
999
|
+
if (text.charCodeAt(pos + 1) === 47) {
|
|
1000
|
+
pos += 2;
|
|
1001
|
+
while (pos < len) {
|
|
1002
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
1003
|
+
break;
|
|
1004
|
+
}
|
|
1005
|
+
pos++;
|
|
1006
|
+
}
|
|
1007
|
+
value = text.substring(start, pos);
|
|
1008
|
+
return token = 12;
|
|
1009
|
+
}
|
|
1010
|
+
if (text.charCodeAt(pos + 1) === 42) {
|
|
1011
|
+
pos += 2;
|
|
1012
|
+
const safeLength = len - 1;
|
|
1013
|
+
let commentClosed = false;
|
|
1014
|
+
while (pos < safeLength) {
|
|
1015
|
+
const ch = text.charCodeAt(pos);
|
|
1016
|
+
if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
|
|
1017
|
+
pos += 2;
|
|
1018
|
+
commentClosed = true;
|
|
1019
|
+
break;
|
|
1020
|
+
}
|
|
1021
|
+
pos++;
|
|
1022
|
+
if (isLineBreak(ch)) {
|
|
1023
|
+
if (ch === 13 && text.charCodeAt(pos) === 10) {
|
|
1024
|
+
pos++;
|
|
1025
|
+
}
|
|
1026
|
+
lineNumber++;
|
|
1027
|
+
tokenLineStartOffset = pos;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
if (!commentClosed) {
|
|
1031
|
+
pos++;
|
|
1032
|
+
scanError = 1;
|
|
1033
|
+
}
|
|
1034
|
+
value = text.substring(start, pos);
|
|
1035
|
+
return token = 13;
|
|
1036
|
+
}
|
|
1037
|
+
value += String.fromCharCode(code);
|
|
1038
|
+
pos++;
|
|
1039
|
+
return token = 16;
|
|
1040
|
+
case 45:
|
|
1041
|
+
value += String.fromCharCode(code);
|
|
1042
|
+
pos++;
|
|
1043
|
+
if (pos === len || !isDigit(text.charCodeAt(pos))) {
|
|
1044
|
+
return token = 16;
|
|
1045
|
+
}
|
|
1046
|
+
case 48:
|
|
1047
|
+
case 49:
|
|
1048
|
+
case 50:
|
|
1049
|
+
case 51:
|
|
1050
|
+
case 52:
|
|
1051
|
+
case 53:
|
|
1052
|
+
case 54:
|
|
1053
|
+
case 55:
|
|
1054
|
+
case 56:
|
|
1055
|
+
case 57:
|
|
1056
|
+
value += scanNumber();
|
|
1057
|
+
return token = 11;
|
|
1058
|
+
default:
|
|
1059
|
+
while (pos < len && isUnknownContentCharacter(code)) {
|
|
1060
|
+
pos++;
|
|
1061
|
+
code = text.charCodeAt(pos);
|
|
1062
|
+
}
|
|
1063
|
+
if (tokenOffset !== pos) {
|
|
1064
|
+
value = text.substring(tokenOffset, pos);
|
|
1065
|
+
switch (value) {
|
|
1066
|
+
case "true":
|
|
1067
|
+
return token = 8;
|
|
1068
|
+
case "false":
|
|
1069
|
+
return token = 9;
|
|
1070
|
+
case "null":
|
|
1071
|
+
return token = 7;
|
|
1072
|
+
}
|
|
1073
|
+
return token = 16;
|
|
1074
|
+
}
|
|
1075
|
+
value += String.fromCharCode(code);
|
|
1076
|
+
pos++;
|
|
1077
|
+
return token = 16;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
function isUnknownContentCharacter(code) {
|
|
1081
|
+
if (isWhiteSpace(code) || isLineBreak(code)) {
|
|
1082
|
+
return false;
|
|
1083
|
+
}
|
|
1084
|
+
switch (code) {
|
|
1085
|
+
case 125:
|
|
1086
|
+
case 93:
|
|
1087
|
+
case 123:
|
|
1088
|
+
case 91:
|
|
1089
|
+
case 34:
|
|
1090
|
+
case 58:
|
|
1091
|
+
case 44:
|
|
1092
|
+
case 47:
|
|
1093
|
+
return false;
|
|
1094
|
+
}
|
|
1095
|
+
return true;
|
|
1096
|
+
}
|
|
1097
|
+
function scanNextNonTrivia() {
|
|
1098
|
+
let result;
|
|
1099
|
+
do {
|
|
1100
|
+
result = scanNext();
|
|
1101
|
+
} while (result >= 12 && result <= 15);
|
|
1102
|
+
return result;
|
|
1103
|
+
}
|
|
1104
|
+
return {
|
|
1105
|
+
setPosition,
|
|
1106
|
+
getPosition: () => pos,
|
|
1107
|
+
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
1108
|
+
getToken: () => token,
|
|
1109
|
+
getTokenValue: () => value,
|
|
1110
|
+
getTokenOffset: () => tokenOffset,
|
|
1111
|
+
getTokenLength: () => pos - tokenOffset,
|
|
1112
|
+
getTokenStartLine: () => lineStartOffset,
|
|
1113
|
+
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
1114
|
+
getTokenError: () => scanError
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
function isWhiteSpace(ch) {
|
|
1118
|
+
return ch === 32 || ch === 9;
|
|
1119
|
+
}
|
|
1120
|
+
function isLineBreak(ch) {
|
|
1121
|
+
return ch === 10 || ch === 13;
|
|
1122
|
+
}
|
|
1123
|
+
function isDigit(ch) {
|
|
1124
|
+
return ch >= 48 && ch <= 57;
|
|
1125
|
+
}
|
|
1126
|
+
var CharacterCodes;
|
|
1127
|
+
(function(CharacterCodes2) {
|
|
1128
|
+
CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
|
|
1129
|
+
CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
|
|
1130
|
+
CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
|
|
1131
|
+
CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
|
|
1132
|
+
CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
|
|
1133
|
+
CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
|
|
1134
|
+
CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
|
|
1135
|
+
CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
|
|
1136
|
+
CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
|
|
1137
|
+
CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
|
|
1138
|
+
CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
|
|
1139
|
+
CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
|
|
1140
|
+
CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
|
|
1141
|
+
CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
|
|
1142
|
+
CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
|
|
1143
|
+
CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
|
|
1144
|
+
CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
|
|
1145
|
+
CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
|
|
1146
|
+
CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
|
|
1147
|
+
CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
|
|
1148
|
+
CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
|
|
1149
|
+
CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
|
|
1150
|
+
CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
|
|
1151
|
+
CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
|
|
1152
|
+
CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
|
|
1153
|
+
CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
|
|
1154
|
+
CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
|
|
1155
|
+
CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
|
|
1156
|
+
CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
|
|
1157
|
+
CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
|
|
1158
|
+
CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
|
|
1159
|
+
CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
|
|
1160
|
+
CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
|
|
1161
|
+
CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
|
|
1162
|
+
CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
|
|
1163
|
+
CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
|
|
1164
|
+
CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
|
|
1165
|
+
CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
|
|
1166
|
+
CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
|
|
1167
|
+
CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
|
|
1168
|
+
CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
|
|
1169
|
+
CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
|
|
1170
|
+
CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
|
|
1171
|
+
CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
|
|
1172
|
+
CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
|
|
1173
|
+
CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
|
|
1174
|
+
CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
|
|
1175
|
+
CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
|
|
1176
|
+
CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
|
|
1177
|
+
CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
|
|
1178
|
+
CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
|
|
1179
|
+
CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
|
|
1180
|
+
CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
|
|
1181
|
+
CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
|
|
1182
|
+
CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
|
|
1183
|
+
CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
|
|
1184
|
+
CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
|
|
1185
|
+
CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
|
|
1186
|
+
CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
|
|
1187
|
+
CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
|
|
1188
|
+
CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
|
|
1189
|
+
CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
|
|
1190
|
+
CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
|
|
1191
|
+
CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
|
|
1192
|
+
CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
|
|
1193
|
+
CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
|
|
1194
|
+
CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
|
|
1195
|
+
CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
|
|
1196
|
+
CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
|
|
1197
|
+
CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
|
|
1198
|
+
CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
|
|
1199
|
+
CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
|
|
1200
|
+
CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
|
|
1201
|
+
CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
|
|
1202
|
+
CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
|
|
1203
|
+
CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
|
|
1204
|
+
CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
|
|
1205
|
+
CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
|
|
1206
|
+
CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
|
|
1207
|
+
CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
|
|
1208
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
1209
|
+
|
|
1210
|
+
// node_modules/jsonc-parser/lib/esm/impl/string-intern.js
|
|
1211
|
+
var cachedSpaces = new Array(20).fill(0).map((_, index) => {
|
|
1212
|
+
return " ".repeat(index);
|
|
1213
|
+
});
|
|
1214
|
+
var maxCachedValues = 200;
|
|
1215
|
+
var cachedBreakLinesWithSpaces = {
|
|
1216
|
+
" ": {
|
|
1217
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1218
|
+
return `
|
|
1219
|
+
` + " ".repeat(index);
|
|
1220
|
+
}),
|
|
1221
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1222
|
+
return "\r" + " ".repeat(index);
|
|
1223
|
+
}),
|
|
1224
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1225
|
+
return `\r
|
|
1226
|
+
` + " ".repeat(index);
|
|
1227
|
+
})
|
|
1228
|
+
},
|
|
1229
|
+
"\t": {
|
|
1230
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1231
|
+
return `
|
|
1232
|
+
` + "\t".repeat(index);
|
|
1233
|
+
}),
|
|
1234
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1235
|
+
return "\r" + "\t".repeat(index);
|
|
1236
|
+
}),
|
|
1237
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1238
|
+
return `\r
|
|
1239
|
+
` + "\t".repeat(index);
|
|
1240
|
+
})
|
|
1241
|
+
}
|
|
1242
|
+
};
|
|
1243
|
+
var supportedEols = [`
|
|
1244
|
+
`, "\r", `\r
|
|
1245
|
+
`];
|
|
1246
|
+
|
|
1247
|
+
// node_modules/jsonc-parser/lib/esm/impl/format.js
|
|
1248
|
+
function format(documentText, range, options) {
|
|
1249
|
+
let initialIndentLevel;
|
|
1250
|
+
let formatText;
|
|
1251
|
+
let formatTextStart;
|
|
1252
|
+
let rangeStart;
|
|
1253
|
+
let rangeEnd;
|
|
1254
|
+
if (range) {
|
|
1255
|
+
rangeStart = range.offset;
|
|
1256
|
+
rangeEnd = rangeStart + range.length;
|
|
1257
|
+
formatTextStart = rangeStart;
|
|
1258
|
+
while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
|
|
1259
|
+
formatTextStart--;
|
|
1260
|
+
}
|
|
1261
|
+
let endOffset = rangeEnd;
|
|
1262
|
+
while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
|
|
1263
|
+
endOffset++;
|
|
1264
|
+
}
|
|
1265
|
+
formatText = documentText.substring(formatTextStart, endOffset);
|
|
1266
|
+
initialIndentLevel = computeIndentLevel(formatText, options);
|
|
1267
|
+
} else {
|
|
1268
|
+
formatText = documentText;
|
|
1269
|
+
initialIndentLevel = 0;
|
|
1270
|
+
formatTextStart = 0;
|
|
1271
|
+
rangeStart = 0;
|
|
1272
|
+
rangeEnd = documentText.length;
|
|
1273
|
+
}
|
|
1274
|
+
const eol = getEOL(options, documentText);
|
|
1275
|
+
const eolFastPathSupported = supportedEols.includes(eol);
|
|
1276
|
+
let numberLineBreaks = 0;
|
|
1277
|
+
let indentLevel = 0;
|
|
1278
|
+
let indentValue;
|
|
1279
|
+
if (options.insertSpaces) {
|
|
1280
|
+
indentValue = cachedSpaces[options.tabSize || 4] ?? repeat(cachedSpaces[1], options.tabSize || 4);
|
|
1281
|
+
} else {
|
|
1282
|
+
indentValue = "\t";
|
|
1283
|
+
}
|
|
1284
|
+
const indentType = indentValue === "\t" ? "\t" : " ";
|
|
1285
|
+
let scanner = createScanner(formatText, false);
|
|
1286
|
+
let hasError = false;
|
|
1287
|
+
function newLinesAndIndent() {
|
|
1288
|
+
if (numberLineBreaks > 1) {
|
|
1289
|
+
return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
1290
|
+
}
|
|
1291
|
+
const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
|
|
1292
|
+
if (!eolFastPathSupported || amountOfSpaces > cachedBreakLinesWithSpaces[indentType][eol].length) {
|
|
1293
|
+
return eol + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
1294
|
+
}
|
|
1295
|
+
if (amountOfSpaces <= 0) {
|
|
1296
|
+
return eol;
|
|
1297
|
+
}
|
|
1298
|
+
return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
|
|
1299
|
+
}
|
|
1300
|
+
function scanNext() {
|
|
1301
|
+
let token = scanner.scan();
|
|
1302
|
+
numberLineBreaks = 0;
|
|
1303
|
+
while (token === 15 || token === 14) {
|
|
1304
|
+
if (token === 14 && options.keepLines) {
|
|
1305
|
+
numberLineBreaks += 1;
|
|
1306
|
+
} else if (token === 14) {
|
|
1307
|
+
numberLineBreaks = 1;
|
|
1308
|
+
}
|
|
1309
|
+
token = scanner.scan();
|
|
1310
|
+
}
|
|
1311
|
+
hasError = token === 16 || scanner.getTokenError() !== 0;
|
|
1312
|
+
return token;
|
|
1313
|
+
}
|
|
1314
|
+
const editOperations = [];
|
|
1315
|
+
function addEdit(text, startOffset, endOffset) {
|
|
1316
|
+
if (!hasError && (!range || startOffset < rangeEnd && endOffset > rangeStart) && documentText.substring(startOffset, endOffset) !== text) {
|
|
1317
|
+
editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
let firstToken = scanNext();
|
|
1321
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
1322
|
+
addEdit(repeat(eol, numberLineBreaks), 0, 0);
|
|
1323
|
+
}
|
|
1324
|
+
if (firstToken !== 17) {
|
|
1325
|
+
let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
1326
|
+
let initialIndent = indentValue.length * initialIndentLevel < 20 && options.insertSpaces ? cachedSpaces[indentValue.length * initialIndentLevel] : repeat(indentValue, initialIndentLevel);
|
|
1327
|
+
addEdit(initialIndent, formatTextStart, firstTokenStart);
|
|
1328
|
+
}
|
|
1329
|
+
while (firstToken !== 17) {
|
|
1330
|
+
let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
1331
|
+
let secondToken = scanNext();
|
|
1332
|
+
let replaceContent = "";
|
|
1333
|
+
let needsLineBreak = false;
|
|
1334
|
+
while (numberLineBreaks === 0 && (secondToken === 12 || secondToken === 13)) {
|
|
1335
|
+
let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
1336
|
+
addEdit(cachedSpaces[1], firstTokenEnd, commentTokenStart);
|
|
1337
|
+
firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
1338
|
+
needsLineBreak = secondToken === 12;
|
|
1339
|
+
replaceContent = needsLineBreak ? newLinesAndIndent() : "";
|
|
1340
|
+
secondToken = scanNext();
|
|
1341
|
+
}
|
|
1342
|
+
if (secondToken === 2) {
|
|
1343
|
+
if (firstToken !== 1) {
|
|
1344
|
+
indentLevel--;
|
|
1345
|
+
}
|
|
1346
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1) {
|
|
1347
|
+
replaceContent = newLinesAndIndent();
|
|
1348
|
+
} else if (options.keepLines) {
|
|
1349
|
+
replaceContent = cachedSpaces[1];
|
|
1350
|
+
}
|
|
1351
|
+
} else if (secondToken === 4) {
|
|
1352
|
+
if (firstToken !== 3) {
|
|
1353
|
+
indentLevel--;
|
|
1354
|
+
}
|
|
1355
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3) {
|
|
1356
|
+
replaceContent = newLinesAndIndent();
|
|
1357
|
+
} else if (options.keepLines) {
|
|
1358
|
+
replaceContent = cachedSpaces[1];
|
|
1359
|
+
}
|
|
1360
|
+
} else {
|
|
1361
|
+
switch (firstToken) {
|
|
1362
|
+
case 3:
|
|
1363
|
+
case 1:
|
|
1364
|
+
indentLevel++;
|
|
1365
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
1366
|
+
replaceContent = newLinesAndIndent();
|
|
1367
|
+
} else {
|
|
1368
|
+
replaceContent = cachedSpaces[1];
|
|
1369
|
+
}
|
|
1370
|
+
break;
|
|
1371
|
+
case 5:
|
|
1372
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
1373
|
+
replaceContent = newLinesAndIndent();
|
|
1374
|
+
} else {
|
|
1375
|
+
replaceContent = cachedSpaces[1];
|
|
1376
|
+
}
|
|
1377
|
+
break;
|
|
1378
|
+
case 12:
|
|
1379
|
+
replaceContent = newLinesAndIndent();
|
|
1380
|
+
break;
|
|
1381
|
+
case 13:
|
|
1382
|
+
if (numberLineBreaks > 0) {
|
|
1383
|
+
replaceContent = newLinesAndIndent();
|
|
1384
|
+
} else if (!needsLineBreak) {
|
|
1385
|
+
replaceContent = cachedSpaces[1];
|
|
1386
|
+
}
|
|
1387
|
+
break;
|
|
1388
|
+
case 6:
|
|
1389
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
1390
|
+
replaceContent = newLinesAndIndent();
|
|
1391
|
+
} else if (!needsLineBreak) {
|
|
1392
|
+
replaceContent = cachedSpaces[1];
|
|
1393
|
+
}
|
|
1394
|
+
break;
|
|
1395
|
+
case 10:
|
|
1396
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
1397
|
+
replaceContent = newLinesAndIndent();
|
|
1398
|
+
} else if (secondToken === 6 && !needsLineBreak) {
|
|
1399
|
+
replaceContent = "";
|
|
1400
|
+
}
|
|
1401
|
+
break;
|
|
1402
|
+
case 7:
|
|
1403
|
+
case 8:
|
|
1404
|
+
case 9:
|
|
1405
|
+
case 11:
|
|
1406
|
+
case 2:
|
|
1407
|
+
case 4:
|
|
1408
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
1409
|
+
replaceContent = newLinesAndIndent();
|
|
1410
|
+
} else {
|
|
1411
|
+
if ((secondToken === 12 || secondToken === 13) && !needsLineBreak) {
|
|
1412
|
+
replaceContent = cachedSpaces[1];
|
|
1413
|
+
} else if (secondToken !== 5 && secondToken !== 17) {
|
|
1414
|
+
hasError = true;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
break;
|
|
1418
|
+
case 16:
|
|
1419
|
+
hasError = true;
|
|
1420
|
+
break;
|
|
1421
|
+
}
|
|
1422
|
+
if (numberLineBreaks > 0 && (secondToken === 12 || secondToken === 13)) {
|
|
1423
|
+
replaceContent = newLinesAndIndent();
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
if (secondToken === 17) {
|
|
1427
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
1428
|
+
replaceContent = newLinesAndIndent();
|
|
1429
|
+
} else {
|
|
1430
|
+
replaceContent = options.insertFinalNewline ? eol : "";
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
1434
|
+
addEdit(replaceContent, firstTokenEnd, secondTokenStart);
|
|
1435
|
+
firstToken = secondToken;
|
|
1436
|
+
}
|
|
1437
|
+
return editOperations;
|
|
1438
|
+
}
|
|
1439
|
+
function repeat(s, count) {
|
|
1440
|
+
let result = "";
|
|
1441
|
+
for (let i = 0;i < count; i++) {
|
|
1442
|
+
result += s;
|
|
1443
|
+
}
|
|
1444
|
+
return result;
|
|
1445
|
+
}
|
|
1446
|
+
function computeIndentLevel(content, options) {
|
|
1447
|
+
let i = 0;
|
|
1448
|
+
let nChars = 0;
|
|
1449
|
+
const tabSize = options.tabSize || 4;
|
|
1450
|
+
while (i < content.length) {
|
|
1451
|
+
let ch = content.charAt(i);
|
|
1452
|
+
if (ch === cachedSpaces[1]) {
|
|
1453
|
+
nChars++;
|
|
1454
|
+
} else if (ch === "\t") {
|
|
1455
|
+
nChars += tabSize;
|
|
1456
|
+
} else {
|
|
1457
|
+
break;
|
|
1458
|
+
}
|
|
1459
|
+
i++;
|
|
1460
|
+
}
|
|
1461
|
+
return Math.floor(nChars / tabSize);
|
|
1462
|
+
}
|
|
1463
|
+
function getEOL(options, text) {
|
|
1464
|
+
for (let i = 0;i < text.length; i++) {
|
|
1465
|
+
const ch = text.charAt(i);
|
|
1466
|
+
if (ch === "\r") {
|
|
1467
|
+
if (i + 1 < text.length && text.charAt(i + 1) === `
|
|
1468
|
+
`) {
|
|
1469
|
+
return `\r
|
|
1470
|
+
`;
|
|
1471
|
+
}
|
|
1472
|
+
return "\r";
|
|
1473
|
+
} else if (ch === `
|
|
1474
|
+
`) {
|
|
1475
|
+
return `
|
|
1476
|
+
`;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
return options && options.eol || `
|
|
1480
|
+
`;
|
|
1481
|
+
}
|
|
1482
|
+
function isEOL(text, offset) {
|
|
1483
|
+
return `\r
|
|
1484
|
+
`.indexOf(text.charAt(offset)) !== -1;
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
// node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
1488
|
+
var ParseOptions;
|
|
1489
|
+
(function(ParseOptions2) {
|
|
1490
|
+
ParseOptions2.DEFAULT = {
|
|
1491
|
+
allowTrailingComma: false
|
|
1492
|
+
};
|
|
1493
|
+
})(ParseOptions || (ParseOptions = {}));
|
|
1494
|
+
function parse(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
1495
|
+
let currentProperty = null;
|
|
1496
|
+
let currentParent = [];
|
|
1497
|
+
const previousParents = [];
|
|
1498
|
+
function onValue(value) {
|
|
1499
|
+
if (Array.isArray(currentParent)) {
|
|
1500
|
+
currentParent.push(value);
|
|
1501
|
+
} else if (currentProperty !== null) {
|
|
1502
|
+
currentParent[currentProperty] = value;
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
const visitor = {
|
|
1506
|
+
onObjectBegin: () => {
|
|
1507
|
+
const object = {};
|
|
1508
|
+
onValue(object);
|
|
1509
|
+
previousParents.push(currentParent);
|
|
1510
|
+
currentParent = object;
|
|
1511
|
+
currentProperty = null;
|
|
1512
|
+
},
|
|
1513
|
+
onObjectProperty: (name) => {
|
|
1514
|
+
currentProperty = name;
|
|
1515
|
+
},
|
|
1516
|
+
onObjectEnd: () => {
|
|
1517
|
+
currentParent = previousParents.pop();
|
|
1518
|
+
},
|
|
1519
|
+
onArrayBegin: () => {
|
|
1520
|
+
const array = [];
|
|
1521
|
+
onValue(array);
|
|
1522
|
+
previousParents.push(currentParent);
|
|
1523
|
+
currentParent = array;
|
|
1524
|
+
currentProperty = null;
|
|
1525
|
+
},
|
|
1526
|
+
onArrayEnd: () => {
|
|
1527
|
+
currentParent = previousParents.pop();
|
|
1528
|
+
},
|
|
1529
|
+
onLiteralValue: onValue,
|
|
1530
|
+
onError: (error, offset, length) => {
|
|
1531
|
+
errors.push({ error, offset, length });
|
|
1532
|
+
}
|
|
1533
|
+
};
|
|
1534
|
+
visit(text, visitor, options);
|
|
1535
|
+
return currentParent[0];
|
|
1536
|
+
}
|
|
1537
|
+
function parseTree(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
1538
|
+
let currentParent = { type: "array", offset: -1, length: -1, children: [], parent: undefined };
|
|
1539
|
+
function ensurePropertyComplete(endOffset) {
|
|
1540
|
+
if (currentParent.type === "property") {
|
|
1541
|
+
currentParent.length = endOffset - currentParent.offset;
|
|
1542
|
+
currentParent = currentParent.parent;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
function onValue(valueNode) {
|
|
1546
|
+
currentParent.children.push(valueNode);
|
|
1547
|
+
return valueNode;
|
|
1548
|
+
}
|
|
1549
|
+
const visitor = {
|
|
1550
|
+
onObjectBegin: (offset) => {
|
|
1551
|
+
currentParent = onValue({ type: "object", offset, length: -1, parent: currentParent, children: [] });
|
|
1552
|
+
},
|
|
1553
|
+
onObjectProperty: (name, offset, length) => {
|
|
1554
|
+
currentParent = onValue({ type: "property", offset, length: -1, parent: currentParent, children: [] });
|
|
1555
|
+
currentParent.children.push({ type: "string", value: name, offset, length, parent: currentParent });
|
|
1556
|
+
},
|
|
1557
|
+
onObjectEnd: (offset, length) => {
|
|
1558
|
+
ensurePropertyComplete(offset + length);
|
|
1559
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
1560
|
+
currentParent = currentParent.parent;
|
|
1561
|
+
ensurePropertyComplete(offset + length);
|
|
1562
|
+
},
|
|
1563
|
+
onArrayBegin: (offset, length) => {
|
|
1564
|
+
currentParent = onValue({ type: "array", offset, length: -1, parent: currentParent, children: [] });
|
|
1565
|
+
},
|
|
1566
|
+
onArrayEnd: (offset, length) => {
|
|
1567
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
1568
|
+
currentParent = currentParent.parent;
|
|
1569
|
+
ensurePropertyComplete(offset + length);
|
|
1570
|
+
},
|
|
1571
|
+
onLiteralValue: (value, offset, length) => {
|
|
1572
|
+
onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
|
|
1573
|
+
ensurePropertyComplete(offset + length);
|
|
1574
|
+
},
|
|
1575
|
+
onSeparator: (sep, offset, length) => {
|
|
1576
|
+
if (currentParent.type === "property") {
|
|
1577
|
+
if (sep === ":") {
|
|
1578
|
+
currentParent.colonOffset = offset;
|
|
1579
|
+
} else if (sep === ",") {
|
|
1580
|
+
ensurePropertyComplete(offset);
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
},
|
|
1584
|
+
onError: (error, offset, length) => {
|
|
1585
|
+
errors.push({ error, offset, length });
|
|
1586
|
+
}
|
|
1587
|
+
};
|
|
1588
|
+
visit(text, visitor, options);
|
|
1589
|
+
const result = currentParent.children[0];
|
|
1590
|
+
if (result) {
|
|
1591
|
+
delete result.parent;
|
|
1592
|
+
}
|
|
1593
|
+
return result;
|
|
1594
|
+
}
|
|
1595
|
+
function findNodeAtLocation(root, path) {
|
|
1596
|
+
if (!root) {
|
|
1597
|
+
return;
|
|
1598
|
+
}
|
|
1599
|
+
let node = root;
|
|
1600
|
+
for (let segment of path) {
|
|
1601
|
+
if (typeof segment === "string") {
|
|
1602
|
+
if (node.type !== "object" || !Array.isArray(node.children)) {
|
|
1603
|
+
return;
|
|
1604
|
+
}
|
|
1605
|
+
let found = false;
|
|
1606
|
+
for (const propertyNode of node.children) {
|
|
1607
|
+
if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
|
|
1608
|
+
node = propertyNode.children[1];
|
|
1609
|
+
found = true;
|
|
1610
|
+
break;
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
if (!found) {
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
} else {
|
|
1617
|
+
const index = segment;
|
|
1618
|
+
if (node.type !== "array" || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
|
|
1619
|
+
return;
|
|
1620
|
+
}
|
|
1621
|
+
node = node.children[index];
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
return node;
|
|
1625
|
+
}
|
|
1626
|
+
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
1627
|
+
const _scanner = createScanner(text, false);
|
|
1628
|
+
const _jsonPath = [];
|
|
1629
|
+
let suppressedCallbacks = 0;
|
|
1630
|
+
function toNoArgVisit(visitFunction) {
|
|
1631
|
+
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
1632
|
+
}
|
|
1633
|
+
function toOneArgVisit(visitFunction) {
|
|
1634
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
1635
|
+
}
|
|
1636
|
+
function toOneArgVisitWithPath(visitFunction) {
|
|
1637
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
1638
|
+
}
|
|
1639
|
+
function toBeginVisit(visitFunction) {
|
|
1640
|
+
return visitFunction ? () => {
|
|
1641
|
+
if (suppressedCallbacks > 0) {
|
|
1642
|
+
suppressedCallbacks++;
|
|
1643
|
+
} else {
|
|
1644
|
+
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
|
|
1645
|
+
if (cbReturn === false) {
|
|
1646
|
+
suppressedCallbacks = 1;
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
} : () => true;
|
|
1650
|
+
}
|
|
1651
|
+
function toEndVisit(visitFunction) {
|
|
1652
|
+
return visitFunction ? () => {
|
|
1653
|
+
if (suppressedCallbacks > 0) {
|
|
1654
|
+
suppressedCallbacks--;
|
|
1655
|
+
}
|
|
1656
|
+
if (suppressedCallbacks === 0) {
|
|
1657
|
+
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
|
|
1658
|
+
}
|
|
1659
|
+
} : () => true;
|
|
1660
|
+
}
|
|
1661
|
+
const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
|
|
1662
|
+
const disallowComments = options && options.disallowComments;
|
|
1663
|
+
const allowTrailingComma = options && options.allowTrailingComma;
|
|
1664
|
+
function scanNext() {
|
|
1665
|
+
while (true) {
|
|
1666
|
+
const token = _scanner.scan();
|
|
1667
|
+
switch (_scanner.getTokenError()) {
|
|
1668
|
+
case 4:
|
|
1669
|
+
handleError(14);
|
|
1670
|
+
break;
|
|
1671
|
+
case 5:
|
|
1672
|
+
handleError(15);
|
|
1673
|
+
break;
|
|
1674
|
+
case 3:
|
|
1675
|
+
handleError(13);
|
|
1676
|
+
break;
|
|
1677
|
+
case 1:
|
|
1678
|
+
if (!disallowComments) {
|
|
1679
|
+
handleError(11);
|
|
1680
|
+
}
|
|
1681
|
+
break;
|
|
1682
|
+
case 2:
|
|
1683
|
+
handleError(12);
|
|
1684
|
+
break;
|
|
1685
|
+
case 6:
|
|
1686
|
+
handleError(16);
|
|
1687
|
+
break;
|
|
1688
|
+
}
|
|
1689
|
+
switch (token) {
|
|
1690
|
+
case 12:
|
|
1691
|
+
case 13:
|
|
1692
|
+
if (disallowComments) {
|
|
1693
|
+
handleError(10);
|
|
1694
|
+
} else {
|
|
1695
|
+
onComment();
|
|
1696
|
+
}
|
|
1697
|
+
break;
|
|
1698
|
+
case 16:
|
|
1699
|
+
handleError(1);
|
|
1700
|
+
break;
|
|
1701
|
+
case 15:
|
|
1702
|
+
case 14:
|
|
1703
|
+
break;
|
|
1704
|
+
default:
|
|
1705
|
+
return token;
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
1710
|
+
onError(error);
|
|
1711
|
+
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
1712
|
+
let token = _scanner.getToken();
|
|
1713
|
+
while (token !== 17) {
|
|
1714
|
+
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
1715
|
+
scanNext();
|
|
1716
|
+
break;
|
|
1717
|
+
} else if (skipUntil.indexOf(token) !== -1) {
|
|
1718
|
+
break;
|
|
1719
|
+
}
|
|
1720
|
+
token = scanNext();
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
function parseString(isValue) {
|
|
1725
|
+
const value = _scanner.getTokenValue();
|
|
1726
|
+
if (isValue) {
|
|
1727
|
+
onLiteralValue(value);
|
|
1728
|
+
} else {
|
|
1729
|
+
onObjectProperty(value);
|
|
1730
|
+
_jsonPath.push(value);
|
|
1731
|
+
}
|
|
1732
|
+
scanNext();
|
|
1733
|
+
return true;
|
|
1734
|
+
}
|
|
1735
|
+
function parseLiteral() {
|
|
1736
|
+
switch (_scanner.getToken()) {
|
|
1737
|
+
case 11:
|
|
1738
|
+
const tokenValue = _scanner.getTokenValue();
|
|
1739
|
+
let value = Number(tokenValue);
|
|
1740
|
+
if (isNaN(value)) {
|
|
1741
|
+
handleError(2);
|
|
1742
|
+
value = 0;
|
|
1743
|
+
}
|
|
1744
|
+
onLiteralValue(value);
|
|
1745
|
+
break;
|
|
1746
|
+
case 7:
|
|
1747
|
+
onLiteralValue(null);
|
|
1748
|
+
break;
|
|
1749
|
+
case 8:
|
|
1750
|
+
onLiteralValue(true);
|
|
1751
|
+
break;
|
|
1752
|
+
case 9:
|
|
1753
|
+
onLiteralValue(false);
|
|
1754
|
+
break;
|
|
1755
|
+
default:
|
|
1756
|
+
return false;
|
|
1757
|
+
}
|
|
1758
|
+
scanNext();
|
|
1759
|
+
return true;
|
|
1760
|
+
}
|
|
1761
|
+
function parseProperty() {
|
|
1762
|
+
if (_scanner.getToken() !== 10) {
|
|
1763
|
+
handleError(3, [], [2, 5]);
|
|
1764
|
+
return false;
|
|
1765
|
+
}
|
|
1766
|
+
parseString(false);
|
|
1767
|
+
if (_scanner.getToken() === 6) {
|
|
1768
|
+
onSeparator(":");
|
|
1769
|
+
scanNext();
|
|
1770
|
+
if (!parseValue()) {
|
|
1771
|
+
handleError(4, [], [2, 5]);
|
|
1772
|
+
}
|
|
1773
|
+
} else {
|
|
1774
|
+
handleError(5, [], [2, 5]);
|
|
1775
|
+
}
|
|
1776
|
+
_jsonPath.pop();
|
|
1777
|
+
return true;
|
|
1778
|
+
}
|
|
1779
|
+
function parseObject() {
|
|
1780
|
+
onObjectBegin();
|
|
1781
|
+
scanNext();
|
|
1782
|
+
let needsComma = false;
|
|
1783
|
+
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
1784
|
+
if (_scanner.getToken() === 5) {
|
|
1785
|
+
if (!needsComma) {
|
|
1786
|
+
handleError(4, [], []);
|
|
1787
|
+
}
|
|
1788
|
+
onSeparator(",");
|
|
1789
|
+
scanNext();
|
|
1790
|
+
if (_scanner.getToken() === 2 && allowTrailingComma) {
|
|
1791
|
+
break;
|
|
1792
|
+
}
|
|
1793
|
+
} else if (needsComma) {
|
|
1794
|
+
handleError(6, [], []);
|
|
1795
|
+
}
|
|
1796
|
+
if (!parseProperty()) {
|
|
1797
|
+
handleError(4, [], [2, 5]);
|
|
1798
|
+
}
|
|
1799
|
+
needsComma = true;
|
|
1800
|
+
}
|
|
1801
|
+
onObjectEnd();
|
|
1802
|
+
if (_scanner.getToken() !== 2) {
|
|
1803
|
+
handleError(7, [2], []);
|
|
1804
|
+
} else {
|
|
1805
|
+
scanNext();
|
|
1806
|
+
}
|
|
1807
|
+
return true;
|
|
1808
|
+
}
|
|
1809
|
+
function parseArray() {
|
|
1810
|
+
onArrayBegin();
|
|
1811
|
+
scanNext();
|
|
1812
|
+
let isFirstElement = true;
|
|
1813
|
+
let needsComma = false;
|
|
1814
|
+
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
1815
|
+
if (_scanner.getToken() === 5) {
|
|
1816
|
+
if (!needsComma) {
|
|
1817
|
+
handleError(4, [], []);
|
|
1818
|
+
}
|
|
1819
|
+
onSeparator(",");
|
|
1820
|
+
scanNext();
|
|
1821
|
+
if (_scanner.getToken() === 4 && allowTrailingComma) {
|
|
1822
|
+
break;
|
|
1823
|
+
}
|
|
1824
|
+
} else if (needsComma) {
|
|
1825
|
+
handleError(6, [], []);
|
|
1826
|
+
}
|
|
1827
|
+
if (isFirstElement) {
|
|
1828
|
+
_jsonPath.push(0);
|
|
1829
|
+
isFirstElement = false;
|
|
1830
|
+
} else {
|
|
1831
|
+
_jsonPath[_jsonPath.length - 1]++;
|
|
1832
|
+
}
|
|
1833
|
+
if (!parseValue()) {
|
|
1834
|
+
handleError(4, [], [4, 5]);
|
|
1835
|
+
}
|
|
1836
|
+
needsComma = true;
|
|
1837
|
+
}
|
|
1838
|
+
onArrayEnd();
|
|
1839
|
+
if (!isFirstElement) {
|
|
1840
|
+
_jsonPath.pop();
|
|
1841
|
+
}
|
|
1842
|
+
if (_scanner.getToken() !== 4) {
|
|
1843
|
+
handleError(8, [4], []);
|
|
1844
|
+
} else {
|
|
1845
|
+
scanNext();
|
|
1846
|
+
}
|
|
1847
|
+
return true;
|
|
1848
|
+
}
|
|
1849
|
+
function parseValue() {
|
|
1850
|
+
switch (_scanner.getToken()) {
|
|
1851
|
+
case 3:
|
|
1852
|
+
return parseArray();
|
|
1853
|
+
case 1:
|
|
1854
|
+
return parseObject();
|
|
1855
|
+
case 10:
|
|
1856
|
+
return parseString(true);
|
|
1857
|
+
default:
|
|
1858
|
+
return parseLiteral();
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
scanNext();
|
|
1862
|
+
if (_scanner.getToken() === 17) {
|
|
1863
|
+
if (options.allowEmptyContent) {
|
|
1864
|
+
return true;
|
|
1865
|
+
}
|
|
1866
|
+
handleError(4, [], []);
|
|
1867
|
+
return false;
|
|
1868
|
+
}
|
|
1869
|
+
if (!parseValue()) {
|
|
1870
|
+
handleError(4, [], []);
|
|
1871
|
+
return false;
|
|
1872
|
+
}
|
|
1873
|
+
if (_scanner.getToken() !== 17) {
|
|
1874
|
+
handleError(9, [], []);
|
|
1875
|
+
}
|
|
1876
|
+
return true;
|
|
1877
|
+
}
|
|
1878
|
+
function getNodeType(value) {
|
|
1879
|
+
switch (typeof value) {
|
|
1880
|
+
case "boolean":
|
|
1881
|
+
return "boolean";
|
|
1882
|
+
case "number":
|
|
1883
|
+
return "number";
|
|
1884
|
+
case "string":
|
|
1885
|
+
return "string";
|
|
1886
|
+
case "object": {
|
|
1887
|
+
if (!value) {
|
|
1888
|
+
return "null";
|
|
1889
|
+
} else if (Array.isArray(value)) {
|
|
1890
|
+
return "array";
|
|
1891
|
+
}
|
|
1892
|
+
return "object";
|
|
1893
|
+
}
|
|
1894
|
+
default:
|
|
1895
|
+
return "null";
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
// node_modules/jsonc-parser/lib/esm/impl/edit.js
|
|
1900
|
+
function setProperty(text, originalPath, value, options) {
|
|
1901
|
+
const path = originalPath.slice();
|
|
1902
|
+
const errors = [];
|
|
1903
|
+
const root = parseTree(text, errors);
|
|
1904
|
+
let parent = undefined;
|
|
1905
|
+
let lastSegment = undefined;
|
|
1906
|
+
while (path.length > 0) {
|
|
1907
|
+
lastSegment = path.pop();
|
|
1908
|
+
parent = findNodeAtLocation(root, path);
|
|
1909
|
+
if (parent === undefined && value !== undefined) {
|
|
1910
|
+
if (typeof lastSegment === "string") {
|
|
1911
|
+
value = { [lastSegment]: value };
|
|
1912
|
+
} else {
|
|
1913
|
+
value = [value];
|
|
1914
|
+
}
|
|
1915
|
+
} else {
|
|
1916
|
+
break;
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
if (!parent) {
|
|
1920
|
+
if (value === undefined) {
|
|
1921
|
+
throw new Error("Can not delete in empty document");
|
|
1922
|
+
}
|
|
1923
|
+
return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
|
|
1924
|
+
} else if (parent.type === "object" && typeof lastSegment === "string" && Array.isArray(parent.children)) {
|
|
1925
|
+
const existing = findNodeAtLocation(parent, [lastSegment]);
|
|
1926
|
+
if (existing !== undefined) {
|
|
1927
|
+
if (value === undefined) {
|
|
1928
|
+
if (!existing.parent) {
|
|
1929
|
+
throw new Error("Malformed AST");
|
|
1930
|
+
}
|
|
1931
|
+
const propertyIndex = parent.children.indexOf(existing.parent);
|
|
1932
|
+
let removeBegin;
|
|
1933
|
+
let removeEnd = existing.parent.offset + existing.parent.length;
|
|
1934
|
+
if (propertyIndex > 0) {
|
|
1935
|
+
let previous = parent.children[propertyIndex - 1];
|
|
1936
|
+
removeBegin = previous.offset + previous.length;
|
|
1937
|
+
} else {
|
|
1938
|
+
removeBegin = parent.offset + 1;
|
|
1939
|
+
if (parent.children.length > 1) {
|
|
1940
|
+
let next = parent.children[1];
|
|
1941
|
+
removeEnd = next.offset;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: "" }, options);
|
|
1945
|
+
} else {
|
|
1946
|
+
return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
|
|
1947
|
+
}
|
|
1948
|
+
} else {
|
|
1949
|
+
if (value === undefined) {
|
|
1950
|
+
return [];
|
|
1951
|
+
}
|
|
1952
|
+
const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
|
|
1953
|
+
const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map((p) => p.children[0].value)) : parent.children.length;
|
|
1954
|
+
let edit;
|
|
1955
|
+
if (index > 0) {
|
|
1956
|
+
let previous = parent.children[index - 1];
|
|
1957
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1958
|
+
} else if (parent.children.length === 0) {
|
|
1959
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
1960
|
+
} else {
|
|
1961
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty + "," };
|
|
1962
|
+
}
|
|
1963
|
+
return withFormatting(text, edit, options);
|
|
1964
|
+
}
|
|
1965
|
+
} else if (parent.type === "array" && typeof lastSegment === "number" && Array.isArray(parent.children)) {
|
|
1966
|
+
const insertIndex = lastSegment;
|
|
1967
|
+
if (insertIndex === -1) {
|
|
1968
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1969
|
+
let edit;
|
|
1970
|
+
if (parent.children.length === 0) {
|
|
1971
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
1972
|
+
} else {
|
|
1973
|
+
const previous = parent.children[parent.children.length - 1];
|
|
1974
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1975
|
+
}
|
|
1976
|
+
return withFormatting(text, edit, options);
|
|
1977
|
+
} else if (value === undefined && parent.children.length >= 0) {
|
|
1978
|
+
const removalIndex = lastSegment;
|
|
1979
|
+
const toRemove = parent.children[removalIndex];
|
|
1980
|
+
let edit;
|
|
1981
|
+
if (parent.children.length === 1) {
|
|
1982
|
+
edit = { offset: parent.offset + 1, length: parent.length - 2, content: "" };
|
|
1983
|
+
} else if (parent.children.length - 1 === removalIndex) {
|
|
1984
|
+
let previous = parent.children[removalIndex - 1];
|
|
1985
|
+
let offset = previous.offset + previous.length;
|
|
1986
|
+
let parentEndOffset = parent.offset + parent.length;
|
|
1987
|
+
edit = { offset, length: parentEndOffset - 2 - offset, content: "" };
|
|
1988
|
+
} else {
|
|
1989
|
+
edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: "" };
|
|
1990
|
+
}
|
|
1991
|
+
return withFormatting(text, edit, options);
|
|
1992
|
+
} else if (value !== undefined) {
|
|
1993
|
+
let edit;
|
|
1994
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1995
|
+
if (!options.isArrayInsertion && parent.children.length > lastSegment) {
|
|
1996
|
+
const toModify = parent.children[lastSegment];
|
|
1997
|
+
edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
|
|
1998
|
+
} else if (parent.children.length === 0 || lastSegment === 0) {
|
|
1999
|
+
edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + "," };
|
|
2000
|
+
} else {
|
|
2001
|
+
const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
|
|
2002
|
+
const previous = parent.children[index - 1];
|
|
2003
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
2004
|
+
}
|
|
2005
|
+
return withFormatting(text, edit, options);
|
|
2006
|
+
} else {
|
|
2007
|
+
throw new Error(`Can not ${value === undefined ? "remove" : options.isArrayInsertion ? "insert" : "modify"} Array index ${insertIndex} as length is not sufficient`);
|
|
2008
|
+
}
|
|
2009
|
+
} else {
|
|
2010
|
+
throw new Error(`Can not add ${typeof lastSegment !== "number" ? "index" : "property"} to parent of type ${parent.type}`);
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
function withFormatting(text, edit, options) {
|
|
2014
|
+
if (!options.formattingOptions) {
|
|
2015
|
+
return [edit];
|
|
2016
|
+
}
|
|
2017
|
+
let newText = applyEdit(text, edit);
|
|
2018
|
+
let begin = edit.offset;
|
|
2019
|
+
let end = edit.offset + edit.content.length;
|
|
2020
|
+
if (edit.length === 0 || edit.content.length === 0) {
|
|
2021
|
+
while (begin > 0 && !isEOL(newText, begin - 1)) {
|
|
2022
|
+
begin--;
|
|
2023
|
+
}
|
|
2024
|
+
while (end < newText.length && !isEOL(newText, end)) {
|
|
2025
|
+
end++;
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
const edits = format(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
|
|
2029
|
+
for (let i = edits.length - 1;i >= 0; i--) {
|
|
2030
|
+
const edit2 = edits[i];
|
|
2031
|
+
newText = applyEdit(newText, edit2);
|
|
2032
|
+
begin = Math.min(begin, edit2.offset);
|
|
2033
|
+
end = Math.max(end, edit2.offset + edit2.length);
|
|
2034
|
+
end += edit2.content.length - edit2.length;
|
|
2035
|
+
}
|
|
2036
|
+
const editLength = text.length - (newText.length - end) - begin;
|
|
2037
|
+
return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
|
|
2038
|
+
}
|
|
2039
|
+
function applyEdit(text, edit) {
|
|
2040
|
+
return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
// node_modules/jsonc-parser/lib/esm/main.js
|
|
2044
|
+
var ScanError;
|
|
2045
|
+
(function(ScanError2) {
|
|
2046
|
+
ScanError2[ScanError2["None"] = 0] = "None";
|
|
2047
|
+
ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
2048
|
+
ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
2049
|
+
ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
2050
|
+
ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
2051
|
+
ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
2052
|
+
ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
2053
|
+
})(ScanError || (ScanError = {}));
|
|
2054
|
+
var SyntaxKind;
|
|
2055
|
+
(function(SyntaxKind2) {
|
|
2056
|
+
SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
2057
|
+
SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
2058
|
+
SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
2059
|
+
SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
2060
|
+
SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
|
|
2061
|
+
SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
|
|
2062
|
+
SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
|
|
2063
|
+
SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
|
|
2064
|
+
SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
|
|
2065
|
+
SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
|
|
2066
|
+
SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
|
|
2067
|
+
SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
2068
|
+
SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
2069
|
+
SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
2070
|
+
SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
|
|
2071
|
+
SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
|
|
2072
|
+
SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
|
|
2073
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
2074
|
+
var parse2 = parse;
|
|
2075
|
+
var ParseErrorCode;
|
|
2076
|
+
(function(ParseErrorCode2) {
|
|
2077
|
+
ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
2078
|
+
ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
2079
|
+
ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
2080
|
+
ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
|
|
2081
|
+
ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
|
|
2082
|
+
ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
|
|
2083
|
+
ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
2084
|
+
ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
2085
|
+
ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
2086
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
2087
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
2088
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
2089
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
2090
|
+
ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
2091
|
+
ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
2092
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
2093
|
+
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
2094
|
+
function modify(text, path, value, options) {
|
|
2095
|
+
return setProperty(text, path, value, options);
|
|
2096
|
+
}
|
|
2097
|
+
function applyEdits(text, edits) {
|
|
2098
|
+
let sortedEdits = edits.slice(0).sort((a, b) => {
|
|
2099
|
+
const diff = a.offset - b.offset;
|
|
2100
|
+
if (diff === 0) {
|
|
2101
|
+
return a.length - b.length;
|
|
2102
|
+
}
|
|
2103
|
+
return diff;
|
|
2104
|
+
});
|
|
2105
|
+
let lastModifiedOffset = text.length;
|
|
2106
|
+
for (let i = sortedEdits.length - 1;i >= 0; i--) {
|
|
2107
|
+
let e = sortedEdits[i];
|
|
2108
|
+
if (e.offset + e.length <= lastModifiedOffset) {
|
|
2109
|
+
text = applyEdit(text, e);
|
|
2110
|
+
} else {
|
|
2111
|
+
throw new Error("Overlapping edit");
|
|
2112
|
+
}
|
|
2113
|
+
lastModifiedOffset = e.offset;
|
|
2114
|
+
}
|
|
2115
|
+
return text;
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
// src/shared/claude-settings.ts
|
|
2119
|
+
var settingsPath = join7(homedir3(), ".claude", "settings.json");
|
|
2120
|
+
function readClaudeSettings() {
|
|
2121
|
+
if (!existsSync8(settingsPath)) {
|
|
2122
|
+
return {};
|
|
2123
|
+
}
|
|
2124
|
+
const content = readFileSync5(settingsPath, "utf8");
|
|
2125
|
+
return parse2(content) ?? {};
|
|
2126
|
+
}
|
|
2127
|
+
function writeClaudeSettings(settings) {
|
|
2128
|
+
const dir = dirname4(settingsPath);
|
|
2129
|
+
if (!existsSync8(dir)) {
|
|
2130
|
+
mkdirSync4(dir, { recursive: true });
|
|
2131
|
+
}
|
|
2132
|
+
let content;
|
|
2133
|
+
if (existsSync8(settingsPath)) {
|
|
2134
|
+
content = readFileSync5(settingsPath, "utf8");
|
|
2135
|
+
for (const [key, value] of Object.entries(settings)) {
|
|
2136
|
+
const edits = modify(content, [key], value, {});
|
|
2137
|
+
content = applyEdits(content, edits);
|
|
2138
|
+
}
|
|
2139
|
+
const existing = parse2(content) ?? {};
|
|
2140
|
+
for (const key of Object.keys(existing)) {
|
|
2141
|
+
if (!(key in settings)) {
|
|
2142
|
+
const edits = modify(content, [key], undefined, {});
|
|
2143
|
+
content = applyEdits(content, edits);
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
} else {
|
|
2147
|
+
content = JSON.stringify(settings, null, 2);
|
|
2148
|
+
}
|
|
2149
|
+
const tmp = settingsPath + ".tmp";
|
|
2150
|
+
writeFileSync5(tmp, content, "utf8");
|
|
2151
|
+
renameSync2(tmp, settingsPath);
|
|
2152
|
+
}
|
|
2153
|
+
function registerMcpServer(name, entry) {
|
|
2154
|
+
const settings = readClaudeSettings();
|
|
2155
|
+
if (!settings.mcpServers) {
|
|
2156
|
+
settings.mcpServers = {};
|
|
2157
|
+
}
|
|
2158
|
+
settings.mcpServers[name] = entry;
|
|
2159
|
+
writeClaudeSettings(settings);
|
|
2160
|
+
}
|
|
2161
|
+
function removeMcpServer(name) {
|
|
2162
|
+
const settings = readClaudeSettings();
|
|
2163
|
+
if (settings.mcpServers) {
|
|
2164
|
+
delete settings.mcpServers[name];
|
|
2165
|
+
writeClaudeSettings(settings);
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
function registerHook(event, rule) {
|
|
2169
|
+
const settings = readClaudeSettings();
|
|
2170
|
+
if (!settings.hooks) {
|
|
2171
|
+
settings.hooks = {};
|
|
2172
|
+
}
|
|
2173
|
+
if (!settings.hooks[event]) {
|
|
2174
|
+
settings.hooks[event] = [];
|
|
2175
|
+
}
|
|
2176
|
+
const rules = settings.hooks[event];
|
|
2177
|
+
for (const hookCmd of rule.hooks) {
|
|
2178
|
+
let replaced = false;
|
|
2179
|
+
for (let i = 0;i < rules.length; i++) {
|
|
2180
|
+
const existingIdx = rules[i].hooks.findIndex((h) => h.command === hookCmd.command);
|
|
2181
|
+
if (existingIdx !== -1) {
|
|
2182
|
+
rules[i] = rule;
|
|
2183
|
+
replaced = true;
|
|
2184
|
+
break;
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
if (!replaced) {
|
|
2188
|
+
rules.push(rule);
|
|
2189
|
+
break;
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
writeClaudeSettings(settings);
|
|
2193
|
+
}
|
|
2194
|
+
|
|
663
2195
|
// src/cli/commands/install.ts
|
|
664
2196
|
function resolveOmxSource() {
|
|
665
2197
|
try {
|
|
666
|
-
const cliDir =
|
|
2198
|
+
const cliDir = dirname5(fileURLToPath2(import.meta.url));
|
|
667
2199
|
const pkgRoot = resolve4(cliDir, "..", "..");
|
|
668
|
-
const source =
|
|
669
|
-
if (
|
|
2200
|
+
const source = join8(pkgRoot, "dist", "omx", "index.mjs");
|
|
2201
|
+
if (existsSync9(source))
|
|
670
2202
|
return source;
|
|
671
2203
|
} catch {}
|
|
672
2204
|
try {
|
|
673
|
-
const req =
|
|
2205
|
+
const req = createRequire2(import.meta.url);
|
|
674
2206
|
return req.resolve("@ksm0709/context/omx");
|
|
675
2207
|
} catch {
|
|
676
2208
|
return null;
|
|
677
2209
|
}
|
|
678
2210
|
}
|
|
679
2211
|
function installOmx(projectDir, sourcePath) {
|
|
680
|
-
if (!
|
|
2212
|
+
if (!existsSync9(sourcePath)) {
|
|
681
2213
|
process.stderr.write(`Could not find OMX plugin source file: ${sourcePath}
|
|
682
2214
|
`);
|
|
683
2215
|
process.exit(1);
|
|
684
2216
|
return;
|
|
685
2217
|
}
|
|
686
|
-
const targetDir =
|
|
687
|
-
|
|
688
|
-
copyFileSync(sourcePath,
|
|
2218
|
+
const targetDir = join8(projectDir, ".omx", "hooks");
|
|
2219
|
+
mkdirSync5(targetDir, { recursive: true });
|
|
2220
|
+
copyFileSync(sourcePath, join8(targetDir, "context.mjs"));
|
|
689
2221
|
process.stdout.write(`Installed context plugin to .omx/hooks/context.mjs
|
|
690
2222
|
`);
|
|
691
2223
|
if (ensureMcpRegistered()) {
|
|
@@ -693,6 +2225,41 @@ function installOmx(projectDir, sourcePath) {
|
|
|
693
2225
|
`);
|
|
694
2226
|
}
|
|
695
2227
|
}
|
|
2228
|
+
function installOmc(projectDir) {
|
|
2229
|
+
scaffoldIfNeeded(projectDir);
|
|
2230
|
+
injectIntoAgentsMd(join8(projectDir, "AGENTS.md"), STATIC_KNOWLEDGE_CONTEXT);
|
|
2231
|
+
let bunPath = "bun";
|
|
2232
|
+
try {
|
|
2233
|
+
bunPath = execSync("which bun", { encoding: "utf-8" }).trim();
|
|
2234
|
+
} catch {}
|
|
2235
|
+
const mcpPath = resolveMcpPath();
|
|
2236
|
+
const hookBasePath = join8(dirname5(mcpPath), "omc") + "/";
|
|
2237
|
+
removeMcpServer("context_mcp");
|
|
2238
|
+
registerMcpServer("context-mcp", { command: bunPath, args: [mcpPath], enabled: true });
|
|
2239
|
+
registerHook("SessionStart", {
|
|
2240
|
+
matcher: "startup",
|
|
2241
|
+
hooks: [
|
|
2242
|
+
{
|
|
2243
|
+
type: "command",
|
|
2244
|
+
command: `${bunPath} ${hookBasePath}session-start-hook.js`,
|
|
2245
|
+
timeout: 15,
|
|
2246
|
+
statusMessage: "Initializing context plugin..."
|
|
2247
|
+
}
|
|
2248
|
+
]
|
|
2249
|
+
});
|
|
2250
|
+
registerHook("Stop", {
|
|
2251
|
+
hooks: [
|
|
2252
|
+
{
|
|
2253
|
+
type: "command",
|
|
2254
|
+
command: `${bunPath} ${hookBasePath}stop-hook.js`,
|
|
2255
|
+
timeout: 10,
|
|
2256
|
+
statusMessage: "Checking turn completion..."
|
|
2257
|
+
}
|
|
2258
|
+
]
|
|
2259
|
+
});
|
|
2260
|
+
process.stdout.write(`Successfully installed context (omc) plugin.
|
|
2261
|
+
`);
|
|
2262
|
+
}
|
|
696
2263
|
function runInstall(args) {
|
|
697
2264
|
const [subcommand] = args;
|
|
698
2265
|
switch (subcommand) {
|
|
@@ -707,8 +2274,12 @@ function runInstall(args) {
|
|
|
707
2274
|
installOmx(process.cwd(), source);
|
|
708
2275
|
break;
|
|
709
2276
|
}
|
|
2277
|
+
case "omc":
|
|
2278
|
+
case "claude":
|
|
2279
|
+
installOmc(process.cwd());
|
|
2280
|
+
break;
|
|
710
2281
|
case undefined:
|
|
711
|
-
process.stderr.write(`Missing install target. Usage: context install omx
|
|
2282
|
+
process.stderr.write(`Missing install target. Usage: context install <omx|omc>
|
|
712
2283
|
`);
|
|
713
2284
|
process.exit(1);
|
|
714
2285
|
break;
|