tazuna 0.15.0 → 0.17.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * WinForms Designer.vb の要約(UI サマリー)。
2
+ * WinForms Designer.vb / Designer.cs の要約(UI サマリー)。
3
3
  *
4
4
  * デザイナー自動生成コード(InitializeComponent)を軽量解析し、
5
5
  * 「どんなコントロールが何という名前で存在し、表示テキストは何か、
@@ -10,6 +10,11 @@
10
10
  * VB の完全な構文解析は行わない(行単位の正規表現マッチ)。
11
11
  * 解析できない行は無視する。要約である以上、取りこぼしは許容し、
12
12
  * 原文が必要な場合は Designer 原文を含めるオプション側で対応する。
13
+ *
14
+ * C# の Designer.cs(tazuna 0.17.0〜。parseDesignerCs)も同じ形で要約する。`this.` の有無(.NET 6 以降の
15
+ * デザイナーは付けない)と、型名を前に書く宣言の違いだけを吸収する。C# はイベントの結び付け
16
+ * (`this.btnSave.Click += new System.EventHandler(this.btnSave_Click);`)が Designer.cs にあり、
17
+ * VB の Handles 句のように本体のコードからは見えないため、イベントとハンドラー名も要約に入れる。
13
18
  */
14
19
  /** メンバー宣言: Friend WithEvents btnSave As System.Windows.Forms.Button */
15
20
  const DECLARATION = /^\s*(?:Friend|Public|Private|Protected)(?:\s+Friend)?\s+(?:Shadows\s+)?(?:WithEvents\s+)?([A-Za-z_]\w*)\s+As\s+([A-Za-z_][\w.]*)\s*(?:'.*)?$/;
@@ -154,8 +159,271 @@ function recordParent(parentOf, declared, parentChain, children) {
154
159
  export function renderDesignerControlLines(controls, depth = 0, lines = []) {
155
160
  for (const control of controls) {
156
161
  const textPart = control.text === undefined ? "" : ` — Text "${control.text}"`;
157
- lines.push(`${" ".repeat(depth)}- ${control.name}: ${control.typeName}${textPart}`);
162
+ const eventsPart = control.events === undefined || control.events.length === 0 ? "" : ` — イベント ${formatDesignerEvents(control.events)}`;
163
+ lines.push(`${" ".repeat(depth)}- ${control.name}: ${control.typeName}${textPart}${eventsPart}`);
158
164
  renderDesignerControlLines(control.children, depth + 1, lines);
159
165
  }
160
166
  return lines;
161
167
  }
168
+ /** イベントの一覧を「Click → btnSave_Click, Enter → txt_Enter」の形にする */
169
+ export function formatDesignerEvents(events) {
170
+ return events.map((e) => `${e.event} → ${e.handler}`).join(", ");
171
+ }
172
+ // ---------------------------------------------------------------------------
173
+ // C# の Designer.cs(tazuna 0.17.0〜)
174
+ // ---------------------------------------------------------------------------
175
+ /** フィールド宣言: private System.Windows.Forms.Button btnSave; / private Button btnSave; */
176
+ const CS_DECLARATION = /^\s*(?:(?:private|internal|public|protected)\s+)+(?:readonly\s+)?([A-Za-z_][\w.]*(?:<[\w.,\s<>]*>)?)\s+([A-Za-z_]\w*)\s*(?:=\s*null\s*)?;/;
177
+ /** C# の文字列リテラル("..." のエスケープ付き、または @"..." の逐語的文字列) */
178
+ const CS_STRING = String.raw `(?:"((?:[^"\\]|\\.)*)"|@"((?:[^"]|"")*)")`;
179
+ /** コントロールの Text 代入: this.btnSave.Text = "保存"; / btnSave.Text = "保存"; */
180
+ const CS_CONTROL_TEXT = new RegExp(String.raw `^\s*(?:this\.)?([A-Za-z_]\w*)\.Text\s*=\s*${CS_STRING}\s*;`);
181
+ /** フォーム自身の Text 代入: this.Text = "受注入力"; / Text = "受注入力"; */
182
+ const CS_FORM_TEXT = new RegExp(String.raw `^\s*(?:this\.)?Text\s*=\s*${CS_STRING}\s*;`);
183
+ /** 入れ子: this.pnlHeader.Controls.Add(this.lblCustomer); / Controls.Add(btnSave); */
184
+ const CS_CONTROLS_ADD = /^\s*(?:this\.)?(?:([A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*?)\.)?Controls\.Add\(\s*(?:this\.)?([A-Za-z_]\w*)\s*\)\s*;/;
185
+ /** 一括追加: this.mnuMain.Items.AddRange(new ToolStripItem[] { this.mnuFile, this.mnuEdit }); */
186
+ const CS_ADD_RANGE = /^\s*(?:this\.)?(?:([A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*?)\.)?(?:Controls|Items|DropDownItems)\.AddRange\([^{]*\{([^}]*)\}/;
187
+ /**
188
+ * イベントの結び付け: this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
189
+ * / btnSave.Click += btnSave_Click; / this.Load += new System.EventHandler(this.OrderForm_Load);
190
+ */
191
+ const CS_EVENT = /^\s*(?:this\.)?(?:([A-Za-z_]\w*)\.)?([A-Za-z_]\w*)\s*\+=\s*(?:new\s+[A-Za-z_][\w.<>]*\s*\(\s*)?(?:this\.)?([A-Za-z_]\w*)\s*\)?\s*;/;
192
+ /** partial class OrderForm */
193
+ const CS_CLASS_NAME = /\bclass\s+([A-Za-z_]\w*)/;
194
+ function unescapeCsString(regular, verbatim) {
195
+ if (verbatim !== undefined) {
196
+ return verbatim.replace(/""/g, '"');
197
+ }
198
+ return (regular ?? "").replace(/\\(u[0-9a-fA-F]{4}|.)/g, (_, c) => {
199
+ if (c.length === 5) {
200
+ return String.fromCharCode(Number.parseInt(c.slice(1), 16));
201
+ }
202
+ switch (c) {
203
+ case "n":
204
+ return "\n";
205
+ case "r":
206
+ return "\r";
207
+ case "t":
208
+ return "\t";
209
+ case "0":
210
+ return "\0";
211
+ default:
212
+ return c;
213
+ }
214
+ });
215
+ }
216
+ /**
217
+ * 文字列・文字リテラルの外の ( と ) の数の差(複数行にまたがる AddRange をつなぐため)。
218
+ * // のコメントは数えない
219
+ */
220
+ function parenDepthDelta(line) {
221
+ let depth = 0;
222
+ for (let i = 0; i < line.length; i += 1) {
223
+ const c = line[i];
224
+ if (c === "/" && line[i + 1] === "/") {
225
+ break;
226
+ }
227
+ if (c === "@" && line[i + 1] === '"') {
228
+ i += 2;
229
+ while (i < line.length && !(line[i] === '"' && line[i + 1] !== '"')) {
230
+ i += line[i] === '"' ? 2 : 1;
231
+ }
232
+ continue;
233
+ }
234
+ if (c === '"' || c === "'") {
235
+ i += 1;
236
+ while (i < line.length && line[i] !== c) {
237
+ i += line[i] === "\\" ? 2 : 1;
238
+ }
239
+ continue;
240
+ }
241
+ if (c === "(") {
242
+ depth += 1;
243
+ }
244
+ else if (c === ")") {
245
+ depth -= 1;
246
+ }
247
+ }
248
+ return depth;
249
+ }
250
+ /** 括弧が閉じるまでの行を 1 行につなぐ(VS は AddRange の要素を 1 つずつ改行して書く) */
251
+ function joinCsStatements(source) {
252
+ const out = [];
253
+ let pending;
254
+ let depth = 0;
255
+ for (const raw of source.split(/\r?\n/)) {
256
+ const trimmed = raw.trim();
257
+ if (pending === undefined) {
258
+ if (trimmed.startsWith("//")) {
259
+ continue;
260
+ }
261
+ depth = parenDepthDelta(raw);
262
+ if (depth > 0) {
263
+ pending = raw;
264
+ }
265
+ else {
266
+ out.push(raw);
267
+ }
268
+ continue;
269
+ }
270
+ if (trimmed.startsWith("//")) {
271
+ continue;
272
+ }
273
+ pending += ` ${trimmed}`;
274
+ depth += parenDepthDelta(raw);
275
+ if (depth <= 0) {
276
+ out.push(pending);
277
+ pending = undefined;
278
+ }
279
+ }
280
+ if (pending !== undefined) {
281
+ out.push(pending);
282
+ }
283
+ return out;
284
+ }
285
+ /**
286
+ * Designer.cs のソースを要約する(parseDesignerVb と同じ形)。
287
+ * コントロールのフィールド宣言が 1 件も見つからなければ controlCount = 0 を返す
288
+ */
289
+ export function parseDesignerCs(source) {
290
+ let className;
291
+ let formText;
292
+ const declared = new Map();
293
+ const parentOf = new Map();
294
+ const formEvents = [];
295
+ /** 宣言より前に出てくる Text・イベント(C# はフィールド宣言がファイルの末尾にある) */
296
+ const texts = new Map();
297
+ const events = [];
298
+ for (const line of joinCsStatements(source)) {
299
+ const trimmed = line.trimStart();
300
+ if (trimmed.startsWith("[") || trimmed.startsWith("#")) {
301
+ continue;
302
+ }
303
+ if (className === undefined) {
304
+ const classMatch = CS_CLASS_NAME.exec(line);
305
+ if (classMatch !== null && !/^\s*\/\//.test(line)) {
306
+ className = classMatch[1] ?? "";
307
+ }
308
+ }
309
+ const declaration = CS_DECLARATION.exec(line);
310
+ if (declaration !== null) {
311
+ const typeName = declaration[1] ?? "";
312
+ const name = declaration[2] ?? "";
313
+ if (name !== "components" && !isInfrastructureType(typeName)) {
314
+ declared.set(name, { typeName: shortenTypeName(typeName), events: [] });
315
+ }
316
+ continue;
317
+ }
318
+ // this.Text(フォーム自身)を先に見る(CS_CONTROL_TEXT は this をコントロール名として読めてしまう)
319
+ const formTextMatch = CS_FORM_TEXT.exec(line);
320
+ if (formTextMatch !== null) {
321
+ if (formText === undefined) {
322
+ formText = unescapeCsString(formTextMatch[1], formTextMatch[2]);
323
+ }
324
+ continue;
325
+ }
326
+ const controlText = CS_CONTROL_TEXT.exec(line);
327
+ if (controlText !== null) {
328
+ const name = controlText[1] ?? "";
329
+ if (name !== "this" && !texts.has(name)) {
330
+ texts.set(name, unescapeCsString(controlText[2], controlText[3]));
331
+ }
332
+ continue;
333
+ }
334
+ const add = CS_CONTROLS_ADD.exec(line);
335
+ if (add !== null) {
336
+ const parent = add[1] === "this" ? undefined : add[1];
337
+ recordParentLater(parentOf, parent, [add[2] ?? ""]);
338
+ continue;
339
+ }
340
+ const addRange = CS_ADD_RANGE.exec(line);
341
+ if (addRange !== null) {
342
+ const parent = addRange[1] === "this" ? undefined : addRange[1];
343
+ const children = (addRange[2] ?? "")
344
+ .split(",")
345
+ .map((part) => part.trim().replace(/^this\./, ""))
346
+ .filter((part) => /^[A-Za-z_]\w*$/.test(part));
347
+ recordParentLater(parentOf, parent, children);
348
+ continue;
349
+ }
350
+ const event = CS_EVENT.exec(line);
351
+ if (event !== null) {
352
+ events.push({
353
+ control: event[1] === "this" ? undefined : event[1],
354
+ event: { event: event[2] ?? "", handler: event[3] ?? "" },
355
+ });
356
+ }
357
+ }
358
+ for (const [name, text] of texts) {
359
+ const entry = declared.get(name);
360
+ if (entry !== undefined && entry.text === undefined) {
361
+ entry.text = text;
362
+ }
363
+ }
364
+ for (const { control, event } of events) {
365
+ if (control === undefined) {
366
+ formEvents.push(event);
367
+ continue;
368
+ }
369
+ declared.get(control)?.events.push(event);
370
+ }
371
+ // 親の名前を宣言済みのコントロールへ解決する(SplitContainer1.Panel1 は先頭の要素へ寄せる)
372
+ const resolvedParentOf = new Map();
373
+ for (const [child, chain] of parentOf) {
374
+ let parentName;
375
+ if (chain !== undefined) {
376
+ if (declared.has(chain)) {
377
+ parentName = chain;
378
+ }
379
+ else {
380
+ const firstSegment = chain.split(".")[0] ?? "";
381
+ parentName = declared.has(firstSegment) ? firstSegment : undefined;
382
+ }
383
+ }
384
+ if (child !== parentName) {
385
+ resolvedParentOf.set(child, parentName);
386
+ }
387
+ }
388
+ const nodes = new Map();
389
+ for (const [name, entry] of declared) {
390
+ const node = { name, typeName: entry.typeName, children: [] };
391
+ if (entry.text !== undefined) {
392
+ node.text = entry.text;
393
+ }
394
+ if (entry.events.length > 0) {
395
+ node.events = entry.events;
396
+ }
397
+ nodes.set(name, node);
398
+ }
399
+ const rootControls = [];
400
+ for (const [name, node] of nodes) {
401
+ const parentName = resolvedParentOf.get(name);
402
+ const parent = parentName === undefined ? undefined : nodes.get(parentName);
403
+ if (parent !== undefined && parent !== node) {
404
+ parent.children.push(node);
405
+ }
406
+ else {
407
+ rootControls.push(node);
408
+ }
409
+ }
410
+ const summary = { rootControls, controlCount: declared.size };
411
+ if (className !== undefined) {
412
+ summary.className = className;
413
+ }
414
+ if (formText !== undefined) {
415
+ summary.formText = formText;
416
+ }
417
+ if (formEvents.length > 0) {
418
+ summary.formEvents = formEvents;
419
+ }
420
+ return summary;
421
+ }
422
+ /** 親の候補を記録する(C# は宣言が後ろにあるため、名前の解決は最後に行う)。既に親が付いた子は上書きしない */
423
+ function recordParentLater(parentOf, parentChain, children) {
424
+ for (const child of children) {
425
+ if (!parentOf.has(child)) {
426
+ parentOf.set(child, parentChain);
427
+ }
428
+ }
429
+ }
@@ -0,0 +1,297 @@
1
+ /**
2
+ * .vbproj のビルド環境の要約(<environment>。手順文 v10、2026-11-02)。
3
+ *
4
+ * パックには .vbproj 本体が入らないため、AI には Visual Basic の言語の版・.NET Framework の版・
5
+ * Option の設定・参照が見えなかった。VS2013 世代(Visual Basic 12.0)では文字列補間 $"..."・
6
+ * NameOf・?. がビルドエラーになるのに、手順文は「Option Strict On を前提に」と決め打ちだった
7
+ * (2026-10-26 の手順文の見直しの改善候補 1、設計書 §25.7)。
8
+ *
9
+ * 値は静的に読んだもの(parseVbproj の environment)をそのまま載せる。言語の版の指定
10
+ * (LangVersion)が無い旧スタイルのプロジェクトだけは、ToolsVersion の Visual Studio の既定の版と
11
+ * 「みなす」と明記して上限を書く(推測したことを宣言する。原則 3)。新しい Visual Studio で
12
+ * ビルドしていても古い構文は通るため、低い方に倒して困ることはない。
13
+ *
14
+ * C# の .csproj(tazuna 0.17.0〜)も同じ形で載せる。言語の版は、LangVersion が無ければ旧スタイルは
15
+ * ToolsVersion の Visual Studio の既定、SDK スタイルはターゲット フレームワークの既定の版と「みなす」と明記する
16
+ * (SDK はターゲット フレームワークで既定の C# の版を決める)。VB には無い Nullable・ImplicitUsings と、
17
+ * プロジェクト全体の using(<Using Include>)を載せる。VB だけのときの出力は C# 対応の前と同じ。
18
+ *
19
+ * 純粋関数。I/O なし。
20
+ */
21
+ import { projectFilesLabel } from "../projectLanguage.js";
22
+ /** ToolsVersion → その形式を作る Visual Studio と、その既定の Visual Basic の版 */
23
+ const TOOLS_VERSIONS = {
24
+ "2.0": { studio: "Visual Studio 2005", vb: 8 },
25
+ "3.5": { studio: "Visual Studio 2008", vb: 9 },
26
+ "4.0": { studio: "Visual Studio 2010 / 2012", vb: 10, note: "古い方の Visual Studio 2010" },
27
+ "12.0": { studio: "Visual Studio 2013", vb: 12 },
28
+ "14.0": { studio: "Visual Studio 2015", vb: 14 },
29
+ "15.0": { studio: "Visual Studio 2017", vb: 15 },
30
+ current: { studio: "Visual Studio 2019 以降", vb: 16 },
31
+ };
32
+ /** 版ごとに増えた主な構文(上限より新しいものを「使えない」として挙げる。15.0 より後は細かいので載せない) */
33
+ const VB_FEATURES = [
34
+ { vb: 9, features: ["LINQ", "ラムダ式", "If 演算子", "Option Infer の型推論"] },
35
+ { vb: 10, features: ["自動実装プロパティ", "コレクション初期化子 From", "暗黙の行継続", "複数行のラムダ・Sub ラムダ"] },
36
+ { vb: 11, features: ["Async / Await", "Iterator / Yield"] },
37
+ {
38
+ vb: 14,
39
+ features: [
40
+ '文字列補間 $"..."',
41
+ "NameOf",
42
+ "Null 条件演算子 ?.",
43
+ "複数行の文字列リテラル",
44
+ "ReadOnly 自動実装プロパティ",
45
+ ],
46
+ },
47
+ { vb: 15, features: ["タプル", "2 進数リテラル &B"] },
48
+ ];
49
+ /** ToolsVersion → その形式を作る Visual Studio と、その既定の C# の版(VS2019 以降は .NET Framework の既定の 7.3) */
50
+ const CS_TOOLS_VERSIONS = {
51
+ "2.0": { studio: "Visual Studio 2005", cs: 2 },
52
+ "3.5": { studio: "Visual Studio 2008", cs: 3 },
53
+ "4.0": { studio: "Visual Studio 2010 / 2012", cs: 4, note: "古い方の Visual Studio 2010" },
54
+ "12.0": { studio: "Visual Studio 2013", cs: 5 },
55
+ "14.0": { studio: "Visual Studio 2015", cs: 6 },
56
+ "15.0": { studio: "Visual Studio 2017", cs: 7 },
57
+ current: { studio: "Visual Studio 2019 以降", cs: 7.3, note: "Visual Studio 2019 以降(.NET Framework)" },
58
+ };
59
+ /**
60
+ * 版ごとに増えた主な構文(上限より新しいものを「使えない」として挙げる。AI が書きがちなものに絞る。
61
+ * 12 より後は細かいので載せない)
62
+ */
63
+ const CS_FEATURES = [
64
+ { cs: 3, features: ["LINQ", "ラムダ式", "var", "拡張メソッド", "自動実装プロパティ", "オブジェクト初期化子"] },
65
+ { cs: 4, features: ["dynamic", "名前付き引数", "省略可能な引数"] },
66
+ { cs: 5, features: ["async / await"] },
67
+ {
68
+ cs: 6,
69
+ features: ['文字列補間 $"..."', "nameof", "Null 条件演算子 ?.", "式形式のメンバー =>", "get だけの自動実装プロパティ"],
70
+ },
71
+ { cs: 7, features: ["タプル", "out var", "is による型パターン", "ローカル関数", "2 進数リテラル 0b"] },
72
+ { cs: 7.1, features: ["default リテラル"] },
73
+ { cs: 8, features: ["switch 式", "null 許容参照型", "using 宣言", "??=", "インデックスと範囲 ^ .."] },
74
+ { cs: 9, features: ["record", "init アクセサー", "ターゲット型の new()", "トップレベル ステートメント"] },
75
+ { cs: 10, features: ["ファイル スコープの名前空間 namespace X;", "global using"] },
76
+ { cs: 11, features: ['生文字列リテラル """..."""', "required メンバー"] },
77
+ { cs: 12, features: ["プライマリ コンストラクター", "コレクション式 [...]"] },
78
+ ];
79
+ /**
80
+ * SDK スタイルで LangVersion が無いときの既定の C# の版(ターゲット フレームワークで決まる)。
81
+ * 分からないもの(MSBuild 式など)は undefined
82
+ */
83
+ function defaultCsVersionOf(framework) {
84
+ const tfm = framework.trim().toLowerCase();
85
+ const modern = /^net(\d+)\.(\d+)(?:-[a-z0-9.]+)?$/.exec(tfm);
86
+ if (modern !== null) {
87
+ const major = Number(modern[1]);
88
+ // net5.0 → C# 9、以降 1 つずつ(net10.0 → C# 14)
89
+ return major >= 5 ? major + 4 : undefined;
90
+ }
91
+ if (/^net(?:coreapp3\.\d|standard2\.1)$/.test(tfm)) {
92
+ return 8;
93
+ }
94
+ if (/^(?:net[1-4]\d*|netstandard[12]\.\d|netcoreapp[12]\.\d)$/.test(tfm) || /^v\d/.test(tfm)) {
95
+ return 7.3;
96
+ }
97
+ return undefined;
98
+ }
99
+ /** 参照・Imports を並べる上限(超えた分は件数だけ) */
100
+ const LIST_LIMIT = 40;
101
+ function formatVersion(vb) {
102
+ return Number.isInteger(vb) ? `${vb}.0` : String(vb);
103
+ }
104
+ /** C# の版の表記(7.3 / 10。整数は .0 を付けない。C# の呼び方に合わせる) */
105
+ function formatCsVersion(cs) {
106
+ return String(cs);
107
+ }
108
+ /** 上限より新しい版の構文を「14.0 以降の …、15.0 以降の …」の形で */
109
+ function unavailableFeatures(limit) {
110
+ return listUnavailable(VB_FEATURES.map((entry) => ({ version: entry.vb, features: entry.features })), limit, formatVersion);
111
+ }
112
+ function listUnavailable(table, limit, format) {
113
+ const parts = table.filter((entry) => entry.version > limit).map((entry) => {
114
+ const features = entry.features.join("・");
115
+ // 英数字で始まるときは和文との間を空ける(「11.0 以降の Async」)
116
+ return `${format(entry.version)} 以降の${/^[\x21-\x7e]/.test(features) ? " " : ""}${features}`;
117
+ });
118
+ return parts.length === 0 ? undefined : `${parts.join("、")} は使えない`;
119
+ }
120
+ function unavailableCsFeatures(limit) {
121
+ return listUnavailable(CS_FEATURES.map((entry) => ({ version: entry.cs, features: entry.features })), limit, formatCsVersion);
122
+ }
123
+ function joinLimited(values) {
124
+ if (values.length <= LIST_LIMIT) {
125
+ return values.join(", ");
126
+ }
127
+ return `${values.slice(0, LIST_LIMIT).join(", ")} ほか ${values.length - LIST_LIMIT} 件`;
128
+ }
129
+ /** 構成で値が分かれるときは併記する */
130
+ function joinValues(values) {
131
+ return values.length <= 1 ? (values[0] ?? "") : `${values.join(" / ")}(構成で分かれる)`;
132
+ }
133
+ /** Visual Basic の言語の版の行 */
134
+ function describeLanguage(source, environment) {
135
+ const numeric = environment.langVersions
136
+ .map((value) => Number.parseFloat(value))
137
+ .filter((value) => Number.isFinite(value));
138
+ if (environment.langVersions.length > 0) {
139
+ if (numeric.length === 0) {
140
+ return `${joinValues(environment.langVersions)}(LangVersion の指定)`;
141
+ }
142
+ const limit = Math.min(...numeric);
143
+ const unavailable = unavailableFeatures(limit);
144
+ const lower = environment.langVersions.length > 1 ? "。低い方に合わせる" : "";
145
+ return `${formatVersion(limit)} まで(LangVersion の指定: ${environment.langVersions.join(" / ")}${lower})${unavailable === undefined ? "" : `。${unavailable}`}`;
146
+ }
147
+ if (source.style === "sdk") {
148
+ return "SDK の既定(LangVersion の指定なし。SDK スタイルは Visual Studio 2017 以降の形式)";
149
+ }
150
+ const toolsVersion = environment.toolsVersion;
151
+ const known = toolsVersion === undefined ? undefined : TOOLS_VERSIONS[toolsVersion.toLowerCase()];
152
+ if (toolsVersion === undefined || known === undefined) {
153
+ return toolsVersion === undefined
154
+ ? "不明(ToolsVersion・LangVersion の指定なし)"
155
+ : `不明(ToolsVersion ${toolsVersion}・LangVersion の指定なし)`;
156
+ }
157
+ const unavailable = unavailableFeatures(known.vb);
158
+ return `${formatVersion(known.vb)} まで(LangVersion の指定なし。ToolsVersion ${toolsVersion} は ${known.studio} の形式のため、${known.note ?? known.studio} の既定の Visual Basic ${formatVersion(known.vb)} とみなす)${unavailable === undefined ? "" : `。${unavailable}`}`;
159
+ }
160
+ /** C# の言語の版の行 */
161
+ function describeCsLanguage(source, environment) {
162
+ const numeric = environment.langVersions
163
+ .map((value) => Number.parseFloat(value))
164
+ .filter((value) => Number.isFinite(value));
165
+ if (environment.langVersions.length > 0) {
166
+ if (numeric.length === 0) {
167
+ return `${joinValues(environment.langVersions)}(LangVersion の指定)`;
168
+ }
169
+ const limit = Math.min(...numeric);
170
+ const unavailable = unavailableCsFeatures(limit);
171
+ const lower = environment.langVersions.length > 1 ? "。低い方に合わせる" : "";
172
+ return `${formatCsVersion(limit)} まで(LangVersion の指定: ${environment.langVersions.join(" / ")}${lower})${unavailable === undefined ? "" : `。${unavailable}`}`;
173
+ }
174
+ if (source.style === "sdk") {
175
+ const defaults = environment.targetFrameworks.map(defaultCsVersionOf);
176
+ if (environment.targetFrameworks.length === 0 || defaults.some((value) => value === undefined)) {
177
+ return "SDK の既定(LangVersion の指定なし。SDK スタイルはターゲット フレームワークの既定の版になる)";
178
+ }
179
+ const limit = Math.min(...defaults);
180
+ const frameworks = environment.targetFrameworks.join(" / ");
181
+ // 英数字の後は和文との間を空ける(「net8.0 の既定」「net48 / net6.0 のうち低い方の既定」)
182
+ const which = environment.targetFrameworks.length > 1 ? `${frameworks} のうち低い方` : `${frameworks} `;
183
+ const unavailable = unavailableCsFeatures(limit);
184
+ return `${formatCsVersion(limit)} まで(LangVersion の指定なし。SDK スタイルはターゲット フレームワークの既定の版になるため、${which}の既定の C# ${formatCsVersion(limit)} とみなす)${unavailable === undefined ? "" : `。${unavailable}`}`;
185
+ }
186
+ const toolsVersion = environment.toolsVersion;
187
+ const known = toolsVersion === undefined ? undefined : CS_TOOLS_VERSIONS[toolsVersion.toLowerCase()];
188
+ if (toolsVersion === undefined || known === undefined) {
189
+ return toolsVersion === undefined
190
+ ? "不明(ToolsVersion・LangVersion の指定なし)"
191
+ : `不明(ToolsVersion ${toolsVersion}・LangVersion の指定なし)`;
192
+ }
193
+ const unavailable = unavailableCsFeatures(known.cs);
194
+ return `${formatCsVersion(known.cs)} まで(LangVersion の指定なし。ToolsVersion ${toolsVersion} は ${known.studio} の形式のため、${known.note ?? known.studio} の既定の C# ${formatCsVersion(known.cs)} とみなす)${unavailable === undefined ? "" : `。${unavailable}`}`;
195
+ }
196
+ /** C# の Nullable・ImplicitUsings の行 */
197
+ function describeCsOptions(environment) {
198
+ const lines = [];
199
+ const enabled = (values) => values.some((value) => ["enable", "true"].includes(value.trim().toLowerCase()));
200
+ if (environment.nullable.length > 0) {
201
+ lines.push(`Nullable: ${joinValues(environment.nullable)}${enabled(environment.nullable) ? "(null 許容参照型が有効。null になり得る参照型には ? を付ける)" : ""}`);
202
+ }
203
+ if (environment.implicitUsings.length > 0) {
204
+ lines.push(`ImplicitUsings: ${joinValues(environment.implicitUsings)}${enabled(environment.implicitUsings) ? "(System・System.IO・System.Linq など SDK の既定の名前空間は using を書かなくても使える)" : ""}`);
205
+ }
206
+ return lines;
207
+ }
208
+ function describeFramework(environment) {
209
+ if (environment.targetFrameworks.length === 0) {
210
+ return undefined;
211
+ }
212
+ const legacy = environment.targetFrameworks.every((value) => /^v\d/i.test(value));
213
+ return legacy
214
+ ? `.NET Framework: ${joinValues(environment.targetFrameworks)}`
215
+ : `ターゲット フレームワーク: ${joinValues(environment.targetFrameworks)}`;
216
+ }
217
+ function describeOptions(environment) {
218
+ const parts = [
219
+ ["Strict", environment.optionStrict],
220
+ ["Explicit", environment.optionExplicit],
221
+ ["Infer", environment.optionInfer],
222
+ ["Compare", environment.optionCompare],
223
+ ]
224
+ .filter(([, values]) => values.length > 0)
225
+ .map(([name, values]) => `${name} ${joinValues(values)}`);
226
+ return parts.length === 0 ? undefined : `Option: ${parts.join(" / ")}(ファイル先頭の Option 文があればそちらが優先)`;
227
+ }
228
+ function describeSource(source) {
229
+ if (source.language === "cs") {
230
+ return describeCsSource(source);
231
+ }
232
+ const head = `- ${source.label}(${source.projectPath})`;
233
+ const environment = source.environment;
234
+ if (environment === undefined) {
235
+ return [head, " - .vbproj を XML として読めなかったため不明"];
236
+ }
237
+ const lines = [
238
+ ` - 形式: ${source.style === "sdk" ? "SDK スタイル" : `旧スタイル${environment.toolsVersion === undefined ? "" : `(ToolsVersion ${environment.toolsVersion})`}`}`,
239
+ ` - Visual Basic: ${describeLanguage(source, environment)}`,
240
+ ];
241
+ const framework = describeFramework(environment);
242
+ if (framework !== undefined) {
243
+ lines.push(` - ${framework}`);
244
+ }
245
+ const options = describeOptions(environment);
246
+ if (options !== undefined) {
247
+ lines.push(` - ${options}`);
248
+ }
249
+ if (environment.rootNamespaces.length > 0) {
250
+ lines.push(` - ルート名前空間: ${joinValues(environment.rootNamespaces)}(ファイルに Namespace を書かなくても、この名前空間に入る)`);
251
+ }
252
+ if (environment.imports.length > 0) {
253
+ lines.push(` - プロジェクト全体の Imports: ${joinLimited(environment.imports)}`);
254
+ }
255
+ if (environment.references.length > 0) {
256
+ lines.push(` - 参照: ${joinLimited(environment.references)}`);
257
+ }
258
+ return [head, ...lines];
259
+ }
260
+ function describeCsSource(source) {
261
+ const head = `- ${source.label}(${source.projectPath})`;
262
+ const environment = source.environment;
263
+ if (environment === undefined) {
264
+ return [head, " - .csproj を XML として読めなかったため不明"];
265
+ }
266
+ const lines = [
267
+ ` - 形式: ${source.style === "sdk" ? "SDK スタイル" : `旧スタイル${environment.toolsVersion === undefined ? "" : `(ToolsVersion ${environment.toolsVersion})`}`}`,
268
+ ` - C#: ${describeCsLanguage(source, environment)}`,
269
+ ];
270
+ const framework = describeFramework(environment);
271
+ if (framework !== undefined) {
272
+ lines.push(` - ${framework}`);
273
+ }
274
+ lines.push(...describeCsOptions(environment).map((line) => ` - ${line}`));
275
+ if (environment.rootNamespaces.length > 0) {
276
+ lines.push(` - 既定の名前空間: ${joinValues(environment.rootNamespaces)}(C# は各ファイルの namespace 宣言で名前空間が決まる。新しいファイルには同じフォルダの既存ファイルと同じ形で namespace を書く)`);
277
+ }
278
+ if (environment.imports.length > 0) {
279
+ lines.push(` - プロジェクト全体の using(global using): ${joinLimited(environment.imports)}`);
280
+ }
281
+ if (environment.references.length > 0) {
282
+ lines.push(` - 参照: ${joinLimited(environment.references)}`);
283
+ }
284
+ return [head, ...lines];
285
+ }
286
+ /** <environment> ブロック(閉じタグまで。末尾の改行なし)。プロジェクトが無ければ undefined */
287
+ export function renderEnvironmentBlock(sources) {
288
+ if (sources.length === 0) {
289
+ return undefined;
290
+ }
291
+ return [
292
+ "<environment>",
293
+ `${projectFilesLabel(sources.map((source) => source.language ?? "vb"))} から読み取ったビルド環境(静的に読んだ値。Condition は評価せず、構成で値が分かれるときは併記):`,
294
+ ...sources.flatMap(describeSource),
295
+ "</environment>",
296
+ ].join("\n");
297
+ }