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 <cursoragent@cursor.com>
This commit is contained in:
1 parent
2406059fc2
commit
cb2f4e4618
10 files changed
+270
-72
No files matched your search
+89
-28
@@ -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<void> {
|
||||
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<void> {
|
||||
async function checkCli(): Promise<void> {
|
||||
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<boolean> {
|
||||
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<void> {
|
||||
const open =
|
||||
vscode.workspace.getConfiguration("marqdo").get<string>(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<void> {
|
||||
if (!(await ensureCliOrOfferInstall())) {
|
||||
return;
|
||||
@@ -168,13 +207,35 @@ async function diagnoseDocument(doc: vscode.TextDocument): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function startView(): Promise<void> {
|
||||
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<string>("viewHost") ?? "127.0.0.1";
|
||||
const port = cfg.get<number>("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<void> {
|
||||
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<void> {
|
||||
const port = cfg.get<number>("debugPort") ?? 7430;
|
||||
output.show(true);
|
||||
try {
|
||||
const url = await debugServer.start(target, host, port);
|
||||
const open = cfg.get<string>("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<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function stopView(): Promise<void> {
|
||||
await viewServer.stop();
|
||||
void vscode.window.setStatusBarMessage("Marqdo view stopped", 3000);
|
||||
}
|
||||
|
||||
async function stopDebug(): Promise<void> {
|
||||
await debugServer.stop();
|
||||
void vscode.window.setStatusBarMessage("Marqdo debug stopped", 3000);
|
||||
|
||||
Reference in new issue
Block a user