@lcap/nasl 2.18.0-beta.3 → 2.18.0
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/bak/translator.js +1 -1
- package/out/bak/translator.js.map +1 -1
- package/out/concepts/LogicItem__.js.map +1 -1
- package/out/concepts/Logic__.js +4 -4
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MatchExpression__.d.ts +97 -0
- package/out/concepts/MatchExpression__.js +281 -0
- package/out/concepts/MatchExpression__.js.map +1 -0
- package/out/concepts/Match__.js +1 -1
- package/out/concepts/Match__.js.map +1 -1
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/OqlQueryComponent__.js.map +1 -1
- package/out/concepts/Param__.js +2 -2
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/Return__.js +1 -1
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/StringInterpolation__.d.ts +16 -16
- package/out/concepts/StringInterpolation__.js +12 -12
- package/out/concepts/StringInterpolation__.js.map +1 -1
- package/out/concepts/ValidationRule__.js.map +1 -1
- package/out/concepts/Variable__.js +1 -1
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/View__.js +2 -2
- package/out/concepts/View__.js.map +1 -1
- package/out/server/naslServer.d.ts +2 -1
- package/out/server/naslServer.js +84 -38
- package/out/server/naslServer.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/sql-parser/index.d.ts +1 -0
- package/out/templator/sql-parser/index.js +228 -0
- package/out/templator/sql-parser/index.js.map +1 -0
- package/out/templator/sql-parser/parser.js +26664 -0
- package/out/templator/sql-parser/parser.js.map +1 -0
- package/package.json +3 -4
- package/src/automate/engine/dist/index.dev.js +517 -0
- package/src/bak/translator.js +1 -1
- package/src/common/dist/BaseNode.js +1101 -0
- package/src/concepts/CallInterface__.ts +9 -9
- package/src/concepts/Destination__.ts +9 -9
- package/src/concepts/ExternalDestination__.ts +5 -5
- package/src/concepts/LogicItem__.ts +4 -0
- package/src/concepts/Logic__.ts +42 -5
- package/src/concepts/Match__.ts +21 -1
- package/src/concepts/MemberExpression__.ts +11 -0
- package/src/concepts/OqlQueryComponent__.ts +7 -0
- package/src/concepts/Param__.ts +3 -2
- package/src/concepts/Return__.ts +5 -1
- package/src/concepts/StringInterpolation__.ts +26 -26
- package/src/concepts/UnaryExpression__.ts +4 -4
- package/src/concepts/ValidationRule__.ts +1 -1
- package/src/concepts/Variable__.ts +1 -1
- package/src/concepts/ViewElement__.ts +1 -1
- package/src/concepts/View__.ts +2 -2
- package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +24 -0
- package/src/concepts/dist/Anchor__.js +179 -0
- package/src/concepts/dist/Assignment__.js +301 -0
- package/src/concepts/dist/CallFunction__.js +473 -0
- package/src/concepts/dist/CallInterface__.js +533 -0
- package/src/concepts/dist/CallLogic__.js +864 -0
- package/src/concepts/dist/ForEachStatement__.js +426 -0
- package/src/concepts/dist/MatchCase__.js +587 -0
- package/src/concepts/dist/MemberExpression__.js +348 -0
- package/src/concepts/dist/Param__.js +537 -0
- package/src/concepts/dist/Return__.js +493 -0
- package/src/generator/dist/genBundleFiles.js +414 -0
- package/src/server/dist/formatTsUtils.js +683 -0
- package/src/server/dist/naslServer.js +3396 -0
- package/src/server/naslServer.ts +84 -39
- package/src/service/storage/dist/init.js +541 -0
- package/src/templator/genQueryComponent.ts +8 -3
- package/ts-worker/dist/webpack.config.dev.js +104 -0
- package/ts-worker/lib/cancellationToken.js +67 -0
- package/ts-worker/lib/dist/tsserver.dev.js +22953 -0
- package/ts-worker/lib/harness.js +1 -1
- package/ts-worker/sources/lib/dist/tsserver.dev.js +22912 -0
- package/ts-worker/src/start.js +1 -1
- package/ts-worker/webpack.config.js +3 -1
- package/dist/bundle.js +0 -3962
- package/dist/bundle.js.LICENSE.txt +0 -16
- package/out/generator/release.d.ts +0 -1
- package/out/generator/release.js +0 -51
- package/out/generator/release.js.map +0 -1
|
@@ -0,0 +1,3396 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
50
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
51
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
52
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
53
|
+
r[k] = a[j];
|
|
54
|
+
return r;
|
|
55
|
+
};
|
|
56
|
+
exports.__esModule = true;
|
|
57
|
+
exports.NaslServer = exports.getDisplayString2Type = void 0;
|
|
58
|
+
/// #if process.env.BUILD_TARGET === 'node'
|
|
59
|
+
var fs = require("fs-extra");
|
|
60
|
+
var path = require("path");
|
|
61
|
+
var worker_threads_1 = require("worker_threads");
|
|
62
|
+
/// #endif
|
|
63
|
+
var config_1 = require("../config");
|
|
64
|
+
var Messager_1 = require("../common/Messager");
|
|
65
|
+
var getMemberIdentifier_1 = require("../server/getMemberIdentifier");
|
|
66
|
+
var concepts_1 = require("../concepts");
|
|
67
|
+
var translator_1 = require("../translator");
|
|
68
|
+
var storage_1 = require("../service/storage");
|
|
69
|
+
var translator_2 = require("./translator");
|
|
70
|
+
var common_1 = require("../common");
|
|
71
|
+
var diagnostic_1 = require("../manager/diagnostic");
|
|
72
|
+
var createUiTs_1 = require("./createUiTs");
|
|
73
|
+
var coreTypeList_1 = require("../concepts/basics/types/coreTypeList");
|
|
74
|
+
var formatTsUtils_1 = require("./formatTsUtils");
|
|
75
|
+
var naslStdlibMap_1 = require("./naslStdlibMap");
|
|
76
|
+
var jsoner = require("../service/storage/jsoner");
|
|
77
|
+
var EventEmitter_1 = require("../common/EventEmitter");
|
|
78
|
+
var EmbeddedTSFileLineMap = {
|
|
79
|
+
Entity: 3
|
|
80
|
+
};
|
|
81
|
+
var EmbeddedTSFileOffsetMap = {
|
|
82
|
+
Variable: 12
|
|
83
|
+
};
|
|
84
|
+
// 要Check的文件
|
|
85
|
+
var filesToCheck = new Set();
|
|
86
|
+
// 单个文件正在change,不允许同时两个文件一起change
|
|
87
|
+
var singleFileChangeIng = false;
|
|
88
|
+
var isChangeInterface = false; //判断是否导入接口
|
|
89
|
+
var actionArr = []; //用于导入接口收集更改的节点
|
|
90
|
+
var timer = null; //超时器用于收集导入接口相关
|
|
91
|
+
// 联合类型切割取出类型
|
|
92
|
+
function getDisplayString2Type(displayString) {
|
|
93
|
+
// 取出匹配的内容
|
|
94
|
+
var reg = /<([^()]+)>/g;
|
|
95
|
+
// 解决extends 导致类型缺失的问题
|
|
96
|
+
displayString = (displayString === null || displayString === void 0 ? void 0 : displayString.replace('T extends ', '')) || '';
|
|
97
|
+
var types = reg.exec(displayString);
|
|
98
|
+
// 取出提示的类型,组成是数组
|
|
99
|
+
var typeList = types[1].split(' | ').map(function (item) {
|
|
100
|
+
if (/<([^()]+)>/g.exec(item)) {
|
|
101
|
+
return item;
|
|
102
|
+
}
|
|
103
|
+
else if (item.includes(' ')) {
|
|
104
|
+
var strs = item.split(' ');
|
|
105
|
+
var type = strs[strs.length - 1];
|
|
106
|
+
return type;
|
|
107
|
+
}
|
|
108
|
+
else if (item.includes('.')) {
|
|
109
|
+
var strs = item.split('.');
|
|
110
|
+
var type = strs[strs.length - 1];
|
|
111
|
+
return type;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
return item;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return typeList;
|
|
118
|
+
}
|
|
119
|
+
exports.getDisplayString2Type = getDisplayString2Type;
|
|
120
|
+
var NaslServer = /** @class */ (function () {
|
|
121
|
+
function NaslServer() {
|
|
122
|
+
var _this = this;
|
|
123
|
+
this.messager = undefined;
|
|
124
|
+
this.worker = undefined;
|
|
125
|
+
/**
|
|
126
|
+
* 按道理 fileSourceMap: new Map<string, SourceMap>() 比较合理,
|
|
127
|
+
* 但是要多维护一层 vertex 增删 -> file 增删的关系问题,
|
|
128
|
+
* 先用挂在点上面,简单的方法实现,后期再考虑解耦
|
|
129
|
+
*/
|
|
130
|
+
this.file2NodeMap = new Map();
|
|
131
|
+
this.elementsLogic = {};
|
|
132
|
+
// 错误日志收集
|
|
133
|
+
this.diagnosticManager = undefined;
|
|
134
|
+
this.embeddedTSEmitter = undefined;
|
|
135
|
+
// 需要执行修改的文件
|
|
136
|
+
this.changeStackList = [];
|
|
137
|
+
/// #if process.env.BUILD_TARGET === 'node'
|
|
138
|
+
if (globalThis.process) // For TS build
|
|
139
|
+
this.worker = new worker_threads_1.Worker(path.join(__dirname, '../../ts-worker/src/index.js'));
|
|
140
|
+
// worker = new Worker(path.join(__dirname, '../../../src/static/ts-worker.js'));
|
|
141
|
+
/// #endif
|
|
142
|
+
/// #if process.env.BUILD_TARGET !== 'node'
|
|
143
|
+
if (globalThis.window) // For TS build
|
|
144
|
+
this.worker = new worker_threads_1.Worker('/ts-worker.js');
|
|
145
|
+
/// #endif
|
|
146
|
+
this.diagnosticManager = new diagnostic_1.DiagnosticManager();
|
|
147
|
+
this.messager = new Messager_1["default"]({
|
|
148
|
+
protocol: 'ts-worker',
|
|
149
|
+
sender: 'ide',
|
|
150
|
+
context: this,
|
|
151
|
+
getReceiver: function () { return _this.worker; },
|
|
152
|
+
getSender: function () { return _this.worker; },
|
|
153
|
+
handleMessage: function (_a) {
|
|
154
|
+
var data = _a.data;
|
|
155
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
156
|
+
var records;
|
|
157
|
+
return __generator(this, function (_b) {
|
|
158
|
+
switch (_b.label) {
|
|
159
|
+
case 0:
|
|
160
|
+
if (!(data && data.event === 'publishDiagnostics')) return [3 /*break*/, 2];
|
|
161
|
+
return [4 /*yield*/, this._resolveDiagnosticRecords(data.records)];
|
|
162
|
+
case 1:
|
|
163
|
+
records = _b.sent();
|
|
164
|
+
this.diagnosticManager.pushAll(records);
|
|
165
|
+
_b.label = 2;
|
|
166
|
+
case 2: return [2 /*return*/];
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
// 监听所有改变操作
|
|
173
|
+
this.embeddedTSEmitter = new EventEmitter_1.EventEmitter();
|
|
174
|
+
this.embeddedTSEmitter.on('change', function ($event) {
|
|
175
|
+
// 收集到一个行为集合
|
|
176
|
+
var eventValue = $event.value;
|
|
177
|
+
eventValue.forEach(function (item) { return __awaiter(_this, void 0, void 0, function () {
|
|
178
|
+
return __generator(this, function (_a) {
|
|
179
|
+
this.changeStackList.push(item.originEvent);
|
|
180
|
+
return [2 /*return*/];
|
|
181
|
+
});
|
|
182
|
+
}); });
|
|
183
|
+
// 如果有长度开始执行状态机
|
|
184
|
+
if (_this.changeStackList.length) {
|
|
185
|
+
_this.changeFileNext();
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
NaslServer.prototype.start = function () {
|
|
190
|
+
return this.messager.requestCommand('start');
|
|
191
|
+
};
|
|
192
|
+
NaslServer.prototype.terminate = function () {
|
|
193
|
+
this.worker.terminate();
|
|
194
|
+
};
|
|
195
|
+
NaslServer.prototype.createUiTs = function (allComponent) {
|
|
196
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
197
|
+
var _a, code, elementsLogic;
|
|
198
|
+
var _this = this;
|
|
199
|
+
return __generator(this, function (_b) {
|
|
200
|
+
switch (_b.label) {
|
|
201
|
+
case 0: return [4 /*yield*/, createUiTs_1["default"](allComponent)];
|
|
202
|
+
case 1:
|
|
203
|
+
_a = _b.sent(), code = _a.code, elementsLogic = _a.elementsLogic;
|
|
204
|
+
// 放入生產的uits文件
|
|
205
|
+
return [4 /*yield*/, this.addFile({
|
|
206
|
+
file: 'nasl.ui.definition.ts',
|
|
207
|
+
fileContent: code
|
|
208
|
+
})];
|
|
209
|
+
case 2:
|
|
210
|
+
// 放入生產的uits文件
|
|
211
|
+
_b.sent();
|
|
212
|
+
Object.keys(naslStdlibMap_1["default"]).forEach(function (libFileName) { return __awaiter(_this, void 0, void 0, function () {
|
|
213
|
+
return __generator(this, function (_a) {
|
|
214
|
+
switch (_a.label) {
|
|
215
|
+
case 0: return [4 /*yield*/, this.addFile({
|
|
216
|
+
file: '/' + libFileName,
|
|
217
|
+
fileContent: naslStdlibMap_1["default"][libFileName]
|
|
218
|
+
})];
|
|
219
|
+
case 1:
|
|
220
|
+
_a.sent();
|
|
221
|
+
return [2 /*return*/];
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}); });
|
|
225
|
+
this.elementsLogic = elementsLogic;
|
|
226
|
+
// 全部文件加载完毕开始初始化
|
|
227
|
+
return [4 /*yield*/, this.getDiagnosticRecordsAndPushAll()];
|
|
228
|
+
case 3:
|
|
229
|
+
// 全部文件加载完毕开始初始化
|
|
230
|
+
_b.sent();
|
|
231
|
+
return [2 /*return*/];
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
NaslServer.prototype.contentToFile = function (module, results) {
|
|
237
|
+
var _this = this;
|
|
238
|
+
var _a, _b;
|
|
239
|
+
module.structures.forEach(function (structure) {
|
|
240
|
+
try {
|
|
241
|
+
var result = structure.toEmbeddedTSFile();
|
|
242
|
+
results.push(result);
|
|
243
|
+
// sourceMap都存在目录级别内容下,在页面层级下去找
|
|
244
|
+
structure.sourceMap = result.sourceMap;
|
|
245
|
+
_this.file2NodeMap.set(result.filePath, structure);
|
|
246
|
+
}
|
|
247
|
+
catch (err) {
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
(_a = module.frontendVariables) === null || _a === void 0 ? void 0 : _a.forEach(function (frontendVariable) {
|
|
251
|
+
try {
|
|
252
|
+
var result = frontendVariable.toEmbeddedTSFile();
|
|
253
|
+
results.push(result);
|
|
254
|
+
// sourceMap都存在目录级别内容下,在页面层级下去找
|
|
255
|
+
frontendVariable.sourceMap = result.sourceMap;
|
|
256
|
+
_this.file2NodeMap.set(result.filePath, frontendVariable);
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
console.log(err);
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
(_b = module.dataSources) === null || _b === void 0 ? void 0 : _b.forEach(function (dataSource) {
|
|
263
|
+
// 本身dataSource也要生成一个文件用于改名
|
|
264
|
+
try {
|
|
265
|
+
var result = dataSource.toEmbeddedTSFile();
|
|
266
|
+
results.push(result);
|
|
267
|
+
// sourceMap都存在目录级别内容下,在页面层级下去找
|
|
268
|
+
dataSource.sourceMap = result.sourceMap;
|
|
269
|
+
_this.file2NodeMap.set(result.filePath, dataSource);
|
|
270
|
+
}
|
|
271
|
+
catch (err) {
|
|
272
|
+
}
|
|
273
|
+
dataSource.entities.forEach(function (entity) {
|
|
274
|
+
try {
|
|
275
|
+
var result = entity.toEmbeddedTSFile();
|
|
276
|
+
results.push(result);
|
|
277
|
+
// sourceMap都存在目录级别内容下,在页面层级下去找
|
|
278
|
+
entity.sourceMap = result.sourceMap;
|
|
279
|
+
_this.file2NodeMap.set(result.filePath, entity);
|
|
280
|
+
}
|
|
281
|
+
catch (err) {
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
module.interfaces.forEach(function (_interface) {
|
|
286
|
+
try {
|
|
287
|
+
var result = _interface.toEmbeddedTSFile();
|
|
288
|
+
results.push(result);
|
|
289
|
+
// sourceMap都存在目录级别内容下,在页面层级下去找
|
|
290
|
+
_interface.sourceMap = result.sourceMap;
|
|
291
|
+
_this.file2NodeMap.set(result.filePath, _interface);
|
|
292
|
+
}
|
|
293
|
+
catch (err) {
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
module.enums.forEach(function (_enum) {
|
|
297
|
+
try {
|
|
298
|
+
var result = _enum.toEmbeddedTSFile();
|
|
299
|
+
results.push(result);
|
|
300
|
+
// sourceMap都存在目录级别内容下,在页面层级下去找
|
|
301
|
+
_enum.sourceMap = result.sourceMap;
|
|
302
|
+
_this.file2NodeMap.set(result.filePath, _enum);
|
|
303
|
+
}
|
|
304
|
+
catch (err) {
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
module.logics.forEach(function (logic) {
|
|
308
|
+
try {
|
|
309
|
+
if (!(logic instanceof concepts_1.Logic))
|
|
310
|
+
return;
|
|
311
|
+
var result = logic.toEmbeddedTSFile();
|
|
312
|
+
results.push(result);
|
|
313
|
+
logic.sourceMap = result.sourceMap;
|
|
314
|
+
_this.file2NodeMap.set(result.filePath, logic);
|
|
315
|
+
}
|
|
316
|
+
catch (err) {
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
// view的生成
|
|
320
|
+
if (!config_1.config.closeViews) {
|
|
321
|
+
this.view2TSFile(module.views, results);
|
|
322
|
+
}
|
|
323
|
+
module.processes.forEach(function (process) {
|
|
324
|
+
try {
|
|
325
|
+
var result = process.toEmbeddedTSFile();
|
|
326
|
+
results.push(result);
|
|
327
|
+
process.sourceMap = result.sourceMap;
|
|
328
|
+
_this.file2NodeMap.set(result.filePath, process);
|
|
329
|
+
}
|
|
330
|
+
catch (err) {
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
if (module instanceof concepts_1.App) {
|
|
334
|
+
module.roles.forEach(function (role) {
|
|
335
|
+
try {
|
|
336
|
+
var result = role.toEmbeddedTSFile();
|
|
337
|
+
results.push(result);
|
|
338
|
+
// sourceMap都存在目录级别内容下,在页面层级下去找
|
|
339
|
+
role.sourceMap = result.sourceMap;
|
|
340
|
+
_this.file2NodeMap.set(result.filePath, role);
|
|
341
|
+
}
|
|
342
|
+
catch (err) {
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
NaslServer.prototype.view2TSFile = function (viewsChildren, results) {
|
|
348
|
+
var _this = this;
|
|
349
|
+
// 如果有子页面
|
|
350
|
+
if (viewsChildren && viewsChildren.length) {
|
|
351
|
+
viewsChildren.forEach(function (view) {
|
|
352
|
+
try {
|
|
353
|
+
var result = view.toEmbeddedTSFile();
|
|
354
|
+
results.push(result);
|
|
355
|
+
view.sourceMap = result.sourceMap;
|
|
356
|
+
_this.file2NodeMap.set(result.filePath, view);
|
|
357
|
+
if (view.children.length) {
|
|
358
|
+
_this.view2TSFile(view.children, results);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
catch (err) {
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
NaslServer.prototype.openApp = function (app) {
|
|
367
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
368
|
+
var results, files;
|
|
369
|
+
var _this = this;
|
|
370
|
+
return __generator(this, function (_a) {
|
|
371
|
+
switch (_a.label) {
|
|
372
|
+
case 0:
|
|
373
|
+
results = [];
|
|
374
|
+
try {
|
|
375
|
+
// app的创建内容
|
|
376
|
+
this.contentToFile(app, results);
|
|
377
|
+
// 其他模块的创建内容
|
|
378
|
+
app.dependencies.forEach(function (item) { return _this.contentToFile(item, results); });
|
|
379
|
+
app.interfaceDependencies.forEach(function (item) { return _this.contentToFile(item, results); });
|
|
380
|
+
app.componentDependencies.forEach(function (item) { return _this.contentToFile(item, results); });
|
|
381
|
+
}
|
|
382
|
+
catch (err) {
|
|
383
|
+
console.log(err);
|
|
384
|
+
}
|
|
385
|
+
files = results.map(function (result) { return ({
|
|
386
|
+
file: result.filePath,
|
|
387
|
+
fileContent: result.code
|
|
388
|
+
}); });
|
|
389
|
+
return [4 /*yield*/, this.writeFiles(files)];
|
|
390
|
+
case 1:
|
|
391
|
+
_a.sent();
|
|
392
|
+
this._debugInFileStorage(app, files);
|
|
393
|
+
// 修改名称回调
|
|
394
|
+
common_1.registerCommand('tsRename.change', function (value, callback) {
|
|
395
|
+
callback(value);
|
|
396
|
+
});
|
|
397
|
+
// 删除回调
|
|
398
|
+
common_1.registerCommand('tsDelete.change', function (callback) {
|
|
399
|
+
callback();
|
|
400
|
+
});
|
|
401
|
+
return [2 /*return*/];
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
};
|
|
406
|
+
NaslServer.prototype.refreshApp = function (app) {
|
|
407
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
408
|
+
return __generator(this, function (_a) {
|
|
409
|
+
switch (_a.label) {
|
|
410
|
+
case 0:
|
|
411
|
+
// 清除所有问题
|
|
412
|
+
this.diagnosticManager.clear();
|
|
413
|
+
return [4 /*yield*/, this.deleteDirectoryFiles({ directoryName: '/embedded' })];
|
|
414
|
+
case 1:
|
|
415
|
+
_a.sent();
|
|
416
|
+
// 清楚check count的数量
|
|
417
|
+
return [4 /*yield*/, this.messager.requestCommand('_clearTimeout')];
|
|
418
|
+
case 2:
|
|
419
|
+
// 清楚check count的数量
|
|
420
|
+
_a.sent();
|
|
421
|
+
// 重新加载app下内容
|
|
422
|
+
return [4 /*yield*/, this.openApp(app)];
|
|
423
|
+
case 3:
|
|
424
|
+
// 重新加载app下内容
|
|
425
|
+
_a.sent();
|
|
426
|
+
// 重新check一遍所有内容
|
|
427
|
+
return [4 /*yield*/, this.getDiagnosticRecordsAndPushAll()];
|
|
428
|
+
case 4:
|
|
429
|
+
// 重新check一遍所有内容
|
|
430
|
+
_a.sent();
|
|
431
|
+
// 重新补一遍标注
|
|
432
|
+
return [4 /*yield*/, this.createdNaslAnnotatedJSON(app)];
|
|
433
|
+
case 5:
|
|
434
|
+
// 重新补一遍标注
|
|
435
|
+
_a.sent();
|
|
436
|
+
return [2 /*return*/];
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
};
|
|
441
|
+
/**
|
|
442
|
+
* 初始化之前添加文件
|
|
443
|
+
*/
|
|
444
|
+
NaslServer.prototype.addFile = function (file) {
|
|
445
|
+
return this.messager.requestCommand('addFile', file);
|
|
446
|
+
};
|
|
447
|
+
/**
|
|
448
|
+
* 只新增文件
|
|
449
|
+
* @param {*} files
|
|
450
|
+
*/
|
|
451
|
+
NaslServer.prototype.writeFiles = function (files) {
|
|
452
|
+
return this.messager.requestCommand('writeFiles', files);
|
|
453
|
+
};
|
|
454
|
+
/**
|
|
455
|
+
* 新增、修改
|
|
456
|
+
* 删除文件 文件用修改内容为空模拟,防止报错
|
|
457
|
+
* @param {*} args
|
|
458
|
+
*/
|
|
459
|
+
NaslServer.prototype.updateFiles = function (args) {
|
|
460
|
+
return this.messager.requestCommand('updateFiles', args);
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* 清除一个目录下的所有文件
|
|
464
|
+
*/
|
|
465
|
+
NaslServer.prototype.deleteDirectoryFiles = function (args) {
|
|
466
|
+
return this.messager.requestCommand('deleteDirectoryFiles', args);
|
|
467
|
+
};
|
|
468
|
+
NaslServer.prototype._debugInFileStorage = function (node, openFiles) {
|
|
469
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
470
|
+
var app, e_1, e_2;
|
|
471
|
+
var _this = this;
|
|
472
|
+
return __generator(this, function (_a) {
|
|
473
|
+
switch (_a.label) {
|
|
474
|
+
case 0:
|
|
475
|
+
app = node;
|
|
476
|
+
if (node.concept !== 'App') {
|
|
477
|
+
app = node.rootNode || node.app;
|
|
478
|
+
}
|
|
479
|
+
if (!globalThis.window) return [3 /*break*/, 4];
|
|
480
|
+
_a.label = 1;
|
|
481
|
+
case 1:
|
|
482
|
+
_a.trys.push([1, 3, , 4]);
|
|
483
|
+
return [4 /*yield*/, Promise.all(openFiles.map(function (file) { return __awaiter(_this, void 0, void 0, function () {
|
|
484
|
+
var res;
|
|
485
|
+
return __generator(this, function (_a) {
|
|
486
|
+
switch (_a.label) {
|
|
487
|
+
case 0: return [4 /*yield*/, storage_1["default"].post('/api/App/debugEmbedded?id=' + app.id, file)];
|
|
488
|
+
case 1:
|
|
489
|
+
res = _a.sent();
|
|
490
|
+
return [2 /*return*/, res.data];
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
}); }))];
|
|
494
|
+
case 2:
|
|
495
|
+
_a.sent();
|
|
496
|
+
return [3 /*break*/, 4];
|
|
497
|
+
case 3:
|
|
498
|
+
e_1 = _a.sent();
|
|
499
|
+
console.error(e_1);
|
|
500
|
+
return [3 /*break*/, 4];
|
|
501
|
+
case 4:
|
|
502
|
+
if (!globalThis.process) return [3 /*break*/, 8];
|
|
503
|
+
_a.label = 5;
|
|
504
|
+
case 5:
|
|
505
|
+
_a.trys.push([5, 7, , 8]);
|
|
506
|
+
return [4 /*yield*/, Promise.all(openFiles.map(function (file) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
507
|
+
return [2 /*return*/, fs.outputFile(path.join(__dirname, '../debug/apps', app.id, file.file), file.fileContent)];
|
|
508
|
+
}); }); }))];
|
|
509
|
+
case 6:
|
|
510
|
+
_a.sent();
|
|
511
|
+
return [3 /*break*/, 8];
|
|
512
|
+
case 7:
|
|
513
|
+
e_2 = _a.sent();
|
|
514
|
+
console.error(e_2);
|
|
515
|
+
return [3 /*break*/, 8];
|
|
516
|
+
case 8: return [2 /*return*/];
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
};
|
|
521
|
+
NaslServer.prototype.open = function () {
|
|
522
|
+
return this.messager.requestCommand('open');
|
|
523
|
+
};
|
|
524
|
+
NaslServer.prototype.updateOpen = function (args) {
|
|
525
|
+
return this.messager.requestCommand('updateOpen', args);
|
|
526
|
+
};
|
|
527
|
+
NaslServer.prototype.fileReferences = function (filePath) {
|
|
528
|
+
return this.messager.requestCommand('fileReferences', filePath);
|
|
529
|
+
};
|
|
530
|
+
NaslServer.prototype.references = function (args) {
|
|
531
|
+
var _a;
|
|
532
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
533
|
+
return __generator(this, function (_b) {
|
|
534
|
+
switch (_b.label) {
|
|
535
|
+
case 0: return [4 /*yield*/, this.messager.requestCommand('references', args)];
|
|
536
|
+
case 1: return [2 /*return*/, (_a = (_b.sent())) === null || _a === void 0 ? void 0 : _a.response];
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
};
|
|
541
|
+
NaslServer.prototype.getValueSelectCompletion = function (node, value, noFilterList) {
|
|
542
|
+
var _a = this.getCurrentSource(node), currentSource = _a.currentSource, fileNode = _a.fileNode;
|
|
543
|
+
// console.log(currentSource, fileNode);
|
|
544
|
+
if (currentSource && fileNode) {
|
|
545
|
+
return this._getValueSelectCompletion({
|
|
546
|
+
file: fileNode.getEmbeddedFilePath(),
|
|
547
|
+
range: {
|
|
548
|
+
line: translator_1.lsp2tspNumber(currentSource.range.start.line),
|
|
549
|
+
offset: translator_1.lsp2tspNumber(currentSource.range.start.character)
|
|
550
|
+
},
|
|
551
|
+
value: value,
|
|
552
|
+
noFilterList: noFilterList
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
console.log('没找到节点', node, currentSource, fileNode);
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
NaslServer.prototype._getValueSelectCompletion = function (args) {
|
|
560
|
+
return this.messager.requestCommand('getValueSelectCompletion', args);
|
|
561
|
+
};
|
|
562
|
+
/**
|
|
563
|
+
* 获取 Convert 的可选类型
|
|
564
|
+
* @param node 传入当前已经选择的变量
|
|
565
|
+
* @returns 可以选择的类型数组
|
|
566
|
+
*/
|
|
567
|
+
NaslServer.prototype.getConvertTypeInfo = function (node) {
|
|
568
|
+
var _a;
|
|
569
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
570
|
+
var callFunction, _b, currentSource, fileNode, quickInfo, displayString, typeList, res_1, err_1;
|
|
571
|
+
return __generator(this, function (_c) {
|
|
572
|
+
switch (_c.label) {
|
|
573
|
+
case 0:
|
|
574
|
+
if (!(node && node instanceof concepts_1.BaseNode)) return [3 /*break*/, 5];
|
|
575
|
+
callFunction = node.parentNode.parentNode;
|
|
576
|
+
_b = this.getCurrentSource(callFunction), currentSource = _b.currentSource, fileNode = _b.fileNode;
|
|
577
|
+
_c.label = 1;
|
|
578
|
+
case 1:
|
|
579
|
+
_c.trys.push([1, 3, , 4]);
|
|
580
|
+
return [4 /*yield*/, this._getTypeQuickinfo({
|
|
581
|
+
file: fileNode.getEmbeddedFilePath(),
|
|
582
|
+
line: translator_1.lsp2tspNumber(currentSource.range.start.line),
|
|
583
|
+
offset: translator_1.lsp2tspNumber(currentSource.range.start.character) + "nasl.util.C".length
|
|
584
|
+
})];
|
|
585
|
+
case 2:
|
|
586
|
+
quickInfo = _c.sent();
|
|
587
|
+
if (quickInfo.responseRequired) {
|
|
588
|
+
displayString = ((_a = quickInfo === null || quickInfo === void 0 ? void 0 : quickInfo.response) === null || _a === void 0 ? void 0 : _a.displayString) || '';
|
|
589
|
+
typeList = getDisplayString2Type(displayString);
|
|
590
|
+
res_1 = [];
|
|
591
|
+
typeList.forEach(function (type) {
|
|
592
|
+
var typeAnnotation = coreTypeList_1.primitiveTypeList.find(function (typeAnnotation) { return typeAnnotation.typeName === type; });
|
|
593
|
+
if (typeAnnotation) {
|
|
594
|
+
res_1.push(typeAnnotation);
|
|
595
|
+
}
|
|
596
|
+
else if (type === 'unknown' || type === 'never') {
|
|
597
|
+
return null;
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
if (!res_1.length) {
|
|
601
|
+
return [2 /*return*/, []];
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
return [2 /*return*/, [{ title: '基础类型', children: res_1 }]];
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
return [3 /*break*/, 4];
|
|
608
|
+
case 3:
|
|
609
|
+
err_1 = _c.sent();
|
|
610
|
+
console.log(err_1);
|
|
611
|
+
// 如果有异常就先放开全部可选,兜底逻辑
|
|
612
|
+
return [2 /*return*/, []];
|
|
613
|
+
case 4: return [3 /*break*/, 6];
|
|
614
|
+
case 5:
|
|
615
|
+
// 字符串 和 inter
|
|
616
|
+
return [2 /*return*/, [{ title: '基础类型', children: [coreTypeList_1.primitiveTypeList[4]] }]];
|
|
617
|
+
case 6: return [2 /*return*/];
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
};
|
|
622
|
+
/**
|
|
623
|
+
* 获取表单的dataschema类型
|
|
624
|
+
* @param node 当前表单节点
|
|
625
|
+
* @param allType 是不是需要全部类型 默认不要
|
|
626
|
+
* @returns 全部类型的str 或者 最后一个.后的内容
|
|
627
|
+
*/
|
|
628
|
+
NaslServer.prototype.getDataSchemaType = function (node, allType) {
|
|
629
|
+
var _a;
|
|
630
|
+
if (allType === void 0) { allType = false; }
|
|
631
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
632
|
+
var _b, currentSource, fileNode, quickInfo, displayString, flag, types, typeStr, str, strs, type;
|
|
633
|
+
return __generator(this, function (_c) {
|
|
634
|
+
switch (_c.label) {
|
|
635
|
+
case 0:
|
|
636
|
+
if (!(node instanceof concepts_1.ViewElement))
|
|
637
|
+
return [2 /*return*/];
|
|
638
|
+
_b = this.getCurrentSource(node), currentSource = _b.currentSource, fileNode = _b.fileNode;
|
|
639
|
+
return [4 /*yield*/, this._getTypeQuickinfo({
|
|
640
|
+
file: fileNode.getEmbeddedFilePath(),
|
|
641
|
+
line: translator_1.lsp2tspNumber(currentSource.range.start.line),
|
|
642
|
+
offset: translator_1.lsp2tspNumber(currentSource.range.start.character) + "new nasl.ui.".length
|
|
643
|
+
})];
|
|
644
|
+
case 1:
|
|
645
|
+
quickInfo = _c.sent();
|
|
646
|
+
if (quickInfo.responseRequired) {
|
|
647
|
+
displayString = ((_a = quickInfo === null || quickInfo === void 0 ? void 0 : quickInfo.response) === null || _a === void 0 ? void 0 : _a.displayString) || '';
|
|
648
|
+
flag = displayString.includes('<') && displayString.includes('>');
|
|
649
|
+
types = /\<([^()]+)\>/g.exec(displayString);
|
|
650
|
+
typeStr = types && types[1];
|
|
651
|
+
if (flag) {
|
|
652
|
+
// 自定义结构的展示
|
|
653
|
+
if (typeStr.includes('__name: "AStructure_')) {
|
|
654
|
+
return [2 /*return*/, typeStr.replaceAll(' ', '')
|
|
655
|
+
.replaceAll('\n', '')
|
|
656
|
+
.replace(/__name:"AStructure_\w{8}";/g, '')
|
|
657
|
+
.replace(/dataSources.([^.]+).entities.([^;]+)/g, function ($1, $2, $3) { return ($3 + "(" + $2 + ")"); })];
|
|
658
|
+
}
|
|
659
|
+
else if (typeStr.startsWith('{') && typeStr.endsWith('}')) {
|
|
660
|
+
/**
|
|
661
|
+
* {
|
|
662
|
+
text: nasl.core.String;
|
|
663
|
+
value: nasl.core.String;
|
|
664
|
+
}
|
|
665
|
+
*/
|
|
666
|
+
return [2 /*return*/, typeStr.replaceAll(' ', '')
|
|
667
|
+
.replaceAll('\n', '')
|
|
668
|
+
.replaceAll('nasl.core.', '')];
|
|
669
|
+
}
|
|
670
|
+
str = '';
|
|
671
|
+
// 取出T的值
|
|
672
|
+
typeStr = formatTsUtils_1.getPlatformType(typeStr);
|
|
673
|
+
// 如果要全量的内容
|
|
674
|
+
if (allType) {
|
|
675
|
+
return [2 /*return*/, typeStr];
|
|
676
|
+
}
|
|
677
|
+
// 取出剩下的剩下的类型的最后一项
|
|
678
|
+
if (/\<([^()]+)\>/g.exec(typeStr)) {
|
|
679
|
+
str = typeStr;
|
|
680
|
+
}
|
|
681
|
+
else if (typeStr.includes('.')) {
|
|
682
|
+
strs = typeStr.split('.');
|
|
683
|
+
type = strs[strs.length - 1];
|
|
684
|
+
str = type;
|
|
685
|
+
}
|
|
686
|
+
else {
|
|
687
|
+
str = typeStr;
|
|
688
|
+
}
|
|
689
|
+
str = str === 'any' || str === 'unknown' || str === 'never' ? '' : str;
|
|
690
|
+
return [2 /*return*/, str];
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
return [2 /*return*/, ''];
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
});
|
|
697
|
+
};
|
|
698
|
+
/**
|
|
699
|
+
* ts的 quickInfo方法,查询指定位置的详情
|
|
700
|
+
* @param args 文件信息数组
|
|
701
|
+
* @returns 查询到的
|
|
702
|
+
*/
|
|
703
|
+
NaslServer.prototype._getTypeQuickinfo = function (args) {
|
|
704
|
+
return this.messager.requestCommand('quickInfo', args);
|
|
705
|
+
};
|
|
706
|
+
NaslServer.prototype._getQuickInfoFull = function (args) {
|
|
707
|
+
return this.messager.requestCommand('quickInfoFull', args);
|
|
708
|
+
};
|
|
709
|
+
/**
|
|
710
|
+
* 获取nasl节点的 指定位置的详情
|
|
711
|
+
* 而且可以返回正确类型
|
|
712
|
+
* @param args 文件信息数组
|
|
713
|
+
* @returns 查询到的
|
|
714
|
+
*/
|
|
715
|
+
NaslServer.prototype.getNaslNodeQuickInfoFull = function (args) {
|
|
716
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
717
|
+
var result;
|
|
718
|
+
return __generator(this, function (_a) {
|
|
719
|
+
switch (_a.label) {
|
|
720
|
+
case 0: return [4 /*yield*/, this._getQuickInfoFull(args)];
|
|
721
|
+
case 1:
|
|
722
|
+
result = _a.sent();
|
|
723
|
+
return [2 /*return*/, result];
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
});
|
|
727
|
+
};
|
|
728
|
+
NaslServer.prototype._getTypeFull = function (args) {
|
|
729
|
+
return this.messager.requestCommand('typeFull', args);
|
|
730
|
+
};
|
|
731
|
+
NaslServer.prototype._getTypeBatch = function (args) {
|
|
732
|
+
return this.messager.requestCommand('typeBatch', args);
|
|
733
|
+
};
|
|
734
|
+
NaslServer.prototype.getNaslNodeTypeFull = function (args) {
|
|
735
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
736
|
+
var result;
|
|
737
|
+
return __generator(this, function (_a) {
|
|
738
|
+
switch (_a.label) {
|
|
739
|
+
case 0: return [4 /*yield*/, this._getTypeFull(args)];
|
|
740
|
+
case 1:
|
|
741
|
+
result = _a.sent();
|
|
742
|
+
return [2 /*return*/, result];
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
});
|
|
746
|
+
};
|
|
747
|
+
NaslServer.prototype.getNaslNodeTypeBatch = function (args) {
|
|
748
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
749
|
+
var result;
|
|
750
|
+
return __generator(this, function (_a) {
|
|
751
|
+
switch (_a.label) {
|
|
752
|
+
case 0: return [4 /*yield*/, this._getTypeBatch(args)];
|
|
753
|
+
case 1:
|
|
754
|
+
result = _a.sent();
|
|
755
|
+
return [2 /*return*/, result];
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
});
|
|
759
|
+
};
|
|
760
|
+
/**
|
|
761
|
+
* 获取已经选中的内容的 下一级的内容
|
|
762
|
+
* @param node 已经选中的内容
|
|
763
|
+
* @param noFilterList 不过滤的key 的数据
|
|
764
|
+
* @returns 可以选择的数据数组
|
|
765
|
+
*/
|
|
766
|
+
NaslServer.prototype.getSelectNextCompletion = function (node, noFilterList) {
|
|
767
|
+
var _a = this.getCurrentSource(node), currentSource = _a.currentSource, fileNode = _a.fileNode;
|
|
768
|
+
// console.log(currentSource, fileNode);
|
|
769
|
+
if (currentSource && fileNode) {
|
|
770
|
+
return this._getSelectNextCompletion({
|
|
771
|
+
file: fileNode.getEmbeddedFilePath(),
|
|
772
|
+
range: {
|
|
773
|
+
line: translator_1.lsp2tspNumber(currentSource.range.start.line),
|
|
774
|
+
offset: translator_1.lsp2tspNumber(currentSource.range.start.character)
|
|
775
|
+
},
|
|
776
|
+
noFilterList: noFilterList
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
console.log('没找到节点', currentSource, fileNode);
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
NaslServer.prototype._getSelectNextCompletion = function (args) {
|
|
784
|
+
return this.messager.requestCommand('getSelectNextCompletion', args);
|
|
785
|
+
};
|
|
786
|
+
/**
|
|
787
|
+
* 获取诊断信息
|
|
788
|
+
* @param fileNames 多个文件名
|
|
789
|
+
* @returns 诊断结果
|
|
790
|
+
*/
|
|
791
|
+
NaslServer.prototype.getDiagnosticRecords = function (fileNames) {
|
|
792
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
793
|
+
var records, diagnosticRecords;
|
|
794
|
+
return __generator(this, function (_a) {
|
|
795
|
+
switch (_a.label) {
|
|
796
|
+
case 0: return [4 /*yield*/, this.messager.requestCommand('getDiagnosticRecords', fileNames)];
|
|
797
|
+
case 1:
|
|
798
|
+
records = (_a.sent());
|
|
799
|
+
return [4 /*yield*/, this._resolveDiagnosticRecords(records)];
|
|
800
|
+
case 2:
|
|
801
|
+
diagnosticRecords = _a.sent();
|
|
802
|
+
return [2 /*return*/, diagnosticRecords];
|
|
803
|
+
}
|
|
804
|
+
});
|
|
805
|
+
});
|
|
806
|
+
};
|
|
807
|
+
NaslServer.prototype.getDiagnosticRecordsAndPushAll = function (fileNames) {
|
|
808
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
809
|
+
var records;
|
|
810
|
+
return __generator(this, function (_a) {
|
|
811
|
+
switch (_a.label) {
|
|
812
|
+
case 0: return [4 /*yield*/, this.getDiagnosticRecords(fileNames)];
|
|
813
|
+
case 1:
|
|
814
|
+
records = _a.sent();
|
|
815
|
+
return [2 /*return*/];
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
});
|
|
819
|
+
};
|
|
820
|
+
/**
|
|
821
|
+
* 处理诊断结果
|
|
822
|
+
* @param records 结果
|
|
823
|
+
* @returns 过滤或者转换后的诊断结果
|
|
824
|
+
*/
|
|
825
|
+
NaslServer.prototype._resolveDiagnosticRecords = function (records) {
|
|
826
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
827
|
+
var _this = this;
|
|
828
|
+
return __generator(this, function (_a) {
|
|
829
|
+
switch (_a.label) {
|
|
830
|
+
case 0:
|
|
831
|
+
if (!records.length) return [3 /*break*/, 2];
|
|
832
|
+
return [4 /*yield*/, this.IncrementalAnnotationJSON(records)];
|
|
833
|
+
case 1:
|
|
834
|
+
_a.sent();
|
|
835
|
+
_a.label = 2;
|
|
836
|
+
case 2:
|
|
837
|
+
records.forEach(function (record) {
|
|
838
|
+
var _a, _b;
|
|
839
|
+
var node = record.node;
|
|
840
|
+
if (!node)
|
|
841
|
+
return;
|
|
842
|
+
// 先获取原来的节点先清除一下之前有异常的节点,下面重新赋值
|
|
843
|
+
var oldRecord = _this.diagnosticManager.getRecord(record.id);
|
|
844
|
+
oldRecord === null || oldRecord === void 0 ? void 0 : oldRecord.semanticDiagnostics.forEach(function (item) {
|
|
845
|
+
if (item.node) {
|
|
846
|
+
item.node.tsErrorDetail = undefined;
|
|
847
|
+
// 如果logic中有报错就把标识置为true
|
|
848
|
+
if (item.node.logic) {
|
|
849
|
+
item.node.logic.haveError = false;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
// 清空一些状态
|
|
854
|
+
oldRecord === null || oldRecord === void 0 ? void 0 : oldRecord.suggestionDiagnostics.forEach(function (item) {
|
|
855
|
+
if (item.node) {
|
|
856
|
+
item.node.tsErrorDetail = undefined;
|
|
857
|
+
if (item.node && item.node instanceof concepts_1.Logic) {
|
|
858
|
+
item.node.isSmpty = false;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
// 语义诊断
|
|
863
|
+
if (isChangeInterface) {
|
|
864
|
+
_this.existStructureFix(record.semanticDiagnostics, node, _this);
|
|
865
|
+
}
|
|
866
|
+
// 单独处理 oql 语义错误提示
|
|
867
|
+
if (record.node instanceof concepts_1.Logic) {
|
|
868
|
+
record === null || record === void 0 ? void 0 : record.syntaxDiagnostics.forEach(function (item) {
|
|
869
|
+
var minRange = _this._findMinRange(item, record.node);
|
|
870
|
+
if (minRange.node instanceof concepts_1.OqlQueryComponent) {
|
|
871
|
+
if (item.text === 'Invalid character.') {
|
|
872
|
+
record.semanticDiagnostics.push(item);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
record.semanticDiagnostics = record.semanticDiagnostics
|
|
878
|
+
.map(function (diag) { return _this._resolveDiagnostic(diag, node, record); })
|
|
879
|
+
.filter(function (diag) { return !!diag; });
|
|
880
|
+
(_a = record.semanticDiagnostics).push.apply(_a, _this._attachDiagnostics(node));
|
|
881
|
+
// 建议诊断
|
|
882
|
+
// 实体下的建议不用展示,因为都是平台自己写的逻辑
|
|
883
|
+
// if (node instanceof Entity) {
|
|
884
|
+
// record.suggestionDiagnostics = [];
|
|
885
|
+
// }
|
|
886
|
+
// if (node instanceof View) {
|
|
887
|
+
// // event在view中不展示建议使用,提示关闭掉
|
|
888
|
+
// record.suggestionDiagnostics = record.suggestionDiagnostics.filter((item) => !item.text.includes(`'event'`));
|
|
889
|
+
// }
|
|
890
|
+
// if (node instanceof Logic) {
|
|
891
|
+
// // logic在for循环中,不展示any提示
|
|
892
|
+
// record.suggestionDiagnostics = record.suggestionDiagnostics.filter((item) => !item.text.includes(`implicitly has an 'any' type, but a better type may be inferred from usage.`));
|
|
893
|
+
// }
|
|
894
|
+
record.suggestionDiagnostics = record.suggestionDiagnostics
|
|
895
|
+
.filter(function (item) { return ["'__LogicEmpty' is declared but its value is never read.", "'__destinationEmpty__' is declared but its value is never read."].includes(item.text); })
|
|
896
|
+
.map(function (diag) { return _this._resolveDiagnostic(diag, node, record); })
|
|
897
|
+
.filter(function (diag) { return !!diag; });
|
|
898
|
+
(_b = record.suggestionDiagnostics).push.apply(_b, _this._attachSuggestionDiagnostics(node));
|
|
899
|
+
});
|
|
900
|
+
return [2 /*return*/, records];
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
});
|
|
904
|
+
};
|
|
905
|
+
/**
|
|
906
|
+
* 额外的建议诊断
|
|
907
|
+
* @param fileNode 文件级别的节点
|
|
908
|
+
* @returns 诊断结果
|
|
909
|
+
*/
|
|
910
|
+
NaslServer.prototype._attachSuggestionDiagnostics = function (fileNode) {
|
|
911
|
+
var _this = this;
|
|
912
|
+
var diagnostics = [];
|
|
913
|
+
if (fileNode instanceof concepts_1.Logic || fileNode instanceof concepts_1.View) {
|
|
914
|
+
// 判断逻辑是否已经删除
|
|
915
|
+
if (fileNode instanceof concepts_1.Logic && fileNode.parentNode instanceof concepts_1.App && !fileNode.parentNode.logics.includes(fileNode))
|
|
916
|
+
return diagnostics;
|
|
917
|
+
// 判断页面是否已经删除
|
|
918
|
+
var removed = false;
|
|
919
|
+
var curNode = fileNode;
|
|
920
|
+
// 递归检查,防止从顶层页面开始删除影响子页面内容检查
|
|
921
|
+
while (curNode instanceof concepts_1.View && !removed) {
|
|
922
|
+
if (curNode.parentNode instanceof concepts_1.View && !curNode.parentNode.children.includes(curNode)
|
|
923
|
+
|| curNode.parentNode instanceof concepts_1.App && !curNode.parentNode.views.includes(curNode)) {
|
|
924
|
+
removed = true;
|
|
925
|
+
}
|
|
926
|
+
curNode = curNode.parentNode;
|
|
927
|
+
}
|
|
928
|
+
if (removed)
|
|
929
|
+
return diagnostics;
|
|
930
|
+
fileNode === null || fileNode === void 0 ? void 0 : fileNode.sourceMap.forEach(function (value, node) { return __awaiter(_this, void 0, void 0, function () {
|
|
931
|
+
var _a, cases_1, expression_1, typeAnnotationMap_1, maxTypeAnnotationInfo_1, maxTypeAnnotation_1, sortedTypeKey, _b, typeAnnotation, cases_2;
|
|
932
|
+
var _this = this;
|
|
933
|
+
return __generator(this, function (_c) {
|
|
934
|
+
if (node instanceof concepts_1.Match) {
|
|
935
|
+
_a = node || {}, cases_1 = _a.cases, expression_1 = _a.expression;
|
|
936
|
+
typeAnnotationMap_1 = {};
|
|
937
|
+
maxTypeAnnotationInfo_1 = {
|
|
938
|
+
typeAnnotation: null,
|
|
939
|
+
count: 0
|
|
940
|
+
};
|
|
941
|
+
if (Array.isArray(cases_1)) {
|
|
942
|
+
cases_1.forEach(function (caseItem, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
943
|
+
var isDisabled, enumerableItems, currTypeAnnotation, _a, typeKind, typeNamespace, typeName, typeArguments, nameArr, typeNode, enums, children, map_1, enumerableKeys, typeAnnotation, sortedTypeKey, typeAnnotationInfo, count;
|
|
944
|
+
var _b, _c;
|
|
945
|
+
return __generator(this, function (_d) {
|
|
946
|
+
isDisabled = false;
|
|
947
|
+
// 是最后一项
|
|
948
|
+
if (index === cases_1.length - 1) {
|
|
949
|
+
enumerableItems = [];
|
|
950
|
+
currTypeAnnotation = expression_1 === null || expression_1 === void 0 ? void 0 : expression_1.__TypeAnnotation;
|
|
951
|
+
_a = currTypeAnnotation || {}, typeKind = _a.typeKind, typeNamespace = _a.typeNamespace, typeName = _a.typeName, typeArguments = _a.typeArguments;
|
|
952
|
+
if (typeKind === 'union' && Array.isArray(typeArguments)) {
|
|
953
|
+
enumerableItems = typeArguments.map(function (typeArg) {
|
|
954
|
+
var typeArgJson = typeArg;
|
|
955
|
+
if (typeArg instanceof concepts_1.TypeAnnotation) {
|
|
956
|
+
typeArgJson = typeArg.toJSON();
|
|
957
|
+
}
|
|
958
|
+
return new concepts_1.TypeAnnotation(typeArgJson);
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
else if (typeKind === 'reference') {
|
|
962
|
+
nameArr = [typeName];
|
|
963
|
+
if (typeNamespace) {
|
|
964
|
+
nameArr.unshift(typeNamespace);
|
|
965
|
+
}
|
|
966
|
+
typeNode = ((_c = (_b = node.app) === null || _b === void 0 ? void 0 : _b.findNodeByCompleteName) === null || _c === void 0 ? void 0 : _c.call(_b, nameArr.join('.'))) || {};
|
|
967
|
+
if (typeNode.concept === 'Enum') {
|
|
968
|
+
enums = getMemberIdentifier_1.formatEnums([typeNode]);
|
|
969
|
+
children = ((enums === null || enums === void 0 ? void 0 : enums[0]) || {}).children;
|
|
970
|
+
if (Array.isArray(children)) {
|
|
971
|
+
enumerableItems = children.map(function (child) { return child === null || child === void 0 ? void 0 : child.expression; });
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
else if (typeKind === 'primitive' && typeNamespace === 'nasl.core' && typeName === 'Boolean') {
|
|
976
|
+
enumerableItems = [
|
|
977
|
+
new concepts_1.BooleanLiteral({
|
|
978
|
+
value: 'true'
|
|
979
|
+
}),
|
|
980
|
+
new concepts_1.BooleanLiteral({
|
|
981
|
+
value: 'false'
|
|
982
|
+
}),
|
|
983
|
+
];
|
|
984
|
+
}
|
|
985
|
+
if (Array.isArray(enumerableItems) && enumerableItems.length) {
|
|
986
|
+
map_1 = {};
|
|
987
|
+
cases_1.forEach(function (caseItem) {
|
|
988
|
+
var patterns = (caseItem || {}).patterns;
|
|
989
|
+
if (Array.isArray(patterns)) {
|
|
990
|
+
patterns.forEach(function (pattern) {
|
|
991
|
+
if (pattern instanceof concepts_1.TypeAnnotation) {
|
|
992
|
+
var patternTypeKey = pattern.typeKey;
|
|
993
|
+
map_1[patternTypeKey] = true;
|
|
994
|
+
}
|
|
995
|
+
else if (pattern instanceof concepts_1.MemberExpression || pattern instanceof concepts_1.BooleanLiteral) {
|
|
996
|
+
var patternValue = pattern.getValue();
|
|
997
|
+
map_1[patternValue] = true;
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
enumerableKeys = Object.keys(map_1);
|
|
1003
|
+
if (enumerableKeys.length === enumerableItems.length) {
|
|
1004
|
+
isDisabled = true;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
if (!isDisabled) {
|
|
1009
|
+
typeAnnotation = caseItem.__TypeAnnotation;
|
|
1010
|
+
// 仅处理有类型的情况,返回类型为void的情况由其他地方处理成报错
|
|
1011
|
+
if (typeAnnotation) {
|
|
1012
|
+
sortedTypeKey = typeAnnotation === null || typeAnnotation === void 0 ? void 0 : typeAnnotation.sortedTypeKey;
|
|
1013
|
+
if (!typeAnnotationMap_1[sortedTypeKey]) {
|
|
1014
|
+
typeAnnotationMap_1[sortedTypeKey] = {
|
|
1015
|
+
typeAnnotation: typeAnnotation,
|
|
1016
|
+
cases: [],
|
|
1017
|
+
count: 0
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
typeAnnotationInfo = typeAnnotationMap_1[sortedTypeKey];
|
|
1021
|
+
typeAnnotationInfo.cases.push(caseItem);
|
|
1022
|
+
typeAnnotationInfo.count++;
|
|
1023
|
+
count = typeAnnotationInfo.count;
|
|
1024
|
+
if (maxTypeAnnotationInfo_1.count < count) {
|
|
1025
|
+
maxTypeAnnotationInfo_1 = {
|
|
1026
|
+
typeAnnotation: typeAnnotation,
|
|
1027
|
+
count: count
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
return [2 /*return*/, typeAnnotation];
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
return [2 /*return*/];
|
|
1034
|
+
});
|
|
1035
|
+
}); });
|
|
1036
|
+
}
|
|
1037
|
+
maxTypeAnnotation_1 = maxTypeAnnotationInfo_1.typeAnnotation;
|
|
1038
|
+
for (sortedTypeKey in typeAnnotationMap_1) {
|
|
1039
|
+
_b = typeAnnotationMap_1[sortedTypeKey], typeAnnotation = _b.typeAnnotation, cases_2 = _b.cases;
|
|
1040
|
+
if ((maxTypeAnnotation_1 === null || maxTypeAnnotation_1 === void 0 ? void 0 : maxTypeAnnotation_1.sortedTypeKey) !== (typeAnnotation === null || typeAnnotation === void 0 ? void 0 : typeAnnotation.sortedTypeKey)) {
|
|
1041
|
+
if (Array.isArray(cases_2)) {
|
|
1042
|
+
cases_2.forEach(function (caseItem) {
|
|
1043
|
+
var body = (caseItem || {}).body;
|
|
1044
|
+
var diagnostic = {
|
|
1045
|
+
node: caseItem,
|
|
1046
|
+
severity: 'warning',
|
|
1047
|
+
message: '分支类型不一致'
|
|
1048
|
+
};
|
|
1049
|
+
if (Array.isArray(body) && body.length) {
|
|
1050
|
+
var lastExpression = body[body.length - 1];
|
|
1051
|
+
diagnostic.node = lastExpression;
|
|
1052
|
+
diagnostic.message = (lastExpression === null || lastExpression === void 0 ? void 0 : lastExpression.toUI()) + "\u671F\u671B\u7684\u7C7B\u578B\u662F" + (maxTypeAnnotation_1 === null || maxTypeAnnotation_1 === void 0 ? void 0 : maxTypeAnnotation_1.headTitle);
|
|
1053
|
+
lastExpression.tsErrorDetail = diagnostic;
|
|
1054
|
+
diagnostics.push(diagnostic);
|
|
1055
|
+
}
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
return [2 /*return*/];
|
|
1062
|
+
});
|
|
1063
|
+
}); });
|
|
1064
|
+
}
|
|
1065
|
+
return diagnostics;
|
|
1066
|
+
};
|
|
1067
|
+
/**
|
|
1068
|
+
* 额外的诊断
|
|
1069
|
+
* @param fileNode 文件级别的节点
|
|
1070
|
+
* @returns 诊断结果
|
|
1071
|
+
*/
|
|
1072
|
+
NaslServer.prototype._attachDiagnostics = function (fileNode) {
|
|
1073
|
+
var _this = this;
|
|
1074
|
+
var _a;
|
|
1075
|
+
var diagnostics = [];
|
|
1076
|
+
if (fileNode instanceof concepts_1.View) {
|
|
1077
|
+
// 判断页面是否已经删除
|
|
1078
|
+
var removed = false;
|
|
1079
|
+
var curNode = fileNode;
|
|
1080
|
+
// 递归检查,防止从顶层页面开始删除影响子页面内容检查
|
|
1081
|
+
while (curNode instanceof concepts_1.View && !removed) {
|
|
1082
|
+
if (curNode.parentNode instanceof concepts_1.View && !curNode.parentNode.children.includes(curNode)
|
|
1083
|
+
|| curNode.parentNode instanceof concepts_1.App && !curNode.parentNode.views.includes(curNode)) {
|
|
1084
|
+
removed = true;
|
|
1085
|
+
}
|
|
1086
|
+
curNode = curNode.parentNode;
|
|
1087
|
+
}
|
|
1088
|
+
if (removed)
|
|
1089
|
+
return diagnostics;
|
|
1090
|
+
fileNode.traverseChildren(function (node) {
|
|
1091
|
+
if (node instanceof concepts_1.ViewElement && node.view === fileNode) {
|
|
1092
|
+
if (node.tag) {
|
|
1093
|
+
node.bindAttrs.forEach(function (bindAttr) {
|
|
1094
|
+
if ((bindAttr.model || bindAttr.sync) && bindAttr.expression) {
|
|
1095
|
+
var bindExpression = bindAttr.expression;
|
|
1096
|
+
var diagnostic = void 0;
|
|
1097
|
+
if (bindExpression.concept !== 'Identifier' && bindExpression.concept !== 'MemberExpression') {
|
|
1098
|
+
diagnostic = {
|
|
1099
|
+
node: bindAttr,
|
|
1100
|
+
severity: 'error',
|
|
1101
|
+
message: '页面元素双向绑定:只允许绑定可赋值的变量和属性。'
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
else {
|
|
1105
|
+
if (bindExpression.isEnum()) {
|
|
1106
|
+
diagnostic = {
|
|
1107
|
+
node: bindAttr,
|
|
1108
|
+
severity: 'error',
|
|
1109
|
+
message: '页面元素双向绑定:只允许绑定可赋值的变量和属性。'
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
if (diagnostic) {
|
|
1114
|
+
bindAttr.tsErrorDetail = diagnostic;
|
|
1115
|
+
diagnostics.push(diagnostic);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
else if ((node instanceof concepts_1.Variable || node instanceof concepts_1.Return) && node.view === fileNode) {
|
|
1122
|
+
if (!node.typeAnnotation && !node.__TypeAnnotation) {
|
|
1123
|
+
var nodeTypeName_1 = node.concept === 'Return' ? '输出参数' : '局部变量';
|
|
1124
|
+
var msg_1;
|
|
1125
|
+
fileNode.traverseChildren(function (nodeIn) {
|
|
1126
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1127
|
+
if (nodeIn && (nodeIn instanceof concepts_1.BatchAssignment || (nodeIn instanceof concepts_1.Assignment && ((_a = nodeIn.left) === null || _a === void 0 ? void 0 : _a.name)))) {
|
|
1128
|
+
// 子页面内部逻辑过滤
|
|
1129
|
+
if (nodeIn.view !== fileNode)
|
|
1130
|
+
return;
|
|
1131
|
+
// 跟变量无关的赋值过滤
|
|
1132
|
+
var jsCode_1 = nodeIn.toJS();
|
|
1133
|
+
if (!jsCode_1.includes(node.name + " = "))
|
|
1134
|
+
return;
|
|
1135
|
+
// 逻辑内局部变量、输出参数、输入参数过滤
|
|
1136
|
+
if (((_b = nodeIn.logic) === null || _b === void 0 ? void 0 : _b.variables.find(function (lVar) { return jsCode_1.includes(lVar.name + " = "); })) || ((_c = nodeIn.logic) === null || _c === void 0 ? void 0 : _c.returns.find(function (lRet) { return jsCode_1.includes(lRet.name + " = "); }))
|
|
1137
|
+
|| ((_d = nodeIn.logic) === null || _d === void 0 ? void 0 : _d.params.find(function (lPar) { return jsCode_1.includes(lPar.name + " = "); }))
|
|
1138
|
+
|| ((_e = nodeIn.logic) === null || _e === void 0 ? void 0 : _e.virtualParams.find(function (vParam) { return jsCode_1.includes(vParam.name + " = "); })))
|
|
1139
|
+
return;
|
|
1140
|
+
if (node instanceof concepts_1.Variable
|
|
1141
|
+
&& node.parentNode instanceof concepts_1.View
|
|
1142
|
+
&& (((_f = nodeIn.logic) === null || _f === void 0 ? void 0 : _f.params.find(function (param) { return jsCode_1.includes(param.name); })) || ((_g = nodeIn.logic) === null || _g === void 0 ? void 0 : _g.virtualParams.find(function (vParam) { return jsCode_1.includes(vParam.name); }))
|
|
1143
|
+
|| ((_h = nodeIn.logic) === null || _h === void 0 ? void 0 : _h.variables.find(function (variable) { return jsCode_1.includes(variable.name); })))) {
|
|
1144
|
+
// 直接赋值 logic 内局部变量、输入参数直接提示系统无法推断类型
|
|
1145
|
+
if (!nodeIn.tsErrorDetail) {
|
|
1146
|
+
var diagnostic_2 = {
|
|
1147
|
+
node: nodeIn,
|
|
1148
|
+
severity: 'error',
|
|
1149
|
+
message: "\u9875\u9762" + nodeTypeName_1 + " " + node.name + " \u8D4B\u503C\u9875\u9762\u903B\u8F91\u5185\u5C40\u90E8\u53D8\u91CF\u6216\u8F93\u5165\u53C2\u6570\u65F6\uFF0C\u7CFB\u7EDF\u65E0\u6CD5\u63A8\u5BFC\u7C7B\u578B\u3002"
|
|
1150
|
+
};
|
|
1151
|
+
nodeIn.tsErrorDetail = diagnostic_2;
|
|
1152
|
+
diagnostics.push(diagnostic_2);
|
|
1153
|
+
}
|
|
1154
|
+
msg_1 = '系统无法推断类型。';
|
|
1155
|
+
}
|
|
1156
|
+
else {
|
|
1157
|
+
if (!nodeIn.tsErrorDetail) {
|
|
1158
|
+
var diagnostic_3 = {
|
|
1159
|
+
node: nodeIn,
|
|
1160
|
+
severity: 'error',
|
|
1161
|
+
message: nodeIn.label + "\u5DE6\u8FB9 " + node.name + " \u672A\u8BBE\u7F6E\u7C7B\u578B\uFF0C\u53F3\u8FB9\u5FC5\u987B\u4E3A\u6709\u8FD4\u56DE\u503C\u7684\u5185\u5BB9\u3002"
|
|
1162
|
+
};
|
|
1163
|
+
nodeIn.tsErrorDetail = diagnostic_3;
|
|
1164
|
+
diagnostics.push(diagnostic_3);
|
|
1165
|
+
}
|
|
1166
|
+
msg_1 = '必须赋值有返回值的内容。';
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
});
|
|
1170
|
+
if (!msg_1)
|
|
1171
|
+
msg_1 = '未设置类型或未赋值,直接赋值系统会自动推断类型。';
|
|
1172
|
+
var diagnostic = {
|
|
1173
|
+
node: node,
|
|
1174
|
+
severity: 'error',
|
|
1175
|
+
message: nodeTypeName_1 + " " + node.name + " " + msg_1
|
|
1176
|
+
};
|
|
1177
|
+
node.tsErrorDetail = diagnostic;
|
|
1178
|
+
diagnostics.push(diagnostic);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
else {
|
|
1182
|
+
_this.checkNodeError(node, diagnostics);
|
|
1183
|
+
}
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
if (fileNode instanceof concepts_1.DataSource) {
|
|
1187
|
+
var dataSourceGroup = (_a = fileNode.rootNode.configuration) === null || _a === void 0 ? void 0 : _a.getGroup('dataSource');
|
|
1188
|
+
if (dataSourceGroup) {
|
|
1189
|
+
var property_1 = dataSourceGroup.getProperty(fileNode.name);
|
|
1190
|
+
if (property_1 && property_1.values) {
|
|
1191
|
+
property_1.values.forEach(function (propertyValue) {
|
|
1192
|
+
if (!propertyValue.value && fileNode.name !== 'defaultDS') {
|
|
1193
|
+
var diagnostic = {
|
|
1194
|
+
node: fileNode,
|
|
1195
|
+
severity: 'error',
|
|
1196
|
+
message: "\u6570\u636E\u6E90\u914D\u7F6E\uFF1A\u6570\u636E\u6E90" + property_1.name + (propertyValue.env === 'dev' ? '开发环境' : '生产环境') + "\u672A\u914D\u7F6E\u6570\u636E\u4FE1\u606F",
|
|
1197
|
+
// 保留原来的内容方便查询一些问题
|
|
1198
|
+
originalDiagnostic: {
|
|
1199
|
+
fileName: '',
|
|
1200
|
+
start: null,
|
|
1201
|
+
end: null,
|
|
1202
|
+
category: 'error',
|
|
1203
|
+
text: "Data Source is not config"
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
diagnostics.push(diagnostic);
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
if (fileNode instanceof concepts_1.Logic) {
|
|
1213
|
+
// 判断逻辑是否已经删除
|
|
1214
|
+
if (fileNode.parentNode instanceof concepts_1.App && !fileNode.parentNode.logics.includes(fileNode))
|
|
1215
|
+
return diagnostics;
|
|
1216
|
+
fileNode === null || fileNode === void 0 ? void 0 : fileNode.sourceMap.forEach(function (value, node) { return __awaiter(_this, void 0, void 0, function () {
|
|
1217
|
+
var diagnostic, nodeTypeName, used_1, msg, diagnostic;
|
|
1218
|
+
return __generator(this, function (_a) {
|
|
1219
|
+
// SqlQueryComponent内部返回值类型,如果是嵌套的就需要报错
|
|
1220
|
+
if ((node instanceof concepts_1.OqlQueryComponent || node instanceof concepts_1.SqlQueryComponent) && node.getTypeBanError()) {
|
|
1221
|
+
diagnostic = {
|
|
1222
|
+
node: node,
|
|
1223
|
+
severity: 'error',
|
|
1224
|
+
message: 'SQL查询:返回类型内部,不支持复杂类型。'
|
|
1225
|
+
};
|
|
1226
|
+
node.tsErrorDetail = diagnostic;
|
|
1227
|
+
diagnostics.push(diagnostic);
|
|
1228
|
+
}
|
|
1229
|
+
if (node instanceof concepts_1.Return || node instanceof concepts_1.Variable) {
|
|
1230
|
+
if (!node.typeAnnotation && !node.__TypeAnnotation) {
|
|
1231
|
+
nodeTypeName = node.concept === 'Return' ? '输出参数' : '局部变量';
|
|
1232
|
+
used_1 = false;
|
|
1233
|
+
fileNode === null || fileNode === void 0 ? void 0 : fileNode.sourceMap.forEach(function (valueIn, nodeIn) {
|
|
1234
|
+
var _a;
|
|
1235
|
+
if (!used_1 && nodeIn
|
|
1236
|
+
&& (nodeIn instanceof concepts_1.BatchAssignment || (nodeIn instanceof concepts_1.Assignment && ((_a = nodeIn.left) === null || _a === void 0 ? void 0 : _a.name)))
|
|
1237
|
+
&& nodeIn.toJS().includes(node.name + " = ")) {
|
|
1238
|
+
used_1 = true;
|
|
1239
|
+
if (!nodeIn.tsErrorDetail) {
|
|
1240
|
+
var diagnostic_4 = {
|
|
1241
|
+
node: nodeIn,
|
|
1242
|
+
severity: 'error',
|
|
1243
|
+
message: nodeIn.label + "\u5DE6\u8FB9 " + node.name + " \u672A\u8BBE\u7F6E\u7C7B\u578B\uFF0C\u53F3\u8FB9\u5FC5\u987B\u4E3A\u6709\u8FD4\u56DE\u503C\u7684\u5185\u5BB9\u3002"
|
|
1244
|
+
};
|
|
1245
|
+
nodeIn.tsErrorDetail = diagnostic_4;
|
|
1246
|
+
diagnostics.push(diagnostic_4);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
});
|
|
1250
|
+
msg = used_1 ? '必须赋值有返回值的内容。' : '未设置类型或未赋值。直接赋值系统可以自动推断类型。';
|
|
1251
|
+
diagnostic = {
|
|
1252
|
+
node: node,
|
|
1253
|
+
severity: 'error',
|
|
1254
|
+
message: nodeTypeName + " " + node.name + " " + msg
|
|
1255
|
+
};
|
|
1256
|
+
node.tsErrorDetail = diagnostic;
|
|
1257
|
+
diagnostics.push(diagnostic);
|
|
1258
|
+
}
|
|
1259
|
+
else {
|
|
1260
|
+
node.tsErrorDetail = undefined;
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
this.checkNodeError(node, diagnostics);
|
|
1264
|
+
return [2 /*return*/];
|
|
1265
|
+
});
|
|
1266
|
+
}); });
|
|
1267
|
+
}
|
|
1268
|
+
return diagnostics;
|
|
1269
|
+
};
|
|
1270
|
+
NaslServer.prototype.checkNodeError = function (node, diagnostics) {
|
|
1271
|
+
var _a, _b, _c, _d, _e;
|
|
1272
|
+
if (!node)
|
|
1273
|
+
return;
|
|
1274
|
+
// 如果节点是match的看看节点里是不是有重复的
|
|
1275
|
+
if (node instanceof concepts_1.Match) {
|
|
1276
|
+
var typeMap_1 = {};
|
|
1277
|
+
if ((_a = node.expression) === null || _a === void 0 ? void 0 : _a.__TypeAnnotation) {
|
|
1278
|
+
var _f = node.expression.__TypeAnnotation, typeName = _f.typeName, typeNamespace = _f.typeNamespace;
|
|
1279
|
+
if (typeName === 'Union' || typeName === 'Boolean' || (typeNamespace === null || typeNamespace === void 0 ? void 0 : typeNamespace.endsWith('enums'))) {
|
|
1280
|
+
node.cases.forEach(function (item) {
|
|
1281
|
+
if (Array.isArray(item.patterns)) {
|
|
1282
|
+
item.patterns.forEach(function (pattern) {
|
|
1283
|
+
var _a, _b;
|
|
1284
|
+
if (pattern instanceof concepts_1.TypeAnnotation) {
|
|
1285
|
+
if (typeMap_1[pattern.sortedTypeKey]) {
|
|
1286
|
+
typeMap_1[pattern.sortedTypeKey].push(pattern);
|
|
1287
|
+
}
|
|
1288
|
+
else {
|
|
1289
|
+
typeMap_1[pattern.sortedTypeKey] = [pattern];
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
else if (pattern instanceof concepts_1.MemberExpression) {
|
|
1293
|
+
if (pattern.completeName && ((_b = (_a = pattern.object) === null || _a === void 0 ? void 0 : _a.namespace) === null || _b === void 0 ? void 0 : _b.endsWith('enums'))) {
|
|
1294
|
+
var onlyKey = pattern.completeName;
|
|
1295
|
+
if (typeMap_1[onlyKey]) {
|
|
1296
|
+
typeMap_1[onlyKey].push(pattern);
|
|
1297
|
+
}
|
|
1298
|
+
else {
|
|
1299
|
+
typeMap_1[onlyKey] = [pattern];
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
else if (pattern instanceof concepts_1.BooleanLiteral) {
|
|
1304
|
+
var onlyKey = pattern.concept + pattern.value;
|
|
1305
|
+
if (typeMap_1[onlyKey]) {
|
|
1306
|
+
typeMap_1[onlyKey].push(pattern);
|
|
1307
|
+
}
|
|
1308
|
+
else {
|
|
1309
|
+
typeMap_1[onlyKey] = [pattern];
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
Object.keys(typeMap_1).forEach(function (item) {
|
|
1318
|
+
if (typeMap_1[item].length > 1) {
|
|
1319
|
+
typeMap_1[item].forEach(function (nodeItem) {
|
|
1320
|
+
var diagnostic = {
|
|
1321
|
+
node: nodeItem,
|
|
1322
|
+
severity: 'error',
|
|
1323
|
+
message: '匹配:重复添加类型',
|
|
1324
|
+
titleTip: '重复添加此项'
|
|
1325
|
+
};
|
|
1326
|
+
nodeItem.tsErrorDetail = diagnostic;
|
|
1327
|
+
diagnostics.push(diagnostic);
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
// 如果节点是match的patterns 里的
|
|
1333
|
+
if ((node === null || node === void 0 ? void 0 : node.parentKey) === 'patterns' && node.parentNode instanceof concepts_1.MatchCase) {
|
|
1334
|
+
var matchNode = node.getAncestor('Match');
|
|
1335
|
+
var matchExpressionType = (_c = (_b = matchNode) === null || _b === void 0 ? void 0 : _b.expression) === null || _c === void 0 ? void 0 : _c.__TypeAnnotation;
|
|
1336
|
+
// 判断union类型是不是重复
|
|
1337
|
+
// 先使用ts原始的报错,这个先注释掉
|
|
1338
|
+
if (node instanceof concepts_1.TypeAnnotation && (matchExpressionType === null || matchExpressionType === void 0 ? void 0 : matchExpressionType.typeKind) === 'union') {
|
|
1339
|
+
var haveType = matchExpressionType === null || matchExpressionType === void 0 ? void 0 : matchExpressionType.typeArguments.find(function (item) { return item.sortedTypeKey === node.sortedTypeKey; });
|
|
1340
|
+
if (!haveType) {
|
|
1341
|
+
var diagnostic = {
|
|
1342
|
+
node: node,
|
|
1343
|
+
severity: 'error',
|
|
1344
|
+
message: '匹配:选择类型不存在',
|
|
1345
|
+
titleTip: '该类型已被删除'
|
|
1346
|
+
};
|
|
1347
|
+
node.tsErrorDetail = diagnostic;
|
|
1348
|
+
diagnostics.push(diagnostic);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
if (node.tsErrorDetail) {
|
|
1352
|
+
if ((_d = matchExpressionType === null || matchExpressionType === void 0 ? void 0 : matchExpressionType.typeNamespace) === null || _d === void 0 ? void 0 : _d.includes('enums')) {
|
|
1353
|
+
node.tsErrorDetail.titleTip = '该枚举值已被删除';
|
|
1354
|
+
}
|
|
1355
|
+
else if (!node.tsErrorDetail.titleTip) {
|
|
1356
|
+
node.tsErrorDetail.titleTip = '该值已被删除';
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
// 如果forEach 中的each的内容是union类型就要提示报错
|
|
1361
|
+
if ((node === null || node === void 0 ? void 0 : node.parentKey) === 'each' && ((_e = node === null || node === void 0 ? void 0 : node.__TypeAnnotation) === null || _e === void 0 ? void 0 : _e.typeKind) === 'union') {
|
|
1362
|
+
var diagnostic = {
|
|
1363
|
+
node: node,
|
|
1364
|
+
severity: 'error',
|
|
1365
|
+
message: 'ForEach:参数类型不一致!传入类型:联合类型。接受类型:List类型。'
|
|
1366
|
+
};
|
|
1367
|
+
node.tsErrorDetail = diagnostic;
|
|
1368
|
+
diagnostics.push(diagnostic);
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1371
|
+
/* 接口导入查找 */
|
|
1372
|
+
NaslServer.prototype.existStructureFix = function (semanticDiagnostics, node, that) {
|
|
1373
|
+
var _this = this;
|
|
1374
|
+
var module;
|
|
1375
|
+
semanticDiagnostics.map(function (diag) {
|
|
1376
|
+
var _a, _b, _c, _d;
|
|
1377
|
+
var minRange = _this._findMinRange(diag, node);
|
|
1378
|
+
if ((_a = diag.text) === null || _a === void 0 ? void 0 : _a.includes('has no exported member named')) {
|
|
1379
|
+
if (minRange.node instanceof concepts_1.Logic) {
|
|
1380
|
+
return null;
|
|
1381
|
+
}
|
|
1382
|
+
var typeAnnotation = minRange.node instanceof concepts_1.TypeAnnotation ? minRange.node.upperNode.typeAnnotation : minRange.node.typeAnnotation;
|
|
1383
|
+
var regNamespace = /<(\S*)>/;
|
|
1384
|
+
var typeKey = (typeAnnotation.typeKey.match(regNamespace) && typeAnnotation.typeKey.match(regNamespace)[1]) || typeAnnotation.typeKey;
|
|
1385
|
+
var typeKeyArr = typeKey.split('.');
|
|
1386
|
+
if (typeKeyArr[0] === 'apis') {
|
|
1387
|
+
var structureName_1 = typeKeyArr[3];
|
|
1388
|
+
var moduleName_1 = typeKeyArr[1];
|
|
1389
|
+
var app = typeAnnotation.upperNode.app;
|
|
1390
|
+
if (!app) {
|
|
1391
|
+
return null;
|
|
1392
|
+
}
|
|
1393
|
+
module = (_b = app.interfaceDependencies) === null || _b === void 0 ? void 0 : _b.find(function (item) { return item.name === moduleName_1; });
|
|
1394
|
+
var existStructure = (_c = module === null || module === void 0 ? void 0 : module.structures) === null || _c === void 0 ? void 0 : _c.find(function (item) { return item.name.toUpperCase() === structureName_1.toUpperCase(); });
|
|
1395
|
+
if (!existStructure) {
|
|
1396
|
+
var realName_1 = structureName_1.replace(/\d*$/, function (m) { return String(''); });
|
|
1397
|
+
existStructure = (_d = module === null || module === void 0 ? void 0 : module.structures) === null || _d === void 0 ? void 0 : _d.find(function (item) { return item.name.toUpperCase() === realName_1.toUpperCase(); });
|
|
1398
|
+
}
|
|
1399
|
+
if (existStructure) {
|
|
1400
|
+
var editTypeAnnotation = JSON.parse(JSON.stringify(typeAnnotation).replace(new RegExp(structureName_1, 'g'), existStructure.name));
|
|
1401
|
+
actionArr.push({ target: typeAnnotation.parentNode, typeannotation: editTypeAnnotation });
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
return null;
|
|
1405
|
+
}
|
|
1406
|
+
else {
|
|
1407
|
+
return diag;
|
|
1408
|
+
}
|
|
1409
|
+
});
|
|
1410
|
+
if (actionArr.length) {
|
|
1411
|
+
if (timer)
|
|
1412
|
+
return;
|
|
1413
|
+
timer = window.setTimeout(function () {
|
|
1414
|
+
var app = actionArr[0].target.app;
|
|
1415
|
+
app.emit('collect:start', {
|
|
1416
|
+
actionMsg: '设置导入接口数据类型错误'
|
|
1417
|
+
});
|
|
1418
|
+
module.isAdd && module.setIsAdd(false);
|
|
1419
|
+
actionArr.forEach(function (item) {
|
|
1420
|
+
item.target.setDataType(concepts_1.TypeAnnotation.from(item.typeannotation));
|
|
1421
|
+
});
|
|
1422
|
+
app.emit('collect:end');
|
|
1423
|
+
actionArr = [];
|
|
1424
|
+
isChangeInterface = false;
|
|
1425
|
+
clearTimeout(timer);
|
|
1426
|
+
timer = null;
|
|
1427
|
+
}, 2000);
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
/**
|
|
1431
|
+
* 单个问题的诊断处理
|
|
1432
|
+
* @param diagnostic 诊断问题
|
|
1433
|
+
* @param fileNode 页面节点
|
|
1434
|
+
* @returns 处理后的结果
|
|
1435
|
+
*/
|
|
1436
|
+
NaslServer.prototype._resolveDiagnostic = function (diagnostic, fileNode, record) {
|
|
1437
|
+
// 拓展模块中的翻译先过滤掉,因为有错用户也不能修改
|
|
1438
|
+
if (fileNode.module)
|
|
1439
|
+
return;
|
|
1440
|
+
var minRange = this._findMinRange(diagnostic, fileNode);
|
|
1441
|
+
var tsErrorDetail = {
|
|
1442
|
+
severity: diagnostic.category === 'error' ? 'error' : 'warning',
|
|
1443
|
+
message: translator_2.translateDiagnosticMessage(diagnostic.text),
|
|
1444
|
+
// 保留原来的内容方便查询一些问题
|
|
1445
|
+
originalDiagnostic: diagnostic
|
|
1446
|
+
};
|
|
1447
|
+
var result;
|
|
1448
|
+
if (minRange) {
|
|
1449
|
+
// 节点的error要置为true
|
|
1450
|
+
result = translator_2.naslNodeTranslateMessage(minRange, tsErrorDetail);
|
|
1451
|
+
}
|
|
1452
|
+
else {
|
|
1453
|
+
// 没找到节点, 先把问题暴露出来
|
|
1454
|
+
result = tsErrorDetail;
|
|
1455
|
+
}
|
|
1456
|
+
if (result)
|
|
1457
|
+
result.id = record.filePath + (result ? JSON.stringify({ start: result.originalDiagnostic.start, end: result.originalDiagnostic.end }) : '');
|
|
1458
|
+
return result;
|
|
1459
|
+
};
|
|
1460
|
+
/**
|
|
1461
|
+
* 通过节点诊断反过来查找节点
|
|
1462
|
+
* @param diagnostic 诊断信息
|
|
1463
|
+
* @param fileNode 文件级别节点
|
|
1464
|
+
* @returns 找到的节点
|
|
1465
|
+
*/
|
|
1466
|
+
NaslServer.prototype._findMinRange = function (diagnostic, fileNode) {
|
|
1467
|
+
var minRange;
|
|
1468
|
+
var sourceMap = fileNode.sourceMap;
|
|
1469
|
+
for (var _i = 0, _a = sourceMap.entries(); _i < _a.length; _i++) {
|
|
1470
|
+
var _b = _a[_i], node = _b[0], item = _b[1];
|
|
1471
|
+
/**
|
|
1472
|
+
* 当前内容的开始行 <= 诊断开始的行 &&
|
|
1473
|
+
* 当前内容的结束行 >= 诊断结束的行
|
|
1474
|
+
*/
|
|
1475
|
+
if (translator_1.lsp2tspNumber(item.range.start.line) <= diagnostic.start.line && translator_1.lsp2tspNumber(item.range.end.line) >= diagnostic.end.line) {
|
|
1476
|
+
// 如果找到某一行
|
|
1477
|
+
if (translator_1.lsp2tspNumber(item.range.start.line) === diagnostic.start.line && translator_1.lsp2tspNumber(item.range.end.line) === diagnostic.end.line) {
|
|
1478
|
+
// 在行的范围但是又不在列的范围,不用给默认值,给了反而不对,
|
|
1479
|
+
// 需要在列的范围内
|
|
1480
|
+
if (translator_1.lsp2tspNumber(item.range.start.character) <= diagnostic.start.offset && translator_1.lsp2tspNumber(item.range.end.character) >= diagnostic.end.offset) {
|
|
1481
|
+
// 比列更靠近 ,满足条件且长度更短
|
|
1482
|
+
// 如果先走到下面有一个默认值了就像在if for里面有个表达式
|
|
1483
|
+
// if for的内容也是包括当前的所以会重新赋值
|
|
1484
|
+
if (!minRange || item.code.length < minRange.item.code.length) {
|
|
1485
|
+
minRange = { item: item, node: node };
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
else {
|
|
1490
|
+
// 没有节点 或者 行差比较小比已有的小就可以
|
|
1491
|
+
// 一般出现在一大块上,多半是if for 等等没有参数
|
|
1492
|
+
if (!minRange || item.range.end.line - item.range.start.line < minRange.item.range.end.line - minRange.item.range.start.line) {
|
|
1493
|
+
minRange = { node: node, item: item };
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
if (!minRange) {
|
|
1499
|
+
if (fileNode instanceof concepts_1.View) {
|
|
1500
|
+
return { node: fileNode, item: sourceMap.get(fileNode) };
|
|
1501
|
+
}
|
|
1502
|
+
console.log(minRange, '需要特殊看下,为什么没找到内容-------------');
|
|
1503
|
+
}
|
|
1504
|
+
return minRange;
|
|
1505
|
+
};
|
|
1506
|
+
/**
|
|
1507
|
+
* 查看当前节点是不是有引用
|
|
1508
|
+
* @param node 节点
|
|
1509
|
+
* @returns 查找到的数组
|
|
1510
|
+
*/
|
|
1511
|
+
NaslServer.prototype._isHaveRef = function (node) {
|
|
1512
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1513
|
+
var _a, currentSource, fileNode, refsList, newRefs, lists, moduleName_2, item, fileNode_1, newRefs, logicNode, currentSource_1, parentRefs, viewNode, currentSource_2, code, viewIndex, viewRefs, filterViewRefs, code, prefix, prefixIndex, methodsNameIndex, methods, methodRefs_1;
|
|
1514
|
+
var _this = this;
|
|
1515
|
+
return __generator(this, function (_b) {
|
|
1516
|
+
switch (_b.label) {
|
|
1517
|
+
case 0:
|
|
1518
|
+
_a = this.getCurrentSource(node), currentSource = _a.currentSource, fileNode = _a.fileNode;
|
|
1519
|
+
refsList = [];
|
|
1520
|
+
if (!currentSource) return [3 /*break*/, 2];
|
|
1521
|
+
return [4 /*yield*/, this.references({
|
|
1522
|
+
file: fileNode.getEmbeddedFilePath(),
|
|
1523
|
+
line: translator_1.lsp2tspNumber(currentSource.range.start.line),
|
|
1524
|
+
offset: translator_1.lsp2tspNumber(currentSource.range.start.character)
|
|
1525
|
+
})];
|
|
1526
|
+
case 1:
|
|
1527
|
+
newRefs = _b.sent();
|
|
1528
|
+
refsList = __spreadArrays(newRefs.refs);
|
|
1529
|
+
return [3 /*break*/, 4];
|
|
1530
|
+
case 2:
|
|
1531
|
+
if (!(node instanceof concepts_1.Module)) return [3 /*break*/, 4];
|
|
1532
|
+
lists = node.logics || node.structures || node.enums;
|
|
1533
|
+
moduleName_2 = fileNode.getEmbeddedFilePath();
|
|
1534
|
+
if (!lists.length) return [3 /*break*/, 4];
|
|
1535
|
+
item = lists[0];
|
|
1536
|
+
fileNode_1 = this.getCurrentSource(item).fileNode;
|
|
1537
|
+
if (!fileNode_1) return [3 /*break*/, 4];
|
|
1538
|
+
return [4 /*yield*/, this.references({
|
|
1539
|
+
file: fileNode_1.getEmbeddedFilePath(),
|
|
1540
|
+
line: 1,
|
|
1541
|
+
offset: 22
|
|
1542
|
+
})];
|
|
1543
|
+
case 3:
|
|
1544
|
+
newRefs = _b.sent();
|
|
1545
|
+
refsList = newRefs.refs.filter(function (item) { return !item.file.startsWith(moduleName_2); });
|
|
1546
|
+
// 多塞一个 ,删除的时候就有值了, 上面过滤了之后可能是空的
|
|
1547
|
+
refsList.unshift(newRefs.refs[0]);
|
|
1548
|
+
_b.label = 4;
|
|
1549
|
+
case 4:
|
|
1550
|
+
// 如果是DataSource就需要在单独,查一边来修改名字
|
|
1551
|
+
if (node instanceof concepts_1.DataSource) {
|
|
1552
|
+
// 过滤一把不需要改的信息
|
|
1553
|
+
refsList = refsList.filter(function (item) {
|
|
1554
|
+
var dataSourceFile = fileNode.getEmbeddedFilePath();
|
|
1555
|
+
var entityFilePrefix = dataSourceFile.replace('.ts', '');
|
|
1556
|
+
/**
|
|
1557
|
+
* 特殊处理,因为关联属性或者关联实体等等都是在实体里,在实体中因为自己不可以是自己的类型
|
|
1558
|
+
* 所以全部过滤掉了,
|
|
1559
|
+
* 但是在datasource里面在实体里会有大量的引用,不需要全部修改.只需要处理除了11个函数之外的引用
|
|
1560
|
+
* 所以底部内容是11个函数,所以这里就 用entity的行数 减去11个函数的行数,然后其余的在进行处理
|
|
1561
|
+
* 进行过滤
|
|
1562
|
+
*/
|
|
1563
|
+
// 不要数据源下面的实体里的引用 ,保留原始的节点内容
|
|
1564
|
+
var flag = false;
|
|
1565
|
+
if (item.file.includes(entityFilePrefix)) {
|
|
1566
|
+
var entity = _this.file2NodeMap.get(item.file);
|
|
1567
|
+
var currentSource_3 = _this.getCurrentSource(entity).currentSource;
|
|
1568
|
+
// 42 11个函数的总行数
|
|
1569
|
+
if (item.end.line < currentSource_3.range.end.line - 42 && item.start.line > 1) {
|
|
1570
|
+
flag = true;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
// 属于实体而且需要修改和查到 || 不是实体前缀的 || 他本身
|
|
1574
|
+
return flag || !item.file.includes(entityFilePrefix) || dataSourceFile === item.file;
|
|
1575
|
+
});
|
|
1576
|
+
}
|
|
1577
|
+
// 如果是entity就需要在单独,查一边来修改名字
|
|
1578
|
+
if (node instanceof concepts_1.Entity) {
|
|
1579
|
+
// 过滤一把不需要改的信息
|
|
1580
|
+
refsList = refsList.filter(function (item) { return fileNode.getEmbeddedFilePath() !== item.file || item.isDefinition === true; });
|
|
1581
|
+
// 不再当前文件里
|
|
1582
|
+
// 或者在当前列表但是位置小于entity的结束位置
|
|
1583
|
+
}
|
|
1584
|
+
if (node instanceof concepts_1.Return) {
|
|
1585
|
+
// 过滤一下最后出去的值
|
|
1586
|
+
refsList = refsList.filter(function (item) { return !item.lineText.includes('return '); });
|
|
1587
|
+
}
|
|
1588
|
+
if (!(node instanceof concepts_1.Param && node.parentNode instanceof concepts_1.Logic && node.parentKey !== 'virtualParams')) return [3 /*break*/, 6];
|
|
1589
|
+
logicNode = node.parentNode;
|
|
1590
|
+
currentSource_1 = this.getCurrentSource(logicNode).currentSource;
|
|
1591
|
+
return [4 /*yield*/, this.references({
|
|
1592
|
+
file: fileNode.getEmbeddedFilePath(),
|
|
1593
|
+
line: translator_1.lsp2tspNumber(currentSource_1.range.start.line),
|
|
1594
|
+
offset: translator_1.lsp2tspNumber(currentSource_1.range.start.character)
|
|
1595
|
+
})];
|
|
1596
|
+
case 5:
|
|
1597
|
+
parentRefs = _b.sent();
|
|
1598
|
+
refsList = __spreadArrays(refsList, parentRefs.refs);
|
|
1599
|
+
_b.label = 6;
|
|
1600
|
+
case 6:
|
|
1601
|
+
if (!(node instanceof concepts_1.Param && (node.parentNode instanceof concepts_1.View || node.parentNode instanceof concepts_1.Process))) return [3 /*break*/, 8];
|
|
1602
|
+
viewNode = node.parentNode;
|
|
1603
|
+
currentSource_2 = this.getCurrentSource(viewNode).currentSource;
|
|
1604
|
+
code = currentSource_2.code;
|
|
1605
|
+
viewIndex = code.indexOf(' {');
|
|
1606
|
+
return [4 /*yield*/, this.references({
|
|
1607
|
+
file: fileNode.getEmbeddedFilePath(),
|
|
1608
|
+
line: translator_1.lsp2tspNumber(currentSource_2.range.start.line),
|
|
1609
|
+
offset: translator_1.lsp2tspNumber(currentSource_2.range.start.character + viewIndex)
|
|
1610
|
+
})];
|
|
1611
|
+
case 7:
|
|
1612
|
+
viewRefs = _b.sent();
|
|
1613
|
+
filterViewRefs = [];
|
|
1614
|
+
if (node.parentNode instanceof concepts_1.View) {
|
|
1615
|
+
filterViewRefs = viewRefs.refs.filter(function (item) { return item.lineText.includes('.$destination('); });
|
|
1616
|
+
}
|
|
1617
|
+
else {
|
|
1618
|
+
// 如果是参数修改, 就需要把Process的引用查找出来
|
|
1619
|
+
filterViewRefs = viewRefs.refs.filter(function (item) { return item.lineText.includes('.launch('); });
|
|
1620
|
+
}
|
|
1621
|
+
refsList = __spreadArrays(refsList, filterViewRefs);
|
|
1622
|
+
_b.label = 8;
|
|
1623
|
+
case 8:
|
|
1624
|
+
if (!(node instanceof concepts_1.ViewElement)) return [3 /*break*/, 10];
|
|
1625
|
+
if (!currentSource) return [3 /*break*/, 10];
|
|
1626
|
+
code = currentSource.code;
|
|
1627
|
+
prefix = '__elements.';
|
|
1628
|
+
prefixIndex = code.indexOf(prefix) !== -1 ? code.indexOf(prefix) : 0;
|
|
1629
|
+
methodsNameIndex = prefixIndex + prefix.length;
|
|
1630
|
+
return [4 /*yield*/, this.references({
|
|
1631
|
+
file: fileNode.getEmbeddedFilePath(),
|
|
1632
|
+
line: translator_1.lsp2tspNumber(currentSource.range.start.line),
|
|
1633
|
+
offset: translator_1.lsp2tspNumber(currentSource.range.start.character + methodsNameIndex)
|
|
1634
|
+
})];
|
|
1635
|
+
case 9:
|
|
1636
|
+
methods = _b.sent();
|
|
1637
|
+
methodRefs_1 = [];
|
|
1638
|
+
methods.refs.forEach(function (item) {
|
|
1639
|
+
// 定义里的格式,在删除的时候留下来占位
|
|
1640
|
+
// 重命名的时候会过滤
|
|
1641
|
+
// 这里只过滤 __elements.button = new nasl.ui.Button<any>这种格式
|
|
1642
|
+
// 处理声明组件名可能重复的问题, 查找引用不提示
|
|
1643
|
+
var find = methodRefs_1.find(function (findItem) { return item.lineText === findItem.lineText && item.lineText.includes(': nasl.ui.'); });
|
|
1644
|
+
if (!find) {
|
|
1645
|
+
methodRefs_1.push(item);
|
|
1646
|
+
}
|
|
1647
|
+
});
|
|
1648
|
+
refsList = __spreadArrays(methodRefs_1);
|
|
1649
|
+
_b.label = 10;
|
|
1650
|
+
case 10:
|
|
1651
|
+
// console.log(refsList, 'refsList');
|
|
1652
|
+
return [2 /*return*/, refsList];
|
|
1653
|
+
}
|
|
1654
|
+
});
|
|
1655
|
+
});
|
|
1656
|
+
};
|
|
1657
|
+
/**
|
|
1658
|
+
* 查找引用,并且做一些 修改前的准备工作,
|
|
1659
|
+
* 有引用有的话,就返回集合
|
|
1660
|
+
* @param node 当前重命名的节点
|
|
1661
|
+
* @param newValue 传递过来的新值,给MemberExpression用的比较特殊
|
|
1662
|
+
* 而且,这个新值不一定会用到,MemberExpression在批量更新的时候,可以取到新的value, 这里需要位置信息防止 a.a.a.a 中的一个a发生修改
|
|
1663
|
+
* @returns 找到的引用
|
|
1664
|
+
*/
|
|
1665
|
+
NaslServer.prototype._renamePrepare = function (node, refsList, newValue) {
|
|
1666
|
+
var _this = this;
|
|
1667
|
+
var oldName = node === null || node === void 0 ? void 0 : node.name;
|
|
1668
|
+
var result = refsList
|
|
1669
|
+
.map(function (record) {
|
|
1670
|
+
var fileNode = _this.file2NodeMap.get(record.file);
|
|
1671
|
+
if (!fileNode)
|
|
1672
|
+
return null;
|
|
1673
|
+
var minRange = _this._findMinRange(record, fileNode);
|
|
1674
|
+
if (minRange) {
|
|
1675
|
+
// 节点上ts临时变量标识,如果有这个就不rename
|
|
1676
|
+
if (minRange.node.noTsReName) {
|
|
1677
|
+
return null;
|
|
1678
|
+
}
|
|
1679
|
+
// 如果节点是TypeAnnotation类型,
|
|
1680
|
+
// 很复杂,可能是多级嵌套结构
|
|
1681
|
+
// 不一定只修改typeName
|
|
1682
|
+
if (minRange.node instanceof concepts_1.TypeAnnotation) {
|
|
1683
|
+
// console.log(record);
|
|
1684
|
+
// 如果是fake的逻辑,内部的重命名都不需要修改
|
|
1685
|
+
// if ((minRange.node?.parentNode as any).logic && (minRange.node?.parentNode as any).logic?.fake) {
|
|
1686
|
+
// return null;
|
|
1687
|
+
// }
|
|
1688
|
+
minRange.setTypeMethods = 'setTypeName';
|
|
1689
|
+
}
|
|
1690
|
+
// 如果节点是logic修改引发calllogic修改
|
|
1691
|
+
if (minRange.node instanceof concepts_1.CallLogic && node instanceof concepts_1.Logic) {
|
|
1692
|
+
minRange.setTypeMethods = 'setCalleeName';
|
|
1693
|
+
}
|
|
1694
|
+
if (minRange.node instanceof concepts_1.CallLogic && node instanceof concepts_1.ViewElement) {
|
|
1695
|
+
minRange.setTypeMethods = 'setCalleeNamespace';
|
|
1696
|
+
minRange.newValue = 'elements.' + newValue + '.logics';
|
|
1697
|
+
}
|
|
1698
|
+
// 如果节点是实体修改引发calllogic修改
|
|
1699
|
+
if (minRange.node instanceof concepts_1.CallLogic && (node instanceof concepts_1.Entity || node instanceof concepts_1.View || node instanceof concepts_1.Process || node instanceof concepts_1.ProcessElement)) {
|
|
1700
|
+
// 匹配到的内容,当前这一行的内容;
|
|
1701
|
+
// 因为要用下面的点位信息
|
|
1702
|
+
/**
|
|
1703
|
+
* 如果namespce是 'app.views.Student.views.404.views.505.views.update'
|
|
1704
|
+
* 在ts中会是'app.views.Student.views.$404.views.$505.views.update'
|
|
1705
|
+
* 但是505 要改名为 666 ,要存的是666
|
|
1706
|
+
* 'app.views.Student.views.404.views.666.views.update'
|
|
1707
|
+
* 1.取到转后的
|
|
1708
|
+
* 2.在匹配到的内容中取转后的namespace的位置
|
|
1709
|
+
* 3.然后把namespace中的 $替换成 ''
|
|
1710
|
+
*
|
|
1711
|
+
*/
|
|
1712
|
+
var tsCalleeNamespace = minRange.node.tsCalleeNamespace;
|
|
1713
|
+
// 先看下标位置
|
|
1714
|
+
var lineText = record.lineText;
|
|
1715
|
+
var index = lineText.indexOf(tsCalleeNamespace);
|
|
1716
|
+
// 在把开始结束位置的-开始位置,来知道是哪里要替换
|
|
1717
|
+
var start = record.start.offset - index - 1;
|
|
1718
|
+
var end = record.end.offset - index - 1;
|
|
1719
|
+
// 新的完整的value
|
|
1720
|
+
var newTsNameSpace = tsCalleeNamespace.substring(0, start) + newValue + tsCalleeNamespace.substring(end, tsCalleeNamespace.length);
|
|
1721
|
+
newTsNameSpace = newTsNameSpace.replace(/.\$/g, '.');
|
|
1722
|
+
minRange.setTypeMethods = 'setCalleeNamespace';
|
|
1723
|
+
minRange.newValue = newTsNameSpace;
|
|
1724
|
+
}
|
|
1725
|
+
// 如果参数修改影响了 callLogic
|
|
1726
|
+
if (minRange.node instanceof concepts_1.CallLogic && node instanceof concepts_1.Param) {
|
|
1727
|
+
return null;
|
|
1728
|
+
// 逻辑第几个位置发生修改,对应的calllogic对应位置的内容要进行修改
|
|
1729
|
+
// minRange.setTypeMethods = 'setArgumentName';
|
|
1730
|
+
// const nodeArguments = minRange.node.arguments;
|
|
1731
|
+
// minRange.newValue = [...nodeArguments];
|
|
1732
|
+
// const LogicNode = node.parentNode;
|
|
1733
|
+
// const paramIndex = (LogicNode as Logic).params.findIndex((param) => param === node);
|
|
1734
|
+
// console.log(node, nodeArguments);
|
|
1735
|
+
// if (paramIndex !== -1) {
|
|
1736
|
+
// minRange.setTypeMethods = 'setArgumentName';
|
|
1737
|
+
// minRange.newValue = {
|
|
1738
|
+
// argument: nodeArguments[paramIndex],
|
|
1739
|
+
// newKeyword: newValue,
|
|
1740
|
+
// };
|
|
1741
|
+
// } else {
|
|
1742
|
+
// return null;
|
|
1743
|
+
// }
|
|
1744
|
+
}
|
|
1745
|
+
// 如果节点是Identifier表达式
|
|
1746
|
+
if (minRange.node instanceof concepts_1.Identifier) {
|
|
1747
|
+
// 匹配到的内容,当前这一行的内容;
|
|
1748
|
+
// 因为要用下面的点位信息
|
|
1749
|
+
var name = minRange.node.name;
|
|
1750
|
+
// 如果name不改,那就是要改命名空间
|
|
1751
|
+
if (newValue === name) {
|
|
1752
|
+
var namespace = minRange.node.namespace;
|
|
1753
|
+
// 先看下标位置
|
|
1754
|
+
var lineText = record.lineText;
|
|
1755
|
+
var index = lineText.indexOf(namespace);
|
|
1756
|
+
// 在把开始结束位置的-开始位置,来知道是哪里要替换
|
|
1757
|
+
var start = record.start.offset - index - 1;
|
|
1758
|
+
var end = record.end.offset - index - 1;
|
|
1759
|
+
// 新的完整的value
|
|
1760
|
+
var newTextValue = namespace.substring(0, start) + newValue + namespace.substring(end, namespace.length);
|
|
1761
|
+
minRange.setTypeMethods = 'setNamespace';
|
|
1762
|
+
minRange.newValue = newTextValue;
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
// 如果是枚举修改,枚举的值刚好在Identifier 中选了 就修改值
|
|
1766
|
+
if (minRange.node instanceof concepts_1.Identifier && node instanceof concepts_1.Enum) {
|
|
1767
|
+
minRange.newValue = newValue;
|
|
1768
|
+
minRange.setTypeMethods = 'setName';
|
|
1769
|
+
}
|
|
1770
|
+
// 如果修改逻辑,改到了Identifier表达式,只能说明是在属性里有使用了
|
|
1771
|
+
if (minRange.node instanceof concepts_1.Identifier && node instanceof concepts_1.Logic) {
|
|
1772
|
+
minRange.newValue = newValue;
|
|
1773
|
+
minRange.setTypeMethods = 'setName';
|
|
1774
|
+
}
|
|
1775
|
+
// 如果节点是MemberExpression表达式
|
|
1776
|
+
if (minRange.node instanceof concepts_1.MemberExpression) {
|
|
1777
|
+
// 枚举key的特殊性,因为它不是原来的key+value形式的
|
|
1778
|
+
// 是加了中括号啥的,所以直接赋值新值
|
|
1779
|
+
if (node instanceof concepts_1.EnumItem) {
|
|
1780
|
+
var newTextValue = node.parentNode.name + '.' + newValue;
|
|
1781
|
+
minRange.newValue = newTextValue;
|
|
1782
|
+
}
|
|
1783
|
+
else {
|
|
1784
|
+
// 匹配到的内容,当前这一行的内容;
|
|
1785
|
+
// 因为要用下面的点位信息
|
|
1786
|
+
var a = record.lineText;
|
|
1787
|
+
// 之前的内容
|
|
1788
|
+
var oldValue = minRange.node.getValue();
|
|
1789
|
+
var index = a.indexOf(oldValue);
|
|
1790
|
+
var start = record.start.offset - index - 1;
|
|
1791
|
+
var end = record.end.offset - index - 1;
|
|
1792
|
+
var newTextValue = oldValue.substring(0, start) + newValue + oldValue.substring(end, oldValue.length);
|
|
1793
|
+
// MemberExpression可能改的是多层中的某一个
|
|
1794
|
+
// 倒序, 对比看是哪里发生了修改
|
|
1795
|
+
// 比较特殊就把新匹配到的值返回内部自己看要改那个地方的值
|
|
1796
|
+
minRange.newValue = newTextValue;
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
if (node instanceof concepts_1.Entity) {
|
|
1800
|
+
// 如果是修改实体,引发节点依赖实体发生改变的
|
|
1801
|
+
if (minRange.node instanceof concepts_1.EntityProperty) {
|
|
1802
|
+
minRange.setTypeMethods = 'setRelationEntity';
|
|
1803
|
+
}
|
|
1804
|
+
else if (minRange.node instanceof concepts_1.QueryFieldExpression || minRange.node instanceof concepts_1.QueryGroupByExpression) {
|
|
1805
|
+
minRange.setTypeMethods = 'setEntityAsName';
|
|
1806
|
+
}
|
|
1807
|
+
else if (minRange.node instanceof concepts_1.QueryFromExpression || minRange.node instanceof concepts_1.QueryJoinExpression) {
|
|
1808
|
+
minRange.setTypeMethods = 'setEntityName';
|
|
1809
|
+
}
|
|
1810
|
+
else if (minRange.node instanceof concepts_1.BindAttribute && minRange.node.name === 'url') {
|
|
1811
|
+
// 如果是查找到 上传地址的链接引用
|
|
1812
|
+
var newName = newValue.replace(/[A-Z]/g, function (item) { return '-' + item.toLowerCase(); });
|
|
1813
|
+
newName = newName[0] === '-' ? newName.slice(1) : newName;
|
|
1814
|
+
var newTextValue = node.parentNode.name === 'defaultDS' ? "/api/" + newName + "/import" : "/api/" + node.parentNode.name + "/" + newName + "/import";
|
|
1815
|
+
minRange.setTypeMethods = 'setUrlValue';
|
|
1816
|
+
minRange.newValue = newTextValue;
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
// 如果是修改实体属性,要同步实体属性
|
|
1820
|
+
if (minRange.node instanceof concepts_1.EntityProperty && node instanceof concepts_1.EntityProperty && record.lineText.includes('@nasl.annotation.EntityRelation')) {
|
|
1821
|
+
minRange.setTypeMethods = 'setRelationProperty';
|
|
1822
|
+
}
|
|
1823
|
+
// 如果要修改索引的
|
|
1824
|
+
if (minRange.node instanceof concepts_1.EntityIndex) {
|
|
1825
|
+
var newPropertyNameList = __spreadArrays(minRange.node.propertyNames);
|
|
1826
|
+
var findIndex = newPropertyNameList.findIndex(function (item) { return item === oldName; });
|
|
1827
|
+
if (findIndex !== -1) {
|
|
1828
|
+
// 修改数组的值
|
|
1829
|
+
newPropertyNameList.splice(findIndex, 1, newValue);
|
|
1830
|
+
minRange.setTypeMethods = 'setPropertyNameList';
|
|
1831
|
+
minRange.newValue = newPropertyNameList;
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
// 如果是跳转逻辑的修改
|
|
1835
|
+
// 跳转逻辑本身页面 都需要带 View前缀
|
|
1836
|
+
if (node instanceof concepts_1.View && minRange.node instanceof concepts_1.Destination) {
|
|
1837
|
+
/**
|
|
1838
|
+
* 如果namespce是 'app.views.Student.views.404.views.505.views.update'
|
|
1839
|
+
* 在ts中会是'app.views.Student.views.$404.views.$505.views.update'
|
|
1840
|
+
* 但是505 要改名为 666 ,要存的是666
|
|
1841
|
+
* 'app.views.Student.views.404.views.666.views.update'
|
|
1842
|
+
* 1.取到转后的
|
|
1843
|
+
* 2.在匹配到的内容中取转后的namespace的位置
|
|
1844
|
+
* 3.然后把namespace中的 $替换成 ''
|
|
1845
|
+
*
|
|
1846
|
+
*/
|
|
1847
|
+
var tsCalleeNamespace = minRange.node.tsCalleeNamespace;
|
|
1848
|
+
var tsName = minRange.node.tsName;
|
|
1849
|
+
var oldValue = tsCalleeNamespace + '.' + tsName;
|
|
1850
|
+
// 先看下标位置
|
|
1851
|
+
var lineText = record.lineText;
|
|
1852
|
+
var index = lineText.indexOf(oldValue);
|
|
1853
|
+
// 在把开始结束位置的-开始位置,来知道是哪里要替换
|
|
1854
|
+
var start = record.start.offset - index - 1;
|
|
1855
|
+
var end = record.end.offset - index - 1;
|
|
1856
|
+
if (start > tsCalleeNamespace.length) {
|
|
1857
|
+
minRange.setTypeMethods = 'setViewName';
|
|
1858
|
+
minRange.newValue = newValue;
|
|
1859
|
+
}
|
|
1860
|
+
else {
|
|
1861
|
+
// 新的完整的value
|
|
1862
|
+
var newTsNameSpace = tsCalleeNamespace.substring(0, start) + newValue + tsCalleeNamespace.substring(end, tsCalleeNamespace.length);
|
|
1863
|
+
minRange.setTypeMethods = 'setViewNamespace';
|
|
1864
|
+
newTsNameSpace = newTsNameSpace.replace(/\.\$/g, '.');
|
|
1865
|
+
minRange.newValue = newTsNameSpace;
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
// 如果是事件修改
|
|
1869
|
+
// 如果是view也需要加前缀
|
|
1870
|
+
// logic 和 views名称修改 可能会触发bindEvent修改
|
|
1871
|
+
if (minRange.node instanceof concepts_1.BindEvent) {
|
|
1872
|
+
// 页面逻辑直接赋值就可以, 因为是相对路径
|
|
1873
|
+
if (node instanceof concepts_1.ViewElement) {
|
|
1874
|
+
minRange.setTypeMethods = 'setCalleeNamespace';
|
|
1875
|
+
minRange.newValue = 'elements.' + newValue + '.logics';
|
|
1876
|
+
}
|
|
1877
|
+
else {
|
|
1878
|
+
/**
|
|
1879
|
+
* 如果namespce是 'app.views.Student.views.404.views.505.views.update'
|
|
1880
|
+
* 在ts中会是'app.views.Student.views.$404.views.$505.views.update'
|
|
1881
|
+
* 但是505 要改名为 666 ,要存的是666
|
|
1882
|
+
* 'app.views.Student.views.404.views.666.views.update'
|
|
1883
|
+
* 1.取到转后的
|
|
1884
|
+
* 2.在匹配到的内容中取转后的namespace的位置
|
|
1885
|
+
* 3.然后把namespace中的 $替换成 ''
|
|
1886
|
+
*/
|
|
1887
|
+
var tsCalleeNamespace = minRange.node.tsCalleeNamespace;
|
|
1888
|
+
var oldValue = tsCalleeNamespace;
|
|
1889
|
+
// 先看下标位置
|
|
1890
|
+
var lineText = record.lineText;
|
|
1891
|
+
var index = lineText.indexOf(oldValue);
|
|
1892
|
+
// 在把开始结束位置的-开始位置,来知道是哪里要替换
|
|
1893
|
+
var start = record.start.offset - index - 1;
|
|
1894
|
+
var end = record.end.offset - index - 1;
|
|
1895
|
+
// 新的完整的value
|
|
1896
|
+
if (start > tsCalleeNamespace.length) {
|
|
1897
|
+
minRange.setTypeMethods = 'setCalleeName';
|
|
1898
|
+
minRange.newValue = newValue;
|
|
1899
|
+
}
|
|
1900
|
+
else {
|
|
1901
|
+
// 新的完整的value
|
|
1902
|
+
var newTsNameSpace = tsCalleeNamespace.substring(0, start) + newValue + tsCalleeNamespace.substring(end, tsCalleeNamespace.length);
|
|
1903
|
+
minRange.setTypeMethods = 'setCalleeNamespace';
|
|
1904
|
+
newTsNameSpace = newTsNameSpace.replace(/\.\$/g, '.');
|
|
1905
|
+
minRange.newValue = newTsNameSpace;
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
if (minRange.node instanceof concepts_1.Destination && node instanceof concepts_1.Param) {
|
|
1910
|
+
// 因为view是key value 绑定所以需要重新赋值
|
|
1911
|
+
if (node.parentNode instanceof concepts_1.View) {
|
|
1912
|
+
var nodeArguments = minRange.node.arguments;
|
|
1913
|
+
var findArgument = nodeArguments.find(function (item) { return node.name === item.keyword; });
|
|
1914
|
+
if (findArgument) {
|
|
1915
|
+
minRange.setTypeMethods = 'setArgumentsKeyWord';
|
|
1916
|
+
minRange.newValue = {
|
|
1917
|
+
findArgument: findArgument,
|
|
1918
|
+
newKeyword: newValue
|
|
1919
|
+
};
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
else {
|
|
1923
|
+
// 如果是修改param查找到Destination就不操作
|
|
1924
|
+
return null;
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
if (minRange.node instanceof concepts_1.Interface && node instanceof concepts_1.Logic) {
|
|
1928
|
+
minRange.setTypeMethods = 'setOriginLogicName';
|
|
1929
|
+
}
|
|
1930
|
+
// 如果是role改名,就需要查到变更后的数组
|
|
1931
|
+
if ((minRange.node instanceof concepts_1.View || minRange.node instanceof concepts_1.ViewElement) && node instanceof concepts_1.Role) {
|
|
1932
|
+
// oldName旧的节点存的值
|
|
1933
|
+
// newValue用户输入值
|
|
1934
|
+
// node.bindRoles 存的
|
|
1935
|
+
minRange.setTypeMethods = 'setBindRoles';
|
|
1936
|
+
var str = minRange.node.bindRoles.toString().replace(oldName, newValue);
|
|
1937
|
+
var newBindRoles = str.split(',');
|
|
1938
|
+
minRange.newValue = newBindRoles;
|
|
1939
|
+
}
|
|
1940
|
+
// 修改枚举值找到了EntityProperty就说明给了默认值
|
|
1941
|
+
if (node instanceof concepts_1.EnumItem) {
|
|
1942
|
+
if (minRange.node instanceof concepts_1.EntityProperty || minRange.node instanceof concepts_1.StructureProperty) {
|
|
1943
|
+
minRange.setTypeMethods = 'setDefaultValue';
|
|
1944
|
+
}
|
|
1945
|
+
if (minRange.node instanceof concepts_1.Param || minRange.node instanceof concepts_1.Variable || minRange.node instanceof concepts_1.Return) {
|
|
1946
|
+
minRange.setTypeMethods = 'setDefaultValue';
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
// 如果修改的是dataSource属性
|
|
1950
|
+
if (node instanceof concepts_1.DataSource) {
|
|
1951
|
+
var setTypeNamespace = function (typeNamespace, record) {
|
|
1952
|
+
// 先看下标位置
|
|
1953
|
+
var lineText = record.lineText;
|
|
1954
|
+
var index = lineText.indexOf(typeNamespace);
|
|
1955
|
+
// 在把开始结束位置的-开始位置,来知道是哪里要替换
|
|
1956
|
+
var start = record.start.offset - index - 1;
|
|
1957
|
+
var end = record.end.offset - index - 1;
|
|
1958
|
+
// 新的完整的value
|
|
1959
|
+
var newTextValue = typeNamespace.substring(0, start) + newValue + typeNamespace.substring(end, typeNamespace.length);
|
|
1960
|
+
minRange.newValue = newTextValue;
|
|
1961
|
+
return newTextValue;
|
|
1962
|
+
};
|
|
1963
|
+
if (minRange.node instanceof concepts_1.TypeAnnotation) {
|
|
1964
|
+
minRange.setTypeMethods = 'setTypeNamespace';
|
|
1965
|
+
var newValue_1 = setTypeNamespace(minRange.node.typeNamespace, record);
|
|
1966
|
+
minRange.newValue = newValue_1;
|
|
1967
|
+
}
|
|
1968
|
+
else if (minRange.node instanceof concepts_1.QueryFromExpression || minRange.node instanceof concepts_1.QueryJoinExpression) {
|
|
1969
|
+
minRange.setTypeMethods = 'setEntityNamespace';
|
|
1970
|
+
var newValue_2 = setTypeNamespace(minRange.node.entityNamespace, record);
|
|
1971
|
+
minRange.newValue = newValue_2;
|
|
1972
|
+
}
|
|
1973
|
+
else if (minRange.node instanceof concepts_1.QueryFieldExpression) {
|
|
1974
|
+
return null;
|
|
1975
|
+
}
|
|
1976
|
+
else if (minRange.node instanceof concepts_1.CallLogic) {
|
|
1977
|
+
minRange.setTypeMethods = 'setCalleeNamespace';
|
|
1978
|
+
var newValue_3 = setTypeNamespace(minRange.node.calleeNamespace, record);
|
|
1979
|
+
minRange.newValue = newValue_3;
|
|
1980
|
+
}
|
|
1981
|
+
else if (minRange.node instanceof concepts_1.EntityProperty) {
|
|
1982
|
+
minRange.setTypeMethods = 'setRelationNamespace';
|
|
1983
|
+
var newValue_4 = setTypeNamespace(minRange.node.relationNamespace, record);
|
|
1984
|
+
minRange.newValue = newValue_4;
|
|
1985
|
+
}
|
|
1986
|
+
else if (minRange.node instanceof concepts_1.SqlQueryComponent || minRange.node instanceof concepts_1.OqlQueryComponent) {
|
|
1987
|
+
minRange.setTypeMethods = 'renameDataSource';
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
if (minRange.node instanceof concepts_1.QueryFieldExpression && node instanceof concepts_1.EntityProperty) {
|
|
1991
|
+
minRange.setTypeMethods = 'setPropertyName';
|
|
1992
|
+
}
|
|
1993
|
+
if (minRange.node instanceof concepts_1.QueryGroupByExpression && node instanceof concepts_1.EntityProperty) {
|
|
1994
|
+
minRange.setTypeMethods = 'setPropertyName';
|
|
1995
|
+
}
|
|
1996
|
+
// 如果跳转链接或者页面变量同一个param和TypeAnnotation 有两个过滤掉一个
|
|
1997
|
+
if ((minRange.node instanceof concepts_1.Param || minRange.node instanceof concepts_1.Variable || minRange.node instanceof concepts_1.Return)
|
|
1998
|
+
&& (node instanceof concepts_1.Entity || node instanceof concepts_1.Enum || node instanceof concepts_1.Structure)) {
|
|
1999
|
+
return null;
|
|
2000
|
+
}
|
|
2001
|
+
if (minRange.node instanceof concepts_1.Destination && (node instanceof concepts_1.Process || node instanceof concepts_1.ProcessElement)) {
|
|
2002
|
+
return null;
|
|
2003
|
+
}
|
|
2004
|
+
if (minRange.node instanceof concepts_1.Assignee && (node instanceof concepts_1.Process || node instanceof concepts_1.ProcessElement)) {
|
|
2005
|
+
return null;
|
|
2006
|
+
}
|
|
2007
|
+
// 枚举修改枚举名,比较特殊
|
|
2008
|
+
if (minRange.node instanceof concepts_1.EnumItem && node instanceof concepts_1.Enum) {
|
|
2009
|
+
// 什么都不做,用来跳过修改
|
|
2010
|
+
return null;
|
|
2011
|
+
}
|
|
2012
|
+
// params修改 查找bindevent不需要修改
|
|
2013
|
+
if (minRange.node instanceof concepts_1.BindEvent && node instanceof concepts_1.Param) {
|
|
2014
|
+
return null;
|
|
2015
|
+
}
|
|
2016
|
+
/**
|
|
2017
|
+
* 理论上 logic setName只能自己触发,别的地方查到引用都不用重命名
|
|
2018
|
+
* 流程改名不触发Logic改名
|
|
2019
|
+
* 如果是修改param查找到logic就不操作
|
|
2020
|
+
* 除非想在内部修改别的内容所以暂时屏蔽掉
|
|
2021
|
+
*/
|
|
2022
|
+
if (minRange.node instanceof concepts_1.Logic && node !== minRange.node) {
|
|
2023
|
+
return null;
|
|
2024
|
+
}
|
|
2025
|
+
if (node instanceof concepts_1.Param && minRange.node instanceof concepts_1.Interface) {
|
|
2026
|
+
return null;
|
|
2027
|
+
}
|
|
2028
|
+
// 如果是被影响的是页面
|
|
2029
|
+
if (minRange.node instanceof concepts_1.View) {
|
|
2030
|
+
if (node instanceof concepts_1.View) {
|
|
2031
|
+
// 如果是子页面修改
|
|
2032
|
+
// 父页面引起子页面改名,就可以不改了,自动同步
|
|
2033
|
+
if (minRange.node !== node) {
|
|
2034
|
+
return null;
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
else if (!(node instanceof concepts_1.Role)) {
|
|
2038
|
+
/**
|
|
2039
|
+
* 无论是逻辑还是实体中的key,修改都不应该触发
|
|
2040
|
+
* 理论上除了组件自己改名可以触发
|
|
2041
|
+
* 下面这里 不属于Role是因为上面代码里有, 不符合 规范 的role改名存在所以先保留
|
|
2042
|
+
*/
|
|
2043
|
+
return null;
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
// 如果是被影响的是页面元素
|
|
2047
|
+
if (minRange.node instanceof concepts_1.ViewElement) {
|
|
2048
|
+
if (node instanceof concepts_1.ViewElement) {
|
|
2049
|
+
if (minRange.node !== node) {
|
|
2050
|
+
return null;
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
else if (!(node instanceof concepts_1.Role)) {
|
|
2054
|
+
/**
|
|
2055
|
+
* 无论是逻辑还是实体中的key,修改都不应该触发
|
|
2056
|
+
* 理论上除了组件自己改名可以触发
|
|
2057
|
+
* 下面这里 不属于Role是因为上面代码里有, 不符合 规范 的role改名存在所以先保留
|
|
2058
|
+
*/
|
|
2059
|
+
return null;
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
else {
|
|
2064
|
+
console.log('没找到节点需要排查', record, fileNode.sourceMap);
|
|
2065
|
+
}
|
|
2066
|
+
return minRange;
|
|
2067
|
+
})
|
|
2068
|
+
// 过滤掉不需要操作的
|
|
2069
|
+
.filter(function (item) { return !!item; });
|
|
2070
|
+
return result;
|
|
2071
|
+
};
|
|
2072
|
+
// 增加参数的副作用,用于更新logic和view
|
|
2073
|
+
NaslServer.prototype._addParamsEffect = function (refsList, node) {
|
|
2074
|
+
var _this = this;
|
|
2075
|
+
var parantNode = node === null || node === void 0 ? void 0 : node.parentNode;
|
|
2076
|
+
refsList.forEach(function (record) {
|
|
2077
|
+
var fileNode = _this.file2NodeMap.get(record.file);
|
|
2078
|
+
if (!fileNode)
|
|
2079
|
+
return null;
|
|
2080
|
+
var minRange = _this._findMinRange(record, fileNode);
|
|
2081
|
+
if (minRange) {
|
|
2082
|
+
// 如果找到节点是callLogic就去更新
|
|
2083
|
+
if (minRange.node instanceof concepts_1.CallLogic && node instanceof concepts_1.Param) {
|
|
2084
|
+
minRange.node.setCalleeArgName(parantNode);
|
|
2085
|
+
}
|
|
2086
|
+
// 如果节点参数增加页面也要更新
|
|
2087
|
+
if (minRange.node instanceof concepts_1.Destination && node instanceof concepts_1.Param) {
|
|
2088
|
+
minRange.node.setViewArgument(parantNode);
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
});
|
|
2092
|
+
};
|
|
2093
|
+
NaslServer.prototype._addParamsPrepare = function (node, refsList, needAdd) {
|
|
2094
|
+
if (needAdd) {
|
|
2095
|
+
var App_1 = node === null || node === void 0 ? void 0 : node.rootNode;
|
|
2096
|
+
var parantNode = node === null || node === void 0 ? void 0 : node.parentNode;
|
|
2097
|
+
// 收集修改
|
|
2098
|
+
App_1.emit('collect:start', {
|
|
2099
|
+
actionMsg: '增加逻辑参数'
|
|
2100
|
+
});
|
|
2101
|
+
var index = node.getIndexOfParent();
|
|
2102
|
+
node.create({
|
|
2103
|
+
index: index,
|
|
2104
|
+
parentNode: parantNode,
|
|
2105
|
+
parentKey: node.parentKey
|
|
2106
|
+
});
|
|
2107
|
+
this._addParamsEffect(refsList, node);
|
|
2108
|
+
// 结束修改 ,批量操作
|
|
2109
|
+
App_1.emit('collect:end');
|
|
2110
|
+
return node;
|
|
2111
|
+
}
|
|
2112
|
+
this._addParamsEffect(refsList, node);
|
|
2113
|
+
return node;
|
|
2114
|
+
};
|
|
2115
|
+
// 查找引用
|
|
2116
|
+
NaslServer.prototype.findReferences = function (node) {
|
|
2117
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2118
|
+
var refsList, result, resMap, nodeMap;
|
|
2119
|
+
var _this = this;
|
|
2120
|
+
return __generator(this, function (_a) {
|
|
2121
|
+
switch (_a.label) {
|
|
2122
|
+
case 0: return [4 /*yield*/, this._isHaveRef(node)];
|
|
2123
|
+
case 1:
|
|
2124
|
+
refsList = _a.sent();
|
|
2125
|
+
// 如果查找引用查到自己里面的引用不展示
|
|
2126
|
+
refsList = refsList.filter(function (item) {
|
|
2127
|
+
// 自己引用自己的过滤掉
|
|
2128
|
+
// 删除的时候过滤一把组件删除提示
|
|
2129
|
+
// 展示组件自己屏蔽掉
|
|
2130
|
+
return !item.isDefinition && !item.lineText.includes(' = new nasl.ui.');
|
|
2131
|
+
});
|
|
2132
|
+
result = new Map();
|
|
2133
|
+
resMap = new Map();
|
|
2134
|
+
nodeMap = new Map();
|
|
2135
|
+
try {
|
|
2136
|
+
refsList.forEach(function (record) {
|
|
2137
|
+
var fileNode = _this.file2NodeMap.get(record.file);
|
|
2138
|
+
if (!fileNode)
|
|
2139
|
+
return;
|
|
2140
|
+
var minRange = _this._findMinRange(record, fileNode);
|
|
2141
|
+
// 过滤一把不需要改的信息
|
|
2142
|
+
if (minRange) {
|
|
2143
|
+
// 拼装树
|
|
2144
|
+
_this._getTreeMap(minRange, fileNode, resMap, nodeMap);
|
|
2145
|
+
}
|
|
2146
|
+
});
|
|
2147
|
+
if (resMap.size > 0) {
|
|
2148
|
+
result = this.handleTreeMap(resMap);
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
catch (err) {
|
|
2152
|
+
console.log(err);
|
|
2153
|
+
}
|
|
2154
|
+
return [2 /*return*/, result];
|
|
2155
|
+
}
|
|
2156
|
+
});
|
|
2157
|
+
});
|
|
2158
|
+
};
|
|
2159
|
+
// 获取节点的上层渲染
|
|
2160
|
+
NaslServer.prototype._getTreeMap = function (minRange, fileNode, resMap, nodeMap) {
|
|
2161
|
+
var minRangeNode = minRange.node;
|
|
2162
|
+
var currentNode = minRangeNode;
|
|
2163
|
+
var parantNode = currentNode;
|
|
2164
|
+
// 顺序队列
|
|
2165
|
+
var queue = [];
|
|
2166
|
+
// 先插入自己,如果没有在往上找,
|
|
2167
|
+
// 一直到file节点的父级
|
|
2168
|
+
while (!(parantNode instanceof concepts_1.App)) {
|
|
2169
|
+
// 找到上一级 在map对象中构造出他的子集
|
|
2170
|
+
currentNode = parantNode;
|
|
2171
|
+
parantNode = parantNode.parentNode;
|
|
2172
|
+
// 如果第一次就塞入子集和父节点,以后就只用父节点了
|
|
2173
|
+
// 因为部分节点没有name,先过滤掉
|
|
2174
|
+
// if (currentNode.name) {
|
|
2175
|
+
// }
|
|
2176
|
+
// 排除一些不放入集合的节点
|
|
2177
|
+
var isNeedPush = true;
|
|
2178
|
+
// 如果不是ViewElement 或者 Assignment , 或者如果是的话, 排除l-root
|
|
2179
|
+
if (currentNode instanceof concepts_1.ViewElement && currentNode.tag === 'l-root')
|
|
2180
|
+
isNeedPush = false;
|
|
2181
|
+
else if (currentNode instanceof concepts_1.Argument)
|
|
2182
|
+
isNeedPush = false;
|
|
2183
|
+
else if (currentNode instanceof concepts_1.Assignment)
|
|
2184
|
+
isNeedPush = false;
|
|
2185
|
+
else if (currentNode instanceof concepts_1.TypeAnnotation)
|
|
2186
|
+
isNeedPush = false;
|
|
2187
|
+
else if (currentNode instanceof concepts_1.CallQueryComponent)
|
|
2188
|
+
isNeedPush = false;
|
|
2189
|
+
else if (currentNode instanceof concepts_1.QueryFromExpression)
|
|
2190
|
+
isNeedPush = false;
|
|
2191
|
+
else if (currentNode instanceof concepts_1.TypeAnnotation)
|
|
2192
|
+
isNeedPush = false;
|
|
2193
|
+
// 需要放到数组中
|
|
2194
|
+
if (isNeedPush) {
|
|
2195
|
+
// 名称
|
|
2196
|
+
// 赋值图标
|
|
2197
|
+
var icon = '';
|
|
2198
|
+
if (currentNode instanceof concepts_1.ViewElement)
|
|
2199
|
+
icon = 'element';
|
|
2200
|
+
else if (currentNode instanceof concepts_1.BindAttribute)
|
|
2201
|
+
icon = 'attr';
|
|
2202
|
+
else if (currentNode instanceof concepts_1.Destination)
|
|
2203
|
+
icon = 'logicNode';
|
|
2204
|
+
else if (currentNode instanceof concepts_1.CallLogic) {
|
|
2205
|
+
icon = 'interface';
|
|
2206
|
+
}
|
|
2207
|
+
// 相同节点使用一个引用
|
|
2208
|
+
if (nodeMap.get(currentNode)) {
|
|
2209
|
+
queue.unshift(nodeMap.get(currentNode));
|
|
2210
|
+
}
|
|
2211
|
+
else {
|
|
2212
|
+
var quoteNode = { node: currentNode, expanded: true, icon: icon };
|
|
2213
|
+
nodeMap.set(currentNode, quoteNode);
|
|
2214
|
+
queue.unshift(quoteNode);
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
// 一个logic 或者 view可能会有多个顺序队列
|
|
2219
|
+
if (resMap.get(currentNode)) {
|
|
2220
|
+
// 是否展示两个内容全等,但是两个queue的node可能不一样,但是只需要展示一个
|
|
2221
|
+
resMap.get(currentNode).push(queue);
|
|
2222
|
+
}
|
|
2223
|
+
else {
|
|
2224
|
+
resMap.set(currentNode, [queue]);
|
|
2225
|
+
}
|
|
2226
|
+
};
|
|
2227
|
+
NaslServer.prototype.handleTreeMap = function (resMap) {
|
|
2228
|
+
var _this = this;
|
|
2229
|
+
var treeNodeMap = new Map();
|
|
2230
|
+
resMap.forEach(function (value, fileNode) {
|
|
2231
|
+
// 循环处理tree的queue
|
|
2232
|
+
var treeObj = _this.handleTreeQueue(value);
|
|
2233
|
+
treeNodeMap.set(fileNode, treeObj);
|
|
2234
|
+
});
|
|
2235
|
+
return treeNodeMap;
|
|
2236
|
+
};
|
|
2237
|
+
/**
|
|
2238
|
+
* 处理tree的队列,把相同节点进行合并
|
|
2239
|
+
* 这里把当前二维数组进行一个整合
|
|
2240
|
+
* @param arr 当前页面下的queue的二维数组,一个数组下有多条链路
|
|
2241
|
+
* @returns 最后要使用到的节点和对应的子集
|
|
2242
|
+
*/
|
|
2243
|
+
NaslServer.prototype.handleTreeQueue = function (queueLists) {
|
|
2244
|
+
var map = new Map();
|
|
2245
|
+
var root = null;
|
|
2246
|
+
if (!queueLists.length)
|
|
2247
|
+
return;
|
|
2248
|
+
for (var _i = 0, queueLists_1 = queueLists; _i < queueLists_1.length; _i++) {
|
|
2249
|
+
var queueList = queueLists_1[_i];
|
|
2250
|
+
var preNode = null;
|
|
2251
|
+
var _loop_1 = function (queueItem) {
|
|
2252
|
+
if (!map.get(queueItem)) {
|
|
2253
|
+
map.set(queueItem, []);
|
|
2254
|
+
}
|
|
2255
|
+
if (preNode) {
|
|
2256
|
+
var find = map.get(preNode).find(function (item) { return item === queueItem; });
|
|
2257
|
+
if (!find) {
|
|
2258
|
+
map.get(preNode).push(queueItem);
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
else {
|
|
2262
|
+
root = queueItem;
|
|
2263
|
+
}
|
|
2264
|
+
preNode = queueItem;
|
|
2265
|
+
};
|
|
2266
|
+
for (var _a = 0, queueList_1 = queueList; _a < queueList_1.length; _a++) {
|
|
2267
|
+
var queueItem = queueList_1[_a];
|
|
2268
|
+
_loop_1(queueItem);
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
var children = this._recursionCreateResult(root, map);
|
|
2272
|
+
return children;
|
|
2273
|
+
};
|
|
2274
|
+
/**
|
|
2275
|
+
* 递归调用输出结果
|
|
2276
|
+
* @param root 一个根节点
|
|
2277
|
+
* @param map 当前所有节点的map对象
|
|
2278
|
+
* @returns 当前节点,最后输出所有节点
|
|
2279
|
+
*/
|
|
2280
|
+
NaslServer.prototype._recursionCreateResult = function (root, map) {
|
|
2281
|
+
var _this = this;
|
|
2282
|
+
var children = (map.get(root) || []).map(function (item) { return _this._recursionCreateResult(item, map); });
|
|
2283
|
+
if (children && children.length) {
|
|
2284
|
+
root.children = children;
|
|
2285
|
+
}
|
|
2286
|
+
return root;
|
|
2287
|
+
};
|
|
2288
|
+
/**
|
|
2289
|
+
* 获取
|
|
2290
|
+
* 当前this上下文 的Source 和 父级文件级别的节点
|
|
2291
|
+
*/
|
|
2292
|
+
NaslServer.prototype.getCurrentSource = function (node) {
|
|
2293
|
+
if (node instanceof concepts_1.App || node instanceof concepts_1.Theme)
|
|
2294
|
+
return { fileNode: null };
|
|
2295
|
+
var sourceMap = node.sourceMap;
|
|
2296
|
+
var fileNode = node;
|
|
2297
|
+
// 如果没有sourceMap,就继续向上找 ,或者到module结束
|
|
2298
|
+
// 如果 节点找到 app 或者module 停止 或者entity找到DataSource为止
|
|
2299
|
+
// 如果当前节点是view就不要向上查找了
|
|
2300
|
+
while (!sourceMap
|
|
2301
|
+
&& fileNode
|
|
2302
|
+
&& !(fileNode.parentNode instanceof concepts_1.App)
|
|
2303
|
+
&& !(fileNode.parentNode instanceof concepts_1.Module)
|
|
2304
|
+
&& !(fileNode.parentNode instanceof concepts_1.DataSource)
|
|
2305
|
+
&& !(fileNode instanceof concepts_1.View)) {
|
|
2306
|
+
fileNode = fileNode.parentNode;
|
|
2307
|
+
sourceMap = fileNode === null || fileNode === void 0 ? void 0 : fileNode.sourceMap;
|
|
2308
|
+
}
|
|
2309
|
+
var currentSource = sourceMap && sourceMap.get(node);
|
|
2310
|
+
if (currentSource) {
|
|
2311
|
+
// 这里处理一些加了注解或者需要定制位置的节点的取值
|
|
2312
|
+
this.handlingCurrentSourceException(currentSource, node);
|
|
2313
|
+
return { currentSource: currentSource, fileNode: fileNode };
|
|
2314
|
+
}
|
|
2315
|
+
return { fileNode: fileNode };
|
|
2316
|
+
};
|
|
2317
|
+
NaslServer.prototype.handlingCurrentSourceException = function (currentSource, node) {
|
|
2318
|
+
// 如果有前面的一些注解,元素在最后一行输出的值就给最后一行
|
|
2319
|
+
if (node instanceof concepts_1.EntityProperty) {
|
|
2320
|
+
if (currentSource.range.start.line !== currentSource.range.end.line) {
|
|
2321
|
+
currentSource.range.start = __assign(__assign({}, currentSource.range.start), { line: currentSource.range.end.line });
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
};
|
|
2325
|
+
// 获取element方法的可选值
|
|
2326
|
+
NaslServer.prototype.getFieldKeySelectCompletion = function (node, fieldKey) {
|
|
2327
|
+
var _a = this.getCurrentSource(node), currentSource = _a.currentSource, fileNode = _a.fileNode;
|
|
2328
|
+
if (currentSource && fileNode) {
|
|
2329
|
+
return this._getFieldKeySelectCompletion({
|
|
2330
|
+
file: fileNode.getEmbeddedFilePath(),
|
|
2331
|
+
range: {
|
|
2332
|
+
line: translator_1.lsp2tspNumber(currentSource.range.start.line),
|
|
2333
|
+
offset: translator_1.lsp2tspNumber(currentSource.range.start.character)
|
|
2334
|
+
},
|
|
2335
|
+
getFieldKey: fieldKey
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
else {
|
|
2339
|
+
console.log('没找到节点', currentSource, fileNode);
|
|
2340
|
+
}
|
|
2341
|
+
};
|
|
2342
|
+
NaslServer.prototype._getFieldKeySelectCompletion = function (args) {
|
|
2343
|
+
return this.messager.requestCommand('getFieldKeySelectCompletion', args);
|
|
2344
|
+
};
|
|
2345
|
+
/**
|
|
2346
|
+
* 获取模块下多个CallInterface 被依赖的页面节点
|
|
2347
|
+
* 查找callInterface 被依赖的页面级别的节点,要让他们重新生成一次代码,因为多个Interface重新导入,需要查找到引用的额内容
|
|
2348
|
+
* 对应引用地方,需要重新生成,因为是生成方控制是不是必填的,
|
|
2349
|
+
* @param oldInterfaceModule 发生修改的module,查他下面的Interface被引用的地方
|
|
2350
|
+
* @returns 查找到的有引用这个内容的页面级别节点
|
|
2351
|
+
*/
|
|
2352
|
+
NaslServer.prototype.findModulesCallInterfaceFileRef = function (oldInterfaceModule) {
|
|
2353
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2354
|
+
var oldInterfaces, fileNodes, i, item, refsList;
|
|
2355
|
+
var _this = this;
|
|
2356
|
+
return __generator(this, function (_a) {
|
|
2357
|
+
switch (_a.label) {
|
|
2358
|
+
case 0:
|
|
2359
|
+
oldInterfaces = oldInterfaceModule.interfaces;
|
|
2360
|
+
fileNodes = new Set();
|
|
2361
|
+
i = 0;
|
|
2362
|
+
_a.label = 1;
|
|
2363
|
+
case 1:
|
|
2364
|
+
if (!(i < oldInterfaces.length)) return [3 /*break*/, 4];
|
|
2365
|
+
item = oldInterfaces[i];
|
|
2366
|
+
return [4 /*yield*/, this._isHaveRef(item)];
|
|
2367
|
+
case 2:
|
|
2368
|
+
refsList = _a.sent();
|
|
2369
|
+
refsList.forEach(function (record) {
|
|
2370
|
+
if (record.isDefinition)
|
|
2371
|
+
return;
|
|
2372
|
+
var fileNode = _this.file2NodeMap.get(record.file);
|
|
2373
|
+
if (fileNode) {
|
|
2374
|
+
fileNodes.add(fileNode);
|
|
2375
|
+
}
|
|
2376
|
+
});
|
|
2377
|
+
_a.label = 3;
|
|
2378
|
+
case 3:
|
|
2379
|
+
i++;
|
|
2380
|
+
return [3 /*break*/, 1];
|
|
2381
|
+
case 4: return [2 /*return*/, __spreadArrays(fileNodes)];
|
|
2382
|
+
}
|
|
2383
|
+
});
|
|
2384
|
+
});
|
|
2385
|
+
};
|
|
2386
|
+
/**
|
|
2387
|
+
* 查找calllogic 被依赖的页面级别的节点,要让他们重新生成一次代码,因为logic,参数必填非必填发生修改,
|
|
2388
|
+
* 对应引用地方,需要重新生成,因为是生成方控制是不是必填的,
|
|
2389
|
+
* @param logic 发生修改的logic
|
|
2390
|
+
* @returns 查找到的有引用这个内容的页面级别节点
|
|
2391
|
+
*/
|
|
2392
|
+
NaslServer.prototype.findCallLogicFileRef = function (logic) {
|
|
2393
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2394
|
+
var fileNodes, refsList;
|
|
2395
|
+
var _this = this;
|
|
2396
|
+
return __generator(this, function (_a) {
|
|
2397
|
+
switch (_a.label) {
|
|
2398
|
+
case 0:
|
|
2399
|
+
fileNodes = new Set();
|
|
2400
|
+
return [4 /*yield*/, this._isHaveRef(logic)];
|
|
2401
|
+
case 1:
|
|
2402
|
+
refsList = _a.sent();
|
|
2403
|
+
refsList.forEach(function (record) {
|
|
2404
|
+
if (record.isDefinition)
|
|
2405
|
+
return;
|
|
2406
|
+
var fileNode = _this.file2NodeMap.get(record.file);
|
|
2407
|
+
if (fileNode) {
|
|
2408
|
+
fileNodes.add(fileNode);
|
|
2409
|
+
}
|
|
2410
|
+
});
|
|
2411
|
+
return [2 /*return*/, __spreadArrays(fileNodes)];
|
|
2412
|
+
}
|
|
2413
|
+
});
|
|
2414
|
+
});
|
|
2415
|
+
};
|
|
2416
|
+
/**获取当前节点的已知类型
|
|
2417
|
+
* @param node 当前要获取类型的节点
|
|
2418
|
+
* @returns 不需要去查就可以返回类型的节点
|
|
2419
|
+
*/
|
|
2420
|
+
NaslServer.prototype.getCurrentNodeKnownTypeAnnotation = function (node) {
|
|
2421
|
+
var _a;
|
|
2422
|
+
if (node.concept === 'StringLiteral' || node.concept === 'BooleanLiteral' || node.concept === 'NullLiteral') {
|
|
2423
|
+
var type = 'String';
|
|
2424
|
+
switch (node.concept) {
|
|
2425
|
+
case 'NullLiteral':
|
|
2426
|
+
type = 'Null';
|
|
2427
|
+
break;
|
|
2428
|
+
case 'BooleanLiteral':
|
|
2429
|
+
type = 'Boolean';
|
|
2430
|
+
break;
|
|
2431
|
+
}
|
|
2432
|
+
return concepts_1.TypeAnnotation.createPrimitive(type);
|
|
2433
|
+
}
|
|
2434
|
+
// 这些原有类型的 比较的 返回值肯定就是布尔值,就不去调用ls
|
|
2435
|
+
if (node instanceof concepts_1.BinaryExpression && (['==', '!=', '>', '<', '>=', '<='].includes(node.operator))) {
|
|
2436
|
+
return concepts_1.TypeAnnotation.createPrimitive('Boolean');
|
|
2437
|
+
}
|
|
2438
|
+
// Convert和new都是自身携带类型的,就不进行修改
|
|
2439
|
+
if (node instanceof concepts_1.CallFunction && node.calleeNamespace === 'nasl.util' && (node.calleeName === 'Convert' || node.calleeName === 'New')) {
|
|
2440
|
+
if (node.typeArguments.length) {
|
|
2441
|
+
return node.typeArguments[0];
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
// Convert和new都是自身携带类型的,就不进行修改
|
|
2445
|
+
if (node instanceof concepts_1.CallLogic && node.calleeNamespace === 'nasl.util' && (node.calleeName === 'jsonDeserialize')) {
|
|
2446
|
+
if (node.typeArguments.length) {
|
|
2447
|
+
return node.typeArguments[0];
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
// 特殊处理param有类型错误的
|
|
2451
|
+
if (node instanceof concepts_1.Param) {
|
|
2452
|
+
// index在nasl foreach上有脏数据
|
|
2453
|
+
if (node.parentKey === 'index' && node.parentNode instanceof concepts_1.ForEachStatement) {
|
|
2454
|
+
return concepts_1.TypeAnnotation.createPrimitive('Integer');
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
if (node instanceof concepts_1.CallQueryComponent || node instanceof concepts_1.SqlQueryComponent || node instanceof concepts_1.OqlQueryComponent) {
|
|
2458
|
+
return node.typeAnnotation;
|
|
2459
|
+
}
|
|
2460
|
+
// 老数据可能typeKind 的primitive缺失
|
|
2461
|
+
if (node instanceof concepts_1.NumericLiteral && node.typeAnnotation) {
|
|
2462
|
+
return concepts_1.TypeAnnotation.from(__assign(__assign({}, (_a = node.typeAnnotation) === null || _a === void 0 ? void 0 : _a.toJSON()), { typeKind: 'primitive' }));
|
|
2463
|
+
}
|
|
2464
|
+
};
|
|
2465
|
+
/**
|
|
2466
|
+
* 获取传入节点的TypeAnnotation
|
|
2467
|
+
* @param nodes {filePath: string, node: BaseNode, item: SourceMapItem}
|
|
2468
|
+
* @returns Map<BaseNode, TypeAnnotation | { typeAnnotation: TypeAnnotation, option: any }>
|
|
2469
|
+
* 普通的TypeAnnotation,额外的可能携带 option
|
|
2470
|
+
* 这里会处理callloigc callinterface 和 callfuntion 的 argment的参数一起携带回去,
|
|
2471
|
+
* 也就是说如果 只传入了这个也会一起返回argment的节点,所以返回map最好去get结果
|
|
2472
|
+
*/
|
|
2473
|
+
NaslServer.prototype.getQuickInfoNodesTypeMap = function (nodes, lotFlag) {
|
|
2474
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2475
|
+
var args, getFromOthers, types, newQuickInfoNodes, resultMap;
|
|
2476
|
+
var _this = this;
|
|
2477
|
+
return __generator(this, function (_a) {
|
|
2478
|
+
switch (_a.label) {
|
|
2479
|
+
case 0:
|
|
2480
|
+
args = [];
|
|
2481
|
+
getFromOthers = new Map();
|
|
2482
|
+
types = new Map();
|
|
2483
|
+
newQuickInfoNodes = [];
|
|
2484
|
+
nodes.forEach(function (itemDetail) {
|
|
2485
|
+
var _a, _b, _c;
|
|
2486
|
+
var node = itemDetail.node, filePath = itemDetail.filePath, item = itemDetail.item;
|
|
2487
|
+
// 先按照顺序占位
|
|
2488
|
+
types.set(node, null);
|
|
2489
|
+
// 获取已知节点类型的类型
|
|
2490
|
+
var nodeTypeAnnotation = _this.getCurrentNodeKnownTypeAnnotation(node);
|
|
2491
|
+
if (nodeTypeAnnotation) {
|
|
2492
|
+
types.set(node, nodeTypeAnnotation);
|
|
2493
|
+
node.__TypeAnnotation = nodeTypeAnnotation;
|
|
2494
|
+
return;
|
|
2495
|
+
}
|
|
2496
|
+
// 要通过自己或者依赖关系拿的,二次遍历
|
|
2497
|
+
if ([
|
|
2498
|
+
'Argument',
|
|
2499
|
+
'Assignment',
|
|
2500
|
+
'MatchCase',
|
|
2501
|
+
].includes(node.concept)) {
|
|
2502
|
+
getFromOthers.set(node, null);
|
|
2503
|
+
}
|
|
2504
|
+
if ([
|
|
2505
|
+
'Return',
|
|
2506
|
+
'Variable',
|
|
2507
|
+
].includes(node.concept) && node.typeAnnotation) {
|
|
2508
|
+
node.__TypeAnnotation = node.typeAnnotation;
|
|
2509
|
+
return;
|
|
2510
|
+
}
|
|
2511
|
+
if (![
|
|
2512
|
+
'Identifier',
|
|
2513
|
+
'UnaryExpression',
|
|
2514
|
+
'BinaryExpression',
|
|
2515
|
+
'CallLogic',
|
|
2516
|
+
'CallFunction',
|
|
2517
|
+
'CallInterface',
|
|
2518
|
+
'MemberExpression',
|
|
2519
|
+
'Return',
|
|
2520
|
+
'Variable',
|
|
2521
|
+
'Match',
|
|
2522
|
+
].includes(node.concept))
|
|
2523
|
+
return;
|
|
2524
|
+
// 要去ls那边获取的
|
|
2525
|
+
newQuickInfoNodes.push(itemDetail);
|
|
2526
|
+
var fileDetail = {
|
|
2527
|
+
file: filePath,
|
|
2528
|
+
line: translator_1.lsp2tspNumber(item.range.start.line),
|
|
2529
|
+
offset: translator_1.lsp2tspNumber(item.range.start.character)
|
|
2530
|
+
};
|
|
2531
|
+
if (node.concept === 'BinaryExpression'
|
|
2532
|
+
|| node.concept === 'CallLogic'
|
|
2533
|
+
|| node.concept === 'CallFunction'
|
|
2534
|
+
|| node.concept === 'CallInterface') {
|
|
2535
|
+
// 如果没有括号 ,括号就在外面,就 -1
|
|
2536
|
+
// 有括号就找到括号的位置 然后 -1
|
|
2537
|
+
var indexOf = 0;
|
|
2538
|
+
if (item.code.indexOf('(') === -1) {
|
|
2539
|
+
indexOf = -1;
|
|
2540
|
+
}
|
|
2541
|
+
else {
|
|
2542
|
+
// 如果有泛型先往前找一找
|
|
2543
|
+
if (item.code.includes('<')) {
|
|
2544
|
+
indexOf = item.code.indexOf('<');
|
|
2545
|
+
}
|
|
2546
|
+
else {
|
|
2547
|
+
indexOf = item.code.indexOf('(');
|
|
2548
|
+
}
|
|
2549
|
+
var subStr = item.code.substring(0, indexOf);
|
|
2550
|
+
var codeArr = subStr === null || subStr === void 0 ? void 0 : subStr.split('.');
|
|
2551
|
+
var lastLen = (_a = codeArr === null || codeArr === void 0 ? void 0 : codeArr[codeArr.length - 1]) === null || _a === void 0 ? void 0 : _a.length;
|
|
2552
|
+
indexOf = subStr.length - lastLen;
|
|
2553
|
+
}
|
|
2554
|
+
fileDetail.offset = fileDetail.offset + indexOf;
|
|
2555
|
+
}
|
|
2556
|
+
else if (node.concept === 'MemberExpression' || node.concept === 'Identifier') {
|
|
2557
|
+
if (item.code.includes('.')) {
|
|
2558
|
+
var codeArr = (_b = item.code) === null || _b === void 0 ? void 0 : _b.split('.');
|
|
2559
|
+
var lastLen = (_c = codeArr === null || codeArr === void 0 ? void 0 : codeArr[codeArr.length - 1]) === null || _c === void 0 ? void 0 : _c.length;
|
|
2560
|
+
// MemberExpression取最后一位当做类型
|
|
2561
|
+
var indexOf = item.code.length - lastLen;
|
|
2562
|
+
fileDetail.offset = fileDetail.offset + indexOf;
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
else if (node.concept === 'Match') {
|
|
2566
|
+
// 去查return 后面的返回值,变成函数调用
|
|
2567
|
+
fileDetail.line = item.range.end.line - 1;
|
|
2568
|
+
var indexOf = item.code.indexOf('return __MatchExpressionFuntion');
|
|
2569
|
+
var newCode = item.code.substring(0, indexOf);
|
|
2570
|
+
newCode = newCode.substring(newCode.lastIndexOf('\n'), indexOf);
|
|
2571
|
+
fileDetail.offset = newCode.length + 'return '.length;
|
|
2572
|
+
}
|
|
2573
|
+
args.push(fileDetail);
|
|
2574
|
+
});
|
|
2575
|
+
return [4 /*yield*/, this.getNaslNodeTypeFull(args)];
|
|
2576
|
+
case 1:
|
|
2577
|
+
resultMap = (_a.sent()).response;
|
|
2578
|
+
// console.log(resultMap);
|
|
2579
|
+
// const result = (await this.getNaslNodeQuickInfoFull(args)).response;
|
|
2580
|
+
// console.log(result);
|
|
2581
|
+
args.forEach(function (arg, index) {
|
|
2582
|
+
var _a, _b, _c, _d, _e;
|
|
2583
|
+
var file = arg.file, line = arg.line, offset = arg.offset;
|
|
2584
|
+
var item = (_c = (_b = (_a = resultMap) === null || _a === void 0 ? void 0 : _a[file]) === null || _b === void 0 ? void 0 : _b[line]) === null || _c === void 0 ? void 0 : _c[offset];
|
|
2585
|
+
//const displayString1 = resule1[index]?.displayString;
|
|
2586
|
+
// console.log('位置:', file, line, offset);
|
|
2587
|
+
// console.log('原始:', displayString);
|
|
2588
|
+
// console.log('方案2:', item?.[0]?.nodeType);
|
|
2589
|
+
var nodeTypeAnnotation = formatTsUtils_1.type2TypeAnnotation((_d = item === null || item === void 0 ? void 0 : item[0]) === null || _d === void 0 ? void 0 : _d.nodeType);
|
|
2590
|
+
// console.log(newQuickInfoNodes[index].node, nodeTypeAnnotation, nodeTypeAnnotation?.typeKey);
|
|
2591
|
+
types.set(newQuickInfoNodes[index].node, nodeTypeAnnotation);
|
|
2592
|
+
newQuickInfoNodes[index].node.__TypeAnnotation = nodeTypeAnnotation;
|
|
2593
|
+
newQuickInfoNodes[index].node.__nodeType = (_e = item === null || item === void 0 ? void 0 : item[0]) === null || _e === void 0 ? void 0 : _e.nodeType;
|
|
2594
|
+
// console.log('方案1:', displayString1);
|
|
2595
|
+
});
|
|
2596
|
+
getFromOthers.forEach(function (type, node) {
|
|
2597
|
+
var _a;
|
|
2598
|
+
if (node instanceof concepts_1.Assignment) {
|
|
2599
|
+
if (!types.get(node.left)) {
|
|
2600
|
+
types.set(node.left, types.get(node.right));
|
|
2601
|
+
node.left.__TypeAnnotation = types.get(node.right);
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
else if (node instanceof concepts_1.Argument) {
|
|
2605
|
+
// 如果Argument,但是没可以用的类型,就用原来logic的参数类型
|
|
2606
|
+
var argType = _this.getArgumentTypeAnnotation(node, newQuickInfoNodes, types);
|
|
2607
|
+
types.set(node, argType);
|
|
2608
|
+
node.__TypeAnnotation = argType.typeAnnotation;
|
|
2609
|
+
}
|
|
2610
|
+
else if (node instanceof concepts_1.MatchCase) {
|
|
2611
|
+
// matchCase的类型
|
|
2612
|
+
// 直接从最后一项的返回值取,有就有没有就没有
|
|
2613
|
+
if ((_a = node.body) === null || _a === void 0 ? void 0 : _a.length) {
|
|
2614
|
+
var last = node.body[node.body.length - 1];
|
|
2615
|
+
if (last.__TypeAnnotation) {
|
|
2616
|
+
types.set(node, last.__TypeAnnotation);
|
|
2617
|
+
node.__TypeAnnotation = last.__TypeAnnotation;
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
});
|
|
2622
|
+
// newQuickInfoNodes.forEach((itemDetail, index) => {
|
|
2623
|
+
// const { node, filePath } = itemDetail;
|
|
2624
|
+
// if (!result[index] || node.concept === 'Argument')
|
|
2625
|
+
// return;
|
|
2626
|
+
// // console.log(result[index].displayString, node);
|
|
2627
|
+
// /**
|
|
2628
|
+
// * 这个前缀是给会自动省略命名空间的内容设置的,下个版本干掉,应急的方法
|
|
2629
|
+
// */
|
|
2630
|
+
// let parentPrefix;
|
|
2631
|
+
// if (filePath && (filePath.split('/').length > 3)) {
|
|
2632
|
+
// const arr = filePath.split('/');
|
|
2633
|
+
// if (arr[3] === 'dependencies' || arr[3] === 'interfaceDependencies' || arr[3] === 'componentDependencies') {
|
|
2634
|
+
// const map = {
|
|
2635
|
+
// dependencies: 'extensions',
|
|
2636
|
+
// interfaceDependencies: 'apis',
|
|
2637
|
+
// componentDependencies: 'components',
|
|
2638
|
+
// };
|
|
2639
|
+
// parentPrefix = `${map[arr[3]]}.${arr[4]}.`;
|
|
2640
|
+
// }
|
|
2641
|
+
// }
|
|
2642
|
+
// const nodeTypeAnnotation = displayString2TypeAnnotation(result[index].displayString, parentPrefix);
|
|
2643
|
+
// // console.log(result[index].displayString, items[index], '************', typeAnnotation);
|
|
2644
|
+
// // console.log(node, index, items[index].code, result[index].displayString, '+++++++++++++++++++++++++++', typeAnnotation && typeAnnotation.typeKey)
|
|
2645
|
+
// try {
|
|
2646
|
+
// types.set(node, nodeTypeAnnotation);
|
|
2647
|
+
// /**
|
|
2648
|
+
// * 没有类型标注的情况
|
|
2649
|
+
// * 1.void 没有返回值
|
|
2650
|
+
// * 2.Argment
|
|
2651
|
+
// */
|
|
2652
|
+
// // if (!typeAnnotation) {
|
|
2653
|
+
// // console.log(items[index].code, jsonNode, result[index]);
|
|
2654
|
+
// // console.log(result[index].displayString)
|
|
2655
|
+
// // }
|
|
2656
|
+
// } catch (e) {
|
|
2657
|
+
// console.log(node, node.getNodePath(false));
|
|
2658
|
+
// }
|
|
2659
|
+
// });
|
|
2660
|
+
// // Argument的标注,因为这个位置上可能放任何东西所以直接在其内部去取
|
|
2661
|
+
// newQuickInfoNodes.forEach((itemDetail, index) => {
|
|
2662
|
+
// const { node } = itemDetail;
|
|
2663
|
+
// if (node instanceof Argument) {
|
|
2664
|
+
// // 如果Argument,但是没可以用的类型,就用原来logic的参数类型
|
|
2665
|
+
// const argType = this.getArgumentTypeAnnotation(node, newQuickInfoNodes, result, (types as any));
|
|
2666
|
+
// types.set(node, argType);
|
|
2667
|
+
// }
|
|
2668
|
+
// });
|
|
2669
|
+
console.timeEnd('批量请求');
|
|
2670
|
+
return [2 /*return*/, types];
|
|
2671
|
+
}
|
|
2672
|
+
});
|
|
2673
|
+
});
|
|
2674
|
+
};
|
|
2675
|
+
// 全量标注
|
|
2676
|
+
NaslServer.prototype.getNaslAnnotatedJSON = function (app, releaseFlag) {
|
|
2677
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2678
|
+
var nodes, typesMap, json;
|
|
2679
|
+
return __generator(this, function (_a) {
|
|
2680
|
+
switch (_a.label) {
|
|
2681
|
+
case 0:
|
|
2682
|
+
// 全量标注
|
|
2683
|
+
console.time('全量标注');
|
|
2684
|
+
nodes = [];
|
|
2685
|
+
this.file2NodeMap.forEach(function (fileNode, filePath) {
|
|
2686
|
+
// 先不排除view,传递给后端的时候,去除views下的标注
|
|
2687
|
+
if (!['Structure', 'DataSource', 'Entity', 'Enum', 'Role'].includes(fileNode.concept)) {
|
|
2688
|
+
fileNode.sourceMap.forEach(function (item, node) {
|
|
2689
|
+
nodes.push({
|
|
2690
|
+
filePath: filePath,
|
|
2691
|
+
node: node,
|
|
2692
|
+
item: item
|
|
2693
|
+
});
|
|
2694
|
+
});
|
|
2695
|
+
}
|
|
2696
|
+
});
|
|
2697
|
+
return [4 /*yield*/, this.getQuickInfoNodesTypeMap(nodes, true)];
|
|
2698
|
+
case 1:
|
|
2699
|
+
typesMap = _a.sent();
|
|
2700
|
+
// console.log(typesMap, 'typesMap')
|
|
2701
|
+
console.timeEnd('全量标注');
|
|
2702
|
+
json = app.toJSON();
|
|
2703
|
+
if (releaseFlag) {
|
|
2704
|
+
// 全量标注后对json进行一些修改,为了服务端翻译处理
|
|
2705
|
+
this.annitationToJson(typesMap, json);
|
|
2706
|
+
}
|
|
2707
|
+
return [2 /*return*/, json];
|
|
2708
|
+
}
|
|
2709
|
+
});
|
|
2710
|
+
});
|
|
2711
|
+
};
|
|
2712
|
+
// 加载全量nasl节点标注
|
|
2713
|
+
NaslServer.prototype.createdNaslAnnotatedJSON = function (app) {
|
|
2714
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2715
|
+
var nodes;
|
|
2716
|
+
return __generator(this, function (_a) {
|
|
2717
|
+
switch (_a.label) {
|
|
2718
|
+
case 0:
|
|
2719
|
+
// 全量标注
|
|
2720
|
+
console.time('全量标注');
|
|
2721
|
+
nodes = [];
|
|
2722
|
+
this.file2NodeMap.forEach(function (fileNode, filePath) {
|
|
2723
|
+
// 先不排除view,传递给后端的时候,去除views下的标注
|
|
2724
|
+
if (!['Structure', 'DataSource', 'Entity', 'Enum', 'Role'].includes(fileNode.concept)) {
|
|
2725
|
+
fileNode.sourceMap.forEach(function (item, node) {
|
|
2726
|
+
nodes.push({
|
|
2727
|
+
filePath: filePath,
|
|
2728
|
+
node: node,
|
|
2729
|
+
item: item
|
|
2730
|
+
});
|
|
2731
|
+
});
|
|
2732
|
+
}
|
|
2733
|
+
});
|
|
2734
|
+
return [4 /*yield*/, this.getQuickInfoNodesTypeMap(nodes, true)];
|
|
2735
|
+
case 1:
|
|
2736
|
+
_a.sent();
|
|
2737
|
+
console.timeEnd('全量标注');
|
|
2738
|
+
return [2 /*return*/];
|
|
2739
|
+
}
|
|
2740
|
+
});
|
|
2741
|
+
});
|
|
2742
|
+
};
|
|
2743
|
+
// 增量标注
|
|
2744
|
+
NaslServer.prototype.IncrementalAnnotationJSON = function (records) {
|
|
2745
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2746
|
+
var nodes;
|
|
2747
|
+
var _this = this;
|
|
2748
|
+
return __generator(this, function (_a) {
|
|
2749
|
+
switch (_a.label) {
|
|
2750
|
+
case 0:
|
|
2751
|
+
nodes = [];
|
|
2752
|
+
records.forEach(function (record) {
|
|
2753
|
+
var fileNode = _this.file2NodeMap.get(record.filePath);
|
|
2754
|
+
if (!fileNode)
|
|
2755
|
+
return;
|
|
2756
|
+
record.id = fileNode.id;
|
|
2757
|
+
record.node = fileNode;
|
|
2758
|
+
if (!['Structure', 'DataSource', 'Entity', 'Enum', 'Role'].includes(fileNode.concept)) {
|
|
2759
|
+
fileNode.sourceMap.forEach(function (item, nodeItem) {
|
|
2760
|
+
nodes.push({
|
|
2761
|
+
filePath: record.filePath,
|
|
2762
|
+
node: nodeItem,
|
|
2763
|
+
item: item
|
|
2764
|
+
});
|
|
2765
|
+
});
|
|
2766
|
+
}
|
|
2767
|
+
});
|
|
2768
|
+
return [4 /*yield*/, this.getQuickInfoNodesTypeMap(nodes)];
|
|
2769
|
+
case 1:
|
|
2770
|
+
_a.sent();
|
|
2771
|
+
return [2 /*return*/];
|
|
2772
|
+
}
|
|
2773
|
+
});
|
|
2774
|
+
});
|
|
2775
|
+
};
|
|
2776
|
+
NaslServer.prototype.annitationToJson = function (typesMap, json) {
|
|
2777
|
+
typesMap.forEach(function (value, node) {
|
|
2778
|
+
var _a, _b, _c, _d;
|
|
2779
|
+
// 如果节点本身有类型就不去在塞一遍了
|
|
2780
|
+
// 有值而且没有类型再去设置
|
|
2781
|
+
// 但是Identifier 和 MemberExpression 都用标注出来的因为本身是变量,有类型也需要覆盖一下
|
|
2782
|
+
if (value && (!node.typeAnnotation || node instanceof concepts_1.Identifier || node instanceof concepts_1.MemberExpression)) {
|
|
2783
|
+
var jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
|
|
2784
|
+
if (jsonNode) {
|
|
2785
|
+
if (node instanceof concepts_1.Argument) {
|
|
2786
|
+
jsonNode.defaultValue = value.option.defaultValue;
|
|
2787
|
+
jsonNode.typeAnnotation = (_b = (_a = value) === null || _a === void 0 ? void 0 : _a.typeAnnotation) === null || _b === void 0 ? void 0 : _b.toJSON();
|
|
2788
|
+
}
|
|
2789
|
+
else {
|
|
2790
|
+
jsonNode.typeAnnotation = (_c = value) === null || _c === void 0 ? void 0 : _c.toJSON();
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2793
|
+
}
|
|
2794
|
+
// 旧版本数据查询需要确认是匿名数据结构的 ListTotal 类型
|
|
2795
|
+
if (node instanceof concepts_1.CallQueryComponent && node.ideVersion !== '2.11') {
|
|
2796
|
+
var jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
|
|
2797
|
+
jsonNode.typeAnnotation = {
|
|
2798
|
+
concept: 'TypeAnnotation',
|
|
2799
|
+
typeKind: 'anonymousStructure',
|
|
2800
|
+
typeNamespace: null,
|
|
2801
|
+
typeName: null,
|
|
2802
|
+
typeArguments: [],
|
|
2803
|
+
inferred: false,
|
|
2804
|
+
ruleMap: null,
|
|
2805
|
+
properties: [{
|
|
2806
|
+
concept: 'StructureProperty',
|
|
2807
|
+
name: 'list',
|
|
2808
|
+
label: null,
|
|
2809
|
+
description: null,
|
|
2810
|
+
typeAnnotation: {
|
|
2811
|
+
concept: 'TypeAnnotation',
|
|
2812
|
+
typeKind: 'generic',
|
|
2813
|
+
typeNamespace: 'nasl.collection',
|
|
2814
|
+
typeName: 'List',
|
|
2815
|
+
typeArguments: [jsonNode.typeAnnotation],
|
|
2816
|
+
inferred: null
|
|
2817
|
+
},
|
|
2818
|
+
required: null,
|
|
2819
|
+
defaultValue: null
|
|
2820
|
+
}, {
|
|
2821
|
+
concept: 'StructureProperty',
|
|
2822
|
+
name: 'total',
|
|
2823
|
+
label: null,
|
|
2824
|
+
description: null,
|
|
2825
|
+
typeAnnotation: {
|
|
2826
|
+
concept: 'TypeAnnotation',
|
|
2827
|
+
typeKind: 'primitive',
|
|
2828
|
+
typeNamespace: 'nasl.core',
|
|
2829
|
+
typeName: 'Integer',
|
|
2830
|
+
typeArguments: null,
|
|
2831
|
+
inferred: null
|
|
2832
|
+
},
|
|
2833
|
+
required: null,
|
|
2834
|
+
defaultValue: null
|
|
2835
|
+
}]
|
|
2836
|
+
};
|
|
2837
|
+
}
|
|
2838
|
+
// 特殊处理param有类型错误的
|
|
2839
|
+
if (node instanceof concepts_1.Param) {
|
|
2840
|
+
// index在nasl foreach上有脏数据
|
|
2841
|
+
if (node.parentKey === 'index' && node.parentNode instanceof concepts_1.ForEachStatement) {
|
|
2842
|
+
var jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
|
|
2843
|
+
jsonNode.typeAnnotation = concepts_1.TypeAnnotation.createPrimitive('Integer').toJSON();
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
if (node instanceof concepts_1.Match) {
|
|
2847
|
+
var matchExpression_1 = node.expression;
|
|
2848
|
+
if (((_d = matchExpression_1 === null || matchExpression_1 === void 0 ? void 0 : matchExpression_1.__TypeAnnotation) === null || _d === void 0 ? void 0 : _d.typeKind) === 'union' && (matchExpression_1 instanceof concepts_1.Identifier || matchExpression_1 instanceof concepts_1.MemberExpression)) {
|
|
2849
|
+
var _e = matchExpression_1 === null || matchExpression_1 === void 0 ? void 0 : matchExpression_1.getCurrentSource(), currentSource_4 = _e.currentSource, fileNode = _e.fileNode;
|
|
2850
|
+
fileNode.sourceMap.forEach(function (item, itemNode) {
|
|
2851
|
+
if (itemNode.concept === matchExpression_1.concept && item.code === currentSource_4.code) {
|
|
2852
|
+
var jsonNode = jsoner.queryNodeByPath(json, itemNode.getNodePath(false));
|
|
2853
|
+
jsonNode.typeAnnotation = matchExpression_1.__TypeAnnotation;
|
|
2854
|
+
}
|
|
2855
|
+
});
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
// 特殊处理param有类型错误的
|
|
2859
|
+
if (node instanceof concepts_1.Param && value) {
|
|
2860
|
+
// index在nasl foreach上有脏数据
|
|
2861
|
+
if (node.parentKey === 'index' && node.parentNode instanceof concepts_1.ForEachStatement) {
|
|
2862
|
+
var jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
|
|
2863
|
+
jsonNode.typeAnnotation = value.toJSON();
|
|
2864
|
+
}
|
|
2865
|
+
}
|
|
2866
|
+
});
|
|
2867
|
+
};
|
|
2868
|
+
/**
|
|
2869
|
+
* 获取getArgument的参数位的类型
|
|
2870
|
+
* 如果内部表达式的,就用表达式的,如果没有就试试用默认值的
|
|
2871
|
+
* 获取logic的默认值和原来Arg的类型和默认值对应
|
|
2872
|
+
*/
|
|
2873
|
+
NaslServer.prototype.getArgumentTypeAnnotation = function (node, QuickInfoNodes, types) {
|
|
2874
|
+
var _a, _b, _c;
|
|
2875
|
+
// 直接复用内部expression的type类型
|
|
2876
|
+
if (node.parentNode instanceof concepts_1.CallLogic && node.parentNode.calleeNamespace.includes('entities') && node.parentNode.calleeNamespace.includes('logics') && node.parentNode.calleeName === 'delete') {
|
|
2877
|
+
var nodeType = (_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.__nodeType;
|
|
2878
|
+
if (nodeType && Array.isArray(nodeType.fnParams)) {
|
|
2879
|
+
var index_1 = node.parentNode.arguments.indexOf(node);
|
|
2880
|
+
var type = (_b = nodeType.fnParams[index_1]) === null || _b === void 0 ? void 0 : _b.typeInfo;
|
|
2881
|
+
var nodeTypeAnnotation = formatTsUtils_1.type2TypeAnnotation(type);
|
|
2882
|
+
if (nodeTypeAnnotation) {
|
|
2883
|
+
return {
|
|
2884
|
+
typeAnnotation: nodeTypeAnnotation,
|
|
2885
|
+
option: {}
|
|
2886
|
+
};
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
// 获取返回值结果里找到父级的callLogic || CallInterface的类型填充进去Argument
|
|
2891
|
+
var App = node.app;
|
|
2892
|
+
var parent = (node.parentNode);
|
|
2893
|
+
// 如果nasl包下的 ,很多声明都含有T啥的先用自己内部的
|
|
2894
|
+
if (!parent.calleeNamespace || parent.calleeNamespace.startsWith('nasl')) {
|
|
2895
|
+
if (types.get(node.expression)) {
|
|
2896
|
+
return {
|
|
2897
|
+
typeAnnotation: types.get(node.expression),
|
|
2898
|
+
option: {}
|
|
2899
|
+
};
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
// 用户自己声明的用用户的
|
|
2903
|
+
var callObj = App.findNodeByCompleteName(parent.calleeNamespace + '.' + parent.calleeName);
|
|
2904
|
+
var index = parent.arguments.indexOf(node);
|
|
2905
|
+
var param = ((_c = callObj === null || callObj === void 0 ? void 0 : callObj.params) === null || _c === void 0 ? void 0 : _c[index]) || {};
|
|
2906
|
+
// 取出参数的类型
|
|
2907
|
+
// 设置类型
|
|
2908
|
+
return {
|
|
2909
|
+
typeAnnotation: param.typeAnnotation,
|
|
2910
|
+
// 设置默认值
|
|
2911
|
+
option: { defaultValue: param.defaultValue }
|
|
2912
|
+
};
|
|
2913
|
+
};
|
|
2914
|
+
NaslServer.prototype.getCurrentTypeAnnotation = function (node) {
|
|
2915
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2916
|
+
return __generator(this, function (_a) {
|
|
2917
|
+
if (node.__TypeAnnotation) {
|
|
2918
|
+
return [2 /*return*/, node.__TypeAnnotation];
|
|
2919
|
+
}
|
|
2920
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
2921
|
+
var myTimer = setTimeout(function () {
|
|
2922
|
+
console.log(node, '没有获取到类型');
|
|
2923
|
+
clearTimeout(myTimer);
|
|
2924
|
+
clearInterval(mySetInterval);
|
|
2925
|
+
resolve(node.__TypeAnnotation);
|
|
2926
|
+
}, 600);
|
|
2927
|
+
var mySetInterval = setInterval(function () {
|
|
2928
|
+
if (node.__TypeAnnotation) {
|
|
2929
|
+
resolve(node.__TypeAnnotation);
|
|
2930
|
+
clearInterval(mySetInterval);
|
|
2931
|
+
clearTimeout(myTimer);
|
|
2932
|
+
}
|
|
2933
|
+
}, 50);
|
|
2934
|
+
})];
|
|
2935
|
+
});
|
|
2936
|
+
});
|
|
2937
|
+
};
|
|
2938
|
+
// 获取节点标注,去动态查
|
|
2939
|
+
NaslServer.prototype.getBaseNodesTypeMap = function (nodes) {
|
|
2940
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2941
|
+
var args, typesMap;
|
|
2942
|
+
return __generator(this, function (_a) {
|
|
2943
|
+
switch (_a.label) {
|
|
2944
|
+
case 0:
|
|
2945
|
+
args = nodes.map(function (item) {
|
|
2946
|
+
var _a = item.getCurrentSource(), currentSource = _a.currentSource, fileNode = _a.fileNode;
|
|
2947
|
+
return {
|
|
2948
|
+
filePath: fileNode.getEmbeddedFilePath(),
|
|
2949
|
+
node: item,
|
|
2950
|
+
item: currentSource
|
|
2951
|
+
};
|
|
2952
|
+
});
|
|
2953
|
+
return [4 /*yield*/, this.getQuickInfoNodesTypeMap(args)];
|
|
2954
|
+
case 1:
|
|
2955
|
+
typesMap = _a.sent();
|
|
2956
|
+
return [2 /*return*/, typesMap];
|
|
2957
|
+
}
|
|
2958
|
+
});
|
|
2959
|
+
});
|
|
2960
|
+
};
|
|
2961
|
+
NaslServer.prototype._getTypeStrFull = function (args) {
|
|
2962
|
+
return this.messager.requestCommand('typeStrFull', args);
|
|
2963
|
+
};
|
|
2964
|
+
NaslServer.prototype.getNaslNodeTypeStrFull = function (args) {
|
|
2965
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2966
|
+
var result;
|
|
2967
|
+
return __generator(this, function (_a) {
|
|
2968
|
+
switch (_a.label) {
|
|
2969
|
+
case 0: return [4 /*yield*/, this._getTypeStrFull(args)];
|
|
2970
|
+
case 1:
|
|
2971
|
+
result = _a.sent();
|
|
2972
|
+
return [2 /*return*/, result];
|
|
2973
|
+
}
|
|
2974
|
+
});
|
|
2975
|
+
});
|
|
2976
|
+
};
|
|
2977
|
+
/**
|
|
2978
|
+
* 处理删除节点
|
|
2979
|
+
* @param fileNode 当前删除节点的文件级别节点
|
|
2980
|
+
* @param targetNode 当前操作的节点
|
|
2981
|
+
* @param result toTs生成的内容
|
|
2982
|
+
*/
|
|
2983
|
+
NaslServer.prototype.handleDelete = function (fileNode, targetNode, result) {
|
|
2984
|
+
var _a, _b;
|
|
2985
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2986
|
+
var filePath, outputFiles, newRefs;
|
|
2987
|
+
return __generator(this, function (_c) {
|
|
2988
|
+
switch (_c.label) {
|
|
2989
|
+
case 0:
|
|
2990
|
+
filePath = fileNode.getEmbeddedFilePath();
|
|
2991
|
+
outputFiles = [];
|
|
2992
|
+
return [4 /*yield*/, this.references({
|
|
2993
|
+
file: result.filePath,
|
|
2994
|
+
line: (_a = EmbeddedTSFileLineMap[fileNode.concept]) !== null && _a !== void 0 ? _a : 2,
|
|
2995
|
+
offset: (_b = EmbeddedTSFileOffsetMap[fileNode.concept]) !== null && _b !== void 0 ? _b : 6
|
|
2996
|
+
})];
|
|
2997
|
+
case 1:
|
|
2998
|
+
newRefs = _c.sent();
|
|
2999
|
+
// 如果是要删除的内容,就是当前的file节点,要关闭当前文件,就把内容置为空
|
|
3000
|
+
if (fileNode === targetNode) {
|
|
3001
|
+
outputFiles = [{ file: filePath, fileContent: '' }];
|
|
3002
|
+
}
|
|
3003
|
+
else {
|
|
3004
|
+
// 如果是要删除logic一个小内容,要覆盖全部内容
|
|
3005
|
+
// 其余要删除的都是把原来的file节点的内容全部覆盖一把
|
|
3006
|
+
outputFiles = [{ file: result.filePath, fileContent: result.code }];
|
|
3007
|
+
}
|
|
3008
|
+
// 更新文件之后
|
|
3009
|
+
return [4 /*yield*/, this.updateFiles({ outputFiles: outputFiles })];
|
|
3010
|
+
case 2:
|
|
3011
|
+
// 更新文件之后
|
|
3012
|
+
_c.sent();
|
|
3013
|
+
newRefs.refs.forEach(function (ref) { return filesToCheck.add(ref.file); });
|
|
3014
|
+
return [2 /*return*/];
|
|
3015
|
+
}
|
|
3016
|
+
});
|
|
3017
|
+
});
|
|
3018
|
+
};
|
|
3019
|
+
/**
|
|
3020
|
+
* 除去rename场景下的更新
|
|
3021
|
+
* @param fileNode 文件级别的节点
|
|
3022
|
+
* @param targetNode 触发修改的节点
|
|
3023
|
+
* @param result 生成代码的code 和位置信息
|
|
3024
|
+
*/
|
|
3025
|
+
NaslServer.prototype.handleChange = function (fileNode, targetNode, result, action) {
|
|
3026
|
+
var _a, _b;
|
|
3027
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3028
|
+
var outputFiles, newRefs, confirmParms;
|
|
3029
|
+
return __generator(this, function (_c) {
|
|
3030
|
+
switch (_c.label) {
|
|
3031
|
+
case 0:
|
|
3032
|
+
this.file2NodeMap.set(result.filePath, fileNode);
|
|
3033
|
+
outputFiles = [{ file: result.filePath, fileContent: result.code }];
|
|
3034
|
+
// 创建和更新都用update,内部会做判断
|
|
3035
|
+
return [4 /*yield*/, this.updateFiles({ outputFiles: outputFiles })];
|
|
3036
|
+
case 1:
|
|
3037
|
+
// 创建和更新都用update,内部会做判断
|
|
3038
|
+
_c.sent();
|
|
3039
|
+
return [4 /*yield*/, this.references({
|
|
3040
|
+
file: result.filePath,
|
|
3041
|
+
line: (_a = EmbeddedTSFileLineMap[fileNode.concept]) !== null && _a !== void 0 ? _a : 2,
|
|
3042
|
+
offset: (_b = EmbeddedTSFileOffsetMap[fileNode.concept]) !== null && _b !== void 0 ? _b : 6
|
|
3043
|
+
})];
|
|
3044
|
+
case 2:
|
|
3045
|
+
newRefs = _c.sent();
|
|
3046
|
+
newRefs.refs.forEach(function (ref) { return filesToCheck.add(ref.file); });
|
|
3047
|
+
// 唤起建立连接弹框
|
|
3048
|
+
// 文件级别的建立连接采取提醒
|
|
3049
|
+
if (action === 'create' && targetNode.__init) {
|
|
3050
|
+
// 清除临时状态, 完成本次创建
|
|
3051
|
+
delete targetNode.__init;
|
|
3052
|
+
if (fileNode === targetNode && filesToCheck.size > 1) {
|
|
3053
|
+
confirmParms = {
|
|
3054
|
+
actionType: 'createEstablishConnection',
|
|
3055
|
+
node: fileNode,
|
|
3056
|
+
icon: 'success'
|
|
3057
|
+
};
|
|
3058
|
+
common_1.invokeCommand('tsConfirm.open', confirmParms, function () { });
|
|
3059
|
+
}
|
|
3060
|
+
}
|
|
3061
|
+
return [2 /*return*/];
|
|
3062
|
+
}
|
|
3063
|
+
});
|
|
3064
|
+
});
|
|
3065
|
+
};
|
|
3066
|
+
/**
|
|
3067
|
+
* 重命名的更新
|
|
3068
|
+
* @param fileNode 文件级别的节点
|
|
3069
|
+
* @param targetNode 触发修改的节点
|
|
3070
|
+
* @param result 生成代码的code 和位置信息
|
|
3071
|
+
* @param isRename 是不是修改名字
|
|
3072
|
+
* @param oldFilePath 如果是改名,文件级别的才会有这个参数,用于文件新增替换
|
|
3073
|
+
*/
|
|
3074
|
+
NaslServer.prototype.handleRename = function (fileNode, targetNode, result, oldFilePath) {
|
|
3075
|
+
var _a, _b, _c, _d, _e, _f;
|
|
3076
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3077
|
+
var outputFiles, oldRefs, newRefs, newRefFileList_1, newRefs2, _g, currentSource, fileNode_2, oldRefs, newRefs2;
|
|
3078
|
+
return __generator(this, function (_h) {
|
|
3079
|
+
switch (_h.label) {
|
|
3080
|
+
case 0:
|
|
3081
|
+
outputFiles = [{ file: result.filePath, fileContent: result.code }];
|
|
3082
|
+
if (!(fileNode === targetNode)) return [3 /*break*/, 4];
|
|
3083
|
+
this.file2NodeMap["delete"](oldFilePath);
|
|
3084
|
+
this.file2NodeMap.set(result.filePath, fileNode);
|
|
3085
|
+
// 修改名字新的添加进去,旧的置为空
|
|
3086
|
+
outputFiles.unshift({ file: oldFilePath, fileContent: '' });
|
|
3087
|
+
return [4 /*yield*/, this.references({
|
|
3088
|
+
file: oldFilePath,
|
|
3089
|
+
line: (_a = EmbeddedTSFileLineMap[fileNode.concept]) !== null && _a !== void 0 ? _a : 2,
|
|
3090
|
+
offset: (_b = EmbeddedTSFileOffsetMap[fileNode.concept]) !== null && _b !== void 0 ? _b : 6
|
|
3091
|
+
})];
|
|
3092
|
+
case 1:
|
|
3093
|
+
oldRefs = _h.sent();
|
|
3094
|
+
oldRefs.refs.forEach(function (ref) { return filesToCheck.add(ref.file); });
|
|
3095
|
+
filesToCheck["delete"](oldFilePath);
|
|
3096
|
+
// 更新文件之后
|
|
3097
|
+
return [4 /*yield*/, this.updateFiles({ outputFiles: outputFiles })];
|
|
3098
|
+
case 2:
|
|
3099
|
+
// 更新文件之后
|
|
3100
|
+
_h.sent();
|
|
3101
|
+
return [4 /*yield*/, this.references({
|
|
3102
|
+
file: result.filePath,
|
|
3103
|
+
line: (_c = EmbeddedTSFileLineMap[fileNode.concept]) !== null && _c !== void 0 ? _c : 2,
|
|
3104
|
+
offset: (_d = EmbeddedTSFileOffsetMap[fileNode.concept]) !== null && _d !== void 0 ? _d : 6
|
|
3105
|
+
})];
|
|
3106
|
+
case 3:
|
|
3107
|
+
newRefs = _h.sent();
|
|
3108
|
+
newRefFileList_1 = new Set();
|
|
3109
|
+
newRefs.refs.forEach(function (ref) {
|
|
3110
|
+
filesToCheck.add(ref.file);
|
|
3111
|
+
newRefFileList_1.add(ref.file);
|
|
3112
|
+
});
|
|
3113
|
+
return [3 /*break*/, 11];
|
|
3114
|
+
case 4:
|
|
3115
|
+
if (!(targetNode instanceof concepts_1.ViewElement)) return [3 /*break*/, 7];
|
|
3116
|
+
/**
|
|
3117
|
+
* 因为页面组件比较特殊
|
|
3118
|
+
* 修改之后只用查页面本身就好了
|
|
3119
|
+
*/
|
|
3120
|
+
// 更新文件之后
|
|
3121
|
+
return [4 /*yield*/, this.updateFiles({ outputFiles: outputFiles })];
|
|
3122
|
+
case 5:
|
|
3123
|
+
/**
|
|
3124
|
+
* 因为页面组件比较特殊
|
|
3125
|
+
* 修改之后只用查页面本身就好了
|
|
3126
|
+
*/
|
|
3127
|
+
// 更新文件之后
|
|
3128
|
+
_h.sent();
|
|
3129
|
+
return [4 /*yield*/, this.references({
|
|
3130
|
+
file: fileNode.getEmbeddedFilePath(),
|
|
3131
|
+
line: (_e = EmbeddedTSFileLineMap[fileNode.concept]) !== null && _e !== void 0 ? _e : 2,
|
|
3132
|
+
offset: (_f = EmbeddedTSFileOffsetMap[fileNode.concept]) !== null && _f !== void 0 ? _f : 6
|
|
3133
|
+
})];
|
|
3134
|
+
case 6:
|
|
3135
|
+
newRefs2 = _h.sent();
|
|
3136
|
+
newRefs2.refs.forEach(function (ref) { return filesToCheck.add(ref.file); });
|
|
3137
|
+
return [3 /*break*/, 11];
|
|
3138
|
+
case 7:
|
|
3139
|
+
_g = this.getCurrentSource(targetNode), currentSource = _g.currentSource, fileNode_2 = _g.fileNode;
|
|
3140
|
+
if (!currentSource) return [3 /*break*/, 11];
|
|
3141
|
+
return [4 /*yield*/, this.references({
|
|
3142
|
+
file: fileNode_2.getEmbeddedFilePath(),
|
|
3143
|
+
line: translator_1.lsp2tspNumber(currentSource.range.start.line),
|
|
3144
|
+
offset: translator_1.lsp2tspNumber(currentSource.range.start.character)
|
|
3145
|
+
})];
|
|
3146
|
+
case 8:
|
|
3147
|
+
oldRefs = _h.sent();
|
|
3148
|
+
oldRefs.refs.forEach(function (ref) { return filesToCheck.add(ref.file); });
|
|
3149
|
+
// 更新文件之后
|
|
3150
|
+
return [4 /*yield*/, this.updateFiles({ outputFiles: outputFiles })];
|
|
3151
|
+
case 9:
|
|
3152
|
+
// 更新文件之后
|
|
3153
|
+
_h.sent();
|
|
3154
|
+
return [4 /*yield*/, this.references({
|
|
3155
|
+
file: fileNode_2.getEmbeddedFilePath(),
|
|
3156
|
+
line: translator_1.lsp2tspNumber(currentSource.range.start.line),
|
|
3157
|
+
offset: translator_1.lsp2tspNumber(currentSource.range.start.character)
|
|
3158
|
+
})];
|
|
3159
|
+
case 10:
|
|
3160
|
+
newRefs2 = _h.sent();
|
|
3161
|
+
newRefs2.refs.forEach(function (ref) { return filesToCheck.add(ref.file); });
|
|
3162
|
+
_h.label = 11;
|
|
3163
|
+
case 11: return [2 /*return*/];
|
|
3164
|
+
}
|
|
3165
|
+
});
|
|
3166
|
+
});
|
|
3167
|
+
};
|
|
3168
|
+
/**
|
|
3169
|
+
* 处理一些节点操作,子节点需要更新并且check的场景
|
|
3170
|
+
* 因为删除,新增父页面,或者重命名会一起
|
|
3171
|
+
* 删除或者新增view而且他有子集 就要执行同样的操作
|
|
3172
|
+
* @param action 当前操作类型
|
|
3173
|
+
* @param fileNode 文件节点
|
|
3174
|
+
* @param targetNode 操作节点 这里要两个相等才会走家去面对哦逻辑
|
|
3175
|
+
* @param oldpath 触发内容的oldpath
|
|
3176
|
+
*/
|
|
3177
|
+
NaslServer.prototype.incidentalAction = function (action, fileNode, targetNode, oldpath) {
|
|
3178
|
+
var _a;
|
|
3179
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3180
|
+
var fileNodeChildren, i, fileNodeItem, result, parentPath, currentOldPath, module_1, results, i, result, node;
|
|
3181
|
+
var _this = this;
|
|
3182
|
+
return __generator(this, function (_b) {
|
|
3183
|
+
switch (_b.label) {
|
|
3184
|
+
case 0:
|
|
3185
|
+
if (!((action === 'create' || action === 'delete' || (action === 'update' && oldpath)) && fileNode === targetNode)) return [3 /*break*/, 19];
|
|
3186
|
+
if (!(fileNode instanceof concepts_1.View && ((_a = fileNode.children) === null || _a === void 0 ? void 0 : _a.length))) return [3 /*break*/, 11];
|
|
3187
|
+
fileNodeChildren = fileNode.children;
|
|
3188
|
+
i = 0;
|
|
3189
|
+
_b.label = 1;
|
|
3190
|
+
case 1:
|
|
3191
|
+
if (!(i < fileNodeChildren.length)) return [3 /*break*/, 11];
|
|
3192
|
+
fileNodeItem = fileNodeChildren[i];
|
|
3193
|
+
result = fileNodeItem.toEmbeddedTSFile();
|
|
3194
|
+
fileNodeItem.sourceMap = result.sourceMap;
|
|
3195
|
+
if (!(action === 'create')) return [3 /*break*/, 4];
|
|
3196
|
+
return [4 /*yield*/, this.handleChange(fileNodeItem, fileNodeItem, result, action)];
|
|
3197
|
+
case 2:
|
|
3198
|
+
_b.sent();
|
|
3199
|
+
return [4 /*yield*/, this.incidentalAction(action, fileNodeItem, fileNodeItem)];
|
|
3200
|
+
case 3:
|
|
3201
|
+
_b.sent();
|
|
3202
|
+
return [3 /*break*/, 10];
|
|
3203
|
+
case 4:
|
|
3204
|
+
if (!(action === 'delete')) return [3 /*break*/, 7];
|
|
3205
|
+
return [4 /*yield*/, this.handleDelete(fileNodeItem, fileNodeItem, result)];
|
|
3206
|
+
case 5:
|
|
3207
|
+
_b.sent();
|
|
3208
|
+
return [4 /*yield*/, this.incidentalAction(action, fileNodeItem, fileNodeItem)];
|
|
3209
|
+
case 6:
|
|
3210
|
+
_b.sent();
|
|
3211
|
+
return [3 /*break*/, 10];
|
|
3212
|
+
case 7:
|
|
3213
|
+
if (!(action === 'update' && oldpath)) return [3 /*break*/, 10];
|
|
3214
|
+
parentPath = oldpath.replace('.ts', '/');
|
|
3215
|
+
currentOldPath = parentPath + fileNodeItem.name + '.ts';
|
|
3216
|
+
// 因为重命名这里只有当前修改父级的 旧名称, 所以他的子集也要根据旧名称去查依赖 更新内容
|
|
3217
|
+
return [4 /*yield*/, this.handleRename(fileNodeItem, fileNodeItem, result, currentOldPath)];
|
|
3218
|
+
case 8:
|
|
3219
|
+
// 因为重命名这里只有当前修改父级的 旧名称, 所以他的子集也要根据旧名称去查依赖 更新内容
|
|
3220
|
+
_b.sent();
|
|
3221
|
+
return [4 /*yield*/, this.incidentalAction(action, fileNodeItem, fileNodeItem, currentOldPath)];
|
|
3222
|
+
case 9:
|
|
3223
|
+
_b.sent();
|
|
3224
|
+
_b.label = 10;
|
|
3225
|
+
case 10:
|
|
3226
|
+
i++;
|
|
3227
|
+
return [3 /*break*/, 1];
|
|
3228
|
+
case 11:
|
|
3229
|
+
if (!(fileNode instanceof concepts_1.Module)) return [3 /*break*/, 18];
|
|
3230
|
+
if (fileNode.type === 'interface' && fileNode.isAdd && action === 'create') {
|
|
3231
|
+
isChangeInterface = true;
|
|
3232
|
+
}
|
|
3233
|
+
module_1 = targetNode;
|
|
3234
|
+
results = [];
|
|
3235
|
+
this.contentToFile(module_1, results);
|
|
3236
|
+
i = 0;
|
|
3237
|
+
_b.label = 12;
|
|
3238
|
+
case 12:
|
|
3239
|
+
if (!(i < results.length)) return [3 /*break*/, 17];
|
|
3240
|
+
result = results[i];
|
|
3241
|
+
node = this.file2NodeMap.get(result.filePath);
|
|
3242
|
+
if (!(action === 'create')) return [3 /*break*/, 14];
|
|
3243
|
+
return [4 /*yield*/, this.handleChange(node, node, result, action)];
|
|
3244
|
+
case 13:
|
|
3245
|
+
_b.sent();
|
|
3246
|
+
return [3 /*break*/, 16];
|
|
3247
|
+
case 14: return [4 /*yield*/, this.handleDelete(node, node, result)];
|
|
3248
|
+
case 15:
|
|
3249
|
+
_b.sent();
|
|
3250
|
+
_b.label = 16;
|
|
3251
|
+
case 16:
|
|
3252
|
+
i++;
|
|
3253
|
+
return [3 /*break*/, 12];
|
|
3254
|
+
case 17:
|
|
3255
|
+
// 删除模块通知更新列表
|
|
3256
|
+
if (action === 'delete') {
|
|
3257
|
+
try {
|
|
3258
|
+
// 如果已经
|
|
3259
|
+
common_1.invokeCommand('module.delete', true);
|
|
3260
|
+
}
|
|
3261
|
+
catch (err) {
|
|
3262
|
+
console.log('module.delete', '组件销毁了,不用唤起了');
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
_b.label = 18;
|
|
3266
|
+
case 18:
|
|
3267
|
+
/**
|
|
3268
|
+
* DataSource只会重命名时候,需要把子集全部重新生成一下
|
|
3269
|
+
*/
|
|
3270
|
+
if (fileNode instanceof concepts_1.DataSource) {
|
|
3271
|
+
fileNode.entities.forEach(function (entity) { return __awaiter(_this, void 0, void 0, function () {
|
|
3272
|
+
var result, parentPath, currentOldPath, err_2;
|
|
3273
|
+
return __generator(this, function (_a) {
|
|
3274
|
+
switch (_a.label) {
|
|
3275
|
+
case 0:
|
|
3276
|
+
_a.trys.push([0, 2, , 3]);
|
|
3277
|
+
result = entity.toEmbeddedTSFile();
|
|
3278
|
+
parentPath = oldpath.replace('.ts', '/');
|
|
3279
|
+
currentOldPath = parentPath + '/entities/' + entity.name + '.ts';
|
|
3280
|
+
// 因为重命名这里只有当前修改父级的 旧名称, 所以他的子集也要根据旧名称去查依赖 更新内容
|
|
3281
|
+
return [4 /*yield*/, this.handleRename(entity, entity, result, currentOldPath)];
|
|
3282
|
+
case 1:
|
|
3283
|
+
// 因为重命名这里只有当前修改父级的 旧名称, 所以他的子集也要根据旧名称去查依赖 更新内容
|
|
3284
|
+
_a.sent();
|
|
3285
|
+
return [3 /*break*/, 3];
|
|
3286
|
+
case 2:
|
|
3287
|
+
err_2 = _a.sent();
|
|
3288
|
+
console.log(err_2);
|
|
3289
|
+
return [3 /*break*/, 3];
|
|
3290
|
+
case 3: return [2 /*return*/];
|
|
3291
|
+
}
|
|
3292
|
+
});
|
|
3293
|
+
}); });
|
|
3294
|
+
}
|
|
3295
|
+
_b.label = 19;
|
|
3296
|
+
case 19: return [2 /*return*/];
|
|
3297
|
+
}
|
|
3298
|
+
});
|
|
3299
|
+
});
|
|
3300
|
+
};
|
|
3301
|
+
NaslServer.prototype.receiveHandleChange = function ($event) {
|
|
3302
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3303
|
+
var action, targetNode, fileNode, result, oldpath;
|
|
3304
|
+
return __generator(this, function (_a) {
|
|
3305
|
+
switch (_a.label) {
|
|
3306
|
+
case 0:
|
|
3307
|
+
singleFileChangeIng = true;
|
|
3308
|
+
action = $event.action;
|
|
3309
|
+
targetNode = $event.target;
|
|
3310
|
+
fileNode = this.getCurrentSource(targetNode).fileNode;
|
|
3311
|
+
if (!(!fileNode || fileNode instanceof concepts_1.Module || fileNode instanceof concepts_1.Configuration)) return [3 /*break*/, 3];
|
|
3312
|
+
if (!(fileNode instanceof concepts_1.Module)) return [3 /*break*/, 2];
|
|
3313
|
+
return [4 /*yield*/, this.incidentalAction(action, fileNode, targetNode)];
|
|
3314
|
+
case 1:
|
|
3315
|
+
_a.sent();
|
|
3316
|
+
_a.label = 2;
|
|
3317
|
+
case 2: return [2 /*return*/];
|
|
3318
|
+
case 3:
|
|
3319
|
+
result = fileNode.toEmbeddedTSFile();
|
|
3320
|
+
// 当前操作的节点
|
|
3321
|
+
// 如果当前没有生成tsFile
|
|
3322
|
+
if (!result) {
|
|
3323
|
+
return [2 /*return*/];
|
|
3324
|
+
}
|
|
3325
|
+
// 修改触发修改文件
|
|
3326
|
+
this._debugInFileStorage(targetNode, [
|
|
3327
|
+
{
|
|
3328
|
+
file: result.filePath,
|
|
3329
|
+
fileContent: result.code
|
|
3330
|
+
},
|
|
3331
|
+
]);
|
|
3332
|
+
fileNode.sourceMap = result.sourceMap;
|
|
3333
|
+
if (!(action === 'update' || action === 'create')) return [3 /*break*/, 9];
|
|
3334
|
+
if (!(($event === null || $event === void 0 ? void 0 : $event.field) !== 'name')) return [3 /*break*/, 6];
|
|
3335
|
+
return [4 /*yield*/, this.handleChange(fileNode, targetNode, result, action)];
|
|
3336
|
+
case 4:
|
|
3337
|
+
_a.sent();
|
|
3338
|
+
return [4 /*yield*/, this.incidentalAction(action, fileNode, targetNode)];
|
|
3339
|
+
case 5:
|
|
3340
|
+
_a.sent();
|
|
3341
|
+
return [3 /*break*/, 9];
|
|
3342
|
+
case 6:
|
|
3343
|
+
oldpath = fileNode.getEmbeddedFilePath($event.oldObject.name);
|
|
3344
|
+
return [4 /*yield*/, this.handleRename(fileNode, targetNode, result, oldpath)];
|
|
3345
|
+
case 7:
|
|
3346
|
+
_a.sent();
|
|
3347
|
+
return [4 /*yield*/, this.incidentalAction(action, fileNode, targetNode, oldpath)];
|
|
3348
|
+
case 8:
|
|
3349
|
+
_a.sent();
|
|
3350
|
+
_a.label = 9;
|
|
3351
|
+
case 9:
|
|
3352
|
+
if (!(action === 'delete')) return [3 /*break*/, 12];
|
|
3353
|
+
return [4 /*yield*/, this.incidentalAction(action, fileNode, targetNode)];
|
|
3354
|
+
case 10:
|
|
3355
|
+
_a.sent();
|
|
3356
|
+
return [4 /*yield*/, this.handleDelete(fileNode, targetNode, result)];
|
|
3357
|
+
case 11:
|
|
3358
|
+
_a.sent();
|
|
3359
|
+
_a.label = 12;
|
|
3360
|
+
case 12: return [2 /*return*/, true];
|
|
3361
|
+
}
|
|
3362
|
+
});
|
|
3363
|
+
});
|
|
3364
|
+
};
|
|
3365
|
+
NaslServer.prototype.changeFileNext = function () {
|
|
3366
|
+
var _this = this;
|
|
3367
|
+
if (!singleFileChangeIng) {
|
|
3368
|
+
var item = this.changeStackList.shift();
|
|
3369
|
+
this.receiveHandleChange(item)["catch"](function (err) {
|
|
3370
|
+
console.log(err, 'receiveHandleChangeErr');
|
|
3371
|
+
})["finally"](function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3372
|
+
return __generator(this, function (_a) {
|
|
3373
|
+
switch (_a.label) {
|
|
3374
|
+
case 0:
|
|
3375
|
+
// 每一个文件与change接触就把状态置为false,让下一个进入
|
|
3376
|
+
singleFileChangeIng = false;
|
|
3377
|
+
if (!this.changeStackList.length) return [3 /*break*/, 1];
|
|
3378
|
+
this.changeFileNext();
|
|
3379
|
+
return [3 /*break*/, 3];
|
|
3380
|
+
case 1:
|
|
3381
|
+
// console.log(Array.from(filesToCheck));
|
|
3382
|
+
return [4 /*yield*/, this.getDiagnosticRecordsAndPushAll(Array.from(filesToCheck))];
|
|
3383
|
+
case 2:
|
|
3384
|
+
// console.log(Array.from(filesToCheck));
|
|
3385
|
+
_a.sent();
|
|
3386
|
+
filesToCheck.clear();
|
|
3387
|
+
_a.label = 3;
|
|
3388
|
+
case 3: return [2 /*return*/];
|
|
3389
|
+
}
|
|
3390
|
+
});
|
|
3391
|
+
}); });
|
|
3392
|
+
}
|
|
3393
|
+
};
|
|
3394
|
+
return NaslServer;
|
|
3395
|
+
}());
|
|
3396
|
+
exports.NaslServer = NaslServer;
|