digital-ide/src/extension.ts
2025-04-11 00:05:09 +08:00

118 lines
4.1 KiB
TypeScript

import * as vscode from 'vscode';
import * as fs from 'fs';
import { MainOutput, ReportType, IProgress } from './global';
import { hdlParam } from './hdlParser';
import * as manager from './manager';
import * as func from './function';
import { hdlMonitor } from './monitor';
import * as lspClient from './function/lsp-client';
import { refreshArchTree } from './function/treeView';
import { hdlFile } from './hdlFs';
import { initialiseI18n, t } from './i18n';
async function registerCommand(context: vscode.ExtensionContext, packageJson: any) {
func.registerFunctionCommands(context);
func.registerTreeViewDataProvider(context);
func.registerLsp(context, packageJson.version);
func.registerToolCommands(context);
func.registerFSM(context);
func.registerNetlist(context);
func.registerWaveViewer(context);
}
function readPackageJson(context: vscode.ExtensionContext): any | undefined {
const extensionPath = context.extensionPath;
const packagePath = extensionPath + '/package.json';
if (!fs.existsSync(packagePath)) {
vscode.window.showErrorMessage("Digital IDE 安装目录已经被污染,请重新安装!");
return undefined;
}
const packageMeta = fs.readFileSync(packagePath, { encoding: 'utf-8' });
return JSON.parse(packageMeta);
}
async function launch(context: vscode.ExtensionContext) {
initialiseI18n(context);
console.log(t('info.welcome.title'));
console.log(t('info.welcome.join-qq-group') + ' https://qm.qq.com/q/1M655h3GsA');
const packageJson = readPackageJson(context);
if (packageJson === undefined) {
return;
}
await vscode.window.withProgress({
location: vscode.ProgressLocation.Window,
title: t('info.progress.register-command')
}, async () => {
await registerCommand(context, packageJson);
});
await vscode.window.withProgress({
location: vscode.ProgressLocation.Window,
title: t('info.progress.initialize-configure')
}, async () => {
// 初始化 OpeParam
// 包含基本的插件的文件系统信息、用户配置文件和系统配置文件的合并数据结构
const refreshPrjConfig = await manager.prjManage.initOpeParam(context);
MainOutput.report('finish initialise opeParam', ReportType.Info);
manager.prjManage.refreshPrjFolder(refreshPrjConfig);
});
await vscode.window.withProgress({
location: vscode.ProgressLocation.Window,
title: t('info.launch.launch-digital-lsp')
}, async () => {
await lspClient.activate(context, packageJson);
});
await vscode.window.withProgress({
location: vscode.ProgressLocation.Window,
title: t('info.progress.initialization')
}, async (progress: vscode.Progress<IProgress>, token: vscode.CancellationToken) => {
// 初始化解析
await manager.prjManage.initialise(context, progress);
// 这里是因为 pl 对象在 initialise 完成初始化,此处再注册它的行为
manager.registerManagerCommands(context);
// 刷新结构树
refreshArchTree();
hdlMonitor.start();
});
MainOutput.report('Digital-IDE 已经启动,当前版本:' + packageJson.version, ReportType.Launch);
console.log(hdlParam);
// show welcome information (if first install)
const welcomeSetting = vscode.workspace.getConfiguration('digital-ide.welcome');
const showWelcome = welcomeSetting.get('show', true);
if (showWelcome) {
// don't show in next time
welcomeSetting.update('show', false, vscode.ConfigurationTarget.Global);
const res = await vscode.window.showInformationMessage(
t('info.welcome.title'),
{ title: t('info.welcome.star'), value: true },
{ title: t('info.welcome.refuse'), value: false },
);
if (res?.value) {
vscode.env.openExternal(vscode.Uri.parse('https://github.com/Digital-EDA/Digital-IDE'));
}
}
}
export function activate(context: vscode.ExtensionContext) {
launch(context);
}
export function deactivate() {
lspClient.deactivate();
}