@lcap/nasl 2.20.0-beta.1 → 2.20.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/automate/engine/index.d.ts +1 -1
- package/out/automate/engine/index.js +7 -7
- package/out/automate/engine/index.js.map +1 -1
- package/out/automate/engine/uniqueName.d.ts +1 -1
- package/out/automate/engine/uniqueName.js +3 -3
- package/out/automate/engine/uniqueName.js.map +1 -1
- package/out/automate/template/myProcess.js +1 -1
- package/out/automate/template/myProcess.js.map +1 -1
- package/out/bak/translator.js +38 -85
- package/out/bak/translator.js.map +1 -1
- package/out/common/BaseNode.d.ts +10 -6
- package/out/common/BaseNode.js +53 -7
- package/out/common/BaseNode.js.map +1 -1
- package/out/concepts/AnonymousFunction__.d.ts +1 -0
- package/out/concepts/AnonymousFunction__.js +40 -2
- package/out/concepts/AnonymousFunction__.js.map +1 -1
- package/out/concepts/App__.d.ts +89 -261
- package/out/concepts/App__.js +315 -367
- package/out/concepts/App__.js.map +1 -1
- package/out/concepts/Assignee__.js.map +1 -1
- package/out/concepts/AssignmentLine__.d.ts +5 -5
- package/out/concepts/AssignmentLine__.js +6 -6
- package/out/concepts/AssignmentLine__.js.map +1 -1
- package/out/concepts/Assignment__.js +1 -2
- package/out/concepts/Assignment__.js.map +1 -1
- package/out/concepts/BatchAssignment__.d.ts +62 -60
- package/out/concepts/BatchAssignment__.js +113 -42
- package/out/concepts/BatchAssignment__.js.map +1 -1
- package/out/concepts/BindAttribute__.d.ts +24 -0
- package/out/concepts/BindAttribute__.js +54 -4
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/BindDirective__.d.ts +5 -0
- package/out/concepts/BindDirective__.js +6 -0
- package/out/concepts/BindDirective__.js.map +1 -1
- package/out/concepts/BindEvent__.d.ts +5 -0
- package/out/concepts/BindEvent__.js +6 -0
- package/out/concepts/BindEvent__.js.map +1 -1
- package/out/concepts/BindStyle__.d.ts +7 -2
- package/out/concepts/BindStyle__.js +9 -3
- package/out/concepts/BindStyle__.js.map +1 -1
- package/out/concepts/BooleanLiteral__.js +0 -8
- package/out/concepts/BooleanLiteral__.js.map +1 -1
- package/out/concepts/CallFunction__.js +90 -38
- package/out/concepts/CallFunction__.js.map +1 -1
- package/out/concepts/CallInterface__.d.ts +7 -0
- package/out/concepts/CallInterface__.js +54 -7
- package/out/concepts/CallInterface__.js.map +1 -1
- package/out/concepts/CallLogic__.d.ts +2 -1
- package/out/concepts/CallLogic__.js +171 -37
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/CallQueryComponent__.js +16 -1
- package/out/concepts/CallQueryComponent__.js.map +1 -1
- package/out/concepts/CompletionProperty__.js +3 -0
- package/out/concepts/CompletionProperty__.js.map +1 -1
- package/out/concepts/ConfigGroup__.js.map +1 -1
- package/out/concepts/ConfigProperty__.js.map +1 -1
- package/out/concepts/Configuration__.js.map +1 -1
- package/out/concepts/Constant__.d.ts +5 -0
- package/out/concepts/Constant__.js +6 -0
- package/out/concepts/Constant__.js.map +1 -1
- package/out/concepts/DataSource__.d.ts +8 -0
- package/out/concepts/DataSource__.js +96 -1
- package/out/concepts/DataSource__.js.map +1 -1
- package/out/concepts/Destination__.d.ts +11 -2
- package/out/concepts/Destination__.js +156 -51
- package/out/concepts/Destination__.js.map +1 -1
- package/out/concepts/EntityProperty__.d.ts +21 -8
- package/out/concepts/EntityProperty__.js +109 -23
- package/out/concepts/EntityProperty__.js.map +1 -1
- package/out/concepts/Entity__.d.ts +32 -0
- package/out/concepts/Entity__.js +117 -2
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/Enum__.js +0 -4
- package/out/concepts/Enum__.js.map +1 -1
- package/out/concepts/Event__.js.map +1 -1
- package/out/concepts/ExternalDestination__.d.ts +73 -0
- package/out/concepts/ExternalDestination__.js +264 -0
- package/out/concepts/ExternalDestination__.js.map +1 -0
- package/out/concepts/ForEachStatement__.d.ts +0 -4
- package/out/concepts/ForEachStatement__.js +4 -8
- package/out/concepts/ForEachStatement__.js.map +1 -1
- package/out/concepts/Frontend__.d.ts +370 -0
- package/out/concepts/Frontend__.js +669 -0
- package/out/concepts/Frontend__.js.map +1 -0
- package/out/concepts/Function__.js.map +1 -1
- package/out/concepts/Identifier__.d.ts +1 -0
- package/out/concepts/Identifier__.js +33 -10
- package/out/concepts/Identifier__.js.map +1 -1
- package/out/concepts/IfStatement__.d.ts +8 -0
- package/out/concepts/IfStatement__.js +22 -0
- package/out/concepts/IfStatement__.js.map +1 -1
- package/out/concepts/InterfaceParam__.js.map +1 -1
- package/out/concepts/Interface__.js.map +1 -1
- package/out/concepts/LogicItem__.d.ts +6 -1
- package/out/concepts/LogicItem__.js +6 -0
- package/out/concepts/LogicItem__.js.map +1 -1
- package/out/concepts/Logic__.d.ts +91 -80
- package/out/concepts/Logic__.js +178 -59
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MatchCase__.d.ts +1 -1
- package/out/concepts/MatchCase__.js +15 -8
- package/out/concepts/MatchCase__.js.map +1 -1
- package/out/concepts/Match__.d.ts +21 -19
- package/out/concepts/Match__.js +118 -26
- package/out/concepts/Match__.js.map +1 -1
- package/out/concepts/MemberExpression__.d.ts +4 -1
- package/out/concepts/MemberExpression__.js +30 -15
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/Module__.js.map +1 -1
- package/out/concepts/Namespace__.js.map +1 -1
- package/out/concepts/NewComposite__.d.ts +345 -0
- package/out/concepts/NewComposite__.js +1068 -0
- package/out/concepts/NewComposite__.js.map +1 -0
- package/out/concepts/NewList__.d.ts +130 -0
- package/out/concepts/NewList__.js +349 -0
- package/out/concepts/NewList__.js.map +1 -0
- package/out/concepts/NewMap__.d.ts +221 -0
- package/out/concepts/NewMap__.js +480 -0
- package/out/concepts/NewMap__.js.map +1 -0
- package/out/concepts/New__.d.ts +19 -0
- package/out/concepts/New__.js +66 -0
- package/out/concepts/New__.js.map +1 -0
- package/out/concepts/NumericLiteral__.js +1 -1
- package/out/concepts/NumericLiteral__.js.map +1 -1
- package/out/concepts/OqlQueryComponent__.d.ts +7 -3
- package/out/concepts/OqlQueryComponent__.js +56 -95
- package/out/concepts/OqlQueryComponent__.js.map +1 -1
- package/out/concepts/Param__.d.ts +8 -1
- package/out/concepts/Param__.js +85 -6
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/ProcessComponent__.js.map +1 -1
- package/out/concepts/ProcessElement__.js +42 -13
- package/out/concepts/ProcessElement__.js.map +1 -1
- package/out/concepts/ProcessOutcomes__.d.ts +30 -0
- package/out/concepts/ProcessOutcomes__.js +87 -0
- package/out/concepts/ProcessOutcomes__.js.map +1 -0
- package/out/concepts/Process__.d.ts +4 -20
- package/out/concepts/Process__.js +0 -7
- package/out/concepts/Process__.js.map +1 -1
- package/out/concepts/QueryJoinExpression__.js.map +1 -1
- package/out/concepts/QueryOrderByExpression__.d.ts +3 -3
- package/out/concepts/QueryOrderByExpression__.js +3 -3
- package/out/concepts/QueryOrderByExpression__.js.map +1 -1
- package/out/concepts/QuerySelectExpression__.js.map +1 -1
- package/out/concepts/Return__.d.ts +5 -0
- package/out/concepts/Return__.js +45 -2
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/SelectMembers__.d.ts +1 -1
- package/out/concepts/SelectMembers__.js +5 -5
- package/out/concepts/SelectMembers__.js.map +1 -1
- package/out/concepts/SqlQueryComponent__.d.ts +2 -4
- package/out/concepts/SqlQueryComponent__.js +9 -88
- package/out/concepts/SqlQueryComponent__.js.map +1 -1
- package/out/concepts/StringInterpolation__.d.ts +113 -0
- package/out/concepts/StringInterpolation__.js +227 -0
- package/out/concepts/StringInterpolation__.js.map +1 -0
- package/out/concepts/StringLiteral__.js +0 -7
- package/out/concepts/StringLiteral__.js.map +1 -1
- package/out/concepts/StructureProperty__.js.map +1 -1
- package/out/concepts/Structure__.js.map +1 -1
- package/out/concepts/Transactional__.d.ts +5 -0
- package/out/concepts/Transactional__.js +6 -0
- package/out/concepts/Transactional__.js.map +1 -1
- package/out/concepts/TypeAnnotation__.d.ts +4 -0
- package/out/concepts/TypeAnnotation__.js +67 -15
- package/out/concepts/TypeAnnotation__.js.map +1 -1
- package/out/concepts/TypeParam__.d.ts +1 -0
- package/out/concepts/TypeParam__.js +2 -0
- package/out/concepts/TypeParam__.js.map +1 -1
- package/out/concepts/UnaryExpression__.js +6 -9
- package/out/concepts/UnaryExpression__.js.map +1 -1
- package/out/concepts/ValidationRule__.js +87 -22
- package/out/concepts/ValidationRule__.js.map +1 -1
- package/out/concepts/Variable__.d.ts +5 -0
- package/out/concepts/Variable__.js +46 -3
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewComponent__.js.map +1 -1
- package/out/concepts/ViewElement__.d.ts +35 -29
- package/out/concepts/ViewElement__.js +138 -54
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.d.ts +10 -3
- package/out/concepts/View__.js +116 -86
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/WhileStatement__.js +1 -1
- package/out/concepts/WhileStatement__.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.auth.js +1 -1
- package/out/concepts/basics/stdlib/nasl.auth.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.browser.js +50 -0
- package/out/concepts/basics/stdlib/nasl.browser.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.logging.js +5 -0
- package/out/concepts/basics/stdlib/nasl.logging.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.ui.js +38 -4
- package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.util.js +214 -62
- package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
- package/out/concepts/index__.d.ts +9 -0
- package/out/concepts/index__.js +9 -0
- package/out/concepts/index__.js.map +1 -1
- package/out/enums/KEYWORDS.d.ts +1 -0
- package/out/enums/KEYWORDS.js +9 -1
- package/out/enums/KEYWORDS.js.map +1 -1
- package/out/generator/genBundleFiles.d.ts +10 -4
- package/out/generator/genBundleFiles.js +127 -162
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/genMetaData.d.ts +2 -11
- package/out/generator/genMetaData.js +185 -51
- package/out/generator/genMetaData.js.map +1 -1
- package/out/generator/genReleaseBody.d.ts +57 -0
- package/out/generator/genReleaseBody.js +380 -0
- package/out/generator/genReleaseBody.js.map +1 -0
- package/out/generator/index.d.ts +2 -0
- package/out/generator/index.js +2 -0
- package/out/generator/index.js.map +1 -1
- package/out/generator/permission.d.ts +17 -0
- package/out/generator/permission.js +221 -0
- package/out/generator/permission.js.map +1 -0
- package/out/index.d.ts +3 -2
- package/out/index.js +7 -1
- package/out/index.js.map +1 -1
- package/out/server/entity2LogicNamespace.js +100 -20
- package/out/server/entity2LogicNamespace.js.map +1 -1
- package/out/server/extendBaseNode.js +33 -20
- package/out/server/extendBaseNode.js.map +1 -1
- package/out/server/formatTsUtils.d.ts +1 -2
- package/out/server/formatTsUtils.js +46 -64
- package/out/server/formatTsUtils.js.map +1 -1
- package/out/server/getLogics.d.ts +2 -1
- package/out/server/getLogics.js +24 -6
- package/out/server/getLogics.js.map +1 -1
- package/out/server/getMemberIdentifier.js +11 -11
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/getProcesses.d.ts +1 -1
- package/out/server/getProcesses.js +1 -1
- package/out/server/getProcesses.js.map +1 -1
- package/out/server/index.d.ts +0 -1
- package/out/server/index.js +2 -27
- package/out/server/index.js.map +1 -1
- package/out/server/naslServer.d.ts +50 -8
- package/out/server/naslServer.js +816 -429
- package/out/server/naslServer.js.map +1 -1
- package/out/server/naslStdlibMap.js +30 -28
- package/out/server/naslStdlibMap.js.map +1 -1
- package/out/server/process2LogicNamespace.js +8 -0
- package/out/server/process2LogicNamespace.js.map +1 -1
- package/out/server/translator.js +90 -12
- package/out/server/translator.js.map +1 -1
- package/out/service/creator/add.configs.js +4 -0
- package/out/service/creator/add.configs.js.map +1 -1
- package/out/service/datasource/api.d.ts +12 -0
- package/out/service/datasource/api.js +14 -0
- package/out/service/datasource/api.js.map +1 -0
- package/out/service/datasource/index.d.ts +2 -0
- package/out/service/datasource/index.js +10 -0
- package/out/service/datasource/index.js.map +1 -0
- package/out/service/defaultErrorMessage.json +97 -0
- package/out/service/logic/api.d.ts +9 -0
- package/out/service/logic/api.js +11 -0
- package/out/service/logic/api.js.map +1 -0
- package/out/service/logic/index.d.ts +2 -0
- package/out/service/logic/index.js +10 -0
- package/out/service/logic/index.js.map +1 -0
- package/out/service/storage/init.js +48 -7
- package/out/service/storage/init.js.map +1 -1
- package/out/templator/genCreateBlock.js +6 -4
- package/out/templator/genCreateBlock.js.map +1 -1
- package/out/templator/genCurdEditMultipleKeyBlock.js +7 -4
- package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
- package/out/templator/genCurdMultipleKeyBlock.js +7 -5
- package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
- package/out/templator/genEditTableBlock.js +4 -5
- package/out/templator/genEditTableBlock.js.map +1 -1
- package/out/templator/genEnumSelectBlock.js +5 -2
- package/out/templator/genEnumSelectBlock.js.map +1 -1
- package/out/templator/genGetBlock.js +4 -3
- package/out/templator/genGetBlock.js.map +1 -1
- package/out/templator/genGridViewBlock.js +18 -16
- package/out/templator/genGridViewBlock.js.map +1 -1
- package/out/templator/genListViewBlock.js +7 -7
- package/out/templator/genListViewBlock.js.map +1 -1
- package/out/templator/genQueryComponent.d.ts +2 -2
- package/out/templator/genQueryComponent.js +4 -1
- package/out/templator/genQueryComponent.js.map +1 -1
- package/out/templator/genTableBlock.js +8 -12
- package/out/templator/genTableBlock.js.map +1 -1
- package/out/templator/genUpdateBlock.js +4 -3
- package/out/templator/genUpdateBlock.js.map +1 -1
- package/out/templator/utils.js +1 -1
- package/out/templator/utils.js.map +1 -1
- package/out/test/integration/node-nasl-server.js +10 -38
- package/out/test/integration/node-nasl-server.js.map +1 -1
- package/out/translator/index.d.ts +1 -0
- package/out/translator/index.js +1 -1
- package/out/translator/index.js.map +1 -1
- package/out/utils/index.d.ts +1 -0
- package/out/utils/index.js +38 -1
- package/out/utils/index.js.map +1 -1
- package/out/utils/string.d.ts +15 -2
- package/out/utils/string.js +18 -3
- package/out/utils/string.js.map +1 -1
- package/package.json +1 -1
- package/src/concepts/App__.ts +11 -36
- package/src/concepts/Frontend__.ts +8 -0
- package/src/concepts/ViewElement__.ts +7 -28
- package/src/concepts/View__.ts +1 -1
- package/src/server/getLogics.ts +2 -2
- package/src/server/naslServer.ts +8 -8
- package/src/service/storage/init.ts +3 -4
package/out/server/naslServer.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.NaslServer = void 0;
|
|
29
|
+
exports.NaslServer = exports.getDisplayString2Type = void 0;
|
|
30
30
|
/// #if process.env.BUILD_TARGET === 'node'
|
|
31
31
|
const fs = __importStar(require("fs-extra"));
|
|
32
32
|
const path = __importStar(require("path"));
|
|
@@ -46,17 +46,45 @@ const coreTypeList_1 = require("../concepts/basics/types/coreTypeList");
|
|
|
46
46
|
const formatTsUtils_1 = require("./formatTsUtils");
|
|
47
47
|
const naslStdlibMap_1 = __importDefault(require("./naslStdlibMap"));
|
|
48
48
|
const jsoner = __importStar(require("../service/storage/jsoner"));
|
|
49
|
+
const EventEmitter_1 = require("../common/EventEmitter");
|
|
49
50
|
const EmbeddedTSFileLineMap = {
|
|
50
51
|
Entity: 3,
|
|
51
52
|
};
|
|
52
53
|
const EmbeddedTSFileOffsetMap = {
|
|
53
54
|
Variable: 12,
|
|
54
55
|
};
|
|
55
|
-
// 要Check的文件
|
|
56
|
-
const filesToCheck = new Set();
|
|
57
56
|
let isChangeInterface = false; //判断是否导入接口
|
|
58
57
|
let actionArr = []; //用于导入接口收集更改的节点
|
|
59
58
|
let timer = null; //超时器用于收集导入接口相关
|
|
59
|
+
// 联合类型切割取出类型
|
|
60
|
+
function getDisplayString2Type(displayString) {
|
|
61
|
+
// 取出匹配的内容
|
|
62
|
+
const reg = /<([^()]+)>/g;
|
|
63
|
+
// 解决extends 导致类型缺失的问题
|
|
64
|
+
displayString = displayString?.replace('T extends ', '') || '';
|
|
65
|
+
const types = reg.exec(displayString);
|
|
66
|
+
// 取出提示的类型,组成是数组
|
|
67
|
+
const typeList = types[1].split(' | ').map((item) => {
|
|
68
|
+
if (/<([^()]+)>/g.exec(item)) {
|
|
69
|
+
return item;
|
|
70
|
+
}
|
|
71
|
+
else if (item.includes(' ')) {
|
|
72
|
+
const strs = item.split(' ');
|
|
73
|
+
const type = strs[strs.length - 1];
|
|
74
|
+
return type;
|
|
75
|
+
}
|
|
76
|
+
else if (item.includes('.')) {
|
|
77
|
+
const strs = item.split('.');
|
|
78
|
+
const type = strs[strs.length - 1];
|
|
79
|
+
return type;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
return item;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return typeList;
|
|
86
|
+
}
|
|
87
|
+
exports.getDisplayString2Type = getDisplayString2Type;
|
|
60
88
|
class NaslServer {
|
|
61
89
|
messager = undefined;
|
|
62
90
|
worker = undefined;
|
|
@@ -69,6 +97,11 @@ class NaslServer {
|
|
|
69
97
|
elementsLogic = {};
|
|
70
98
|
// 错误日志收集
|
|
71
99
|
diagnosticManager = undefined;
|
|
100
|
+
embeddedTSEmitter = undefined;
|
|
101
|
+
// 需要执行修改的文件
|
|
102
|
+
changeStackList = [];
|
|
103
|
+
filesToCheck;
|
|
104
|
+
singleFileChangeIng;
|
|
72
105
|
constructor() {
|
|
73
106
|
/// #if process.env.BUILD_TARGET === 'node'
|
|
74
107
|
if (globalThis.process) // For TS build
|
|
@@ -79,6 +112,10 @@ class NaslServer {
|
|
|
79
112
|
if (globalThis.window) // For TS build
|
|
80
113
|
this.worker = new worker_threads_1.Worker('/ts-worker.js');
|
|
81
114
|
/// #endif
|
|
115
|
+
// 要Check的文件
|
|
116
|
+
this.filesToCheck = new Set();
|
|
117
|
+
// 单个文件正在change,不允许同时两个文件一起change
|
|
118
|
+
this.singleFileChangeIng = false;
|
|
82
119
|
this.diagnosticManager = new diagnostic_1.DiagnosticManager();
|
|
83
120
|
this.messager = new Messager_1.default({
|
|
84
121
|
protocol: 'ts-worker',
|
|
@@ -93,10 +130,54 @@ class NaslServer {
|
|
|
93
130
|
}
|
|
94
131
|
},
|
|
95
132
|
});
|
|
133
|
+
// 监听所有改变操作
|
|
134
|
+
this.embeddedTSEmitter = new EventEmitter_1.EventEmitter();
|
|
135
|
+
this.embeddedTSEmitter.on('change', ($event) => {
|
|
136
|
+
// 收集到一个行为集合
|
|
137
|
+
const eventValue = $event.value;
|
|
138
|
+
eventValue.forEach(async (item) => {
|
|
139
|
+
/**
|
|
140
|
+
* 多个行为进行合并
|
|
141
|
+
* 合并规则是
|
|
142
|
+
* 1.[a,b,c,c] 在cc的时候,在已有一个c,又来一个c的时候,如果他们不都是file级别的节点
|
|
143
|
+
* 就可以前面的内容去掉,只保留最后一个
|
|
144
|
+
* 2.[a,b,c,b,c] 在bc已存在,又来了bc 这就都要保留,因为可能顺序有相关性,不能去掉
|
|
145
|
+
* 理论上只处理同时几个操作 合并,
|
|
146
|
+
* 3.有field的也直接保留
|
|
147
|
+
*/
|
|
148
|
+
try {
|
|
149
|
+
const changeEvent = item.originEvent;
|
|
150
|
+
const changeNode = changeEvent.target;
|
|
151
|
+
const { fileNode } = this.getCurrentSource(changeNode);
|
|
152
|
+
if (changeNode !== fileNode || !changeEvent.field) {
|
|
153
|
+
const findIndex = this.changeStackList.findIndex((changeStackItem) => {
|
|
154
|
+
const target = changeStackItem.target;
|
|
155
|
+
const { fileNode: targetFileNode } = this.getCurrentSource(target);
|
|
156
|
+
return targetFileNode === fileNode;
|
|
157
|
+
});
|
|
158
|
+
if (findIndex === this.changeStackList.length - 1) {
|
|
159
|
+
this.changeStackList.pop();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
this.changeStackList.push(item.originEvent);
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
console.log(err);
|
|
166
|
+
this.changeStackList.push(item.originEvent);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
// 如果有长度开始执行状态机
|
|
170
|
+
if (this.changeStackList.length) {
|
|
171
|
+
this.changeFileNext();
|
|
172
|
+
}
|
|
173
|
+
});
|
|
96
174
|
}
|
|
97
175
|
start() {
|
|
98
176
|
return this.messager.requestCommand('start');
|
|
99
177
|
}
|
|
178
|
+
terminate() {
|
|
179
|
+
this.worker.terminate();
|
|
180
|
+
}
|
|
100
181
|
async createUiTs(allComponent) {
|
|
101
182
|
const { code, elementsLogic } = await (0, createUiTs_1.default)(allComponent);
|
|
102
183
|
// 放入生產的uits文件
|
|
@@ -126,17 +207,34 @@ class NaslServer {
|
|
|
126
207
|
catch (err) {
|
|
127
208
|
}
|
|
128
209
|
});
|
|
129
|
-
module.
|
|
210
|
+
module.frontends?.forEach((frontend) => {
|
|
130
211
|
try {
|
|
131
|
-
const result =
|
|
212
|
+
const result = frontend.toEmbeddedTSFile();
|
|
132
213
|
results.push(result);
|
|
133
214
|
// sourceMap都存在目录级别内容下,在页面层级下去找
|
|
134
|
-
|
|
135
|
-
this.file2NodeMap.set(result.filePath,
|
|
215
|
+
frontend.sourceMap = result.sourceMap;
|
|
216
|
+
this.file2NodeMap.set(result.filePath, frontend);
|
|
136
217
|
}
|
|
137
218
|
catch (err) {
|
|
138
219
|
console.log(err);
|
|
139
220
|
}
|
|
221
|
+
frontend.variables?.forEach((frontendVariable) => {
|
|
222
|
+
try {
|
|
223
|
+
const result = frontendVariable.toEmbeddedTSFile();
|
|
224
|
+
results.push(result);
|
|
225
|
+
// sourceMap都存在目录级别内容下,在页面层级下去找
|
|
226
|
+
frontendVariable.sourceMap = result.sourceMap;
|
|
227
|
+
this.file2NodeMap.set(result.filePath, frontendVariable);
|
|
228
|
+
}
|
|
229
|
+
catch (err) {
|
|
230
|
+
console.log(err);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
// view的生成
|
|
234
|
+
if (!config_1.config.closeViews) {
|
|
235
|
+
this.view2TSFile(frontend.views, results);
|
|
236
|
+
}
|
|
237
|
+
frontend.componentDependencies?.forEach((item) => this.contentToFile(item, results));
|
|
140
238
|
});
|
|
141
239
|
module.dataSources?.forEach((dataSource) => {
|
|
142
240
|
// 本身dataSource也要生成一个文件用于改名
|
|
@@ -195,10 +293,6 @@ class NaslServer {
|
|
|
195
293
|
catch (err) {
|
|
196
294
|
}
|
|
197
295
|
});
|
|
198
|
-
// view的生成
|
|
199
|
-
if (!config_1.config.closeViews) {
|
|
200
|
-
this.view2TSFile(module.views, results);
|
|
201
|
-
}
|
|
202
296
|
module.processes.forEach((process) => {
|
|
203
297
|
try {
|
|
204
298
|
const result = process.toEmbeddedTSFile();
|
|
@@ -249,7 +343,6 @@ class NaslServer {
|
|
|
249
343
|
// 其他模块的创建内容
|
|
250
344
|
app.dependencies.forEach((item) => this.contentToFile(item, results));
|
|
251
345
|
app.interfaceDependencies.forEach((item) => this.contentToFile(item, results));
|
|
252
|
-
app.componentDependencies.forEach((item) => this.contentToFile(item, results));
|
|
253
346
|
}
|
|
254
347
|
catch (err) {
|
|
255
348
|
console.log(err);
|
|
@@ -371,32 +464,6 @@ class NaslServer {
|
|
|
371
464
|
_getValueSelectCompletion(args) {
|
|
372
465
|
return this.messager.requestCommand('getValueSelectCompletion', args);
|
|
373
466
|
}
|
|
374
|
-
// 联合类型切割取出类型
|
|
375
|
-
getDisplayString2Type(displayString) {
|
|
376
|
-
// 取出匹配的内容
|
|
377
|
-
const reg = /<([^()]+)>/g;
|
|
378
|
-
const types = reg.exec(displayString);
|
|
379
|
-
// 取出提示的类型,组成是数组
|
|
380
|
-
const typeList = types[1].split(' | ').map((item) => {
|
|
381
|
-
if (/<([^()]+)>/g.exec(item)) {
|
|
382
|
-
return item;
|
|
383
|
-
}
|
|
384
|
-
else if (item.includes(' ')) {
|
|
385
|
-
const strs = item.split(' ');
|
|
386
|
-
const type = strs[strs.length - 1];
|
|
387
|
-
return type;
|
|
388
|
-
}
|
|
389
|
-
else if (item.includes('.')) {
|
|
390
|
-
const strs = item.split('.');
|
|
391
|
-
const type = strs[strs.length - 1];
|
|
392
|
-
return type;
|
|
393
|
-
}
|
|
394
|
-
else {
|
|
395
|
-
return item;
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
return typeList;
|
|
399
|
-
}
|
|
400
467
|
/**
|
|
401
468
|
* 获取 Convert 的可选类型
|
|
402
469
|
* @param node 传入当前已经选择的变量
|
|
@@ -419,7 +486,7 @@ class NaslServer {
|
|
|
419
486
|
});
|
|
420
487
|
if (quickInfo.responseRequired) {
|
|
421
488
|
const displayString = quickInfo?.response?.displayString || '';
|
|
422
|
-
const typeList =
|
|
489
|
+
const typeList = getDisplayString2Type(displayString);
|
|
423
490
|
const res = [];
|
|
424
491
|
typeList.forEach((type) => {
|
|
425
492
|
const typeAnnotation = coreTypeList_1.primitiveTypeList.find((typeAnnotation) => typeAnnotation.typeName === type);
|
|
@@ -477,6 +544,17 @@ class NaslServer {
|
|
|
477
544
|
.replace(/__name:"AStructure_\w{8}";/g, '')
|
|
478
545
|
.replace(/dataSources.([^.]+).entities.([^;]+)/g, ($1, $2, $3) => (`${$3}(${$2})`));
|
|
479
546
|
}
|
|
547
|
+
else if (typeStr.startsWith('{') && typeStr.endsWith('}')) {
|
|
548
|
+
/**
|
|
549
|
+
* {
|
|
550
|
+
text: nasl.core.String;
|
|
551
|
+
value: nasl.core.String;
|
|
552
|
+
}
|
|
553
|
+
*/
|
|
554
|
+
return typeStr.replaceAll(' ', '')
|
|
555
|
+
.replaceAll('\n', '')
|
|
556
|
+
.replaceAll('nasl.core.', '');
|
|
557
|
+
}
|
|
480
558
|
let str = '';
|
|
481
559
|
// 取出T的值
|
|
482
560
|
typeStr = (0, formatTsUtils_1.getPlatformType)(typeStr);
|
|
@@ -502,6 +580,49 @@ class NaslServer {
|
|
|
502
580
|
}
|
|
503
581
|
return '';
|
|
504
582
|
}
|
|
583
|
+
async getDataSchemaStructureOrTypeAnnotation(node) {
|
|
584
|
+
if (!(node instanceof concepts_1.ViewElement))
|
|
585
|
+
return;
|
|
586
|
+
const { currentSource, fileNode } = this.getCurrentSource(node);
|
|
587
|
+
const quickInfo = await this._getTypeQuickinfo({
|
|
588
|
+
file: fileNode.getEmbeddedFilePath(),
|
|
589
|
+
line: (0, translator_1.lsp2tspNumber)(currentSource.range.start.line),
|
|
590
|
+
offset: (0, translator_1.lsp2tspNumber)(currentSource.range.start.character) + `new nasl.ui.`.length,
|
|
591
|
+
});
|
|
592
|
+
if (quickInfo.responseRequired) {
|
|
593
|
+
const displayString = quickInfo?.response?.displayString || '';
|
|
594
|
+
const flag = displayString.includes('<') && displayString.includes('>');
|
|
595
|
+
if (!flag)
|
|
596
|
+
return;
|
|
597
|
+
const types = /\<([^()]+)\>/g.exec(displayString);
|
|
598
|
+
const typeStr = types && types[1];
|
|
599
|
+
const app = node.app;
|
|
600
|
+
if (typeStr.includes('__name: "AStructure_')) {
|
|
601
|
+
const properties = [];
|
|
602
|
+
typeStr
|
|
603
|
+
.replace(/([^:\s]+):\s+([^;]+);/g, ($1, name, typeKey) => {
|
|
604
|
+
if (name === '__name')
|
|
605
|
+
return;
|
|
606
|
+
typeKey = `app.${typeKey}`;
|
|
607
|
+
const keys = typeKey.split('.');
|
|
608
|
+
const typeName = keys.pop();
|
|
609
|
+
const typeNamespace = keys.join('.');
|
|
610
|
+
properties.push(concepts_1.StructureProperty.from({
|
|
611
|
+
name,
|
|
612
|
+
typeAnnotation: concepts_1.TypeAnnotation.from({
|
|
613
|
+
typeKind: 'reference',
|
|
614
|
+
typeName,
|
|
615
|
+
typeNamespace,
|
|
616
|
+
}),
|
|
617
|
+
}));
|
|
618
|
+
return '';
|
|
619
|
+
});
|
|
620
|
+
return concepts_1.TypeAnnotation.createTypeAnonymousStructure(properties);
|
|
621
|
+
}
|
|
622
|
+
else if (typeStr.startsWith('structures'))
|
|
623
|
+
return app.findNodeByCompleteName(`app.${typeStr}`);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
505
626
|
/**
|
|
506
627
|
* ts的 quickInfo方法,查询指定位置的详情
|
|
507
628
|
* @param args 文件信息数组
|
|
@@ -615,6 +736,17 @@ class NaslServer {
|
|
|
615
736
|
if (isChangeInterface) {
|
|
616
737
|
this.existStructureFix(record.semanticDiagnostics, node, this);
|
|
617
738
|
}
|
|
739
|
+
// 单独处理 oql 语义错误提示
|
|
740
|
+
if (record.node instanceof concepts_1.Logic) {
|
|
741
|
+
record?.syntaxDiagnostics.forEach((item) => {
|
|
742
|
+
const minRange = this._findMinRange(item, record.node);
|
|
743
|
+
if (minRange.node instanceof concepts_1.OqlQueryComponent) {
|
|
744
|
+
if (item.text === 'Invalid character.') {
|
|
745
|
+
record.semanticDiagnostics.push(item);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
}
|
|
618
750
|
record.semanticDiagnostics = record.semanticDiagnostics
|
|
619
751
|
.map((diag) => this._resolveDiagnostic(diag, node, record))
|
|
620
752
|
.filter((diag) => !!diag);
|
|
@@ -633,7 +765,8 @@ class NaslServer {
|
|
|
633
765
|
// record.suggestionDiagnostics = record.suggestionDiagnostics.filter((item) => !item.text.includes(`implicitly has an 'any' type, but a better type may be inferred from usage.`));
|
|
634
766
|
// }
|
|
635
767
|
record.suggestionDiagnostics = record.suggestionDiagnostics
|
|
636
|
-
.filter((item) => [`'__LogicEmpty' is declared but its value is never read.`, `'__destinationEmpty__' is declared but its value is never read
|
|
768
|
+
.filter((item) => [`'__LogicEmpty' is declared but its value is never read.`, `'__destinationEmpty__' is declared but its value is never read.`,
|
|
769
|
+
`'__UpdateNoProperty__' is declared but its value is never read.`].includes(item.text))
|
|
637
770
|
.map((diag) => this._resolveDiagnostic(diag, node, record))
|
|
638
771
|
.filter((diag) => !!diag);
|
|
639
772
|
record.suggestionDiagnostics.push(...this._attachSuggestionDiagnostics(node));
|
|
@@ -657,14 +790,14 @@ class NaslServer {
|
|
|
657
790
|
// 递归检查,防止从顶层页面开始删除影响子页面内容检查
|
|
658
791
|
while (curNode instanceof concepts_1.View && !removed) {
|
|
659
792
|
if (curNode.parentNode instanceof concepts_1.View && !curNode.parentNode.children.includes(curNode)
|
|
660
|
-
|| curNode.parentNode instanceof concepts_1.
|
|
793
|
+
|| curNode.parentNode instanceof concepts_1.Frontend && !curNode.parentNode.views.includes(curNode)) {
|
|
661
794
|
removed = true;
|
|
662
795
|
}
|
|
663
796
|
curNode = curNode.parentNode;
|
|
664
797
|
}
|
|
665
798
|
if (removed)
|
|
666
799
|
return diagnostics;
|
|
667
|
-
fileNode?.sourceMap.forEach(
|
|
800
|
+
fileNode?.sourceMap.forEach((value, node) => {
|
|
668
801
|
if (node instanceof concepts_1.Match) {
|
|
669
802
|
const { cases, expression } = node || {};
|
|
670
803
|
const typeAnnotationMap = {};
|
|
@@ -674,7 +807,7 @@ class NaslServer {
|
|
|
674
807
|
count: 0,
|
|
675
808
|
};
|
|
676
809
|
if (Array.isArray(cases)) {
|
|
677
|
-
cases.forEach(
|
|
810
|
+
cases.forEach((caseItem, index) => {
|
|
678
811
|
let isDisabled = false;
|
|
679
812
|
// 是最后一项
|
|
680
813
|
if (index === cases.length - 1) {
|
|
@@ -714,7 +847,7 @@ class NaslServer {
|
|
|
714
847
|
}),
|
|
715
848
|
];
|
|
716
849
|
}
|
|
717
|
-
if (Array.isArray(enumerableItems)) {
|
|
850
|
+
if (Array.isArray(enumerableItems) && enumerableItems.length) {
|
|
718
851
|
const map = {};
|
|
719
852
|
cases.forEach((caseItem) => {
|
|
720
853
|
const { patterns } = caseItem || {};
|
|
@@ -806,25 +939,40 @@ class NaslServer {
|
|
|
806
939
|
// 递归检查,防止从顶层页面开始删除影响子页面内容检查
|
|
807
940
|
while (curNode instanceof concepts_1.View && !removed) {
|
|
808
941
|
if (curNode.parentNode instanceof concepts_1.View && !curNode.parentNode.children.includes(curNode)
|
|
809
|
-
|| curNode.parentNode instanceof concepts_1.
|
|
942
|
+
|| curNode.parentNode instanceof concepts_1.Frontend && !curNode.parentNode.views.includes(curNode)) {
|
|
810
943
|
removed = true;
|
|
811
944
|
}
|
|
812
945
|
curNode = curNode.parentNode;
|
|
813
946
|
}
|
|
814
947
|
if (removed)
|
|
815
948
|
return diagnostics;
|
|
816
|
-
fileNode.
|
|
949
|
+
fileNode?.sourceMap.forEach((value, node) => {
|
|
817
950
|
if (node instanceof concepts_1.ViewElement && node.view === fileNode) {
|
|
818
951
|
if (node.tag) {
|
|
819
952
|
node.bindAttrs.forEach((bindAttr) => {
|
|
820
|
-
if ((bindAttr.model || bindAttr.sync) && bindAttr.expression
|
|
821
|
-
const
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
953
|
+
if ((bindAttr.model || bindAttr.sync) && bindAttr.expression) {
|
|
954
|
+
const bindExpression = bindAttr.expression;
|
|
955
|
+
let diagnostic;
|
|
956
|
+
if (bindExpression.concept !== 'Identifier' && bindExpression.concept !== 'MemberExpression') {
|
|
957
|
+
diagnostic = {
|
|
958
|
+
node: bindAttr,
|
|
959
|
+
severity: 'error',
|
|
960
|
+
message: '页面元素双向绑定:只允许绑定可赋值的变量和属性。',
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
else {
|
|
964
|
+
if (bindExpression.isEnum()) {
|
|
965
|
+
diagnostic = {
|
|
966
|
+
node: bindAttr,
|
|
967
|
+
severity: 'error',
|
|
968
|
+
message: '页面元素双向绑定:只允许绑定可赋值的变量和属性。',
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
if (diagnostic) {
|
|
973
|
+
bindAttr.tsErrorDetail = diagnostic;
|
|
974
|
+
diagnostics.push(diagnostic);
|
|
975
|
+
}
|
|
828
976
|
}
|
|
829
977
|
});
|
|
830
978
|
}
|
|
@@ -838,34 +986,44 @@ class NaslServer {
|
|
|
838
986
|
// 子页面内部逻辑过滤
|
|
839
987
|
if (nodeIn.view !== fileNode)
|
|
840
988
|
return;
|
|
989
|
+
// 当局部变量、输出参数属于页面内逻辑时,需过滤同页面下不同逻辑下的同名变量
|
|
990
|
+
if (node.logic && node.logic !== nodeIn.logic)
|
|
991
|
+
return;
|
|
841
992
|
// 跟变量无关的赋值过滤
|
|
842
993
|
const jsCode = nodeIn.toJS();
|
|
843
994
|
if (!jsCode.includes(`${node.name} = `))
|
|
844
995
|
return;
|
|
845
|
-
//
|
|
846
|
-
if ((nodeIn.logic?.variables || []).find((lVar) => jsCode.includes(`${lVar.name} = `))
|
|
847
|
-
|| (nodeIn.logic?.returns || []).find((lRet) => jsCode.includes(`${lRet.name} = `))
|
|
848
|
-
|| (nodeIn.logic?.params || []).find((lPar) => jsCode.includes(`${lPar.name} = `)))
|
|
849
|
-
return;
|
|
996
|
+
// 页面局部变量
|
|
850
997
|
if (node instanceof concepts_1.Variable && node.parentNode instanceof concepts_1.View) {
|
|
998
|
+
// 跟页面局部变量无关的赋值过滤
|
|
999
|
+
if (!jsCode.includes(`this.${node.name} = `))
|
|
1000
|
+
return;
|
|
851
1001
|
// 直接赋值 logic 内局部变量、输入参数直接提示系统无法推断类型
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
1002
|
+
if (nodeIn.logic?.params.find((param) => jsCode.includes(param.name))
|
|
1003
|
+
|| nodeIn.logic?.virtualParams.find((vParam) => jsCode.includes(vParam.name))
|
|
1004
|
+
|| nodeIn.logic?.variables.find((variable) => jsCode.includes(variable.name))) {
|
|
1005
|
+
if (!nodeIn.tsErrorDetail) {
|
|
1006
|
+
const diagnostic = {
|
|
1007
|
+
node: nodeIn,
|
|
1008
|
+
severity: 'error',
|
|
1009
|
+
message: `页面${nodeTypeName} ${node.name} 赋值页面逻辑内局部变量或输入参数时,系统无法推导类型。`,
|
|
1010
|
+
};
|
|
1011
|
+
nodeIn.tsErrorDetail = diagnostic;
|
|
1012
|
+
diagnostics.push(diagnostic);
|
|
1013
|
+
}
|
|
864
1014
|
msg = '系统无法推断类型。';
|
|
1015
|
+
}
|
|
865
1016
|
}
|
|
866
|
-
|
|
867
|
-
|
|
1017
|
+
if (!nodeIn.tsErrorDetail) {
|
|
1018
|
+
const diagnostic = {
|
|
1019
|
+
node: nodeIn,
|
|
1020
|
+
severity: 'error',
|
|
1021
|
+
message: `${nodeIn.label}左边 ${node.name} 未设置类型,右边必须为有返回值的内容。`,
|
|
1022
|
+
};
|
|
1023
|
+
nodeIn.tsErrorDetail = diagnostic;
|
|
1024
|
+
diagnostics.push(diagnostic);
|
|
868
1025
|
}
|
|
1026
|
+
msg = '必须赋值有返回值的内容。';
|
|
869
1027
|
}
|
|
870
1028
|
});
|
|
871
1029
|
if (!msg)
|
|
@@ -878,12 +1036,9 @@ class NaslServer {
|
|
|
878
1036
|
node.tsErrorDetail = diagnostic;
|
|
879
1037
|
diagnostics.push(diagnostic);
|
|
880
1038
|
}
|
|
881
|
-
else {
|
|
882
|
-
node.tsErrorDetail = undefined;
|
|
883
|
-
}
|
|
884
1039
|
}
|
|
885
1040
|
else {
|
|
886
|
-
this.
|
|
1041
|
+
this.checkNodeError(node, diagnostics);
|
|
887
1042
|
}
|
|
888
1043
|
});
|
|
889
1044
|
}
|
|
@@ -909,6 +1064,44 @@ class NaslServer {
|
|
|
909
1064
|
};
|
|
910
1065
|
diagnostics.push(diagnostic);
|
|
911
1066
|
}
|
|
1067
|
+
else if (propertyValue.value) {
|
|
1068
|
+
const dataSource = fileNode;
|
|
1069
|
+
// 数据源有连接错误
|
|
1070
|
+
let envText;
|
|
1071
|
+
if (propertyValue.env === 'dev') {
|
|
1072
|
+
if (dataSource.__devConnectError) {
|
|
1073
|
+
envText = '开发';
|
|
1074
|
+
}
|
|
1075
|
+
else if (dataSource.__devConnectError === false) {
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
else if (propertyValue.env === 'online') {
|
|
1080
|
+
if (dataSource.__onlineConnectError) {
|
|
1081
|
+
envText = '生产';
|
|
1082
|
+
}
|
|
1083
|
+
else if (dataSource.__onlineConnectError === false) {
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
// 手动插入报错
|
|
1088
|
+
if (envText) {
|
|
1089
|
+
const diagnostic = {
|
|
1090
|
+
node: fileNode,
|
|
1091
|
+
severity: 'error',
|
|
1092
|
+
message: `数据源配置:数据源 ${property.name} ${envText}环境数据源连接不通,请先检查${envText}环境数据源配置`,
|
|
1093
|
+
// 保留原来的内容方便查询一些问题
|
|
1094
|
+
originalDiagnostic: {
|
|
1095
|
+
fileName: '',
|
|
1096
|
+
start: null,
|
|
1097
|
+
end: null,
|
|
1098
|
+
category: 'error',
|
|
1099
|
+
text: `DataSource connection error`,
|
|
1100
|
+
},
|
|
1101
|
+
};
|
|
1102
|
+
return diagnostics.push(diagnostic);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
912
1105
|
});
|
|
913
1106
|
}
|
|
914
1107
|
}
|
|
@@ -917,26 +1110,36 @@ class NaslServer {
|
|
|
917
1110
|
// 判断逻辑是否已经删除
|
|
918
1111
|
if (fileNode.parentNode instanceof concepts_1.App && !fileNode.parentNode.logics.includes(fileNode))
|
|
919
1112
|
return diagnostics;
|
|
920
|
-
fileNode?.sourceMap.forEach(
|
|
1113
|
+
fileNode?.sourceMap.forEach((value, node) => {
|
|
1114
|
+
//OQL支持返回复合类型数据了
|
|
921
1115
|
// SqlQueryComponent内部返回值类型,如果是嵌套的就需要报错
|
|
922
|
-
if ((node instanceof
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
}
|
|
1116
|
+
// if ((node instanceof OqlQueryComponent || node instanceof SqlQueryComponent) && (node as SqlQueryComponent).getTypeBanError()) {
|
|
1117
|
+
// const diagnostic = {
|
|
1118
|
+
// node,
|
|
1119
|
+
// severity: 'error',
|
|
1120
|
+
// message: 'SQL查询:返回类型内部,不支持复杂类型。',
|
|
1121
|
+
// };
|
|
1122
|
+
// node.tsErrorDetail = diagnostic;
|
|
1123
|
+
// diagnostics.push(diagnostic);
|
|
1124
|
+
// }
|
|
931
1125
|
if (node instanceof concepts_1.Return || node instanceof concepts_1.Variable) {
|
|
932
1126
|
if (!node.typeAnnotation && !node.__TypeAnnotation) {
|
|
933
1127
|
const nodeTypeName = node.concept === 'Return' ? '输出参数' : '局部变量';
|
|
934
1128
|
let used = false;
|
|
935
1129
|
fileNode?.sourceMap.forEach((valueIn, nodeIn) => {
|
|
936
|
-
if (nodeIn
|
|
1130
|
+
if (!used && nodeIn
|
|
937
1131
|
&& (nodeIn instanceof concepts_1.BatchAssignment || (nodeIn instanceof concepts_1.Assignment && nodeIn.left?.name))
|
|
938
1132
|
&& nodeIn.toJS().includes(`${node.name} = `)) {
|
|
939
1133
|
used = true;
|
|
1134
|
+
if (!nodeIn.tsErrorDetail) {
|
|
1135
|
+
const diagnostic = {
|
|
1136
|
+
node: nodeIn,
|
|
1137
|
+
severity: 'error',
|
|
1138
|
+
message: `${nodeIn.label}左边 ${node.name} 未设置类型,右边必须为有返回值的内容。`,
|
|
1139
|
+
};
|
|
1140
|
+
nodeIn.tsErrorDetail = diagnostic;
|
|
1141
|
+
diagnostics.push(diagnostic);
|
|
1142
|
+
}
|
|
940
1143
|
}
|
|
941
1144
|
});
|
|
942
1145
|
const msg = used ? '必须赋值有返回值的内容。' : '未设置类型或未赋值。直接赋值系统可以自动推断类型。';
|
|
@@ -952,31 +1155,61 @@ class NaslServer {
|
|
|
952
1155
|
node.tsErrorDetail = undefined;
|
|
953
1156
|
}
|
|
954
1157
|
}
|
|
955
|
-
this.
|
|
1158
|
+
this.checkNodeError(node, diagnostics);
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
if (fileNode instanceof concepts_1.Process) {
|
|
1162
|
+
fileNode?.sourceMap.forEach((value, node) => {
|
|
1163
|
+
this.checkNodeError(node, diagnostics);
|
|
956
1164
|
});
|
|
957
1165
|
}
|
|
958
1166
|
return diagnostics;
|
|
959
1167
|
}
|
|
960
|
-
|
|
1168
|
+
checkNodeError(node, diagnostics) {
|
|
961
1169
|
if (!node)
|
|
962
1170
|
return;
|
|
963
1171
|
// 如果节点是match的看看节点里是不是有重复的
|
|
964
1172
|
if (node instanceof concepts_1.Match) {
|
|
965
1173
|
const typeMap = {};
|
|
966
|
-
node.
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
1174
|
+
if (node.expression?.__TypeAnnotation) {
|
|
1175
|
+
const { typeName, typeNamespace } = node.expression.__TypeAnnotation;
|
|
1176
|
+
if (typeName === 'Union' || typeName === 'Boolean' || typeNamespace?.endsWith('enums')) {
|
|
1177
|
+
node.cases.forEach((item) => {
|
|
1178
|
+
if (Array.isArray(item.patterns)) {
|
|
1179
|
+
item.patterns.forEach((pattern) => {
|
|
1180
|
+
if (pattern instanceof concepts_1.TypeAnnotation) {
|
|
1181
|
+
if (typeMap[pattern.sortedTypeKey]) {
|
|
1182
|
+
typeMap[pattern.sortedTypeKey].push(pattern);
|
|
1183
|
+
}
|
|
1184
|
+
else {
|
|
1185
|
+
typeMap[pattern.sortedTypeKey] = [pattern];
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
else if (pattern instanceof concepts_1.MemberExpression) {
|
|
1189
|
+
if (pattern.completeName && pattern.object?.namespace?.endsWith('enums')) {
|
|
1190
|
+
const onlyKey = pattern.completeName;
|
|
1191
|
+
if (typeMap[onlyKey]) {
|
|
1192
|
+
typeMap[onlyKey].push(pattern);
|
|
1193
|
+
}
|
|
1194
|
+
else {
|
|
1195
|
+
typeMap[onlyKey] = [pattern];
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
else if (pattern instanceof concepts_1.BooleanLiteral) {
|
|
1200
|
+
const onlyKey = pattern.concept + pattern.value;
|
|
1201
|
+
if (typeMap[onlyKey]) {
|
|
1202
|
+
typeMap[onlyKey].push(pattern);
|
|
1203
|
+
}
|
|
1204
|
+
else {
|
|
1205
|
+
typeMap[onlyKey] = [pattern];
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
976
1209
|
}
|
|
977
1210
|
});
|
|
978
1211
|
}
|
|
979
|
-
}
|
|
1212
|
+
}
|
|
980
1213
|
Object.keys(typeMap).forEach((item) => {
|
|
981
1214
|
if (typeMap[item].length > 1) {
|
|
982
1215
|
typeMap[item].forEach((nodeItem) => {
|
|
@@ -993,7 +1226,7 @@ class NaslServer {
|
|
|
993
1226
|
});
|
|
994
1227
|
}
|
|
995
1228
|
// 如果节点是match的patterns 里的
|
|
996
|
-
if (node
|
|
1229
|
+
if (node?.parentKey === 'patterns' && node.parentNode instanceof concepts_1.MatchCase) {
|
|
997
1230
|
const matchNode = node.getAncestor('Match');
|
|
998
1231
|
const matchExpressionType = matchNode?.expression?.__TypeAnnotation;
|
|
999
1232
|
// 判断union类型是不是重复
|
|
@@ -1010,10 +1243,32 @@ class NaslServer {
|
|
|
1010
1243
|
node.tsErrorDetail = diagnostic;
|
|
1011
1244
|
diagnostics.push(diagnostic);
|
|
1012
1245
|
}
|
|
1246
|
+
// 如果TypeAnnotation 还存在,但是本身已经不是union类型,就是已经从union换别的类型了就都要报错
|
|
1247
|
+
}
|
|
1248
|
+
else if (node instanceof concepts_1.TypeAnnotation && matchExpressionType?.typeKind !== 'union') {
|
|
1249
|
+
const diagnostic = {
|
|
1250
|
+
node,
|
|
1251
|
+
severity: 'error',
|
|
1252
|
+
message: '匹配:选择类型不存在',
|
|
1253
|
+
titleTip: '该类型已被删除',
|
|
1254
|
+
};
|
|
1255
|
+
node.tsErrorDetail = diagnostic;
|
|
1256
|
+
diagnostics.push(diagnostic);
|
|
1257
|
+
// 如果可枚举变量的 ,变量 还存在,但是本身已经是union类型,就是已经从别的类型 换了union就都要报错
|
|
1258
|
+
}
|
|
1259
|
+
else if (!(node instanceof concepts_1.TypeAnnotation) && matchExpressionType?.typeKind === 'union') {
|
|
1260
|
+
const diagnostic = {
|
|
1261
|
+
node,
|
|
1262
|
+
severity: 'error',
|
|
1263
|
+
message: '匹配:选择值不存在',
|
|
1264
|
+
titleTip: '该值无法匹配,请重新选择类型',
|
|
1265
|
+
};
|
|
1266
|
+
node.tsErrorDetail = diagnostic;
|
|
1267
|
+
diagnostics.push(diagnostic);
|
|
1013
1268
|
}
|
|
1014
1269
|
if (node.tsErrorDetail) {
|
|
1015
|
-
//
|
|
1016
|
-
if (matchExpressionType?.typeNamespace?.includes('enums')) {
|
|
1270
|
+
// 如果父级是枚举,而且子集选的是变量,就提示枚举值已被删除
|
|
1271
|
+
if (matchExpressionType?.typeNamespace?.includes('enums') && (node instanceof concepts_1.MemberExpression)) {
|
|
1017
1272
|
node.tsErrorDetail.titleTip = '该枚举值已被删除';
|
|
1018
1273
|
}
|
|
1019
1274
|
else if (!node.tsErrorDetail.titleTip) {
|
|
@@ -1021,6 +1276,35 @@ class NaslServer {
|
|
|
1021
1276
|
}
|
|
1022
1277
|
}
|
|
1023
1278
|
}
|
|
1279
|
+
// 如果forEach 中的each的内容是union类型就要提示报错
|
|
1280
|
+
if (node?.parentKey === 'each' && node?.__TypeAnnotation?.typeKind === 'union') {
|
|
1281
|
+
const diagnostic = {
|
|
1282
|
+
node,
|
|
1283
|
+
severity: 'error',
|
|
1284
|
+
message: 'ForEach:参数类型不一致!传入类型:联合类型。接受类型:List类型。',
|
|
1285
|
+
};
|
|
1286
|
+
node.tsErrorDetail = diagnostic;
|
|
1287
|
+
diagnostics.push(diagnostic);
|
|
1288
|
+
}
|
|
1289
|
+
/**
|
|
1290
|
+
* 如果节点是内置函数
|
|
1291
|
+
* 穷举在线上的情况,不在线上就void报错, calllogic 和 callinterface 因为原来有报错,所以就忽略掉
|
|
1292
|
+
* && 他在父级中,不在body
|
|
1293
|
+
* && 也不再 if的线上
|
|
1294
|
+
* && 也不再 switch的线上consequent
|
|
1295
|
+
* && 也不再草稿区域
|
|
1296
|
+
* && 不在 parentNode.parentNode(只用处理两层的,超过两层上就需要报错,只用直接是参数位第一层的需要) 是 callfunction 和 callInfterfase中,因为这两本身有强制类型,内置函数或者一些带T的声明那种,
|
|
1297
|
+
* && 而且也没有类型,就说明在槽位里,就需要报错
|
|
1298
|
+
*/
|
|
1299
|
+
if (node instanceof concepts_1.CallFunction && node.parentKey !== 'body' && node.parentKey !== 'alternate' && node.parentKey !== 'playground' && node.parentKey !== 'consequent' && node.parentNode?.parentNode?.concept !== 'CallLogic' && node.parentNode?.parentNode?.concept !== 'CallInterface' && !node.__TypeAnnotation) {
|
|
1300
|
+
const diagnostic = {
|
|
1301
|
+
node,
|
|
1302
|
+
severity: 'error',
|
|
1303
|
+
message: `类型不一致,当前内置函数${node.calleeName || ''}无返回值。`,
|
|
1304
|
+
};
|
|
1305
|
+
node.tsErrorDetail = diagnostic;
|
|
1306
|
+
diagnostics.push(diagnostic);
|
|
1307
|
+
}
|
|
1024
1308
|
}
|
|
1025
1309
|
/* 接口导入查找 */
|
|
1026
1310
|
existStructureFix(semanticDiagnostics, node, that) {
|
|
@@ -1328,6 +1612,10 @@ class NaslServer {
|
|
|
1328
1612
|
return null;
|
|
1329
1613
|
const minRange = this._findMinRange(record, fileNode);
|
|
1330
1614
|
if (minRange) {
|
|
1615
|
+
// 节点上ts临时变量标识,如果有这个就不rename
|
|
1616
|
+
if (minRange.node.noTsReName) {
|
|
1617
|
+
return null;
|
|
1618
|
+
}
|
|
1331
1619
|
// 如果节点是TypeAnnotation类型,
|
|
1332
1620
|
// 很复杂,可能是多级嵌套结构
|
|
1333
1621
|
// 不一定只修改typeName
|
|
@@ -1400,7 +1688,7 @@ class NaslServer {
|
|
|
1400
1688
|
// 因为要用下面的点位信息
|
|
1401
1689
|
const name = minRange.node.name;
|
|
1402
1690
|
// 如果name不改,那就是要改命名空间
|
|
1403
|
-
if (newValue === name) {
|
|
1691
|
+
if (node instanceof concepts_1.Frontend || newValue === name) {
|
|
1404
1692
|
const namespace = minRange.node.namespace;
|
|
1405
1693
|
// 先看下标位置
|
|
1406
1694
|
const lineText = record.lineText;
|
|
@@ -1414,10 +1702,16 @@ class NaslServer {
|
|
|
1414
1702
|
minRange.newValue = newTextValue;
|
|
1415
1703
|
}
|
|
1416
1704
|
}
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
minRange.
|
|
1420
|
-
|
|
1705
|
+
if (node instanceof concepts_1.Enum) {
|
|
1706
|
+
// 如果是枚举修改,枚举的值刚好在Identifier 中选了 就修改值
|
|
1707
|
+
if (minRange.node instanceof concepts_1.Identifier) {
|
|
1708
|
+
minRange.newValue = newValue;
|
|
1709
|
+
minRange.setTypeMethods = 'setName';
|
|
1710
|
+
}
|
|
1711
|
+
else if (minRange.node instanceof concepts_1.EntityProperty) {
|
|
1712
|
+
// 如果枚举自己改名引用到了实体字段,而不是实体字段下的类型,就说明是默认值,默认值可以不处理
|
|
1713
|
+
return null;
|
|
1714
|
+
}
|
|
1421
1715
|
}
|
|
1422
1716
|
// 如果修改逻辑,改到了Identifier表达式,只能说明是在属性里有使用了
|
|
1423
1717
|
if (minRange.node instanceof concepts_1.Identifier && node instanceof concepts_1.Logic) {
|
|
@@ -1517,6 +1811,24 @@ class NaslServer {
|
|
|
1517
1811
|
minRange.newValue = newTsNameSpace;
|
|
1518
1812
|
}
|
|
1519
1813
|
}
|
|
1814
|
+
if (node instanceof concepts_1.Frontend && minRange.node instanceof concepts_1.Destination) {
|
|
1815
|
+
const tsCalleeNamespace = minRange.node.tsCalleeNamespace;
|
|
1816
|
+
const tsName = minRange.node.tsName;
|
|
1817
|
+
const oldValue = tsCalleeNamespace + '.' + tsName;
|
|
1818
|
+
// 先看下标位置
|
|
1819
|
+
const lineText = record.lineText;
|
|
1820
|
+
const index = lineText.indexOf(oldValue);
|
|
1821
|
+
// 在把开始结束位置的-开始位置,来知道是哪里要替换
|
|
1822
|
+
const start = record.start.offset - index - 1;
|
|
1823
|
+
const end = record.end.offset - index - 1;
|
|
1824
|
+
if (start <= tsCalleeNamespace.length) {
|
|
1825
|
+
// 新的完整的value
|
|
1826
|
+
let newTsNameSpace = tsCalleeNamespace.substring(0, start) + newValue + tsCalleeNamespace.substring(end, tsCalleeNamespace.length);
|
|
1827
|
+
minRange.setTypeMethods = 'setViewNamespace';
|
|
1828
|
+
newTsNameSpace = newTsNameSpace.replace(/\.\$/g, '.');
|
|
1829
|
+
minRange.newValue = newTsNameSpace;
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1520
1832
|
// 如果是事件修改
|
|
1521
1833
|
// 如果是view也需要加前缀
|
|
1522
1834
|
// logic 和 views名称修改 可能会触发bindEvent修改
|
|
@@ -1636,7 +1948,7 @@ class NaslServer {
|
|
|
1636
1948
|
minRange.newValue = newValue;
|
|
1637
1949
|
}
|
|
1638
1950
|
else if (minRange.node instanceof concepts_1.SqlQueryComponent || minRange.node instanceof concepts_1.OqlQueryComponent) {
|
|
1639
|
-
minRange.setTypeMethods = '
|
|
1951
|
+
minRange.setTypeMethods = 'renameDataSource';
|
|
1640
1952
|
}
|
|
1641
1953
|
}
|
|
1642
1954
|
if (minRange.node instanceof concepts_1.QueryFieldExpression && node instanceof concepts_1.EntityProperty) {
|
|
@@ -1713,8 +2025,7 @@ class NaslServer {
|
|
|
1713
2025
|
}
|
|
1714
2026
|
}
|
|
1715
2027
|
else {
|
|
1716
|
-
console.log('没找到节点需要排查');
|
|
1717
|
-
console.log(record, fileNode.sourceMap);
|
|
2028
|
+
console.log('没找到节点需要排查', record, fileNode.sourceMap);
|
|
1718
2029
|
}
|
|
1719
2030
|
return minRange;
|
|
1720
2031
|
})
|
|
@@ -1732,12 +2043,8 @@ class NaslServer {
|
|
|
1732
2043
|
const minRange = this._findMinRange(record, fileNode);
|
|
1733
2044
|
if (minRange) {
|
|
1734
2045
|
// 如果找到节点是callLogic就去更新
|
|
1735
|
-
if (minRange.node instanceof concepts_1.CallLogic && node instanceof concepts_1.Param) {
|
|
1736
|
-
minRange.node.
|
|
1737
|
-
}
|
|
1738
|
-
// 如果节点参数增加页面也要更新
|
|
1739
|
-
if (minRange.node instanceof concepts_1.Destination && node instanceof concepts_1.Param) {
|
|
1740
|
-
minRange.node.setViewArgument(parantNode);
|
|
2046
|
+
if ((minRange.node instanceof concepts_1.CallLogic || minRange.node instanceof concepts_1.Destination) && node instanceof concepts_1.Param) {
|
|
2047
|
+
minRange.node.addCalleeArg(parantNode);
|
|
1741
2048
|
}
|
|
1742
2049
|
}
|
|
1743
2050
|
});
|
|
@@ -2043,18 +2350,34 @@ class NaslServer {
|
|
|
2043
2350
|
if (node instanceof concepts_1.BinaryExpression && (['==', '!=', '>', '<', '>=', '<='].includes(node.operator))) {
|
|
2044
2351
|
return concepts_1.TypeAnnotation.createPrimitive('Boolean');
|
|
2045
2352
|
}
|
|
2046
|
-
// Convert
|
|
2047
|
-
if (node instanceof concepts_1.CallFunction && node.calleeNamespace === 'nasl.util' &&
|
|
2353
|
+
// Convert和new都是自身携带类型的,就不进行修改
|
|
2354
|
+
if (node instanceof concepts_1.CallFunction && node.calleeNamespace === 'nasl.util' && (['Convert', 'New', 'FromString'].includes(node.calleeName))) {
|
|
2355
|
+
if (node.typeArguments.length) {
|
|
2356
|
+
return node.typeArguments[0];
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
// Convert和new都是自身携带类型的,就不进行修改
|
|
2360
|
+
if (node instanceof concepts_1.CallLogic && node.calleeNamespace === 'nasl.util' && (node.calleeName === 'jsonDeserialize')) {
|
|
2048
2361
|
if (node.typeArguments.length) {
|
|
2049
2362
|
return node.typeArguments[0];
|
|
2050
2363
|
}
|
|
2051
2364
|
}
|
|
2052
|
-
//
|
|
2365
|
+
// 特殊处理param有类型错误的
|
|
2366
|
+
if (node instanceof concepts_1.Param) {
|
|
2367
|
+
// index在nasl foreach上有脏数据
|
|
2368
|
+
if (node.parentKey === 'index' && node.parentNode instanceof concepts_1.ForEachStatement) {
|
|
2369
|
+
return concepts_1.TypeAnnotation.createPrimitive('Integer');
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2053
2372
|
if (node instanceof concepts_1.CallQueryComponent || node instanceof concepts_1.SqlQueryComponent || node instanceof concepts_1.OqlQueryComponent) {
|
|
2054
2373
|
return node.typeAnnotation;
|
|
2055
2374
|
}
|
|
2056
|
-
|
|
2057
|
-
|
|
2375
|
+
// 老数据可能typeKind 的primitive缺失
|
|
2376
|
+
if (node instanceof concepts_1.NumericLiteral && node.typeAnnotation) {
|
|
2377
|
+
return concepts_1.TypeAnnotation.from({
|
|
2378
|
+
...node.typeAnnotation?.toJSON(),
|
|
2379
|
+
typeKind: 'primitive',
|
|
2380
|
+
});
|
|
2058
2381
|
}
|
|
2059
2382
|
}
|
|
2060
2383
|
/**
|
|
@@ -2080,7 +2403,6 @@ class NaslServer {
|
|
|
2080
2403
|
const nodeTypeAnnotation = this.getCurrentNodeKnownTypeAnnotation(node);
|
|
2081
2404
|
if (nodeTypeAnnotation) {
|
|
2082
2405
|
types.set(node, nodeTypeAnnotation);
|
|
2083
|
-
node.__TypeAnnotation = nodeTypeAnnotation;
|
|
2084
2406
|
return;
|
|
2085
2407
|
}
|
|
2086
2408
|
// 要通过自己或者依赖关系拿的,二次遍历
|
|
@@ -2095,7 +2417,7 @@ class NaslServer {
|
|
|
2095
2417
|
'Return',
|
|
2096
2418
|
'Variable',
|
|
2097
2419
|
].includes(node.concept) && node.typeAnnotation) {
|
|
2098
|
-
node
|
|
2420
|
+
types.set(node, node.typeAnnotation);
|
|
2099
2421
|
return;
|
|
2100
2422
|
}
|
|
2101
2423
|
if (![
|
|
@@ -2109,6 +2431,9 @@ class NaslServer {
|
|
|
2109
2431
|
'Return',
|
|
2110
2432
|
'Variable',
|
|
2111
2433
|
'Match',
|
|
2434
|
+
'NewComposite',
|
|
2435
|
+
'NewList',
|
|
2436
|
+
'NewMap',
|
|
2112
2437
|
].includes(node.concept))
|
|
2113
2438
|
return;
|
|
2114
2439
|
// 要去ls那边获取的
|
|
@@ -2125,12 +2450,13 @@ class NaslServer {
|
|
|
2125
2450
|
// 如果没有括号 ,括号就在外面,就 -1
|
|
2126
2451
|
// 有括号就找到括号的位置 然后 -1
|
|
2127
2452
|
let indexOf = 0;
|
|
2128
|
-
if (item.code.
|
|
2453
|
+
if (!item.code.includes('(')) {
|
|
2129
2454
|
indexOf = -1;
|
|
2130
2455
|
}
|
|
2131
2456
|
else {
|
|
2132
|
-
|
|
2133
|
-
|
|
2457
|
+
// 如果有泛型先往前找一找
|
|
2458
|
+
if (item.code.includes('<')) {
|
|
2459
|
+
indexOf = Math.min(item.code.indexOf('<'), item.code.indexOf('('));
|
|
2134
2460
|
}
|
|
2135
2461
|
else {
|
|
2136
2462
|
indexOf = item.code.indexOf('(');
|
|
@@ -2159,11 +2485,21 @@ class NaslServer {
|
|
|
2159
2485
|
newCode = newCode.substring(newCode.lastIndexOf('\n'), indexOf);
|
|
2160
2486
|
fileDetail.offset = newCode.length + 'return '.length;
|
|
2161
2487
|
}
|
|
2488
|
+
else if (['NewComposite', 'NewList', 'NewMap'].includes(node.concept)) {
|
|
2489
|
+
fileDetail.line = item.range.end.line;
|
|
2490
|
+
const indexOf = item.code.indexOf('return __newComposite');
|
|
2491
|
+
let newCode = item.code.substring(0, indexOf);
|
|
2492
|
+
newCode = newCode.substring(newCode.lastIndexOf('\n'), indexOf);
|
|
2493
|
+
fileDetail.offset = newCode.length + 'return '.length;
|
|
2494
|
+
}
|
|
2162
2495
|
args.push(fileDetail);
|
|
2163
2496
|
});
|
|
2497
|
+
console.time('请求');
|
|
2164
2498
|
const resultMap = (await this.getNaslNodeTypeFull(args)).response;
|
|
2499
|
+
console.timeEnd('请求');
|
|
2165
2500
|
// console.log(resultMap);
|
|
2166
2501
|
// const result = (await this.getNaslNodeQuickInfoFull(args)).response;
|
|
2502
|
+
// console.log(result);
|
|
2167
2503
|
args.forEach((arg, index) => {
|
|
2168
2504
|
const { file, line, offset } = arg;
|
|
2169
2505
|
const item = resultMap?.[file]?.[line]?.[offset];
|
|
@@ -2172,24 +2508,21 @@ class NaslServer {
|
|
|
2172
2508
|
// console.log('原始:', displayString);
|
|
2173
2509
|
// console.log('方案2:', item?.[0]?.nodeType);
|
|
2174
2510
|
const nodeTypeAnnotation = (0, formatTsUtils_1.type2TypeAnnotation)(item?.[0]?.nodeType);
|
|
2175
|
-
// console.log(newQuickInfoNodes[index].node, nodeTypeAnnotation,
|
|
2511
|
+
// console.log(newQuickInfoNodes[index].node, nodeTypeAnnotation, nodeTypeAnnotation?.typeKey);
|
|
2176
2512
|
types.set(newQuickInfoNodes[index].node, nodeTypeAnnotation);
|
|
2177
|
-
newQuickInfoNodes[index].node.
|
|
2178
|
-
newQuickInfoNodes[index].node.__nodeType = item?.[0]?.nodeType;
|
|
2513
|
+
newQuickInfoNodes[index].node.__nodeType = Object.freeze(item?.[0]?.nodeType);
|
|
2179
2514
|
// console.log('方案1:', displayString1);
|
|
2180
2515
|
});
|
|
2181
2516
|
getFromOthers.forEach((type, node) => {
|
|
2182
2517
|
if (node instanceof concepts_1.Assignment) {
|
|
2183
2518
|
if (!types.get(node.left)) {
|
|
2184
2519
|
types.set(node.left, types.get(node.right));
|
|
2185
|
-
node.left.__TypeAnnotation = types.get(node.right);
|
|
2186
2520
|
}
|
|
2187
2521
|
}
|
|
2188
2522
|
else if (node instanceof concepts_1.Argument) {
|
|
2189
2523
|
// 如果Argument,但是没可以用的类型,就用原来logic的参数类型
|
|
2190
2524
|
const argType = this.getArgumentTypeAnnotation(node, newQuickInfoNodes, types);
|
|
2191
2525
|
types.set(node, argType);
|
|
2192
|
-
node.__TypeAnnotation = argType.typeAnnotation;
|
|
2193
2526
|
}
|
|
2194
2527
|
else if (node instanceof concepts_1.MatchCase) {
|
|
2195
2528
|
// matchCase的类型
|
|
@@ -2198,11 +2531,30 @@ class NaslServer {
|
|
|
2198
2531
|
const last = node.body[node.body.length - 1];
|
|
2199
2532
|
if (last.__TypeAnnotation) {
|
|
2200
2533
|
types.set(node, last.__TypeAnnotation);
|
|
2201
|
-
node.__TypeAnnotation = last.__TypeAnnotation;
|
|
2202
2534
|
}
|
|
2203
2535
|
}
|
|
2204
2536
|
}
|
|
2205
2537
|
});
|
|
2538
|
+
// 重置类型状态, 并且赋值
|
|
2539
|
+
types.forEach((value, node) => {
|
|
2540
|
+
try {
|
|
2541
|
+
// 因为node可能是经过处理的TypeAnnotation
|
|
2542
|
+
node.__isCorrectTypeAnnotation = true;
|
|
2543
|
+
if (value) {
|
|
2544
|
+
if (value instanceof concepts_1.TypeAnnotation) {
|
|
2545
|
+
node.__TypeAnnotation = Object.freeze(value);
|
|
2546
|
+
}
|
|
2547
|
+
else if (value.typeAnnotation) {
|
|
2548
|
+
node.__TypeAnnotation = Object.freeze(value.typeAnnotation);
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
catch (err) {
|
|
2553
|
+
if (globalThis.window) {
|
|
2554
|
+
console.log(err);
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
});
|
|
2206
2558
|
// newQuickInfoNodes.forEach((itemDetail, index) => {
|
|
2207
2559
|
// const { node, filePath } = itemDetail;
|
|
2208
2560
|
// if (!result[index] || node.concept === 'Argument')
|
|
@@ -2250,12 +2602,10 @@ class NaslServer {
|
|
|
2250
2602
|
// types.set(node, argType);
|
|
2251
2603
|
// }
|
|
2252
2604
|
// });
|
|
2253
|
-
console.timeEnd('批量请求');
|
|
2254
2605
|
return types;
|
|
2255
2606
|
}
|
|
2256
|
-
//
|
|
2607
|
+
// 全量标注并且返回json
|
|
2257
2608
|
async getNaslAnnotatedJSON(app, releaseFlag) {
|
|
2258
|
-
// 全量标注
|
|
2259
2609
|
console.time('全量标注');
|
|
2260
2610
|
const nodes = [];
|
|
2261
2611
|
this.file2NodeMap.forEach((fileNode, filePath) => {
|
|
@@ -2277,14 +2627,13 @@ class NaslServer {
|
|
|
2277
2627
|
const json = app.toJSON();
|
|
2278
2628
|
if (releaseFlag) {
|
|
2279
2629
|
// 全量标注后对json进行一些修改,为了服务端翻译处理
|
|
2280
|
-
this.
|
|
2630
|
+
this.annotationToJson(typesMap, json);
|
|
2281
2631
|
}
|
|
2282
2632
|
return json;
|
|
2283
2633
|
}
|
|
2284
2634
|
// 加载全量nasl节点标注
|
|
2285
2635
|
async createdNaslAnnotatedJSON(app) {
|
|
2286
2636
|
// 全量标注
|
|
2287
|
-
console.time('全量标注');
|
|
2288
2637
|
const nodes = [];
|
|
2289
2638
|
this.file2NodeMap.forEach((fileNode, filePath) => {
|
|
2290
2639
|
// 先不排除view,传递给后端的时候,去除views下的标注
|
|
@@ -2299,10 +2648,10 @@ class NaslServer {
|
|
|
2299
2648
|
}
|
|
2300
2649
|
});
|
|
2301
2650
|
await this.getQuickInfoNodesTypeMap(nodes, true);
|
|
2302
|
-
console.timeEnd('全量标注');
|
|
2303
2651
|
}
|
|
2304
2652
|
// 增量标注
|
|
2305
2653
|
async IncrementalAnnotationJSON(records) {
|
|
2654
|
+
console.time('增量标注');
|
|
2306
2655
|
const nodes = [];
|
|
2307
2656
|
records.forEach((record) => {
|
|
2308
2657
|
const fileNode = this.file2NodeMap.get(record.filePath);
|
|
@@ -2321,8 +2670,9 @@ class NaslServer {
|
|
|
2321
2670
|
}
|
|
2322
2671
|
});
|
|
2323
2672
|
await this.getQuickInfoNodesTypeMap(nodes);
|
|
2673
|
+
console.timeEnd('增量标注');
|
|
2324
2674
|
}
|
|
2325
|
-
|
|
2675
|
+
annotationToJson(typesMap, json) {
|
|
2326
2676
|
typesMap.forEach((value, node) => {
|
|
2327
2677
|
// 如果节点本身有类型就不去在塞一遍了
|
|
2328
2678
|
// 有值而且没有类型再去设置
|
|
@@ -2339,8 +2689,8 @@ class NaslServer {
|
|
|
2339
2689
|
}
|
|
2340
2690
|
}
|
|
2341
2691
|
}
|
|
2342
|
-
|
|
2343
|
-
|
|
2692
|
+
// 旧版本数据查询需要确认是匿名数据结构的 ListTotal 类型
|
|
2693
|
+
if (node instanceof concepts_1.CallQueryComponent && node.ideVersion !== '2.11') {
|
|
2344
2694
|
const jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
|
|
2345
2695
|
jsonNode.typeAnnotation = {
|
|
2346
2696
|
concept: 'TypeAnnotation',
|
|
@@ -2383,6 +2733,14 @@ class NaslServer {
|
|
|
2383
2733
|
}],
|
|
2384
2734
|
};
|
|
2385
2735
|
}
|
|
2736
|
+
// 特殊处理param有类型错误的
|
|
2737
|
+
if (node instanceof concepts_1.Param) {
|
|
2738
|
+
// index在nasl foreach上有脏数据
|
|
2739
|
+
if (node.parentKey === 'index' && node.parentNode instanceof concepts_1.ForEachStatement) {
|
|
2740
|
+
const jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
|
|
2741
|
+
jsonNode.typeAnnotation = concepts_1.TypeAnnotation.createPrimitive('Integer').toJSON();
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2386
2744
|
if (node instanceof concepts_1.Match) {
|
|
2387
2745
|
const matchExpression = node.expression;
|
|
2388
2746
|
if (matchExpression?.__TypeAnnotation?.typeKind === 'union' && (matchExpression instanceof concepts_1.Identifier || matchExpression instanceof concepts_1.MemberExpression)) {
|
|
@@ -2395,6 +2753,14 @@ class NaslServer {
|
|
|
2395
2753
|
});
|
|
2396
2754
|
}
|
|
2397
2755
|
}
|
|
2756
|
+
// 特殊处理param有类型错误的
|
|
2757
|
+
if (node instanceof concepts_1.Param && value) {
|
|
2758
|
+
// index在nasl foreach上有脏数据
|
|
2759
|
+
if (node.parentKey === 'index' && node.parentNode instanceof concepts_1.ForEachStatement) {
|
|
2760
|
+
const jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
|
|
2761
|
+
jsonNode.typeAnnotation = value.toJSON();
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2398
2764
|
});
|
|
2399
2765
|
}
|
|
2400
2766
|
/**
|
|
@@ -2433,7 +2799,7 @@ class NaslServer {
|
|
|
2433
2799
|
// 用户自己声明的用用户的
|
|
2434
2800
|
const callObj = App.findNodeByCompleteName(parent.calleeNamespace + '.' + parent.calleeName);
|
|
2435
2801
|
const index = parent.arguments.indexOf(node);
|
|
2436
|
-
const param = callObj?.params[index] || {};
|
|
2802
|
+
const param = callObj?.params?.[index] || {};
|
|
2437
2803
|
// 取出参数的类型
|
|
2438
2804
|
// 设置类型
|
|
2439
2805
|
return {
|
|
@@ -2442,19 +2808,24 @@ class NaslServer {
|
|
|
2442
2808
|
option: { defaultValue: param.defaultValue },
|
|
2443
2809
|
};
|
|
2444
2810
|
}
|
|
2445
|
-
async getCurrentTypeAnnotation(node) {
|
|
2811
|
+
async getCurrentTypeAnnotation(node, outTime = 600) {
|
|
2446
2812
|
if (node.__TypeAnnotation) {
|
|
2447
2813
|
return node.__TypeAnnotation;
|
|
2448
2814
|
}
|
|
2449
2815
|
return new Promise((resolve, reject) => {
|
|
2450
2816
|
const myTimer = setTimeout(() => {
|
|
2451
|
-
console.
|
|
2817
|
+
console.warn(node, '没有获取到类型');
|
|
2452
2818
|
clearTimeout(myTimer);
|
|
2453
2819
|
clearInterval(mySetInterval);
|
|
2454
|
-
|
|
2455
|
-
|
|
2820
|
+
if (node.__isCorrectTypeAnnotation) {
|
|
2821
|
+
resolve(node.__TypeAnnotation);
|
|
2822
|
+
}
|
|
2823
|
+
else {
|
|
2824
|
+
resolve(null);
|
|
2825
|
+
}
|
|
2826
|
+
}, outTime);
|
|
2456
2827
|
const mySetInterval = setInterval(() => {
|
|
2457
|
-
if (node.
|
|
2828
|
+
if (node.__isCorrectTypeAnnotation) {
|
|
2458
2829
|
resolve(node.__TypeAnnotation);
|
|
2459
2830
|
clearInterval(mySetInterval);
|
|
2460
2831
|
clearTimeout(myTimer);
|
|
@@ -2508,320 +2879,336 @@ class NaslServer {
|
|
|
2508
2879
|
const result = await this._getTypeStrFull(args);
|
|
2509
2880
|
return result;
|
|
2510
2881
|
}
|
|
2511
|
-
}
|
|
2512
|
-
exports.NaslServer = NaslServer;
|
|
2513
|
-
const naslServer = new NaslServer();
|
|
2514
|
-
/**
|
|
2515
|
-
* 处理删除节点
|
|
2516
|
-
* @param fileNode 当前删除节点的文件级别节点
|
|
2517
|
-
* @param targetNode 当前操作的节点
|
|
2518
|
-
* @param result toTs生成的内容
|
|
2519
|
-
*/
|
|
2520
|
-
async function handleDelete(fileNode, targetNode, result) {
|
|
2521
|
-
const filePath = fileNode.getEmbeddedFilePath();
|
|
2522
|
-
// 如果要删除,而且当前要删Logic就直接删除并且清除错误
|
|
2523
2882
|
/**
|
|
2524
|
-
*
|
|
2883
|
+
* 处理删除节点
|
|
2884
|
+
* @param fileNode 当前删除节点的文件级别节点
|
|
2885
|
+
* @param targetNode 当前操作的节点
|
|
2886
|
+
* @param result toTs生成的内容
|
|
2525
2887
|
*/
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
}
|
|
2537
|
-
else {
|
|
2538
|
-
// 如果是要删除logic一个小内容,要覆盖全部内容
|
|
2539
|
-
// 其余要删除的都是把原来的file节点的内容全部覆盖一把
|
|
2540
|
-
outputFiles = [{ file: result.filePath, fileContent: result.code }];
|
|
2541
|
-
}
|
|
2542
|
-
// 更新文件之后
|
|
2543
|
-
await naslServer.updateFiles({ outputFiles });
|
|
2544
|
-
newRefs.refs.forEach((ref) => filesToCheck.add(ref.file));
|
|
2545
|
-
}
|
|
2546
|
-
/**
|
|
2547
|
-
* 除去rename场景下的更新
|
|
2548
|
-
* @param fileNode 文件级别的节点
|
|
2549
|
-
* @param targetNode 触发修改的节点
|
|
2550
|
-
* @param result 生成代码的code 和位置信息
|
|
2551
|
-
*/
|
|
2552
|
-
async function handleChange(fileNode, targetNode, result, action) {
|
|
2553
|
-
naslServer.file2NodeMap.set(result.filePath, fileNode);
|
|
2554
|
-
const outputFiles = [{ file: result.filePath, fileContent: result.code }];
|
|
2555
|
-
// 创建和更新都用update,内部会做判断
|
|
2556
|
-
await naslServer.updateFiles({ outputFiles });
|
|
2557
|
-
// 查一下新函数名的依赖
|
|
2558
|
-
const newRefs = await naslServer.references({
|
|
2559
|
-
file: result.filePath,
|
|
2560
|
-
line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
|
|
2561
|
-
offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
|
|
2562
|
-
});
|
|
2563
|
-
newRefs.refs.forEach((ref) => filesToCheck.add(ref.file));
|
|
2564
|
-
// 唤起建立连接弹框
|
|
2565
|
-
// 文件级别的建立连接采取提醒
|
|
2566
|
-
if (action === 'create' && targetNode.__init) {
|
|
2567
|
-
// 清除临时状态, 完成本次创建
|
|
2568
|
-
delete targetNode.__init;
|
|
2569
|
-
if (fileNode === targetNode && filesToCheck.size > 1) {
|
|
2570
|
-
const confirmParms = {
|
|
2571
|
-
actionType: 'createEstablishConnection',
|
|
2572
|
-
node: fileNode,
|
|
2573
|
-
icon: 'success',
|
|
2574
|
-
};
|
|
2575
|
-
(0, common_1.invokeCommand)('tsConfirm.open', confirmParms, () => { });
|
|
2576
|
-
}
|
|
2577
|
-
}
|
|
2578
|
-
}
|
|
2579
|
-
/**
|
|
2580
|
-
* 重命名的更新
|
|
2581
|
-
* @param fileNode 文件级别的节点
|
|
2582
|
-
* @param targetNode 触发修改的节点
|
|
2583
|
-
* @param result 生成代码的code 和位置信息
|
|
2584
|
-
* @param isRename 是不是修改名字
|
|
2585
|
-
* @param oldFilePath 如果是改名,文件级别的才会有这个参数,用于文件新增替换
|
|
2586
|
-
*/
|
|
2587
|
-
async function handleRename(fileNode, targetNode, result, oldFilePath) {
|
|
2588
|
-
// rename 场景
|
|
2589
|
-
const outputFiles = [{ file: result.filePath, fileContent: result.code }];
|
|
2590
|
-
// 如果是要修改顶级文件名
|
|
2591
|
-
// file节点和当前改得是同一节点
|
|
2592
|
-
if (fileNode === targetNode) {
|
|
2593
|
-
naslServer.file2NodeMap.delete(oldFilePath);
|
|
2594
|
-
naslServer.file2NodeMap.set(result.filePath, fileNode);
|
|
2595
|
-
// 修改名字新的添加进去,旧的置为空
|
|
2596
|
-
outputFiles.unshift({ file: oldFilePath, fileContent: '' });
|
|
2597
|
-
// 查一下旧文件名的依赖
|
|
2598
|
-
const oldRefs = await naslServer.references({
|
|
2599
|
-
file: oldFilePath,
|
|
2888
|
+
async handleDelete(fileNode, targetNode, result) {
|
|
2889
|
+
const filePath = fileNode.getEmbeddedFilePath();
|
|
2890
|
+
// 如果要删除,而且当前要删Logic就直接删除并且清除错误
|
|
2891
|
+
/**
|
|
2892
|
+
* 删除节点中的一个内容,删除了以后,就查一下引用的地方一起查一下异常
|
|
2893
|
+
*/
|
|
2894
|
+
let outputFiles = [];
|
|
2895
|
+
// 删除之前先查一下内容的依赖
|
|
2896
|
+
const newRefs = await this.references({
|
|
2897
|
+
file: result.filePath,
|
|
2600
2898
|
line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
|
|
2601
2899
|
offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
|
|
2602
2900
|
});
|
|
2603
|
-
|
|
2604
|
-
|
|
2901
|
+
// 如果是要删除的内容,就是当前的file节点,要关闭当前文件,就把内容置为空
|
|
2902
|
+
if (fileNode === targetNode) {
|
|
2903
|
+
outputFiles = [{ file: filePath, fileContent: '' }];
|
|
2904
|
+
}
|
|
2905
|
+
else {
|
|
2906
|
+
// 如果是要删除logic一个小内容,要覆盖全部内容
|
|
2907
|
+
// 其余要删除的都是把原来的file节点的内容全部覆盖一把
|
|
2908
|
+
outputFiles = [{ file: result.filePath, fileContent: result.code }];
|
|
2909
|
+
}
|
|
2605
2910
|
// 更新文件之后
|
|
2606
|
-
await
|
|
2911
|
+
await this.updateFiles({ outputFiles });
|
|
2912
|
+
newRefs.refs.forEach((ref) => this.filesToCheck.add(ref.file));
|
|
2913
|
+
}
|
|
2914
|
+
/**
|
|
2915
|
+
* 除去rename场景下的更新
|
|
2916
|
+
* @param fileNode 文件级别的节点
|
|
2917
|
+
* @param targetNode 触发修改的节点
|
|
2918
|
+
* @param result 生成代码的code 和位置信息
|
|
2919
|
+
*/
|
|
2920
|
+
async handleChange(fileNode, targetNode, result, action) {
|
|
2921
|
+
this.file2NodeMap.set(result.filePath, fileNode);
|
|
2922
|
+
const outputFiles = [{ file: result.filePath, fileContent: result.code }];
|
|
2923
|
+
// 创建和更新都用update,内部会做判断
|
|
2924
|
+
await this.updateFiles({ outputFiles });
|
|
2607
2925
|
// 查一下新函数名的依赖
|
|
2608
|
-
const newRefs = await
|
|
2926
|
+
const newRefs = await this.references({
|
|
2609
2927
|
file: result.filePath,
|
|
2610
2928
|
line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
|
|
2611
2929
|
offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
|
|
2612
2930
|
});
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
// }
|
|
2629
|
-
}
|
|
2630
|
-
else if (targetNode instanceof concepts_1.ViewElement) {
|
|
2631
|
-
/**
|
|
2632
|
-
* 因为页面组件比较特殊
|
|
2633
|
-
* 修改之后只用查页面本身就好了
|
|
2634
|
-
*/
|
|
2635
|
-
// 更新文件之后
|
|
2636
|
-
await naslServer.updateFiles({ outputFiles });
|
|
2637
|
-
const newRefs2 = await naslServer.references({
|
|
2638
|
-
file: fileNode.getEmbeddedFilePath(),
|
|
2639
|
-
line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
|
|
2640
|
-
offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
|
|
2641
|
-
});
|
|
2642
|
-
newRefs2.refs.forEach((ref) => filesToCheck.add(ref.file));
|
|
2931
|
+
newRefs.refs.forEach((ref) => this.filesToCheck.add(ref.file));
|
|
2932
|
+
// 唤起建立连接弹框
|
|
2933
|
+
// 文件级别的建立连接采取提醒
|
|
2934
|
+
if (action === 'create' && targetNode.__init) {
|
|
2935
|
+
// 清除临时状态, 完成本次创建
|
|
2936
|
+
delete targetNode.__init;
|
|
2937
|
+
if (fileNode === targetNode && this.filesToCheck.size > 1) {
|
|
2938
|
+
const confirmParms = {
|
|
2939
|
+
actionType: 'createEstablishConnection',
|
|
2940
|
+
node: fileNode,
|
|
2941
|
+
icon: 'success',
|
|
2942
|
+
};
|
|
2943
|
+
(0, common_1.invokeCommand)('tsConfirm.open', confirmParms, () => { });
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2643
2946
|
}
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2947
|
+
/**
|
|
2948
|
+
* 重命名的更新
|
|
2949
|
+
* @param fileNode 文件级别的节点
|
|
2950
|
+
* @param targetNode 触发修改的节点
|
|
2951
|
+
* @param result 生成代码的code 和位置信息
|
|
2952
|
+
* @param isRename 是不是修改名字
|
|
2953
|
+
* @param oldFilePath 如果是改名,文件级别的才会有这个参数,用于文件新增替换
|
|
2954
|
+
*/
|
|
2955
|
+
async handleRename(fileNode, targetNode, result, oldFilePath) {
|
|
2956
|
+
// rename 场景
|
|
2957
|
+
const outputFiles = [{ file: result.filePath, fileContent: result.code }];
|
|
2958
|
+
// 如果是要修改顶级文件名
|
|
2959
|
+
// file节点和当前改得是同一节点
|
|
2960
|
+
if (fileNode === targetNode) {
|
|
2961
|
+
this.file2NodeMap.delete(oldFilePath);
|
|
2962
|
+
this.file2NodeMap.set(result.filePath, fileNode);
|
|
2963
|
+
// 修改名字新的添加进去,旧的置为空
|
|
2964
|
+
outputFiles.unshift({ file: oldFilePath, fileContent: '' });
|
|
2965
|
+
// 查一下旧文件名的依赖
|
|
2966
|
+
const oldRefs = await this.references({
|
|
2967
|
+
file: oldFilePath,
|
|
2968
|
+
line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
|
|
2969
|
+
offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
|
|
2970
|
+
});
|
|
2971
|
+
oldRefs.refs.forEach((ref) => this.filesToCheck.add(ref.file));
|
|
2972
|
+
this.filesToCheck.delete(oldFilePath);
|
|
2973
|
+
// 更新文件之后
|
|
2974
|
+
await this.updateFiles({ outputFiles });
|
|
2975
|
+
// 查一下新函数名的依赖
|
|
2976
|
+
const newRefs = await this.references({
|
|
2977
|
+
file: result.filePath,
|
|
2978
|
+
line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
|
|
2979
|
+
offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
|
|
2980
|
+
});
|
|
2981
|
+
const newRefFileList = new Set();
|
|
2982
|
+
newRefs.refs.forEach((ref) => {
|
|
2983
|
+
this.filesToCheck.add(ref.file);
|
|
2984
|
+
newRefFileList.add(ref.file);
|
|
2985
|
+
});
|
|
2986
|
+
// 文件级别重命名,有依赖才唤起弹框
|
|
2987
|
+
// 唤起重命名,提示有连接弹框
|
|
2988
|
+
// 重命名建立连接先不展示弹框了
|
|
2989
|
+
// if (newRefFileList.size > 1) {
|
|
2990
|
+
// const confirmParms = {
|
|
2991
|
+
// actionType: 'renameEstablishConnection',
|
|
2992
|
+
// node: fileNode,
|
|
2993
|
+
// icon: 'success',
|
|
2994
|
+
// };
|
|
2995
|
+
// invokeCommand('tsConfirm.open', confirmParms, () => {});
|
|
2996
|
+
// }
|
|
2997
|
+
}
|
|
2998
|
+
else if (targetNode instanceof concepts_1.ViewElement) {
|
|
2649
2999
|
/**
|
|
2650
|
-
*
|
|
3000
|
+
* 因为页面组件比较特殊
|
|
3001
|
+
* 修改之后只用查页面本身就好了
|
|
2651
3002
|
*/
|
|
2652
|
-
const oldRefs = await naslServer.references({
|
|
2653
|
-
file: fileNode.getEmbeddedFilePath(),
|
|
2654
|
-
line: (0, translator_1.lsp2tspNumber)(currentSource.range.start.line),
|
|
2655
|
-
offset: (0, translator_1.lsp2tspNumber)(currentSource.range.start.character),
|
|
2656
|
-
});
|
|
2657
|
-
oldRefs.refs.forEach((ref) => filesToCheck.add(ref.file));
|
|
2658
3003
|
// 更新文件之后
|
|
2659
|
-
await
|
|
2660
|
-
const newRefs2 = await
|
|
3004
|
+
await this.updateFiles({ outputFiles });
|
|
3005
|
+
const newRefs2 = await this.references({
|
|
2661
3006
|
file: fileNode.getEmbeddedFilePath(),
|
|
2662
|
-
line:
|
|
2663
|
-
offset:
|
|
3007
|
+
line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
|
|
3008
|
+
offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
|
|
2664
3009
|
});
|
|
2665
|
-
newRefs2.refs.forEach((ref) => filesToCheck.add(ref.file));
|
|
3010
|
+
newRefs2.refs.forEach((ref) => this.filesToCheck.add(ref.file));
|
|
3011
|
+
}
|
|
3012
|
+
else {
|
|
3013
|
+
// 查一下当前属性依赖的文件
|
|
3014
|
+
const { currentSource, fileNode } = this.getCurrentSource(targetNode);
|
|
3015
|
+
// 如果当前节点存在
|
|
3016
|
+
if (currentSource) {
|
|
3017
|
+
/**
|
|
3018
|
+
* 其余的节点修改之后直接查本身就可以了
|
|
3019
|
+
*/
|
|
3020
|
+
const oldRefs = await this.references({
|
|
3021
|
+
file: fileNode.getEmbeddedFilePath(),
|
|
3022
|
+
line: (0, translator_1.lsp2tspNumber)(currentSource.range.start.line),
|
|
3023
|
+
offset: (0, translator_1.lsp2tspNumber)(currentSource.range.start.character),
|
|
3024
|
+
});
|
|
3025
|
+
oldRefs.refs.forEach((ref) => this.filesToCheck.add(ref.file));
|
|
3026
|
+
// 更新文件之后
|
|
3027
|
+
await this.updateFiles({ outputFiles });
|
|
3028
|
+
const newRefs2 = await this.references({
|
|
3029
|
+
file: fileNode.getEmbeddedFilePath(),
|
|
3030
|
+
line: (0, translator_1.lsp2tspNumber)(currentSource.range.start.line),
|
|
3031
|
+
offset: (0, translator_1.lsp2tspNumber)(currentSource.range.start.character),
|
|
3032
|
+
});
|
|
3033
|
+
newRefs2.refs.forEach((ref) => this.filesToCheck.add(ref.file));
|
|
3034
|
+
}
|
|
2666
3035
|
}
|
|
2667
3036
|
}
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
}
|
|
2703
|
-
}
|
|
2704
|
-
// 删除或新增模块
|
|
2705
|
-
// 需要把下面的哦内容全部都更新一遍
|
|
2706
|
-
if (fileNode instanceof concepts_1.Module) {
|
|
2707
|
-
if (fileNode.type === 'interface' && fileNode.isAdd && action === 'create') {
|
|
2708
|
-
isChangeInterface = true;
|
|
2709
|
-
}
|
|
2710
|
-
const module = targetNode;
|
|
2711
|
-
const results = [];
|
|
2712
|
-
naslServer.contentToFile(module, results);
|
|
2713
|
-
for (let i = 0; i < results.length; i++) {
|
|
2714
|
-
const result = results[i];
|
|
2715
|
-
const node = naslServer.file2NodeMap.get(result.filePath);
|
|
2716
|
-
if (action === 'create') {
|
|
2717
|
-
await handleChange(node, node, result, action);
|
|
3037
|
+
/**
|
|
3038
|
+
* 处理一些节点操作,子节点需要更新并且check的场景
|
|
3039
|
+
* 因为删除,新增父页面,或者重命名会一起
|
|
3040
|
+
* 删除或者新增view而且他有子集 就要执行同样的操作
|
|
3041
|
+
* @param action 当前操作类型
|
|
3042
|
+
* @param fileNode 文件节点
|
|
3043
|
+
* @param targetNode 操作节点 这里要两个相等才会走家去面对哦逻辑
|
|
3044
|
+
* @param oldpath 触发内容的oldpath
|
|
3045
|
+
*/
|
|
3046
|
+
async incidentalAction(action, fileNode, targetNode, oldpath) {
|
|
3047
|
+
if ((action === 'create' || action === 'delete' || (action === 'update' && oldpath)) && fileNode === targetNode) {
|
|
3048
|
+
//删除、更改、新增端
|
|
3049
|
+
if (fileNode instanceof concepts_1.Frontend && (fileNode.views?.length || fileNode.variables?.length)) {
|
|
3050
|
+
const fileNodeChildren = [...fileNode.views, ...fileNode.variables];
|
|
3051
|
+
for (let i = 0; i < fileNodeChildren.length; i++) {
|
|
3052
|
+
const fileNodeItem = fileNodeChildren[i];
|
|
3053
|
+
const result = fileNodeItem.toEmbeddedTSFile();
|
|
3054
|
+
fileNodeItem.sourceMap = result.sourceMap;
|
|
3055
|
+
if (action === 'create') {
|
|
3056
|
+
await this.handleChange(fileNodeItem, fileNodeItem, result, action);
|
|
3057
|
+
await this.incidentalAction(action, fileNodeItem, fileNodeItem);
|
|
3058
|
+
}
|
|
3059
|
+
else if (action === 'delete') {
|
|
3060
|
+
await this.handleDelete(fileNodeItem, fileNodeItem, result);
|
|
3061
|
+
await this.incidentalAction(action, fileNodeItem, fileNodeItem);
|
|
3062
|
+
}
|
|
3063
|
+
else if (action === 'update' && oldpath) {
|
|
3064
|
+
const parentPath = oldpath.replace('.ts', '/');
|
|
3065
|
+
const foldName = fileNodeItem.concept === 'View' ? 'views' : 'variables';
|
|
3066
|
+
const currentOldPath = parentPath + foldName + '/' + fileNodeItem.name + '.ts';
|
|
3067
|
+
// 因为重命名这里只有当前修改父级的 旧名称, 所以他的子集也要根据旧名称去查依赖 更新内容
|
|
3068
|
+
await this.handleRename(fileNodeItem, fileNodeItem, result, currentOldPath);
|
|
3069
|
+
await this.incidentalAction(action, fileNodeItem, fileNodeItem, currentOldPath);
|
|
3070
|
+
}
|
|
2718
3071
|
}
|
|
2719
|
-
|
|
2720
|
-
|
|
3072
|
+
}
|
|
3073
|
+
// 删除或者新增页面
|
|
3074
|
+
if (fileNode instanceof concepts_1.View && fileNode.children?.length) {
|
|
3075
|
+
const fileNodeChildren = fileNode.children;
|
|
3076
|
+
for (let i = 0; i < fileNodeChildren.length; i++) {
|
|
3077
|
+
const fileNodeItem = fileNodeChildren[i];
|
|
3078
|
+
const result = fileNodeItem.toEmbeddedTSFile();
|
|
3079
|
+
fileNodeItem.sourceMap = result.sourceMap;
|
|
3080
|
+
if (action === 'create') {
|
|
3081
|
+
await this.handleChange(fileNodeItem, fileNodeItem, result, action);
|
|
3082
|
+
await this.incidentalAction(action, fileNodeItem, fileNodeItem);
|
|
3083
|
+
}
|
|
3084
|
+
else if (action === 'delete') {
|
|
3085
|
+
await this.handleDelete(fileNodeItem, fileNodeItem, result);
|
|
3086
|
+
await this.incidentalAction(action, fileNodeItem, fileNodeItem);
|
|
3087
|
+
}
|
|
3088
|
+
else if (action === 'update' && oldpath) {
|
|
3089
|
+
const parentPath = oldpath.replace('.ts', '/');
|
|
3090
|
+
const currentOldPath = parentPath + fileNodeItem.name + '.ts';
|
|
3091
|
+
// 因为重命名这里只有当前修改父级的 旧名称, 所以他的子集也要根据旧名称去查依赖 更新内容
|
|
3092
|
+
await this.handleRename(fileNodeItem, fileNodeItem, result, currentOldPath);
|
|
3093
|
+
await this.incidentalAction(action, fileNodeItem, fileNodeItem, currentOldPath);
|
|
3094
|
+
}
|
|
2721
3095
|
}
|
|
2722
3096
|
}
|
|
2723
|
-
//
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
3097
|
+
// 删除或新增模块
|
|
3098
|
+
// 需要把下面的哦内容全部都更新一遍
|
|
3099
|
+
if (fileNode instanceof concepts_1.Module) {
|
|
3100
|
+
if (fileNode.type === 'interface' && fileNode.isAdd && action === 'create') {
|
|
3101
|
+
isChangeInterface = true;
|
|
3102
|
+
}
|
|
3103
|
+
const module = targetNode;
|
|
3104
|
+
const results = [];
|
|
3105
|
+
this.contentToFile(module, results);
|
|
3106
|
+
for (let i = 0; i < results.length; i++) {
|
|
3107
|
+
const result = results[i];
|
|
3108
|
+
const node = this.file2NodeMap.get(result.filePath);
|
|
3109
|
+
if (action === 'create') {
|
|
3110
|
+
await this.handleChange(node, node, result, action);
|
|
3111
|
+
}
|
|
3112
|
+
else {
|
|
3113
|
+
await this.handleDelete(node, node, result);
|
|
3114
|
+
}
|
|
2728
3115
|
}
|
|
2729
|
-
|
|
2730
|
-
|
|
3116
|
+
// 删除模块通知更新列表
|
|
3117
|
+
if (action === 'delete') {
|
|
3118
|
+
try {
|
|
3119
|
+
// 如果已经
|
|
3120
|
+
(0, common_1.invokeCommand)('module.delete', true);
|
|
3121
|
+
}
|
|
3122
|
+
catch (err) {
|
|
3123
|
+
console.log('module.delete', '组件销毁了,不用唤起了');
|
|
3124
|
+
}
|
|
2731
3125
|
}
|
|
2732
3126
|
}
|
|
2733
|
-
|
|
2734
|
-
/**
|
|
3127
|
+
/**
|
|
2735
3128
|
* DataSource只会重命名时候,需要把子集全部重新生成一下
|
|
2736
3129
|
*/
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
3130
|
+
if (fileNode instanceof concepts_1.DataSource) {
|
|
3131
|
+
fileNode.entities.forEach(async (entity) => {
|
|
3132
|
+
try {
|
|
3133
|
+
const result = entity.toEmbeddedTSFile();
|
|
3134
|
+
const parentPath = oldpath.replace('.ts', '/');
|
|
3135
|
+
const currentOldPath = parentPath + '/entities/' + entity.name + '.ts';
|
|
3136
|
+
// 因为重命名这里只有当前修改父级的 旧名称, 所以他的子集也要根据旧名称去查依赖 更新内容
|
|
3137
|
+
await this.handleRename(entity, entity, result, currentOldPath);
|
|
3138
|
+
}
|
|
3139
|
+
catch (err) {
|
|
3140
|
+
console.log(err);
|
|
3141
|
+
}
|
|
3142
|
+
});
|
|
3143
|
+
}
|
|
2750
3144
|
}
|
|
2751
3145
|
}
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
}
|
|
2767
|
-
const result = fileNode.toEmbeddedTSFile();
|
|
2768
|
-
// 当前操作的节点
|
|
2769
|
-
// 如果当前没有生成tsFile
|
|
2770
|
-
if (!result) {
|
|
2771
|
-
return;
|
|
2772
|
-
}
|
|
2773
|
-
// 修改触发修改文件
|
|
2774
|
-
naslServer._debugInFileStorage($event.currentTarget, [
|
|
2775
|
-
{
|
|
2776
|
-
file: result.filePath,
|
|
2777
|
-
fileContent: result.code,
|
|
2778
|
-
},
|
|
2779
|
-
]);
|
|
2780
|
-
fileNode.sourceMap = result.sourceMap;
|
|
2781
|
-
if (action === 'update' || action === 'create') {
|
|
2782
|
-
if ($event?.field !== 'name') {
|
|
2783
|
-
await handleChange(fileNode, targetNode, result, action);
|
|
2784
|
-
await incidentalAction(action, fileNode, targetNode);
|
|
3146
|
+
async receiveHandleChange($event) {
|
|
3147
|
+
this.singleFileChangeIng = true;
|
|
3148
|
+
// 行为
|
|
3149
|
+
const action = $event.action;
|
|
3150
|
+
const targetNode = $event.target;
|
|
3151
|
+
// 当前操作的文件节点
|
|
3152
|
+
const { fileNode } = this.getCurrentSource(targetNode);
|
|
3153
|
+
// 如果是导入模块就,就引入对应模块,先不处理module和Configuration,下面的内容会自动创建
|
|
3154
|
+
if (!fileNode || fileNode instanceof concepts_1.Module || fileNode instanceof concepts_1.Configuration) {
|
|
3155
|
+
// module单独处理
|
|
3156
|
+
if (fileNode instanceof concepts_1.Module) {
|
|
3157
|
+
await this.incidentalAction(action, fileNode, targetNode);
|
|
3158
|
+
}
|
|
3159
|
+
return;
|
|
2785
3160
|
}
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
3161
|
+
const result = fileNode.toEmbeddedTSFile();
|
|
3162
|
+
// 当前操作的节点
|
|
3163
|
+
// 如果当前没有生成tsFile
|
|
3164
|
+
if (!result) {
|
|
3165
|
+
return;
|
|
2790
3166
|
}
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
const stackList = [];
|
|
2804
|
-
eventValue.forEach(async (item) => {
|
|
2805
|
-
stackList.push(item.originEvent);
|
|
2806
|
-
});
|
|
2807
|
-
// 异步状态机,一个完成了在执行下一个
|
|
2808
|
-
function next() {
|
|
2809
|
-
const item = stackList.shift();
|
|
2810
|
-
receiveHandleChange(item).then(async () => {
|
|
2811
|
-
if (stackList.length) {
|
|
2812
|
-
next();
|
|
3167
|
+
// 修改触发修改文件
|
|
3168
|
+
this._debugInFileStorage(targetNode, [
|
|
3169
|
+
{
|
|
3170
|
+
file: result.filePath,
|
|
3171
|
+
fileContent: result.code,
|
|
3172
|
+
},
|
|
3173
|
+
]);
|
|
3174
|
+
fileNode.sourceMap = result.sourceMap;
|
|
3175
|
+
if (action === 'update' || action === 'create') {
|
|
3176
|
+
if ($event?.field !== 'name') {
|
|
3177
|
+
await this.handleChange(fileNode, targetNode, result, action);
|
|
3178
|
+
await this.incidentalAction(action, fileNode, targetNode);
|
|
2813
3179
|
}
|
|
2814
3180
|
else {
|
|
2815
|
-
|
|
2816
|
-
|
|
3181
|
+
const oldpath = fileNode.getEmbeddedFilePath($event.oldObject.name);
|
|
3182
|
+
await this.handleRename(fileNode, targetNode, result, oldpath);
|
|
3183
|
+
await this.incidentalAction(action, fileNode, targetNode, oldpath);
|
|
2817
3184
|
}
|
|
2818
|
-
}
|
|
3185
|
+
}
|
|
3186
|
+
// 删除
|
|
3187
|
+
if (action === 'delete') {
|
|
3188
|
+
await this.incidentalAction(action, fileNode, targetNode);
|
|
3189
|
+
await this.handleDelete(fileNode, targetNode, result);
|
|
3190
|
+
}
|
|
3191
|
+
return true;
|
|
2819
3192
|
}
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
3193
|
+
changeFileNext() {
|
|
3194
|
+
if (!this.singleFileChangeIng) {
|
|
3195
|
+
const item = this.changeStackList.shift();
|
|
3196
|
+
this.receiveHandleChange(item).catch((err) => {
|
|
3197
|
+
console.log(err, 'receiveHandleChangeErr');
|
|
3198
|
+
}).finally(async () => {
|
|
3199
|
+
// 每一个文件与change接触就把状态置为false,让下一个进入
|
|
3200
|
+
this.singleFileChangeIng = false;
|
|
3201
|
+
if (this.changeStackList.length) {
|
|
3202
|
+
this.changeFileNext();
|
|
3203
|
+
}
|
|
3204
|
+
else {
|
|
3205
|
+
console.log(Array.from(this.filesToCheck));
|
|
3206
|
+
await this.getDiagnosticRecordsAndPushAll(Array.from(this.filesToCheck));
|
|
3207
|
+
this.filesToCheck.clear();
|
|
3208
|
+
}
|
|
3209
|
+
});
|
|
3210
|
+
}
|
|
2823
3211
|
}
|
|
2824
|
-
}
|
|
2825
|
-
|
|
2826
|
-
exports.default = naslServer;
|
|
3212
|
+
}
|
|
3213
|
+
exports.NaslServer = NaslServer;
|
|
2827
3214
|
//# sourceMappingURL=naslServer.js.map
|