添加了一些注释信息,修改了一些细节

This commit is contained in:
pqcqaq 2024-10-25 23:50:30 +08:00
parent 6ac15290ad
commit 69a6c00399
2 changed files with 65 additions and 3 deletions

View File

@ -37,14 +37,13 @@ import { initTriggerProgram } from './utils/triggers';
import {
activateTriggerPlugin,
deactivateTriggerPlugin,
startAnaylizeAll,
} from './plugins/oakTriggers';
// 初始化配置
// 查找工作区的根目录中的oak.config.json文件排除src和node_modules目录
const exclude: vscode.GlobPattern = new vscode.RelativePattern(
'**',
'{src,node_modules,lib,configuration}'
'{src,node_modules,lib,configuration,native,web,wechatMp}'
);
subscribe(() => {
@ -195,7 +194,7 @@ export async function activate(context: vscode.ExtensionContext) {
'Congratulations, your extension "oak-assistant" is now active!'
);
const uris = await vscode.workspace.findFiles('oak.config.json', exclude);
const uris = await vscode.workspace.findFiles('oak.config.json', exclude, 1);
const fs = vscode.workspace.fs;
if (uris.length === 0) {
// 获取当前工作区

View File

@ -348,6 +348,15 @@ const analyzeTriggerObj = (
return def;
};
/**
* triggers定义
* @param sourceFile
* @param typeChecker
* @param program ts程序
* @param visited 访
* @param meta
* @returns triggers定义
*/
function getTriggersFromSourceFile(
sourceFile: ts.SourceFile,
typeChecker: ts.TypeChecker,
@ -434,6 +443,12 @@ function getTriggersFromSourceFile(
return triggers;
}
/**
* trigger
* @param program ts程序
* @param sourcePath
* @returns triggers定义
*/
const getDefaultExport = (
program: ts.Program | undefined,
sourcePath: string
@ -493,6 +508,10 @@ const getDefaultExport = (
return [];
};
/**
*
* trigger
*/
let updateCount = 0;
// 下面进行trigger的更新
export const updateTriggerByPath = (path: string) => {
@ -599,6 +618,11 @@ export const updateTriggerByPath = (path: string) => {
updateDeounced();
};
/**
* trigger
* @param trigger trigger定义
* @returns uri和诊断信息
*/
export const checkTrigger = (
trigger: TriggerDef
): {
@ -832,6 +856,16 @@ export const checkTrigger = (
};
};
/**
*
* @param sourceFile
* @param start
* @param end
* @param key key
* @param message
* @param level
* @returns
*/
const createDiagnostic = (
sourceFile: ts.SourceFile,
start: number,
@ -861,6 +895,10 @@ const createDiagnostic = (
return dia;
};
/**
* trigger
* @returns uri和诊断信息
*/
export const checkAllTriggers = (): {
[uri: string]: vscode.Diagnostic[];
} => {
@ -871,6 +909,11 @@ export const checkAllTriggers = (): {
return checkTriggers(triggers);
};
/**
* trigger
* @param ts trigger定义
* @returns uri和诊断信息
*/
export const checkTriggers = (ts: TriggerDef[]) => {
const diagnostics: {
[uri: string]: vscode.Diagnostic[];
@ -886,6 +929,11 @@ export const checkTriggers = (ts: TriggerDef[]) => {
return diagnostics;
};
/**
* trigger
* @param path
* @returns
*/
export const checkPathTrigger = (path: string) => {
const norPath = normalizePath(path);
const trigger = triggers.filter((t) => t.path === norPath);
@ -904,10 +952,20 @@ export const checkPathTrigger = (path: string) => {
};
};
/**
* entity的trigger数量
* @param entity entity名称
* @returns trigger数量
*/
export const getTriggerCountByEntity = (entity: string): number => {
return triggers.filter((t) => t.entity === entity).length;
};
/**
* entity的trigger信息
* @param entity entity名称
* @returns trigger信息
*/
export const getTrigersInfoByEntity = (entity: string): TriggerInfo[] => {
return triggers
.filter((t) => t.entity === entity)
@ -933,6 +991,11 @@ const updateDeounced = debounce(() => {
triggerSubscribers.forEach((callback) => callback());
}, 200);
/**
* trigger的更新trigger更新时callback
* @param callback
* @returns
*/
export const subscribeTrigger = (callback: () => void) => {
const setToSubscribers = (callback: () => void) => {
const key = random(0, 100000);