@adanami/kaleido 0.1.0
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/LICENSE +21 -0
- package/README.md +104 -0
- package/dist/cli/index.js +1489 -0
- package/dist/client/assets/abap-08VXUWAP.js +1 -0
- package/dist/client/assets/abnfDiagram-N423BO3Z-BNC_bOwN.js +1 -0
- package/dist/client/assets/apex-BWPQTe0t.js +1 -0
- package/dist/client/assets/arc-BQjVBT7z.js +1 -0
- package/dist/client/assets/architecture-TIHT7OUA-rtiyad39.js +1 -0
- package/dist/client/assets/architectureDiagram-T3A2C74G-NbyTzj4B.js +36 -0
- package/dist/client/assets/array-BifhSqXX.js +1 -0
- package/dist/client/assets/azcli-Bc_sGQ0U.js +1 -0
- package/dist/client/assets/bat-i0X4ZdIN.js +1 -0
- package/dist/client/assets/bicep-B5-_aFwp.js +2 -0
- package/dist/client/assets/blockDiagram-VBNYF7ZC-D7RFrUDl.js +132 -0
- package/dist/client/assets/c4Diagram-5PPSVZJV-CVtHbZ8m.js +10 -0
- package/dist/client/assets/cameligo-DMUM7wLl.js +1 -0
- package/dist/client/assets/channel-Cg-CR3Kv.js +1 -0
- package/dist/client/assets/chunk-2GRJ4B5K-vymlEdvz.js +1 -0
- package/dist/client/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
- package/dist/client/assets/chunk-4I5QYGJK-Dru7MVd5.js +1 -0
- package/dist/client/assets/chunk-5RXB4S5H-_mW4jXZD.js +231 -0
- package/dist/client/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
- package/dist/client/assets/chunk-6Q2QTUOP-C-Jr6Q1u.js +88 -0
- package/dist/client/assets/chunk-7BUUIJ7U-Bb538aSH.js +1 -0
- package/dist/client/assets/chunk-7Z6QIM7H-CH0etl6L.js +10 -0
- package/dist/client/assets/chunk-GF5L2VYU-l0ZYrFWn.js +206 -0
- package/dist/client/assets/chunk-I66GZJ75-CKcp5S17.js +127 -0
- package/dist/client/assets/chunk-JQJVKLGR-BXKeK8Yn.js +156 -0
- package/dist/client/assets/chunk-JWPE2WC7-DVXcaiue.js +1 -0
- package/dist/client/assets/chunk-KBJHAD2P-DPP8q1jj.js +1 -0
- package/dist/client/assets/chunk-KEIR6QF5-BICK3FdT.js +161 -0
- package/dist/client/assets/chunk-NSK5VX7P-CJvQSFjo.js +2 -0
- package/dist/client/assets/chunk-QR6OTTB3-DAmoW-jk.js +62 -0
- package/dist/client/assets/chunk-RYQCIY6F-mEV_z1Vs.js +1 -0
- package/dist/client/assets/chunk-UBXNYLIW-B9FQ3EVs.js +1 -0
- package/dist/client/assets/chunk-W5SLKNZC-B7q4L6_i.js +1 -0
- package/dist/client/assets/chunk-WRU74C26-DwPGHVIY.js +70 -0
- package/dist/client/assets/chunk-XXDRQBXY-B_1m3XyG.js +1 -0
- package/dist/client/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
- package/dist/client/assets/classDiagram-JCYQIIEL-DN-cM4gO.js +1 -0
- package/dist/client/assets/classDiagram-v2-OCEON4UE-DN-cM4gO.js +1 -0
- package/dist/client/assets/clojure-Cm7r79vr.js +1 -0
- package/dist/client/assets/codicon-Brq4_Ui5.ttf +0 -0
- package/dist/client/assets/coffee-Ba7i2nA0.js +1 -0
- package/dist/client/assets/cose-bilkent-JH36ORCC-_wSiGHW9.js +1 -0
- package/dist/client/assets/cpp-C7h46wYY.js +1 -0
- package/dist/client/assets/csharp-BKxtCVv1.js +1 -0
- package/dist/client/assets/csp-bTuwJoIa.js +1 -0
- package/dist/client/assets/css-DIMkf-bt.js +3 -0
- package/dist/client/assets/cynefin-VYW2F7L2-BSXkfF6B.js +1 -0
- package/dist/client/assets/cynefinDiagram-MW4NZA55-DWqP9pCq.js +62 -0
- package/dist/client/assets/cypher-CVaqCwHa.js +1 -0
- package/dist/client/assets/cytoscape.esm-C2x7inlt.js +321 -0
- package/dist/client/assets/dagre-Buvkdvvj.js +1 -0
- package/dist/client/assets/dagre-VZM6K2ZE-D-6mKeP4.js +4 -0
- package/dist/client/assets/dart-onAF5SnQ.js +1 -0
- package/dist/client/assets/defaultLocale-BFoDCU3G.js +1 -0
- package/dist/client/assets/diagram-7IWD3JNH-DwifWIOM.js +30 -0
- package/dist/client/assets/diagram-B4RE2ZJO-CZy5Cter.js +3 -0
- package/dist/client/assets/diagram-LBJQPF4R-D64OHGQ1.js +24 -0
- package/dist/client/assets/diagram-Q27KOJAE-CYJYm3MT.js +24 -0
- package/dist/client/assets/diagram-UB23O5K3-D9XqDFWB.js +41 -0
- package/dist/client/assets/dist-D9557-UX.js +1 -0
- package/dist/client/assets/dockerfile-DZFCIeNp.js +1 -0
- package/dist/client/assets/ebnfDiagram-BXEA7PRR-DXv0laGY.js +1 -0
- package/dist/client/assets/ecl-D05T4iGw.js +1 -0
- package/dist/client/assets/editor.worker-D9zwrD0f.js +30 -0
- package/dist/client/assets/elixir-6RTg0lbw.js +1 -0
- package/dist/client/assets/erDiagram-JOGREHBK-DtgpDnFq.js +85 -0
- package/dist/client/assets/eventmodeling-45OFAUF4-CIrFy3PN.js +1 -0
- package/dist/client/assets/flow9-C5_-GSwl.js +1 -0
- package/dist/client/assets/flowDiagram-UKHOOZJN-CsaPoqV0.js +1 -0
- package/dist/client/assets/freemarker2-C0K9bJg3.js +3 -0
- package/dist/client/assets/fsharp-C8Ef5oNN.js +1 -0
- package/dist/client/assets/ganttDiagram-PKOTCBZU-DbPT_9cm.js +292 -0
- package/dist/client/assets/gitGraph-TEB2WS4Q-BSzJ-zot.js +1 -0
- package/dist/client/assets/gitGraphDiagram-DS77QQ5N-Dv47ST8y.js +106 -0
- package/dist/client/assets/go-C-y9NEjX.js +1 -0
- package/dist/client/assets/graphlib-DS17s2tU.js +1 -0
- package/dist/client/assets/graphql-fmXr3nnJ.js +1 -0
- package/dist/client/assets/handlebars-C5Uh7yG8.js +1 -0
- package/dist/client/assets/hcl-CpzslTdj.js +1 -0
- package/dist/client/assets/html-CVq09h_T.js +1 -0
- package/dist/client/assets/index-BdNjwiL_.css +1 -0
- package/dist/client/assets/index-C-Az4wQZ.js +1288 -0
- package/dist/client/assets/info-DKCQHKI2-DrnuTwtV.js +1 -0
- package/dist/client/assets/infoDiagram-6WML65LV-BbOLkXMO.js +2 -0
- package/dist/client/assets/ini-sBoK_t0W.js +1 -0
- package/dist/client/assets/init-C-OQMol4.js +1 -0
- package/dist/client/assets/ishikawaDiagram-WSZJBQD7-BU0Xf4Jv.js +70 -0
- package/dist/client/assets/java-BEtHBSE6.js +1 -0
- package/dist/client/assets/javascript-BLNuR3ma.js +1 -0
- package/dist/client/assets/journeyDiagram-NVQOT4AX-Be02AxgF.js +139 -0
- package/dist/client/assets/julia-Bri6UV-V.js +1 -0
- package/dist/client/assets/kanban-definition-27J2QSJJ-DAJOmq0i.js +89 -0
- package/dist/client/assets/katex-CXMH3UgJ.js +257 -0
- package/dist/client/assets/kotlin-BOotOW0E.js +1 -0
- package/dist/client/assets/less-B9JPFI3C.js +2 -0
- package/dist/client/assets/lexon-CfSJPG6W.js +1 -0
- package/dist/client/assets/line-CY8MZqA_.js +1 -0
- package/dist/client/assets/linear-VmQ0cgWf.js +1 -0
- package/dist/client/assets/liquid-CqxeTiTR.js +1 -0
- package/dist/client/assets/lua-CsQS60Ue.js +1 -0
- package/dist/client/assets/m3-D-oSqn_W.js +1 -0
- package/dist/client/assets/map-BaFkSB1l.js +1 -0
- package/dist/client/assets/markdown-Cimd5fb3.js +1 -0
- package/dist/client/assets/mdx-CZgnrcpZ.js +1 -0
- package/dist/client/assets/mermaid-parser.core-BNyH4fWd.js +7 -0
- package/dist/client/assets/mermaid.core-D6SqRXfj.js +42 -0
- package/dist/client/assets/mindmap-definition-FAOFIHXS-Cb4njDU8.js +96 -0
- package/dist/client/assets/mips-CIPQ_RoX.js +1 -0
- package/dist/client/assets/msdax-DauUninz.js +1 -0
- package/dist/client/assets/mysql-SOo6toE5.js +1 -0
- package/dist/client/assets/objective-c-FvmIjYaQ.js +1 -0
- package/dist/client/assets/ordinal-BDEzSJ7C.js +1 -0
- package/dist/client/assets/packet-7NZHBO7P-C0OLtmrN.js +1 -0
- package/dist/client/assets/pascal-DrH0SRf2.js +1 -0
- package/dist/client/assets/pascaligo-D-ptJ9y-.js +1 -0
- package/dist/client/assets/path-fybaL0A-.js +1 -0
- package/dist/client/assets/pegDiagram-VL7TDLO6-CUlmavTd.js +1 -0
- package/dist/client/assets/perl-oz_6vUea.js +1 -0
- package/dist/client/assets/pgsql-DTj74zXo.js +1 -0
- package/dist/client/assets/php-nr791fC2.js +1 -0
- package/dist/client/assets/pie-RZYD4A2V-BOaXF8wo.js +1 -0
- package/dist/client/assets/pieDiagram-7S7Q4E2Y-DAuLOXyl.js +39 -0
- package/dist/client/assets/pla-CopQ2nXW.js +1 -0
- package/dist/client/assets/postiats-43DmfD33.js +1 -0
- package/dist/client/assets/powerquery-D3hlyOfw.js +1 -0
- package/dist/client/assets/powershell-DmHpPYUd.js +1 -0
- package/dist/client/assets/protobuf-C531GsRP.js +2 -0
- package/dist/client/assets/pug-Z5eAx3Zn.js +1 -0
- package/dist/client/assets/python-BKTOsIAC.js +1 -0
- package/dist/client/assets/qsharp-DkqhCAOL.js +1 -0
- package/dist/client/assets/quadrantDiagram-CIZ2JOQS-6T2tUzKE.js +7 -0
- package/dist/client/assets/r-BwWrilGY.js +1 -0
- package/dist/client/assets/radar-I7S5WNFK-84ZPjfzV.js +1 -0
- package/dist/client/assets/railroad-3IZDKUUU-BIancogu.js +1 -0
- package/dist/client/assets/railroad-abnf-AHOZXSZD-DY5Umeyq.js +1 -0
- package/dist/client/assets/railroad-ebnf-EBAXGLYW-BvHqcDCh.js +1 -0
- package/dist/client/assets/railroad-peg-LSFZ7HO6-Bcfw7tSJ.js +1 -0
- package/dist/client/assets/railroadDiagram-AXF67PYL-CG4n3oVN.js +1 -0
- package/dist/client/assets/razor-D3D2-y9K.js +1 -0
- package/dist/client/assets/redis-ClamHrr6.js +1 -0
- package/dist/client/assets/redshift-DT7zqm-g.js +1 -0
- package/dist/client/assets/requirementDiagram-LRYGKXZP-mZX3Srsb.js +84 -0
- package/dist/client/assets/restructuredtext-BYgofb2h.js +1 -0
- package/dist/client/assets/rough.esm-Dy-Kn_BL.js +1 -0
- package/dist/client/assets/ruby-DezsRK8O.js +1 -0
- package/dist/client/assets/rust-DdL9SqIa.js +1 -0
- package/dist/client/assets/sankeyDiagram-W5VNT64P-yPa5u_0L.js +40 -0
- package/dist/client/assets/sb-CcwsVR0C.js +1 -0
- package/dist/client/assets/scala-DHpiXF5c.js +1 -0
- package/dist/client/assets/scheme-BeGwcela.js +1 -0
- package/dist/client/assets/scss-gp-XZpBa.js +3 -0
- package/dist/client/assets/sequenceDiagram-SI44F4Z6-CyNIlTWm.js +162 -0
- package/dist/client/assets/shell-CC2rA5mh.js +1 -0
- package/dist/client/assets/sizeCapture-X5ZJPWSS-B0uUizjq.js +1 -0
- package/dist/client/assets/solidity-BEEn4gHE.js +1 -0
- package/dist/client/assets/sophia-CRfGWb83.js +1 -0
- package/dist/client/assets/sparql-D_Lu-MrJ.js +1 -0
- package/dist/client/assets/sql-NEE52Syq.js +1 -0
- package/dist/client/assets/src-CUuFImQF.js +1 -0
- package/dist/client/assets/st-DbInun42.js +1 -0
- package/dist/client/assets/stateDiagram-OKZ733FA-CPylCUxu.js +1 -0
- package/dist/client/assets/stateDiagram-v2-UEYNNEHI-87clA1Da.js +1 -0
- package/dist/client/assets/swift-Bxkupp3x.js +1 -0
- package/dist/client/assets/swimlanes-SLNWSIFB-DBNGs0gR.js +2 -0
- package/dist/client/assets/swimlanesDiagram-ULZ7WXOC-DrshQU12.js +8 -0
- package/dist/client/assets/systemverilog-Bz4Y3fRF.js +1 -0
- package/dist/client/assets/tcl-DISqw1ZD.js +1 -0
- package/dist/client/assets/timeline-definition-Z64GVDOM-BAUrOlpT.js +120 -0
- package/dist/client/assets/treeView-QDETBFTQ-DWU_Tu3e.js +1 -0
- package/dist/client/assets/treemap-6X3UGDF4-C0VSsv4b.js +1 -0
- package/dist/client/assets/twig-De2hgUGE.js +1 -0
- package/dist/client/assets/typescript-DHaWXPl5.js +1 -0
- package/dist/client/assets/typespec-B8J7ngcE.js +1 -0
- package/dist/client/assets/vb-DV3o63ZY.js +1 -0
- package/dist/client/assets/vennDiagram-T6HMQDX7-DMDrxVrh.js +34 -0
- package/dist/client/assets/wardley-OPB4EBWU-2FXuD4eH.js +1 -0
- package/dist/client/assets/wardleyDiagram-T6FBY63Y-B6MdwST-.js +78 -0
- package/dist/client/assets/wgsl-DpFanUEy.js +298 -0
- package/dist/client/assets/xml-UOCAZ6xX.js +1 -0
- package/dist/client/assets/xychartDiagram-ELKLHX3M-4m0lgQEp.js +7 -0
- package/dist/client/assets/yaml-c5v3wojq.js +1 -0
- package/dist/client/index.html +22 -0
- package/dist/eslint-WWJOZ2KR.js +140 -0
- package/dist/server/ts/worker.js +360 -0
- package/package.json +85 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/server/ts/worker.ts
|
|
4
|
+
import { parentPort, workerData } from "worker_threads";
|
|
5
|
+
|
|
6
|
+
// src/server/ts/service.ts
|
|
7
|
+
import { createRequire } from "module";
|
|
8
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "path";
|
|
9
|
+
var PROJECT_IDLE_DISPOSE_MS = 10 * 60 * 1e3;
|
|
10
|
+
var TsService = class {
|
|
11
|
+
constructor(repoRoot) {
|
|
12
|
+
this.repoRoot = repoRoot;
|
|
13
|
+
const loaded = loadTypescript(repoRoot);
|
|
14
|
+
this.ts = loaded.ts;
|
|
15
|
+
this.tsSource = loaded.source;
|
|
16
|
+
this.documentRegistry = this.ts.createDocumentRegistry();
|
|
17
|
+
}
|
|
18
|
+
repoRoot;
|
|
19
|
+
ts;
|
|
20
|
+
tsSource;
|
|
21
|
+
projects = /* @__PURE__ */ new Map();
|
|
22
|
+
documentRegistry;
|
|
23
|
+
get tsVersionInfo() {
|
|
24
|
+
return `${this.ts.version} (${this.tsSource})`;
|
|
25
|
+
}
|
|
26
|
+
isSupportedFile(path) {
|
|
27
|
+
return /\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/.test(path);
|
|
28
|
+
}
|
|
29
|
+
toAbsPath(repoRelPath) {
|
|
30
|
+
const normalized = repoRelPath.replace(/\\/g, "/");
|
|
31
|
+
if (isAbsolute(normalized) || normalized.split("/").includes("..")) {
|
|
32
|
+
throw new Error("Invalid path");
|
|
33
|
+
}
|
|
34
|
+
const abs = resolve(this.repoRoot, normalized);
|
|
35
|
+
if (abs !== this.repoRoot && !abs.startsWith(`${this.repoRoot}${sep}`)) {
|
|
36
|
+
throw new Error("Path outside repository");
|
|
37
|
+
}
|
|
38
|
+
return abs;
|
|
39
|
+
}
|
|
40
|
+
getProjectFor(absPath) {
|
|
41
|
+
const configPath = this.ts.findConfigFile(dirname(absPath), this.ts.sys.fileExists, "tsconfig.json");
|
|
42
|
+
if (!configPath) return null;
|
|
43
|
+
let project = this.projects.get(configPath);
|
|
44
|
+
if (!project) {
|
|
45
|
+
project = new Project(this.ts, configPath, this.documentRegistry);
|
|
46
|
+
this.projects.set(configPath, project);
|
|
47
|
+
}
|
|
48
|
+
project.touch();
|
|
49
|
+
this.disposeIdleProjects();
|
|
50
|
+
return project;
|
|
51
|
+
}
|
|
52
|
+
hover(params) {
|
|
53
|
+
const absPath = this.toAbsPath(params.path);
|
|
54
|
+
if (!this.isSupportedFile(absPath)) return null;
|
|
55
|
+
const project = this.getProjectFor(absPath);
|
|
56
|
+
if (!project) return null;
|
|
57
|
+
return project.hover(absPath, params.line, params.column, params.content);
|
|
58
|
+
}
|
|
59
|
+
diagnostics(params) {
|
|
60
|
+
const absPath = this.toAbsPath(params.path);
|
|
61
|
+
if (!this.isSupportedFile(absPath)) return [];
|
|
62
|
+
const project = this.getProjectFor(absPath);
|
|
63
|
+
if (!project) return [];
|
|
64
|
+
return project.diagnostics(absPath, params.content);
|
|
65
|
+
}
|
|
66
|
+
definition(params) {
|
|
67
|
+
return this.locate("definition", params);
|
|
68
|
+
}
|
|
69
|
+
references(params) {
|
|
70
|
+
return this.locate("references", params);
|
|
71
|
+
}
|
|
72
|
+
locate(kind, params) {
|
|
73
|
+
const absPath = this.toAbsPath(params.path);
|
|
74
|
+
if (!this.isSupportedFile(absPath)) return [];
|
|
75
|
+
const project = this.getProjectFor(absPath);
|
|
76
|
+
if (!project) return [];
|
|
77
|
+
const locations = kind === "definition" ? project.definition(absPath, params.line, params.column, params.content) : project.references(absPath, params.line, params.column, params.content);
|
|
78
|
+
const result = [];
|
|
79
|
+
for (const location of locations) {
|
|
80
|
+
if (location.path === this.repoRoot || !location.path.startsWith(`${this.repoRoot}${sep}`)) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
result.push({ ...location, path: relative(this.repoRoot, location.path).split(sep).join("/") });
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
/** diff 取得後にバックグラウンドで Program を構築しておく (初回 hover の体感改善) */
|
|
88
|
+
warmup(repoRelPaths) {
|
|
89
|
+
setImmediate(() => {
|
|
90
|
+
for (const path of repoRelPaths) {
|
|
91
|
+
try {
|
|
92
|
+
if (!this.isSupportedFile(path)) continue;
|
|
93
|
+
const absPath = this.toAbsPath(path);
|
|
94
|
+
this.getProjectFor(absPath)?.ensureProgram();
|
|
95
|
+
} catch {
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/** watcher からのファイル変更通知 */
|
|
101
|
+
invalidateFile(repoRelPath) {
|
|
102
|
+
try {
|
|
103
|
+
const absPath = this.toAbsPath(repoRelPath);
|
|
104
|
+
for (const project of this.projects.values()) {
|
|
105
|
+
project.bumpDiskVersion(absPath);
|
|
106
|
+
}
|
|
107
|
+
} catch {
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
disposeIdleProjects() {
|
|
111
|
+
const now = Date.now();
|
|
112
|
+
for (const [key, project] of this.projects) {
|
|
113
|
+
if (now - project.lastUsedAt > PROJECT_IDLE_DISPOSE_MS) {
|
|
114
|
+
project.dispose();
|
|
115
|
+
this.projects.delete(key);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
function loadTypescript(repoRoot) {
|
|
121
|
+
const require2 = createRequire(join(repoRoot, "noop.js"));
|
|
122
|
+
try {
|
|
123
|
+
const projectTs = require2("typescript");
|
|
124
|
+
if (typeof projectTs.createLanguageService === "function") {
|
|
125
|
+
return { ts: projectTs, source: "project" };
|
|
126
|
+
}
|
|
127
|
+
} catch {
|
|
128
|
+
}
|
|
129
|
+
const bundledRequire = createRequire(import.meta.url);
|
|
130
|
+
return { ts: bundledRequire("typescript"), source: "bundled" };
|
|
131
|
+
}
|
|
132
|
+
var Project = class {
|
|
133
|
+
constructor(ts, configPath, documentRegistry) {
|
|
134
|
+
this.ts = ts;
|
|
135
|
+
this.projectDir = dirname(configPath);
|
|
136
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
137
|
+
const parsed = ts.parseJsonConfigFileContent(
|
|
138
|
+
configFile.config ?? {},
|
|
139
|
+
ts.sys,
|
|
140
|
+
this.projectDir,
|
|
141
|
+
void 0,
|
|
142
|
+
configPath
|
|
143
|
+
);
|
|
144
|
+
this.compilerOptions = parsed.options;
|
|
145
|
+
this.rootFiles = new Set(parsed.fileNames);
|
|
146
|
+
const host = {
|
|
147
|
+
getScriptFileNames: () => [...this.rootFiles, ...this.extraRoots],
|
|
148
|
+
getScriptVersion: (fileName) => {
|
|
149
|
+
const overlay = this.overlays.get(fileName);
|
|
150
|
+
if (overlay) return `overlay-${overlay.version}`;
|
|
151
|
+
return `disk-${this.diskVersions.get(fileName) ?? 0}`;
|
|
152
|
+
},
|
|
153
|
+
getScriptSnapshot: (fileName) => {
|
|
154
|
+
const overlay = this.overlays.get(fileName);
|
|
155
|
+
if (overlay) return ts.ScriptSnapshot.fromString(overlay.content);
|
|
156
|
+
const content = ts.sys.readFile(fileName);
|
|
157
|
+
if (content === void 0) return void 0;
|
|
158
|
+
return ts.ScriptSnapshot.fromString(content);
|
|
159
|
+
},
|
|
160
|
+
getCurrentDirectory: () => this.projectDir,
|
|
161
|
+
getCompilationSettings: () => this.compilerOptions,
|
|
162
|
+
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),
|
|
163
|
+
fileExists: (fileName) => this.overlays.has(fileName) || ts.sys.fileExists(fileName),
|
|
164
|
+
readFile: (fileName) => this.overlays.get(fileName)?.content ?? ts.sys.readFile(fileName),
|
|
165
|
+
readDirectory: ts.sys.readDirectory,
|
|
166
|
+
directoryExists: ts.sys.directoryExists,
|
|
167
|
+
getDirectories: ts.sys.getDirectories,
|
|
168
|
+
realpath: ts.sys.realpath
|
|
169
|
+
};
|
|
170
|
+
this.languageService = ts.createLanguageService(host, documentRegistry);
|
|
171
|
+
}
|
|
172
|
+
ts;
|
|
173
|
+
languageService;
|
|
174
|
+
rootFiles;
|
|
175
|
+
extraRoots = /* @__PURE__ */ new Set();
|
|
176
|
+
overlays = /* @__PURE__ */ new Map();
|
|
177
|
+
diskVersions = /* @__PURE__ */ new Map();
|
|
178
|
+
compilerOptions;
|
|
179
|
+
projectDir;
|
|
180
|
+
lastUsedAt = Date.now();
|
|
181
|
+
touch() {
|
|
182
|
+
this.lastUsedAt = Date.now();
|
|
183
|
+
}
|
|
184
|
+
ensureProgram() {
|
|
185
|
+
this.languageService.getProgram();
|
|
186
|
+
}
|
|
187
|
+
dispose() {
|
|
188
|
+
this.languageService.dispose();
|
|
189
|
+
}
|
|
190
|
+
bumpDiskVersion(absPath) {
|
|
191
|
+
this.diskVersions.set(absPath, (this.diskVersions.get(absPath) ?? 0) + 1);
|
|
192
|
+
}
|
|
193
|
+
ensureFileInProject(absPath) {
|
|
194
|
+
if (!this.rootFiles.has(absPath) && !this.extraRoots.has(absPath)) {
|
|
195
|
+
this.extraRoots.add(absPath);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
syncOverlay(absPath, content) {
|
|
199
|
+
const existing = this.overlays.get(absPath);
|
|
200
|
+
if (content === void 0) {
|
|
201
|
+
if (existing) this.overlays.delete(absPath);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (existing?.content !== content) {
|
|
205
|
+
this.overlays.set(absPath, {
|
|
206
|
+
content,
|
|
207
|
+
version: (existing?.version ?? 0) + 1
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
getSourceFile(absPath) {
|
|
212
|
+
return this.languageService.getProgram()?.getSourceFile(absPath);
|
|
213
|
+
}
|
|
214
|
+
hover(absPath, line, column, content) {
|
|
215
|
+
this.ensureFileInProject(absPath);
|
|
216
|
+
this.syncOverlay(absPath, content);
|
|
217
|
+
const sourceFile = this.getSourceFile(absPath);
|
|
218
|
+
if (!sourceFile) return null;
|
|
219
|
+
let offset;
|
|
220
|
+
try {
|
|
221
|
+
offset = this.ts.getPositionOfLineAndCharacter(sourceFile, line - 1, column - 1);
|
|
222
|
+
} catch {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
const info = this.languageService.getQuickInfoAtPosition(absPath, offset);
|
|
226
|
+
if (!info) return null;
|
|
227
|
+
const contents = [];
|
|
228
|
+
const display = this.ts.displayPartsToString(info.displayParts);
|
|
229
|
+
if (display) contents.push("```typescript\n" + display + "\n```");
|
|
230
|
+
const docs = this.ts.displayPartsToString(info.documentation);
|
|
231
|
+
if (docs) contents.push(docs);
|
|
232
|
+
for (const tag of info.tags ?? []) {
|
|
233
|
+
const text = this.ts.displayPartsToString(tag.text);
|
|
234
|
+
contents.push(`*@${tag.name}*${text ? ` \u2014 ${text}` : ""}`);
|
|
235
|
+
}
|
|
236
|
+
if (contents.length === 0) return null;
|
|
237
|
+
const start = this.ts.getLineAndCharacterOfPosition(sourceFile, info.textSpan.start);
|
|
238
|
+
const end = this.ts.getLineAndCharacterOfPosition(
|
|
239
|
+
sourceFile,
|
|
240
|
+
info.textSpan.start + info.textSpan.length
|
|
241
|
+
);
|
|
242
|
+
return {
|
|
243
|
+
contents,
|
|
244
|
+
range: {
|
|
245
|
+
startLine: start.line + 1,
|
|
246
|
+
startColumn: start.character + 1,
|
|
247
|
+
endLine: end.line + 1,
|
|
248
|
+
endColumn: end.character + 1
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
definition(absPath, line, column, content) {
|
|
253
|
+
const offset = this.prepareOffset(absPath, line, column, content);
|
|
254
|
+
if (offset === null) return [];
|
|
255
|
+
const defs = this.languageService.getDefinitionAtPosition(absPath, offset) ?? [];
|
|
256
|
+
return this.spansToLocations(defs);
|
|
257
|
+
}
|
|
258
|
+
references(absPath, line, column, content) {
|
|
259
|
+
const offset = this.prepareOffset(absPath, line, column, content);
|
|
260
|
+
if (offset === null) return [];
|
|
261
|
+
const refs = this.languageService.getReferencesAtPosition(absPath, offset) ?? [];
|
|
262
|
+
return this.spansToLocations(refs);
|
|
263
|
+
}
|
|
264
|
+
/** overlay 同期 + 1-based line/column → offset 変換 */
|
|
265
|
+
prepareOffset(absPath, line, column, content) {
|
|
266
|
+
this.ensureFileInProject(absPath);
|
|
267
|
+
this.syncOverlay(absPath, content);
|
|
268
|
+
const sourceFile = this.getSourceFile(absPath);
|
|
269
|
+
if (!sourceFile) return null;
|
|
270
|
+
try {
|
|
271
|
+
return this.ts.getPositionOfLineAndCharacter(sourceFile, line - 1, column - 1);
|
|
272
|
+
} catch {
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
spansToLocations(entries) {
|
|
277
|
+
const program = this.languageService.getProgram();
|
|
278
|
+
const result = [];
|
|
279
|
+
for (const entry of entries) {
|
|
280
|
+
const targetSf = program?.getSourceFile(entry.fileName);
|
|
281
|
+
if (!targetSf) continue;
|
|
282
|
+
const start = this.ts.getLineAndCharacterOfPosition(targetSf, entry.textSpan.start);
|
|
283
|
+
const end = this.ts.getLineAndCharacterOfPosition(
|
|
284
|
+
targetSf,
|
|
285
|
+
entry.textSpan.start + entry.textSpan.length
|
|
286
|
+
);
|
|
287
|
+
result.push({
|
|
288
|
+
path: entry.fileName,
|
|
289
|
+
startLine: start.line + 1,
|
|
290
|
+
startColumn: start.character + 1,
|
|
291
|
+
endLine: end.line + 1,
|
|
292
|
+
endColumn: end.character + 1
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
diagnostics(absPath, content) {
|
|
298
|
+
this.ensureFileInProject(absPath);
|
|
299
|
+
this.syncOverlay(absPath, content);
|
|
300
|
+
const sourceFile = this.getSourceFile(absPath);
|
|
301
|
+
if (!sourceFile) return [];
|
|
302
|
+
const all = [
|
|
303
|
+
...this.languageService.getSyntacticDiagnostics(absPath),
|
|
304
|
+
...this.languageService.getSemanticDiagnostics(absPath)
|
|
305
|
+
];
|
|
306
|
+
const result = [];
|
|
307
|
+
for (const diag of all) {
|
|
308
|
+
if (diag.start === void 0 || diag.length === void 0) continue;
|
|
309
|
+
const start = this.ts.getLineAndCharacterOfPosition(sourceFile, diag.start);
|
|
310
|
+
const end = this.ts.getLineAndCharacterOfPosition(sourceFile, diag.start + diag.length);
|
|
311
|
+
result.push({
|
|
312
|
+
source: "ts",
|
|
313
|
+
severity: diag.category === this.ts.DiagnosticCategory.Error ? "error" : diag.category === this.ts.DiagnosticCategory.Warning ? "warning" : "info",
|
|
314
|
+
message: this.ts.flattenDiagnosticMessageText(diag.messageText, "\n"),
|
|
315
|
+
code: `TS${diag.code}`,
|
|
316
|
+
startLine: start.line + 1,
|
|
317
|
+
startColumn: start.character + 1,
|
|
318
|
+
endLine: end.line + 1,
|
|
319
|
+
endColumn: end.character + 1
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
return result;
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
// src/server/ts/worker.ts
|
|
327
|
+
var port = parentPort;
|
|
328
|
+
if (!port) throw new Error("ts worker must be started as a worker thread");
|
|
329
|
+
var service = new TsService(workerData.repoRoot);
|
|
330
|
+
port.on("message", (message) => {
|
|
331
|
+
const { id, method, params } = message;
|
|
332
|
+
try {
|
|
333
|
+
let result = null;
|
|
334
|
+
switch (method) {
|
|
335
|
+
case "hover":
|
|
336
|
+
result = service.hover(params);
|
|
337
|
+
break;
|
|
338
|
+
case "diagnostics":
|
|
339
|
+
result = service.diagnostics(params);
|
|
340
|
+
break;
|
|
341
|
+
case "definition":
|
|
342
|
+
result = service.definition(params);
|
|
343
|
+
break;
|
|
344
|
+
case "references":
|
|
345
|
+
result = service.references(params);
|
|
346
|
+
break;
|
|
347
|
+
case "warmup":
|
|
348
|
+
service.warmup(params.paths);
|
|
349
|
+
break;
|
|
350
|
+
case "invalidateFile":
|
|
351
|
+
service.invalidateFile(params.path);
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
if (id !== void 0) port.postMessage({ id, result });
|
|
355
|
+
} catch (error) {
|
|
356
|
+
if (id !== void 0) {
|
|
357
|
+
port.postMessage({ id, error: error instanceof Error ? error.message : String(error) });
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adanami/kaleido",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Monaco-based local web file viewer: browse any directory, diff git ranges, with real TypeScript hover, lint diagnostics, comments and review marks",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"kaleido": "./dist/cli/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"viewer",
|
|
15
|
+
"diff",
|
|
16
|
+
"git",
|
|
17
|
+
"code-review",
|
|
18
|
+
"markdown",
|
|
19
|
+
"preview",
|
|
20
|
+
"mermaid",
|
|
21
|
+
"monaco",
|
|
22
|
+
"typescript",
|
|
23
|
+
"cli"
|
|
24
|
+
],
|
|
25
|
+
"author": "bubble0601",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/bubble0601/kaleido.git"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/bubble0601/kaleido#readme",
|
|
31
|
+
"bugs": "https://github.com/bubble0601/kaleido/issues",
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"dev": "node scripts/dev.js",
|
|
37
|
+
"build": "pnpm run build:licenses && pnpm run build:server && pnpm run build:client",
|
|
38
|
+
"build:licenses": "node scripts/extract-licenses.mjs",
|
|
39
|
+
"build:server": "tsup",
|
|
40
|
+
"build:client": "vite build",
|
|
41
|
+
"typecheck": "tsc --noEmit -p tsconfig.node.json && tsc --noEmit -p tsconfig.client.json",
|
|
42
|
+
"start": "pnpm run build && node dist/cli/index.js",
|
|
43
|
+
"prepublishOnly": "pnpm run typecheck && pnpm run build"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20"
|
|
47
|
+
},
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@hono/node-server": "^2.1.0",
|
|
51
|
+
"@hono/zod-validator": "^0.9.0",
|
|
52
|
+
"@iconify/react": "^6.0.2",
|
|
53
|
+
"@parcel/watcher": "^2.6.0",
|
|
54
|
+
"@tanstack/react-query": "^5.101.4",
|
|
55
|
+
"commander": "^15.0.0",
|
|
56
|
+
"env-paths": "^4.0.0",
|
|
57
|
+
"github-markdown-css": "^5.9.0",
|
|
58
|
+
"hono": "^4.13.1",
|
|
59
|
+
"marked": "^18.0.9",
|
|
60
|
+
"mermaid": "^11.16.1",
|
|
61
|
+
"monaco-editor": "^0.56.0",
|
|
62
|
+
"nanoid": "^6.0.1",
|
|
63
|
+
"open": "^11.0.0",
|
|
64
|
+
"react": "^19.2.8",
|
|
65
|
+
"react-dom": "^19.2.8",
|
|
66
|
+
"simple-git": "^3.36.0",
|
|
67
|
+
"typescript": "~5.9.0",
|
|
68
|
+
"zod": "^4.4.3",
|
|
69
|
+
"zustand": "^5.0.14"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@iconify-json/vscode-icons": "^1.2.69",
|
|
73
|
+
"@iconify/utils": "^3.1.4",
|
|
74
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
75
|
+
"@types/node": "^26.1.2",
|
|
76
|
+
"@types/react": "^19.2.18",
|
|
77
|
+
"@types/react-dom": "^19.2.4",
|
|
78
|
+
"@vitejs/plugin-react": "^6.0.5",
|
|
79
|
+
"license-checker-rseidelsohn": "^5.0.1",
|
|
80
|
+
"tailwindcss": "^4.3.3",
|
|
81
|
+
"tsup": "^8.5.1",
|
|
82
|
+
"tsx": "^4.23.10",
|
|
83
|
+
"vite": "^8.2.1"
|
|
84
|
+
}
|
|
85
|
+
}
|