From d1b75d88c5727be9da8d1e6a3d9f323df1604589 Mon Sep 17 00:00:00 2001 From: cflmy Date: Wed, 5 Aug 2026 17:13:58 +0800 Subject: [PATCH] Polish VS Code extension: three toolbar actions and CLI checks. Add Run/View/Debug title icons, logo cover art, version/stdlib install prompts, and LiveServer for view + debug hosts. Co-authored-by: Cursor --- vscode-extension/.vscodeignore | 1 + vscode-extension/ARCHITECTURE.md | 10 +-- vscode-extension/README.md | 2 +- vscode-extension/media/icon.png | Bin 0 -> 1928 bytes vscode-extension/media/logo-source.ico | Bin 0 -> 16958 bytes vscode-extension/media/logo-source.png | Bin 0 -> 262 bytes vscode-extension/package.json | 101 ++++++++++++++++----- vscode-extension/src/cli.ts | 23 +++-- vscode-extension/src/extension.ts | 117 +++++++++++++++++++------ vscode-extension/src/install.ts | 88 ++++++++++++++++--- 10 files changed, 270 insertions(+), 72 deletions(-) create mode 100644 vscode-extension/media/icon.png create mode 100644 vscode-extension/media/logo-source.ico create mode 100644 vscode-extension/media/logo-source.png diff --git a/vscode-extension/.vscodeignore b/vscode-extension/.vscodeignore index 202b045..e5c7d28 100644 --- a/vscode-extension/.vscodeignore +++ b/vscode-extension/.vscodeignore @@ -7,3 +7,4 @@ node_modules/** **/*.map **/*.ts !out/**/*.js +media/logo-source.* diff --git a/vscode-extension/ARCHITECTURE.md b/vscode-extension/ARCHITECTURE.md index cfec5df..989dd70 100644 --- a/vscode-extension/ARCHITECTURE.md +++ b/vscode-extension/ARCHITECTURE.md @@ -46,13 +46,13 @@ path:line:col: message ## CLI 安装(扩展侧) -- 启动时(`onStartupFinished`)检测 CLI + `lib/`;缺失则提示 **Install CLI + stdlib**。 -- 从 GitHub Releases 下载推荐 zip(`marqdo.exe` + `lib/`)到扩展 `globalStorage/cli/`,并写入 `marqdo.cliPath` / `marqdo.libPath`(spawn 时带 `MARQDO_LIB`)。 -- 手动命令:`Marqdo: Install / Repair CLI`、`Marqdo: Check CLI Status`。 -- 当前自动安装预编译包以 **Windows x64** 为主(与现有 Release 资产一致);其它平台无匹配资产时会提示打开 Releases。 +- 启动时(`onStartupFinished`)检测:**CLI 是否存在**、**版本是否 ≥ `marqdo.minCliVersion`(默认 0.1.0)**、**stdlib (`lib/`) 是否可用**。 +- 任一不满足 → 提示用户,由其选择安装 / 打开 Releases / 不再询问。 +- 安装物落到扩展 `globalStorage/cli/`,并写入 `marqdo.cliPath` / `marqdo.libPath`(spawn 时带 `MARQDO_LIB`)。 +- 命令:`Marqdo: Install / Repair CLI`、`Marqdo: Check CLI Status`。 +- 预编译自动安装以 **Windows x64** Release zip 为主。 ## 调试(P3 → 现有入口) - - **已落地**:命令 `Marqdo: Open Debugger` 子进程启动 `marqdo debug --no-open`,再打开浏览器 / Simple Browser。 - **中期**:DAP 适配器包装现有 debug session API(`src/view/debug_api.rs` 语义),避免第三套断点模型。 diff --git a/vscode-extension/README.md b/vscode-extension/README.md index 09f9ed9..3fd863f 100644 --- a/vscode-extension/README.md +++ b/vscode-extension/README.md @@ -2,7 +2,7 @@ | | | |---|---| -| 状态 | **P0 高亮 + P1 Run/Problems + 轻量 Debug 入口**(伴随 Marqdo **v0.1.0**) | +| 状态 | **三按钮 Run / View / Debug + CLI 检测**(扩展 v0.0.5;封面 logo;需 CLI ≥ **0.1.0**) | | 日期 | 2026-08-05 | | 语言仓 | [`cflmy/marqdo`](https://github.com/cflmy/marqdo) `main` | | 扩展仓形态 | **同仓库专用分支** `vscode-extension`(本目录);`main` **不跟踪**本目录 | diff --git a/vscode-extension/media/icon.png b/vscode-extension/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3621a237adffe201135245540f43294ca77024b7 GIT binary patch literal 1928 zcmah~`8%827XH43(2AjY5mb#av{luFXpo?3Wk3mSLnqUzI;}D8QG}+|Rty)XG;|;_ z$E~YXTBH+|ZJ#^+Vt7;5ULk;&k{RhquYprLkz1F+eUeDh9P4)C}RoNzaxmTGgXVZX^2#qvXlLO3eYnT+)!Nn!mJ^A5RM{s?3P za=KZo-}zGiWzw>UQY+2AAxUg1;~VXQi#|1r z-1{A*BKV8L-1B$roMLIQr~WZpvb5%A#FgG5PhpOmh8Dgbtv_dFW53f}n~mYUZgIh1 z5c&w4iW$T5>h4y0UIgElZbk)vU=uACepGH;oPyw1siSTV&O(NeB5W=W=T_&^881&l zIpIQI_8qVR;k`?Xf+I`GJPMDNpPU5#VyiJGRVWQY+xZDy0|__gvXdUiJPp}&L{q!tS>52LW3G6Mf z-};$6U$qr!h>6S9dsOsFcM*!IDI~oD+_vT&OV~IQH>buLowTMJ@Kj(Gm|u{NHN7Pe zSgbSR-2xMiTw&iuT?S0UB{FwW&u}AMMb{r~8wxfc-3oSO+#}WlXF3@0o`M~Fgwk+$ zm52c+t(Rl2U#XD3Ob`Pns1?+U&K)}bEt8;N6Smx%cSD^g^F)kO2Rqa2Jh#-%Fqm9>FO3~j2YV}2Mk`kL^-x|rnoj$sx)(g!| zyuneV4sbbd+B|8*qBppoMI$|C_?2wZhJ&7S#}ZA{&-~YNT~yCeqy8H z^PY(2d8M+;Ci_w@6BVLT?cxVJZSc>%&-8X~=Rwz~Hd`9{B`b&XPH9)$8Qu6P5lU^( zYg^PWB73F4g8^ygu5p9y>kO;e6?6X4E&$sW^WBbfF-3a-ruO2*K$q`L#gXy*?(f|1 z>gEkdM7D1~f8^d?oJp!pst5E084tl}_@Un>7pfkikHf|vm7(&yEn3YY_8ET6h`D`* z*)g{;nd3M6!Iz4d&V+rw`zkppJ73G6)oa#Whx$E}A)ZK=UBxJbn0i|0-&nxU@W{;1 zADxxFnThr^9w>=pqYIIN1jF*&8Nr{d!<PNoFx8?zR37O;g&%uM51_mM&A%_!Qeh9NZoIgKWl{HBNoX zyww)Hpa8W>fJaW|6(YZ+k83~3k{wc9JD($wy^kh&-Zq3s61R`fG#d{u-0VxFH%&Zv z!D{-`UUF1QYh>kG{U^mk7jwM_Cf3N~%ZS;ctv*Tq%{!oETPre^5k=E)E97MtHgm6z5EzT#DT=Q+<7lkttK_h7fsA3;ohIi&V42Yu8qw z?>ib{P%gDh%_qc9K0J0-eHtb4A)>u9PjHPLMbQWKCn~BcxPjLc=>Z8vR|!S$rsSyz z&bCg+v)pcQ+rnfs%Wzz^Y^JD)6*L5GJqP7nAL}zg!|O`RT@_FUxXg%SJ+!`|&_N(3 zjhi7lqWG&&o`YkGbe;Tmw_N9;>5_Q#ooHw{ylkUVm>&%;GA2W z7&*1rTUXn^Cl5``2d5XDbBh!EE{C(9kh)tyuhaCv(FQkU5z9I8HKgtq&}%h4aJ0b< zS;R`5c#e5pem;VuiTU7YfpczgVtEd{gn3;l?>FOUVm{B;_UI%JUc%bEQvDurG#T3R zd~Kg9mKt~o=~p@*5l55Z|F|^&_4kV(E#Cq)wb;^o?_96h?t-`6OHD1d^xiwyYqq=K zE%)}+wDjLI7wv|&;EB~edur-B@1KSCe10F#_qi(0^Y{@s+6`@aUfQS3N@YAg?7!KyvC0f=X+{e`tO;G_Wb?(cxjI=&f!Nwv>V#;d~Kg9mKykx z(9d`z-CJq(^N-kXHAios5i|Qcdv$MB=e3O3Z#9Sd$N@PZ2jqYpkOOi+4#)vHAP3}t z9FPP5r~}jRWyYF_98VWzkI!%Swq0=gNIb_p@BNaO@Zs(nPu3)^)BKG6r%U}`e4kGq ar-Tpp*GN3ac+Xr1o@VxSKIXj~4}wqc+`E4O literal 0 HcmV?d00001 diff --git a/vscode-extension/media/logo-source.png b/vscode-extension/media/logo-source.png new file mode 100644 index 0000000000000000000000000000000000000000..922d14fb980e8966ac26195ebd6fc6ac7f935a1f GIT binary patch literal 262 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=jKx9jP7LeL$-D$|4tTmahE&XX zd()At!GOo*V%VPlQ%e^sxVjWxGCNam9or(Mel$rFs1T^sSMg#aR$h@2cP*nwU%j+%L3PKmt@hi}(9 z&J*~}a>G1fnxMqD@{@Lq-`W-H`d(d|IJuS??4*YIvLX-p!UC*+d4c$zu6{1-oD!M< DP-JCX literal 0 HcmV?d00001 diff --git a/vscode-extension/package.json b/vscode-extension/package.json index 5a714da..cee7a09 100644 --- a/vscode-extension/package.json +++ b/vscode-extension/package.json @@ -2,8 +2,9 @@ "name": "marqdo", "displayName": "Marqdo", "description": "Language support for Marqdo (.mq.md) — code as documentation.", - "version": "0.0.3", + "version": "0.0.5", "publisher": "cflmy", + "icon": "media/icon.png", "repository": { "type": "git", "url": "https://github.com/cflmy/marqdo.git" @@ -55,57 +56,93 @@ "commands": [ { "command": "marqdo.run", - "title": "Marqdo: Run File", - "category": "Marqdo" + "title": "Run File", + "shortTitle": "Run", + "category": "Marqdo", + "icon": "$(play)" + }, + { + "command": "marqdo.view", + "title": "Open View", + "shortTitle": "View", + "category": "Marqdo", + "icon": "$(open-preview)" }, { "command": "marqdo.debug", - "title": "Marqdo: Open Debugger", - "category": "Marqdo" + "title": "Open Debugger", + "shortTitle": "Debug", + "category": "Marqdo", + "icon": "$(debug-alt)" + }, + { + "command": "marqdo.view.stop", + "title": "Stop View", + "category": "Marqdo", + "icon": "$(close)" }, { "command": "marqdo.debug.stop", - "title": "Marqdo: Stop Debugger", - "category": "Marqdo" + "title": "Stop Debugger", + "shortTitle": "Stop Debug", + "category": "Marqdo", + "icon": "$(debug-stop)" }, { "command": "marqdo.catalog", - "title": "Marqdo: Generate Catalog", - "category": "Marqdo" + "title": "Generate Catalog", + "category": "Marqdo", + "icon": "$(book)" }, { "command": "marqdo.showOutput", - "title": "Marqdo: Show Output", - "category": "Marqdo" + "title": "Show Output", + "category": "Marqdo", + "icon": "$(output)" }, { "command": "marqdo.installCli", - "title": "Marqdo: Install / Repair CLI", - "category": "Marqdo" + "title": "Install / Repair CLI", + "category": "Marqdo", + "icon": "$(cloud-download)" }, { "command": "marqdo.checkCli", - "title": "Marqdo: Check CLI Status", - "category": "Marqdo" + "title": "Check CLI Status", + "category": "Marqdo", + "icon": "$(info)" } ], "menus": { "editor/title": [ { "command": "marqdo.run", - "when": "resourceFilename =~ /\\.mq\\.md$/ || editorLangId == marqdo", - "group": "navigation@1" + "when": "editorLangId == marqdo || resourceFilename =~ /\\.mq\\.md$/", + "group": "navigation@90" + }, + { + "command": "marqdo.view", + "when": "editorLangId == marqdo || resourceFilename =~ /\\.mq\\.md$/", + "group": "navigation@91" }, { "command": "marqdo.debug", - "when": "resourceFilename =~ /\\.mq\\.md$/ || editorLangId == marqdo", - "group": "navigation@2" + "when": "editorLangId == marqdo || resourceFilename =~ /\\.mq\\.md$/", + "group": "navigation@92" } ], "commandPalette": [ { "command": "marqdo.run", "when": "editorLangId == marqdo || resourceFilename =~ /\\.mq\\.md$/" + }, + { + "command": "marqdo.view", + "when": "editorLangId == marqdo || resourceFilename =~ /\\.mq\\.md$/" + }, + { + "command": "marqdo.debug", + "when": "editorLangId == marqdo || resourceFilename =~ /\\.mq\\.md$/" } ] }, @@ -138,7 +175,12 @@ "marqdo.autoInstall.checkOnStartup": { "type": "boolean", "default": true, - "description": "On startup, detect missing CLI/stdlib and offer one-click install from GitHub Releases." + "description": "On startup, detect missing/outdated CLI or missing stdlib and offer install from GitHub Releases." + }, + "marqdo.minCliVersion": { + "type": "string", + "default": "0.1.0", + "description": "Minimum required Marqdo CLI version (semver). Older installs trigger an upgrade prompt." }, "marqdo.diagnoseOnSave": { "type": "boolean", @@ -150,6 +192,25 @@ "default": 60000, "description": "Timeout for `marqdo run` / diagnose (milliseconds)." }, + "marqdo.viewHost": { + "type": "string", + "default": "127.0.0.1", + "description": "Host for `marqdo view`." + }, + "marqdo.viewPort": { + "type": "number", + "default": 7429, + "description": "Port for `marqdo view`." + }, + "marqdo.viewOpen": { + "type": "string", + "enum": [ + "external", + "simpleBrowser" + ], + "default": "external", + "description": "How to open the view UI after starting the server." + }, "marqdo.debugHost": { "type": "string", "default": "127.0.0.1", diff --git a/vscode-extension/src/cli.ts b/vscode-extension/src/cli.ts index f10455c..0bdf177 100644 --- a/vscode-extension/src/cli.ts +++ b/vscode-extension/src/cli.ts @@ -129,28 +129,37 @@ export function probeMarqdo( } } -export class DebugServer { +export class LiveServer { private proc: ChildProcessWithoutNullStreams | null = null; private output: vscode.OutputChannel; + private label: string; - constructor(output: vscode.OutputChannel) { + constructor(output: vscode.OutputChannel, label: string) { this.output = output; + this.label = label; } get running(): boolean { return this.proc !== null && this.proc.exitCode === null; } - async start(targetPath: string, host: string, port: number): Promise { + async start( + subcommand: "view" | "debug", + targetPath: string, + host: string, + port: number + ): Promise { if (this.running) { await this.stop(); } const cli = resolveMarqdoCli(); const cwd = workspaceCwd(vscode.Uri.file(targetPath)); - this.output.appendLine(`$ ${cli} debug ${targetPath} --host ${host} --port ${port} --no-open`); + this.output.appendLine( + `$ ${cli} ${subcommand} ${targetPath} --host ${host} --port ${port} --no-open` + ); this.proc = spawn( cli, - ["debug", targetPath, "--host", host, "--port", String(port), "--no-open"], + [subcommand, targetPath, "--host", host, "--port", String(port), "--no-open"], { cwd, shell: process.platform === "win32", @@ -161,11 +170,11 @@ export class DebugServer { this.proc.stdout.on("data", (d: Buffer) => this.output.append(d.toString())); this.proc.stderr.on("data", (d: Buffer) => this.output.append(d.toString())); this.proc.on("exit", (code) => { - this.output.appendLine(`[debug] exited (${code})`); + this.output.appendLine(`[${this.label}] exited (${code})`); this.proc = null; }); this.proc.on("error", (err) => { - this.output.appendLine(`[debug] ${err.message}`); + this.output.appendLine(`[${this.label}] ${err.message}`); this.proc = null; }); await new Promise((r) => setTimeout(r, 600)); diff --git a/vscode-extension/src/extension.ts b/vscode-extension/src/extension.ts index da9a3d8..c248f6a 100644 --- a/vscode-extension/src/extension.ts +++ b/vscode-extension/src/extension.ts @@ -1,5 +1,5 @@ import * as vscode from "vscode"; -import { DebugServer, configureCliResolution, runMarqdo, workspaceCwd } from "./cli"; +import { LiveServer, configureCliResolution, runMarqdo, workspaceCwd } from "./cli"; import { DiagnosticBag } from "./diagnostics"; import { checkInstallStatus, @@ -12,14 +12,16 @@ import { let output: vscode.OutputChannel; let diagnostics: DiagnosticBag; -let debugServer: DebugServer; +let viewServer: LiveServer; +let debugServer: LiveServer; let extContext: vscode.ExtensionContext; export function activate(context: vscode.ExtensionContext): void { extContext = context; output = vscode.window.createOutputChannel("Marqdo"); diagnostics = new DiagnosticBag(); - debugServer = new DebugServer(output); + viewServer = new LiveServer(output, "view"); + debugServer = new LiveServer(output, "debug"); configureCliResolution( context, @@ -31,12 +33,17 @@ export function activate(context: vscode.ExtensionContext): void { output, diagnostics.disposable, vscode.commands.registerCommand("marqdo.run", () => runActiveFile()), + vscode.commands.registerCommand("marqdo.view", () => startView()), vscode.commands.registerCommand("marqdo.debug", () => startDebug()), vscode.commands.registerCommand("marqdo.debug.stop", () => stopDebug()), + vscode.commands.registerCommand("marqdo.view.stop", () => stopView()), vscode.commands.registerCommand("marqdo.catalog", () => runCatalog()), vscode.commands.registerCommand("marqdo.showOutput", () => output.show(true)), vscode.commands.registerCommand("marqdo.installCli", () => installCli()), - vscode.commands.registerCommand("marqdo.checkCli", () => checkCli()), + vscode.commands.registerCommand("marqdo.checkCli", () => checkCli()) + ); + + context.subscriptions.push( vscode.workspace.onDidSaveTextDocument((doc) => { if (doc.languageId === "marqdo" && autoDiagnose()) { void diagnoseDocument(doc); @@ -48,6 +55,7 @@ export function activate(context: vscode.ExtensionContext): void { } export function deactivate(): void { + void viewServer?.stop(); void debugServer?.stop(); } @@ -59,11 +67,8 @@ async function installCli(): Promise { await resetSkipPrompt(extContext); const status = checkInstallStatus(extContext); try { - if (status.cliOk && !status.libOk) { - await installFromGitHub(extContext, output, "stdlib"); - } else { - await installFromGitHub(extContext, output, "bundle"); - } + const mode = status.suggestedMode ?? "bundle"; + await installFromGitHub(extContext, output, mode); } catch (e) { const err = e instanceof Error ? e.message : String(e); output.appendLine(`[install] ${err}`); @@ -77,8 +82,10 @@ async function installCli(): Promise { async function checkCli(): Promise { const status = checkInstallStatus(extContext); output.appendLine(`[check] ${status.detail}`); - if (status.cliOk && status.libOk) { - void vscode.window.showInformationMessage(`Marqdo ready: ${status.version}`); + if (status.cliOk && status.versionOk && status.libOk) { + void vscode.window.showInformationMessage( + `Marqdo ready: ${status.parsedVersion ?? status.version} (≥ ${status.requiredVersion}), stdlib OK` + ); return; } const choice = await vscode.window.showWarningMessage( @@ -106,21 +113,53 @@ function activeMqDoc(): vscode.TextDocument | undefined { async function ensureCliOrOfferInstall(): Promise { const status = checkInstallStatus(extContext); - if (status.cliOk) { + if (status.cliOk && status.versionOk && status.libOk) { return true; } - const choice = await vscode.window.showWarningMessage( - "Marqdo CLI not found. Install the official release (includes stdlib)?", - "Install", - "Cancel" - ); + if (status.cliOk && status.versionOk && !status.libOk) { + const choice = await vscode.window.showWarningMessage( + "Standard library (lib/) is missing. Continue anyway, or install stdlib?", + "Install stdlib", + "Continue", + "Cancel" + ); + if (choice === "Install stdlib") { + await installCli(); + return true; + } + if (choice === "Continue") { + return true; + } + return false; + } + const label = !status.cliOk + ? "Marqdo CLI not found. Install the official release (includes stdlib)?" + : `Marqdo CLI is below ${status.requiredVersion}. Upgrade now?`; + const choice = await vscode.window.showWarningMessage(label, "Install", "Cancel"); if (choice === "Install") { await installCli(); - return checkInstallStatus(extContext).cliOk; + const again = checkInstallStatus(extContext); + return again.cliOk && again.versionOk; } return false; } +function resolveTargetPath(): string | undefined { + const doc = activeMqDoc(); + const folder = vscode.workspace.workspaceFolders?.[0]; + return doc?.uri.fsPath ?? folder?.uri.fsPath; +} + +async function openUrl(url: string, settingKey: "viewOpen" | "debugOpen"): Promise { + const open = + vscode.workspace.getConfiguration("marqdo").get(settingKey) ?? "external"; + if (open === "simpleBrowser") { + await vscode.commands.executeCommand("simpleBrowser.show", url); + } else { + await vscode.env.openExternal(vscode.Uri.parse(url)); + } +} + async function runActiveFile(): Promise { if (!(await ensureCliOrOfferInstall())) { return; @@ -168,13 +207,35 @@ async function diagnoseDocument(doc: vscode.TextDocument): Promise { } } +async function startView(): Promise { + if (!(await ensureCliOrOfferInstall())) { + return; + } + const target = resolveTargetPath(); + if (!target) { + void vscode.window.showWarningMessage("Open a folder or .mq.md file for view."); + return; + } + const cfg = vscode.workspace.getConfiguration("marqdo"); + const host = cfg.get("viewHost") ?? "127.0.0.1"; + const port = cfg.get("viewPort") ?? 7429; + output.show(true); + try { + const url = await viewServer.start("view", target, host, port); + await openUrl(url, "viewOpen"); + void vscode.window.setStatusBarMessage(`Marqdo view: ${url}`, 5000); + } catch (e) { + void vscode.window.showErrorMessage( + `Marqdo view failed: ${e instanceof Error ? e.message : String(e)}` + ); + } +} + async function startDebug(): Promise { if (!(await ensureCliOrOfferInstall())) { return; } - const doc = activeMqDoc(); - const folder = vscode.workspace.workspaceFolders?.[0]; - const target = doc?.uri.fsPath ?? folder?.uri.fsPath; + const target = resolveTargetPath(); if (!target) { void vscode.window.showWarningMessage("Open a folder or .mq.md file to debug."); return; @@ -184,13 +245,8 @@ async function startDebug(): Promise { const port = cfg.get("debugPort") ?? 7430; output.show(true); try { - const url = await debugServer.start(target, host, port); - const open = cfg.get("debugOpen") ?? "external"; - if (open === "simpleBrowser") { - await vscode.commands.executeCommand("simpleBrowser.show", url); - } else { - await vscode.env.openExternal(vscode.Uri.parse(url)); - } + const url = await debugServer.start("debug", target, host, port); + await openUrl(url, "debugOpen"); void vscode.window.setStatusBarMessage(`Marqdo debug: ${url}`, 5000); } catch (e) { void vscode.window.showErrorMessage( @@ -199,6 +255,11 @@ async function startDebug(): Promise { } } +async function stopView(): Promise { + await viewServer.stop(); + void vscode.window.setStatusBarMessage("Marqdo view stopped", 3000); +} + async function stopDebug(): Promise { await debugServer.stop(); void vscode.window.setStatusBarMessage("Marqdo debug stopped", 3000); diff --git a/vscode-extension/src/install.ts b/vscode-extension/src/install.ts index df62512..f4d4018 100644 --- a/vscode-extension/src/install.ts +++ b/vscode-extension/src/install.ts @@ -12,12 +12,40 @@ const MANAGED_DIR = "cli"; export type InstallStatus = { cliOk: boolean; libOk: boolean; + versionOk: boolean; version?: string; + parsedVersion?: string; + requiredVersion: string; cliPath?: string; libRoot?: string; detail: string; + /** Suggested install mode when not fully ready */ + suggestedMode?: "bundle" | "stdlib"; }; +/** Parse first semver-like token from `marqdo --version` output. */ +export function parseCliVersion(raw: string): string | undefined { + const m = raw.match(/(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)/); + return m?.[1]; +} + +/** Compare a.b.c semver (pre-release suffix ignored for ordering). Returns <0 if a Number.parseInt(x, 10) || 0); + const pb = b.split("-")[0].split(".").map((x) => Number.parseInt(x, 10) || 0); + for (let i = 0; i < 3; i++) { + const d = (pa[i] ?? 0) - (pb[i] ?? 0); + if (d !== 0) { + return d; + } + } + return 0; +} + +function requiredVersion(): string { + return cfg().get("minCliVersion")?.trim() || "0.1.0"; +} + type GhAsset = { name: string; browser_download_url: string }; type GhRelease = { tag_name: string; @@ -131,26 +159,52 @@ function stdlibPresent(cliPath: string, context?: vscode.ExtensionContext): { ok } export function checkInstallStatus(context: vscode.ExtensionContext): InstallStatus { + const need = requiredVersion(); const cliPath = resolveCliPath(context); const probe = probeMarqdo(cliPath); if (!probe.ok) { return { cliOk: false, libOk: false, + versionOk: false, + requiredVersion: need, cliPath, - detail: probe.detail, + detail: `Marqdo CLI not found (${probe.detail}). Need ≥ ${need} with stdlib.`, + suggestedMode: "bundle", }; } + const parsed = parseCliVersion(probe.version ?? ""); + const versionOk = parsed !== undefined && compareSemver(parsed, need) >= 0; const lib = stdlibPresent(cliPath, context); + + let suggestedMode: "bundle" | "stdlib" | undefined; + if (!versionOk) { + suggestedMode = "bundle"; + } else if (!lib.ok) { + suggestedMode = "stdlib"; + } + + const parts: string[] = [`CLI ${probe.version}`]; + if (!versionOk) { + parts.push(`version too old (need ≥ ${need}${parsed ? `, found ${parsed}` : ""})`); + } + if (lib.ok) { + parts.push(`stdlib at ${lib.root}`); + } else { + parts.push("stdlib missing (no lib/ next to binary / MARQDO_LIB)"); + } + return { cliOk: true, libOk: lib.ok, + versionOk, version: probe.version, + parsedVersion: parsed, + requiredVersion: need, cliPath, libRoot: lib.root, - detail: lib.ok - ? `CLI ${probe.version}; stdlib at ${lib.root}` - : `CLI ${probe.version}; stdlib missing (no lib/ next to binary, no MARQDO_LIB)`, + detail: parts.join("; "), + suggestedMode, }; } @@ -325,9 +379,13 @@ export async function installFromGitHub( const status = checkInstallStatus(context); output.appendLine(status.detail); - if (status.cliOk && status.libOk) { + if (status.cliOk && status.versionOk && status.libOk) { void vscode.window.showInformationMessage( - `Marqdo installed (${status.version}). Stdlib ready.` + `Marqdo ready (${status.parsedVersion ?? status.version}). Stdlib OK.` + ); + } else if (status.cliOk && !status.versionOk) { + void vscode.window.showWarningMessage( + `Marqdo CLI still below ${status.requiredVersion}. ${status.detail}` ); } else if (status.cliOk && !status.libOk) { void vscode.window.showWarningMessage( @@ -378,24 +436,32 @@ export async function promptIfNeeded( const status = checkInstallStatus(context); output.appendLine(`[install] ${status.detail}`); - if (status.cliOk && status.libOk) { + if (status.cliOk && status.versionOk && status.libOk) { + output.appendLine(`[install] ready (CLI ≥ ${status.requiredVersion}, stdlib present)`); return; } let message: string; let primary: string; + const mode = status.suggestedMode ?? "bundle"; + if (!status.cliOk) { - message = - "Marqdo CLI not found. Download the official release (includes standard library) into the extension?"; + message = `Marqdo CLI not detected. Install CLI ≥ ${status.requiredVersion} with the standard library?`; primary = "Install CLI + stdlib"; + } else if (!status.versionOk) { + message = `Marqdo CLI version is too old (need ≥ ${status.requiredVersion}${ + status.parsedVersion ? `, found ${status.parsedVersion}` : `, raw: ${status.version}` + }). Upgrade now (includes stdlib)?`; + primary = "Upgrade CLI + stdlib"; } else { message = - "Marqdo CLI found, but the standard library (lib/) is missing. Download stdlib into the extension?"; + "Marqdo CLI is OK, but the standard library (lib/) is missing. Download stdlib into the extension?"; primary = "Install stdlib"; } const choice = await vscode.window.showWarningMessage( message, + { modal: false }, primary, "Open Releases", "Don't ask again" @@ -403,7 +469,7 @@ export async function promptIfNeeded( if (choice === primary) { try { - await installFromGitHub(context, output, status.cliOk ? "stdlib" : "bundle"); + await installFromGitHub(context, output, mode); } catch (e) { const err = e instanceof Error ? e.message : String(e); output.appendLine(`[install] ${err}`);