153 lines
6.4 KiB
JavaScript
153 lines
6.4 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || (function () {
|
|
var ownKeys = function(o) {
|
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
var ar = [];
|
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
return ar;
|
|
};
|
|
return ownKeys(o);
|
|
};
|
|
return function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
})();
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.activate = activate;
|
|
exports.deactivate = deactivate;
|
|
const vscode = __importStar(require("vscode"));
|
|
const child_process = __importStar(require("child_process"));
|
|
const path = __importStar(require("path"));
|
|
function activate(context) {
|
|
console.log('CNNL Language Support is now active');
|
|
// 注册编译命令
|
|
const compileCommand = vscode.commands.registerCommand('cnnl.compile', async () => {
|
|
const editor = vscode.window.activeTextEditor;
|
|
if (!editor) {
|
|
vscode.window.showErrorMessage('No active editor');
|
|
return;
|
|
}
|
|
const document = editor.document;
|
|
if (document.languageId !== 'cnnl') {
|
|
vscode.window.showErrorMessage('Current file is not a CNNL file');
|
|
return;
|
|
}
|
|
// 保存文件
|
|
await document.save();
|
|
const config = vscode.workspace.getConfiguration('cnnl');
|
|
const compilerPath = config.get('compilerPath', 'cnnl');
|
|
const enableVerification = config.get('enableVerification', true);
|
|
const filePath = document.uri.fsPath;
|
|
const outputDir = path.join(path.dirname(filePath), 'output');
|
|
// 构建编译命令
|
|
const args = [filePath, '--output', outputDir];
|
|
if (enableVerification) {
|
|
args.push('--verify');
|
|
}
|
|
// 显示输出通道
|
|
const outputChannel = vscode.window.createOutputChannel('CNNL Compiler');
|
|
outputChannel.show();
|
|
outputChannel.appendLine(`Compiling: ${filePath}`);
|
|
outputChannel.appendLine(`Command: ${compilerPath} ${args.join(' ')}`);
|
|
// 执行编译
|
|
try {
|
|
const result = child_process.spawnSync(compilerPath, args, {
|
|
encoding: 'utf8',
|
|
cwd: path.dirname(filePath)
|
|
});
|
|
if (result.error) {
|
|
outputChannel.appendLine(`Error: ${result.error.message}`);
|
|
vscode.window.showErrorMessage(`Compilation failed: ${result.error.message}`);
|
|
return;
|
|
}
|
|
outputChannel.appendLine(result.stdout);
|
|
if (result.stderr) {
|
|
outputChannel.appendLine(result.stderr);
|
|
}
|
|
if (result.status === 0) {
|
|
vscode.window.showInformationMessage('Compilation successful!');
|
|
}
|
|
else {
|
|
vscode.window.showErrorMessage(`Compilation failed with exit code ${result.status}`);
|
|
}
|
|
}
|
|
catch (error) {
|
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
outputChannel.appendLine(`Exception: ${errorMessage}`);
|
|
vscode.window.showErrorMessage(`Compilation error: ${errorMessage}`);
|
|
}
|
|
});
|
|
// 注册验证命令
|
|
const verifyCommand = vscode.commands.registerCommand('cnnl.verify', async () => {
|
|
const editor = vscode.window.activeTextEditor;
|
|
if (!editor) {
|
|
vscode.window.showErrorMessage('No active editor');
|
|
return;
|
|
}
|
|
const document = editor.document;
|
|
if (document.languageId !== 'cnnl') {
|
|
vscode.window.showErrorMessage('Current file is not a CNNL file');
|
|
return;
|
|
}
|
|
await document.save();
|
|
const config = vscode.workspace.getConfiguration('cnnl');
|
|
const compilerPath = config.get('compilerPath', 'cnnl');
|
|
const filePath = document.uri.fsPath;
|
|
const outputDir = path.join(path.dirname(filePath), 'output');
|
|
const outputChannel = vscode.window.createOutputChannel('CNNL Verification');
|
|
outputChannel.show();
|
|
outputChannel.appendLine(`Verifying: ${filePath}`);
|
|
try {
|
|
const result = child_process.spawnSync(compilerPath, [filePath, '--output', outputDir, '--verify'], {
|
|
encoding: 'utf8',
|
|
cwd: path.dirname(filePath)
|
|
});
|
|
if (result.error) {
|
|
outputChannel.appendLine(`Error: ${result.error.message}`);
|
|
vscode.window.showErrorMessage(`Verification failed: ${result.error.message}`);
|
|
return;
|
|
}
|
|
outputChannel.appendLine(result.stdout);
|
|
if (result.stderr) {
|
|
outputChannel.appendLine(result.stderr);
|
|
}
|
|
if (result.status === 0) {
|
|
vscode.window.showInformationMessage('Verification successful!');
|
|
}
|
|
else {
|
|
vscode.window.showErrorMessage(`Verification failed with exit code ${result.status}`);
|
|
}
|
|
}
|
|
catch (error) {
|
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
outputChannel.appendLine(`Exception: ${errorMessage}`);
|
|
vscode.window.showErrorMessage(`Verification error: ${errorMessage}`);
|
|
}
|
|
});
|
|
context.subscriptions.push(compileCommand);
|
|
context.subscriptions.push(verifyCommand);
|
|
}
|
|
function deactivate() {
|
|
console.log('CNNL Language Support is now deactivated');
|
|
}
|
|
//# sourceMappingURL=extension.js.map
|