提供相关配置项,可以关闭triggers检查以节省性能
This commit is contained in:
parent
4b16415e0c
commit
fea9dd2347
|
|
@ -79,10 +79,15 @@
|
|||
"default": true,
|
||||
"description": "启用实体跳转功能"
|
||||
},
|
||||
"oak-assistant.triggerUpdateCount":{
|
||||
"oak-assistant.triggerUpdateCount": {
|
||||
"type": "number",
|
||||
"default": 30,
|
||||
"description": "触发Trigger重载的最小更新次数"
|
||||
},
|
||||
"oak-assistant.enableTriggerCheck": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "启用Trigger检查(极其消耗性能)"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -28,7 +28,11 @@ import {
|
|||
import { preLoadLocales } from './utils/locales';
|
||||
import { createCommonPlugin } from './plugins/common';
|
||||
import { initTriggerProgram } from './utils/triggers';
|
||||
import { activateTriggerPlugin, deactivateTriggerPlugin, startAnaylizeAll } from './plugins/oakTriggers';
|
||||
import {
|
||||
activateTriggerPlugin,
|
||||
deactivateTriggerPlugin,
|
||||
startAnaylizeAll,
|
||||
} from './plugins/oakTriggers';
|
||||
|
||||
// 初始化配置
|
||||
// 查找工作区的根目录中的oak.config.json文件,排除src和node_modules目录
|
||||
|
|
@ -96,6 +100,13 @@ const afterPathSet = async () => {
|
|||
name: '初始化trigger信息',
|
||||
description: '初始化trigger信息',
|
||||
function: async () => {
|
||||
const enabled = vscode.workspace
|
||||
.getConfiguration('oak-assistant')
|
||||
.get('enableTriggerCheck');
|
||||
if (!enabled) {
|
||||
console.log('triggers检查未启用');
|
||||
return;
|
||||
}
|
||||
initTriggerProgram();
|
||||
// startAnaylizeAll(); // 现在只在打开文件的时候检查避免性能损耗
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
import * as vscode from 'vscode';
|
||||
import { checkAllTriggers, checkPathTrigger, updateTriggerByPath } from '../utils/triggers';
|
||||
import {
|
||||
checkAllTriggers,
|
||||
checkPathTrigger,
|
||||
updateTriggerByPath,
|
||||
} from '../utils/triggers';
|
||||
|
||||
const triggersDiagnostics =
|
||||
vscode.languages.createDiagnosticCollection('oakTriggers');
|
||||
|
|
@ -31,11 +35,34 @@ export const startAnaylizeAll = () => {
|
|||
};
|
||||
|
||||
export const activateTriggerPlugin = (context: vscode.ExtensionContext) => {
|
||||
const enabled = vscode.workspace
|
||||
.getConfiguration('oak-assistant')
|
||||
.get('enableTriggerCheck');
|
||||
if (!enabled) {
|
||||
console.log('triggers检查未启用');
|
||||
return;
|
||||
}
|
||||
context.subscriptions.push(triggersDiagnostics);
|
||||
context.subscriptions.push(documentLinkProvider);
|
||||
console.log('triggers检查启用');
|
||||
};
|
||||
|
||||
// 如果配置修改,申请重新加载工作区
|
||||
vscode.workspace.onDidChangeConfiguration((e) => {
|
||||
if (e.affectsConfiguration('oak-assistant.enableTriggerCheck')) {
|
||||
deactivateTriggerPlugin();
|
||||
vscode.window
|
||||
.showInformationMessage('配置已修改,请重新加载', '重新加载')
|
||||
.then((res) => {
|
||||
if (res === '重新加载') {
|
||||
vscode.commands.executeCommand(
|
||||
'workbench.action.reloadWindow'
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 取消注册
|
||||
export const deactivateTriggerPlugin = () => {
|
||||
triggersDiagnostics.clear();
|
||||
|
|
|
|||
|
|
@ -390,6 +390,12 @@ let updateCount = 0;
|
|||
export const updateTriggerByPath = (path: string) => {
|
||||
updateCount++;
|
||||
|
||||
const norPath = normalizePath(path);
|
||||
if (!triggerProgram) {
|
||||
console.error('trigger program not initialized');
|
||||
return;
|
||||
}
|
||||
|
||||
const maxCount = vscode.workspace
|
||||
.getConfiguration('oak-assistant')
|
||||
.get('triggerUpdateCount', 30);
|
||||
|
|
@ -399,12 +405,6 @@ export const updateTriggerByPath = (path: string) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const norPath = normalizePath(path);
|
||||
if (!triggerProgram) {
|
||||
console.error('trigger program not initialized');
|
||||
return;
|
||||
}
|
||||
|
||||
// 读取文件的新内容
|
||||
const fileContent = fs.readFileSync(norPath, 'utf-8');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue