@lcap/nasl 2.18.0-beta.7 → 2.20.0-beta.1

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.
Files changed (336) hide show
  1. package/out/automate/engine/index.js +3 -3
  2. package/out/automate/engine/index.js.map +1 -1
  3. package/out/bak/translator.js +85 -37
  4. package/out/bak/translator.js.map +1 -1
  5. package/out/common/BaseNode.d.ts +6 -10
  6. package/out/common/BaseNode.js +7 -53
  7. package/out/common/BaseNode.js.map +1 -1
  8. package/out/concepts/AnonymousFunction__.js.map +1 -1
  9. package/out/concepts/App__.d.ts +0 -10
  10. package/out/concepts/App__.js +0 -74
  11. package/out/concepts/App__.js.map +1 -1
  12. package/out/concepts/Assignee__.js.map +1 -1
  13. package/out/concepts/AssignmentLine__.d.ts +5 -5
  14. package/out/concepts/AssignmentLine__.js +6 -6
  15. package/out/concepts/AssignmentLine__.js.map +1 -1
  16. package/out/concepts/Assignment__.js +2 -1
  17. package/out/concepts/Assignment__.js.map +1 -1
  18. package/out/concepts/BatchAssignment__.d.ts +60 -60
  19. package/out/concepts/BatchAssignment__.js +41 -68
  20. package/out/concepts/BatchAssignment__.js.map +1 -1
  21. package/out/concepts/BindAttribute__.d.ts +0 -19
  22. package/out/concepts/BindAttribute__.js +2 -39
  23. package/out/concepts/BindAttribute__.js.map +1 -1
  24. package/out/concepts/BindEvent__.js.map +1 -1
  25. package/out/concepts/BindStyle__.d.ts +2 -2
  26. package/out/concepts/BindStyle__.js +3 -3
  27. package/out/concepts/BindStyle__.js.map +1 -1
  28. package/out/concepts/BooleanLiteral__.js +8 -0
  29. package/out/concepts/BooleanLiteral__.js.map +1 -1
  30. package/out/concepts/CallFunction__.js +25 -58
  31. package/out/concepts/CallFunction__.js.map +1 -1
  32. package/out/concepts/CallInterface__.d.ts +0 -7
  33. package/out/concepts/CallInterface__.js +7 -53
  34. package/out/concepts/CallInterface__.js.map +1 -1
  35. package/out/concepts/CallLogic__.d.ts +1 -2
  36. package/out/concepts/CallLogic__.js +25 -89
  37. package/out/concepts/CallLogic__.js.map +1 -1
  38. package/out/concepts/CallQueryComponent__.js +1 -13
  39. package/out/concepts/CallQueryComponent__.js.map +1 -1
  40. package/out/concepts/CompletionProperty__.js +0 -3
  41. package/out/concepts/CompletionProperty__.js.map +1 -1
  42. package/out/concepts/ConfigGroup__.js.map +1 -1
  43. package/out/concepts/ConfigProperty__.js.map +1 -1
  44. package/out/concepts/Configuration__.js.map +1 -1
  45. package/out/concepts/DataSource__.d.ts +0 -6
  46. package/out/concepts/DataSource__.js +0 -41
  47. package/out/concepts/DataSource__.js.map +1 -1
  48. package/out/concepts/Destination__.d.ts +2 -11
  49. package/out/concepts/Destination__.js +48 -148
  50. package/out/concepts/Destination__.js.map +1 -1
  51. package/out/concepts/EntityProperty__.d.ts +8 -21
  52. package/out/concepts/EntityProperty__.js +23 -109
  53. package/out/concepts/EntityProperty__.js.map +1 -1
  54. package/out/concepts/Entity__.d.ts +0 -32
  55. package/out/concepts/Entity__.js +2 -117
  56. package/out/concepts/Entity__.js.map +1 -1
  57. package/out/concepts/Enum__.js +4 -0
  58. package/out/concepts/Enum__.js.map +1 -1
  59. package/out/concepts/Event__.js.map +1 -1
  60. package/out/concepts/ForEachStatement__.d.ts +4 -0
  61. package/out/concepts/ForEachStatement__.js +8 -4
  62. package/out/concepts/ForEachStatement__.js.map +1 -1
  63. package/out/concepts/Function__.js.map +1 -1
  64. package/out/concepts/Identifier__.js +4 -16
  65. package/out/concepts/Identifier__.js.map +1 -1
  66. package/out/concepts/IfStatement__.d.ts +0 -8
  67. package/out/concepts/IfStatement__.js +0 -22
  68. package/out/concepts/IfStatement__.js.map +1 -1
  69. package/out/concepts/InterfaceParam__.js.map +1 -1
  70. package/out/concepts/Interface__.js.map +1 -1
  71. package/out/concepts/LogicItem__.d.ts +1 -1
  72. package/out/concepts/LogicItem__.js.map +1 -1
  73. package/out/concepts/Logic__.d.ts +1 -6
  74. package/out/concepts/Logic__.js +50 -150
  75. package/out/concepts/Logic__.js.map +1 -1
  76. package/out/concepts/MatchCase__.d.ts +1 -1
  77. package/out/concepts/MatchCase__.js +8 -15
  78. package/out/concepts/MatchCase__.js.map +1 -1
  79. package/out/concepts/Match__.d.ts +19 -21
  80. package/out/concepts/Match__.js +25 -112
  81. package/out/concepts/Match__.js.map +1 -1
  82. package/out/concepts/MemberExpression__.d.ts +1 -4
  83. package/out/concepts/MemberExpression__.js +15 -30
  84. package/out/concepts/MemberExpression__.js.map +1 -1
  85. package/out/concepts/Module__.js.map +1 -1
  86. package/out/concepts/Namespace__.js.map +1 -1
  87. package/out/concepts/NumericLiteral__.js +1 -1
  88. package/out/concepts/NumericLiteral__.js.map +1 -1
  89. package/out/concepts/OqlQueryComponent__.d.ts +3 -7
  90. package/out/concepts/OqlQueryComponent__.js +95 -56
  91. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  92. package/out/concepts/Param__.d.ts +1 -1
  93. package/out/concepts/Param__.js +4 -40
  94. package/out/concepts/Param__.js.map +1 -1
  95. package/out/concepts/ProcessComponent__.js.map +1 -1
  96. package/out/concepts/ProcessElement__.js.map +1 -1
  97. package/out/concepts/Process__.js.map +1 -1
  98. package/out/concepts/QueryJoinExpression__.js.map +1 -1
  99. package/out/concepts/QueryOrderByExpression__.d.ts +3 -3
  100. package/out/concepts/QueryOrderByExpression__.js +3 -3
  101. package/out/concepts/QueryOrderByExpression__.js.map +1 -1
  102. package/out/concepts/QuerySelectExpression__.js.map +1 -1
  103. package/out/concepts/Return__.js +2 -38
  104. package/out/concepts/Return__.js.map +1 -1
  105. package/out/concepts/SelectMembers__.d.ts +1 -1
  106. package/out/concepts/SelectMembers__.js +2 -2
  107. package/out/concepts/SelectMembers__.js.map +1 -1
  108. package/out/concepts/SqlQueryComponent__.d.ts +4 -2
  109. package/out/concepts/SqlQueryComponent__.js +88 -9
  110. package/out/concepts/SqlQueryComponent__.js.map +1 -1
  111. package/out/concepts/StringLiteral__.js +7 -0
  112. package/out/concepts/StringLiteral__.js.map +1 -1
  113. package/out/concepts/StructureProperty__.js.map +1 -1
  114. package/out/concepts/Structure__.js.map +1 -1
  115. package/out/concepts/TypeAnnotation__.d.ts +0 -1
  116. package/out/concepts/TypeAnnotation__.js +12 -25
  117. package/out/concepts/TypeAnnotation__.js.map +1 -1
  118. package/out/concepts/TypeParam__.d.ts +0 -1
  119. package/out/concepts/TypeParam__.js +0 -2
  120. package/out/concepts/TypeParam__.js.map +1 -1
  121. package/out/concepts/UnaryExpression__.js +9 -6
  122. package/out/concepts/UnaryExpression__.js.map +1 -1
  123. package/out/concepts/ValidationRule__.js +23 -88
  124. package/out/concepts/ValidationRule__.js.map +1 -1
  125. package/out/concepts/Variable__.js +2 -38
  126. package/out/concepts/Variable__.js.map +1 -1
  127. package/out/concepts/ViewComponent__.js.map +1 -1
  128. package/out/concepts/ViewElement__.d.ts +29 -30
  129. package/out/concepts/ViewElement__.js +52 -118
  130. package/out/concepts/ViewElement__.js.map +1 -1
  131. package/out/concepts/View__.d.ts +3 -4
  132. package/out/concepts/View__.js +83 -97
  133. package/out/concepts/View__.js.map +1 -1
  134. package/out/concepts/WhileStatement__.js +1 -1
  135. package/out/concepts/WhileStatement__.js.map +1 -1
  136. package/out/concepts/basics/stdlib/nasl.browser.js +0 -50
  137. package/out/concepts/basics/stdlib/nasl.browser.js.map +1 -1
  138. package/out/concepts/basics/stdlib/nasl.ui.js +4 -36
  139. package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
  140. package/out/concepts/basics/stdlib/nasl.util.js +43 -63
  141. package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
  142. package/out/concepts/index__.d.ts +0 -2
  143. package/out/concepts/index__.js +0 -2
  144. package/out/concepts/index__.js.map +1 -1
  145. package/out/generator/genBundleFiles.d.ts +2 -5
  146. package/out/generator/genBundleFiles.js +155 -108
  147. package/out/generator/genBundleFiles.js.map +1 -1
  148. package/out/generator/genMetaData.d.ts +10 -1
  149. package/out/generator/genMetaData.js +50 -189
  150. package/out/generator/genMetaData.js.map +1 -1
  151. package/out/generator/index.d.ts +0 -1
  152. package/out/generator/index.js +0 -1
  153. package/out/generator/index.js.map +1 -1
  154. package/out/index.d.ts +2 -3
  155. package/out/index.js +1 -5
  156. package/out/index.js.map +1 -1
  157. package/out/server/entity2LogicNamespace.js +11 -11
  158. package/out/server/entity2LogicNamespace.js.map +1 -1
  159. package/out/server/extendBaseNode.js +18 -4
  160. package/out/server/extendBaseNode.js.map +1 -1
  161. package/out/server/formatTsUtils.d.ts +2 -1
  162. package/out/server/formatTsUtils.js +64 -40
  163. package/out/server/formatTsUtils.js.map +1 -1
  164. package/out/server/getLogics.js +6 -13
  165. package/out/server/getLogics.js.map +1 -1
  166. package/out/server/getMemberIdentifier.js +7 -7
  167. package/out/server/getMemberIdentifier.js.map +1 -1
  168. package/out/server/getProcesses.d.ts +1 -1
  169. package/out/server/getProcesses.js +1 -1
  170. package/out/server/getProcesses.js.map +1 -1
  171. package/out/server/index.d.ts +1 -0
  172. package/out/server/index.js +27 -2
  173. package/out/server/index.js.map +1 -1
  174. package/out/server/naslServer.d.ts +7 -47
  175. package/out/server/naslServer.js +399 -604
  176. package/out/server/naslServer.js.map +1 -1
  177. package/out/server/naslStdlibMap.js +28 -30
  178. package/out/server/naslStdlibMap.js.map +1 -1
  179. package/out/server/translator.js +11 -59
  180. package/out/server/translator.js.map +1 -1
  181. package/out/service/storage/init.js +3 -33
  182. package/out/service/storage/init.js.map +1 -1
  183. package/out/templator/genCreateBlock.js +4 -6
  184. package/out/templator/genCreateBlock.js.map +1 -1
  185. package/out/templator/genCurdEditMultipleKeyBlock.js +4 -7
  186. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  187. package/out/templator/genCurdMultipleKeyBlock.js +5 -7
  188. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  189. package/out/templator/genEnumSelectBlock.js +2 -5
  190. package/out/templator/genEnumSelectBlock.js.map +1 -1
  191. package/out/templator/genGridViewBlock.js +2 -2
  192. package/out/templator/genGridViewBlock.js.map +1 -1
  193. package/out/templator/genListViewBlock.js +2 -2
  194. package/out/templator/genListViewBlock.js.map +1 -1
  195. package/out/templator/genQueryComponent.d.ts +2 -2
  196. package/out/templator/genQueryComponent.js +1 -4
  197. package/out/templator/genQueryComponent.js.map +1 -1
  198. package/out/templator/genTableBlock.js +2 -2
  199. package/out/templator/genTableBlock.js.map +1 -1
  200. package/out/templator/genUpdateBlock.js +3 -4
  201. package/out/templator/genUpdateBlock.js.map +1 -1
  202. package/out/templator/utils.js +1 -1
  203. package/out/templator/utils.js.map +1 -1
  204. package/out/test/integration/node-nasl-server.js +38 -10
  205. package/out/test/integration/node-nasl-server.js.map +1 -1
  206. package/out/translator/index.d.ts +0 -1
  207. package/out/translator/index.js +1 -1
  208. package/out/translator/index.js.map +1 -1
  209. package/out/utils/index.d.ts +0 -1
  210. package/out/utils/index.js +1 -38
  211. package/out/utils/index.js.map +1 -1
  212. package/out/utils/string.d.ts +2 -15
  213. package/out/utils/string.js +3 -18
  214. package/out/utils/string.js.map +1 -1
  215. package/package.json +2 -2
  216. package/sandbox/stdlib/nasl.auth.ts +1 -1
  217. package/sandbox/stdlib/nasl.core.ts +1 -0
  218. package/sandbox/stdlib/nasl.logging.ts +4 -4
  219. package/sandbox/stdlib/nasl.util.ts +8 -4
  220. package/src/automate/engine/index.js +4 -4
  221. package/src/automate/engine/uniqueName.js +3 -3
  222. package/src/automate/template/myProcess.js +1 -1
  223. package/src/automate/upgrader/2.20.js +41 -0
  224. package/src/bak/translator.js +4 -1
  225. package/src/concepts/AnonymousFunction__.ts +48 -2
  226. package/src/concepts/App__.ts +288 -615
  227. package/src/concepts/BatchAssignment__.ts +45 -1
  228. package/src/concepts/BindAttribute__.ts +18 -25
  229. package/src/concepts/BindDirective__.ts +7 -0
  230. package/src/concepts/BindEvent__.ts +7 -0
  231. package/src/concepts/BindStyle__.ts +7 -0
  232. package/src/concepts/CallFunction__.ts +34 -45
  233. package/src/concepts/CallInterface__.ts +2 -1
  234. package/src/concepts/CallLogic__.ts +61 -44
  235. package/src/concepts/CallQueryComponent__.ts +4 -1
  236. package/src/concepts/Constant__.ts +7 -0
  237. package/src/concepts/DataSource__.ts +57 -5
  238. package/src/concepts/Destination__.ts +8 -21
  239. package/src/concepts/Frontend__.ts +937 -0
  240. package/src/concepts/Identifier__.ts +18 -16
  241. package/src/concepts/LogicItem__.ts +8 -1
  242. package/src/concepts/Logic__.ts +128 -142
  243. package/src/concepts/Match__.ts +13 -29
  244. package/src/concepts/NewComposite__.ts +1357 -0
  245. package/src/concepts/NewList__.ts +440 -0
  246. package/src/concepts/NewMap__.ts +666 -0
  247. package/src/concepts/New__.ts +73 -0
  248. package/src/concepts/Param__.ts +245 -199
  249. package/src/concepts/ProcessElement__.ts +43 -36
  250. package/src/concepts/ProcessOutcomes__.ts +90 -0
  251. package/src/concepts/Process__.ts +1 -23
  252. package/src/concepts/Return__.ts +11 -1
  253. package/src/concepts/SelectMembers__.ts +3 -3
  254. package/src/concepts/Transactional__.ts +7 -0
  255. package/src/concepts/TypeAnnotation__.ts +54 -49
  256. package/src/concepts/ValidationRule__.ts +19 -1
  257. package/src/concepts/Variable__.ts +12 -6
  258. package/src/concepts/ViewElement__.ts +51 -7
  259. package/src/concepts/View__.ts +21 -25
  260. package/src/concepts/basics/stdlib/nasl.auth.ts +1 -1
  261. package/src/concepts/basics/stdlib/nasl.logging.ts +5 -0
  262. package/src/concepts/basics/stdlib/nasl.ui.ts +2 -0
  263. package/src/concepts/basics/stdlib/nasl.util.ts +153 -19
  264. package/src/concepts/index__.ts +7 -0
  265. package/src/enums/KEYWORDS.ts +9 -0
  266. package/src/generator/genBundleFiles.ts +43 -29
  267. package/src/generator/genMetaData.ts +5 -10
  268. package/src/generator/genReleaseBody.ts +77 -41
  269. package/src/generator/index.ts +1 -0
  270. package/src/generator/permission.ts +261 -0
  271. package/src/index.ts +1 -1
  272. package/src/server/entity2LogicNamespace.ts +90 -10
  273. package/src/server/extendBaseNode.ts +29 -3
  274. package/src/server/formatTsUtils.ts +6 -0
  275. package/src/server/getLogics.ts +13 -1
  276. package/src/server/getMemberIdentifier.ts +5 -5
  277. package/src/server/naslServer.ts +235 -58
  278. package/src/server/process2LogicNamespace.ts +8 -0
  279. package/src/server/translator.ts +33 -1
  280. package/src/service/creator/add.configs.js +4 -0
  281. package/src/service/datasource/api.js +11 -0
  282. package/src/service/datasource/index.js +6 -0
  283. package/src/service/storage/init.ts +12 -0
  284. package/src/service/video/VideoTranscribe.js +1 -0
  285. package/src/templator/genEditTableBlock.ts +8 -16
  286. package/src/templator/genGetBlock.ts +18 -19
  287. package/src/templator/genGridViewBlock.ts +18 -18
  288. package/src/templator/genListViewBlock.ts +8 -11
  289. package/src/templator/genTableBlock.ts +6 -10
  290. package/ts-worker/lib/tsserver.js +8 -1
  291. package/out/automate/engine/2.14-components.d.ts +0 -1115
  292. package/out/automate/engine/2.14-components.js +0 -1087
  293. package/out/automate/engine/2.14-components.js.map +0 -1
  294. package/out/concepts/ExternalDestination__.d.ts +0 -73
  295. package/out/concepts/ExternalDestination__.js +0 -264
  296. package/out/concepts/ExternalDestination__.js.map +0 -1
  297. package/out/concepts/MatchExpression__.d.ts +0 -97
  298. package/out/concepts/MatchExpression__.js +0 -281
  299. package/out/concepts/MatchExpression__.js.map +0 -1
  300. package/out/concepts/StringInterpolation__.d.ts +0 -113
  301. package/out/concepts/StringInterpolation__.js +0 -227
  302. package/out/concepts/StringInterpolation__.js.map +0 -1
  303. package/out/generator/genReleaseBody.d.ts +0 -41
  304. package/out/generator/genReleaseBody.js +0 -349
  305. package/out/generator/genReleaseBody.js.map +0 -1
  306. package/out/service/defaultErrorMessage.json +0 -97
  307. package/out/service/logic/api.d.ts +0 -9
  308. package/out/service/logic/api.js +0 -11
  309. package/out/service/logic/api.js.map +0 -1
  310. package/out/service/logic/index.d.ts +0 -2
  311. package/out/service/logic/index.js +0 -10
  312. package/out/service/logic/index.js.map +0 -1
  313. package/sandbox/stdlib/dist/nasl.logging.js +0 -0
  314. package/src/automate/engine/dist/index.dev.js +0 -517
  315. package/src/common/dist/BaseNode.js +0 -1101
  316. package/src/concepts/basics/stdlib/dist/nasl.util.js +0 -1503
  317. package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +0 -24
  318. package/src/concepts/dist/Anchor__.js +0 -179
  319. package/src/concepts/dist/Assignment__.js +0 -301
  320. package/src/concepts/dist/CallFunction__.js +0 -513
  321. package/src/concepts/dist/CallInterface__.js +0 -533
  322. package/src/concepts/dist/CallLogic__.js +0 -892
  323. package/src/concepts/dist/ForEachStatement__.js +0 -426
  324. package/src/concepts/dist/MatchCase__.js +0 -587
  325. package/src/concepts/dist/Match__.js +0 -631
  326. package/src/concepts/dist/MemberExpression__.js +0 -348
  327. package/src/concepts/dist/Param__.js +0 -538
  328. package/src/concepts/dist/Return__.js +0 -494
  329. package/src/concepts/dist/Variable__.js +0 -537
  330. package/src/concepts/dist/ViewElement__.js +0 -1680
  331. package/src/generator/dist/genBundleFiles.js +0 -261
  332. package/src/generator/dist/genMetaData.js +0 -249
  333. package/src/server/dist/formatTsUtils.js +0 -683
  334. package/src/server/dist/naslServer.js +0 -3474
  335. package/src/service/storage/dist/init.js +0 -572
  336. package/ts-worker/dist/webpack.config.dev.js +0 -108
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.NaslServer = exports.getDisplayString2Type = void 0;
29
+ exports.NaslServer = void 0;
30
30
  /// #if process.env.BUILD_TARGET === 'node'
31
31
  const fs = __importStar(require("fs-extra"));
32
32
  const path = __importStar(require("path"));
@@ -46,7 +46,6 @@ const coreTypeList_1 = require("../concepts/basics/types/coreTypeList");
46
46
  const formatTsUtils_1 = require("./formatTsUtils");
47
47
  const naslStdlibMap_1 = __importDefault(require("./naslStdlibMap"));
48
48
  const jsoner = __importStar(require("../service/storage/jsoner"));
49
- const EventEmitter_1 = require("../common/EventEmitter");
50
49
  const EmbeddedTSFileLineMap = {
51
50
  Entity: 3,
52
51
  };
@@ -55,40 +54,9 @@ const EmbeddedTSFileOffsetMap = {
55
54
  };
56
55
  // 要Check的文件
57
56
  const filesToCheck = new Set();
58
- // 单个文件正在change,不允许同时两个文件一起change
59
- let singleFileChangeIng = false;
60
57
  let isChangeInterface = false; //判断是否导入接口
61
58
  let actionArr = []; //用于导入接口收集更改的节点
62
59
  let timer = null; //超时器用于收集导入接口相关
63
- // 联合类型切割取出类型
64
- function getDisplayString2Type(displayString) {
65
- // 取出匹配的内容
66
- const reg = /<([^()]+)>/g;
67
- // 解决extends 导致类型缺失的问题
68
- displayString = displayString?.replace('T extends ', '') || '';
69
- const types = reg.exec(displayString);
70
- // 取出提示的类型,组成是数组
71
- const typeList = types[1].split(' | ').map((item) => {
72
- if (/<([^()]+)>/g.exec(item)) {
73
- return item;
74
- }
75
- else if (item.includes(' ')) {
76
- const strs = item.split(' ');
77
- const type = strs[strs.length - 1];
78
- return type;
79
- }
80
- else if (item.includes('.')) {
81
- const strs = item.split('.');
82
- const type = strs[strs.length - 1];
83
- return type;
84
- }
85
- else {
86
- return item;
87
- }
88
- });
89
- return typeList;
90
- }
91
- exports.getDisplayString2Type = getDisplayString2Type;
92
60
  class NaslServer {
93
61
  messager = undefined;
94
62
  worker = undefined;
@@ -101,9 +69,6 @@ class NaslServer {
101
69
  elementsLogic = {};
102
70
  // 错误日志收集
103
71
  diagnosticManager = undefined;
104
- embeddedTSEmitter = undefined;
105
- // 需要执行修改的文件
106
- changeStackList = [];
107
72
  constructor() {
108
73
  /// #if process.env.BUILD_TARGET === 'node'
109
74
  if (globalThis.process) // For TS build
@@ -128,26 +93,10 @@ class NaslServer {
128
93
  }
129
94
  },
130
95
  });
131
- // 监听所有改变操作
132
- this.embeddedTSEmitter = new EventEmitter_1.EventEmitter();
133
- this.embeddedTSEmitter.on('change', ($event) => {
134
- // 收集到一个行为集合
135
- const eventValue = $event.value;
136
- eventValue.forEach(async (item) => {
137
- this.changeStackList.push(item.originEvent);
138
- });
139
- // 如果有长度开始执行状态机
140
- if (this.changeStackList.length) {
141
- this.changeFileNext();
142
- }
143
- });
144
96
  }
145
97
  start() {
146
98
  return this.messager.requestCommand('start');
147
99
  }
148
- terminate() {
149
- this.worker.terminate();
150
- }
151
100
  async createUiTs(allComponent) {
152
101
  const { code, elementsLogic } = await (0, createUiTs_1.default)(allComponent);
153
102
  // 放入生產的uits文件
@@ -422,6 +371,32 @@ class NaslServer {
422
371
  _getValueSelectCompletion(args) {
423
372
  return this.messager.requestCommand('getValueSelectCompletion', args);
424
373
  }
374
+ // 联合类型切割取出类型
375
+ getDisplayString2Type(displayString) {
376
+ // 取出匹配的内容
377
+ const reg = /<([^()]+)>/g;
378
+ const types = reg.exec(displayString);
379
+ // 取出提示的类型,组成是数组
380
+ const typeList = types[1].split(' | ').map((item) => {
381
+ if (/<([^()]+)>/g.exec(item)) {
382
+ return item;
383
+ }
384
+ else if (item.includes(' ')) {
385
+ const strs = item.split(' ');
386
+ const type = strs[strs.length - 1];
387
+ return type;
388
+ }
389
+ else if (item.includes('.')) {
390
+ const strs = item.split('.');
391
+ const type = strs[strs.length - 1];
392
+ return type;
393
+ }
394
+ else {
395
+ return item;
396
+ }
397
+ });
398
+ return typeList;
399
+ }
425
400
  /**
426
401
  * 获取 Convert 的可选类型
427
402
  * @param node 传入当前已经选择的变量
@@ -444,7 +419,7 @@ class NaslServer {
444
419
  });
445
420
  if (quickInfo.responseRequired) {
446
421
  const displayString = quickInfo?.response?.displayString || '';
447
- const typeList = getDisplayString2Type(displayString);
422
+ const typeList = this.getDisplayString2Type(displayString);
448
423
  const res = [];
449
424
  typeList.forEach((type) => {
450
425
  const typeAnnotation = coreTypeList_1.primitiveTypeList.find((typeAnnotation) => typeAnnotation.typeName === type);
@@ -502,17 +477,6 @@ class NaslServer {
502
477
  .replace(/__name:"AStructure_\w{8}";/g, '')
503
478
  .replace(/dataSources.([^.]+).entities.([^;]+)/g, ($1, $2, $3) => (`${$3}(${$2})`));
504
479
  }
505
- else if (typeStr.startsWith('{') && typeStr.endsWith('}')) {
506
- /**
507
- * {
508
- text: nasl.core.String;
509
- value: nasl.core.String;
510
- }
511
- */
512
- return typeStr.replaceAll(' ', '')
513
- .replaceAll('\n', '')
514
- .replaceAll('nasl.core.', '');
515
- }
516
480
  let str = '';
517
481
  // 取出T的值
518
482
  typeStr = (0, formatTsUtils_1.getPlatformType)(typeStr);
@@ -538,49 +502,6 @@ class NaslServer {
538
502
  }
539
503
  return '';
540
504
  }
541
- async getDataSchemaStructureOrTypeAnnotation(node) {
542
- if (!(node instanceof concepts_1.ViewElement))
543
- return;
544
- const { currentSource, fileNode } = this.getCurrentSource(node);
545
- const quickInfo = await this._getTypeQuickinfo({
546
- file: fileNode.getEmbeddedFilePath(),
547
- line: (0, translator_1.lsp2tspNumber)(currentSource.range.start.line),
548
- offset: (0, translator_1.lsp2tspNumber)(currentSource.range.start.character) + `new nasl.ui.`.length,
549
- });
550
- if (quickInfo.responseRequired) {
551
- const displayString = quickInfo?.response?.displayString || '';
552
- const flag = displayString.includes('<') && displayString.includes('>');
553
- if (!flag)
554
- return;
555
- const types = /\<([^()]+)\>/g.exec(displayString);
556
- let typeStr = types && types[1];
557
- const app = node.app;
558
- if (typeStr.includes('__name: "AStructure_')) {
559
- const properties = [];
560
- typeStr
561
- .replace(/([^:\s]+):\s+([^;]+);/g, ($1, name, typeKey) => {
562
- if (name === '__name')
563
- return;
564
- typeKey = `app.${typeKey}`;
565
- const keys = typeKey.split('.');
566
- const typeName = keys.pop();
567
- const typeNamespace = keys.join('.');
568
- properties.push(concepts_1.StructureProperty.from({
569
- name,
570
- typeAnnotation: concepts_1.TypeAnnotation.from({
571
- typeKind: 'reference',
572
- typeName,
573
- typeNamespace,
574
- })
575
- }));
576
- return '';
577
- });
578
- return concepts_1.TypeAnnotation.createTypeAnonymousStructure(properties);
579
- }
580
- else if (typeStr.startsWith('structures'))
581
- return app.findNodeByCompleteName(`app.${typeStr}`);
582
- }
583
- }
584
505
  /**
585
506
  * ts的 quickInfo方法,查询指定位置的详情
586
507
  * @param args 文件信息数组
@@ -694,17 +615,6 @@ class NaslServer {
694
615
  if (isChangeInterface) {
695
616
  this.existStructureFix(record.semanticDiagnostics, node, this);
696
617
  }
697
- // 单独处理 oql 语义错误提示
698
- if (record.node instanceof concepts_1.Logic) {
699
- record?.syntaxDiagnostics.forEach((item) => {
700
- const minRange = this._findMinRange(item, record.node);
701
- if (minRange.node instanceof concepts_1.OqlQueryComponent) {
702
- if (item.text === 'Invalid character.') {
703
- record.semanticDiagnostics.push(item);
704
- }
705
- }
706
- });
707
- }
708
618
  record.semanticDiagnostics = record.semanticDiagnostics
709
619
  .map((diag) => this._resolveDiagnostic(diag, node, record))
710
620
  .filter((diag) => !!diag);
@@ -804,7 +714,7 @@ class NaslServer {
804
714
  }),
805
715
  ];
806
716
  }
807
- if (Array.isArray(enumerableItems) && enumerableItems.length) {
717
+ if (Array.isArray(enumerableItems)) {
808
718
  const map = {};
809
719
  cases.forEach((caseItem) => {
810
720
  const { patterns } = caseItem || {};
@@ -903,33 +813,18 @@ class NaslServer {
903
813
  }
904
814
  if (removed)
905
815
  return diagnostics;
906
- fileNode?.sourceMap.forEach(async (value, node) => {
816
+ fileNode.traverseChildren((node) => {
907
817
  if (node instanceof concepts_1.ViewElement && node.view === fileNode) {
908
818
  if (node.tag) {
909
819
  node.bindAttrs.forEach((bindAttr) => {
910
- if ((bindAttr.model || bindAttr.sync) && bindAttr.expression) {
911
- const bindExpression = bindAttr.expression;
912
- let diagnostic;
913
- if (bindExpression.concept !== 'Identifier' && bindExpression.concept !== 'MemberExpression') {
914
- diagnostic = {
915
- node: bindAttr,
916
- severity: 'error',
917
- message: '页面元素双向绑定:只允许绑定可赋值的变量和属性。',
918
- };
919
- }
920
- else {
921
- if (bindExpression.isEnum()) {
922
- diagnostic = {
923
- node: bindAttr,
924
- severity: 'error',
925
- message: '页面元素双向绑定:只允许绑定可赋值的变量和属性。',
926
- };
927
- }
928
- }
929
- if (diagnostic) {
930
- bindAttr.tsErrorDetail = diagnostic;
931
- diagnostics.push(diagnostic);
932
- }
820
+ if ((bindAttr.model || bindAttr.sync) && bindAttr.expression && bindAttr.expression.concept !== 'Identifier' && bindAttr.expression.concept !== 'MemberExpression') {
821
+ const diagnostic = {
822
+ node: bindAttr,
823
+ severity: 'error',
824
+ message: '页面元素双向绑定:只允许绑定可赋值的变量和属性。',
825
+ };
826
+ bindAttr.tsErrorDetail = diagnostic;
827
+ diagnostics.push(diagnostic);
933
828
  }
934
829
  });
935
830
  }
@@ -943,44 +838,34 @@ class NaslServer {
943
838
  // 子页面内部逻辑过滤
944
839
  if (nodeIn.view !== fileNode)
945
840
  return;
946
- // 当局部变量、输出参数属于页面内逻辑时,需过滤同页面下不同逻辑下的同名变量
947
- if (node.logic && node.logic !== nodeIn.logic)
948
- return;
949
841
  // 跟变量无关的赋值过滤
950
842
  const jsCode = nodeIn.toJS();
951
843
  if (!jsCode.includes(`${node.name} = `))
952
844
  return;
953
- // 页面局部变量
845
+ // 逻辑内局部变量、输出参数、输入参数过滤
846
+ if ((nodeIn.logic?.variables || []).find((lVar) => jsCode.includes(`${lVar.name} = `))
847
+ || (nodeIn.logic?.returns || []).find((lRet) => jsCode.includes(`${lRet.name} = `))
848
+ || (nodeIn.logic?.params || []).find((lPar) => jsCode.includes(`${lPar.name} = `)))
849
+ return;
954
850
  if (node instanceof concepts_1.Variable && node.parentNode instanceof concepts_1.View) {
955
- // 跟页面局部变量无关的赋值过滤
956
- if (!jsCode.includes(`this.${node.name} = `))
957
- return;
958
851
  // 直接赋值 logic 内局部变量、输入参数直接提示系统无法推断类型
959
- if (nodeIn.logic?.params.find((param) => jsCode.includes(param.name))
960
- || nodeIn.logic?.virtualParams.find((vParam) => jsCode.includes(vParam.name))
961
- || nodeIn.logic?.variables.find((variable) => jsCode.includes(variable.name))) {
962
- if (!nodeIn.tsErrorDetail) {
963
- const diagnostic = {
964
- node: nodeIn,
965
- severity: 'error',
966
- message: `页面${nodeTypeName} ${node.name} 赋值页面逻辑内局部变量或输入参数时,系统无法推导类型。`,
967
- };
968
- nodeIn.tsErrorDetail = diagnostic;
969
- diagnostics.push(diagnostic);
970
- }
971
- msg = '系统无法推断类型。';
852
+ let hasVar = false;
853
+ nodeIn.logic?.params.forEach((param) => {
854
+ if (jsCode.includes(param.name))
855
+ hasVar = true;
856
+ });
857
+ if (!hasVar) {
858
+ nodeIn.logic?.variables.forEach((variable) => {
859
+ if (jsCode.includes(variable.name))
860
+ hasVar = true;
861
+ });
972
862
  }
863
+ if (hasVar)
864
+ msg = '系统无法推断类型。';
973
865
  }
974
- if (!nodeIn.tsErrorDetail) {
975
- const diagnostic = {
976
- node: nodeIn,
977
- severity: 'error',
978
- message: `${nodeIn.label}左边 ${node.name} 未设置类型,右边必须为有返回值的内容。`,
979
- };
980
- nodeIn.tsErrorDetail = diagnostic;
981
- diagnostics.push(diagnostic);
866
+ else {
867
+ msg = '必须赋值有返回值的内容。';
982
868
  }
983
- msg = '必须赋值有返回值的内容。';
984
869
  }
985
870
  });
986
871
  if (!msg)
@@ -993,9 +878,12 @@ class NaslServer {
993
878
  node.tsErrorDetail = diagnostic;
994
879
  diagnostics.push(diagnostic);
995
880
  }
881
+ else {
882
+ node.tsErrorDetail = undefined;
883
+ }
996
884
  }
997
885
  else {
998
- this.checkNodeError(node, diagnostics);
886
+ this.checkMatchError(node, diagnostics);
999
887
  }
1000
888
  });
1001
889
  }
@@ -1045,19 +933,10 @@ class NaslServer {
1045
933
  const nodeTypeName = node.concept === 'Return' ? '输出参数' : '局部变量';
1046
934
  let used = false;
1047
935
  fileNode?.sourceMap.forEach((valueIn, nodeIn) => {
1048
- if (!used && nodeIn
936
+ if (nodeIn
1049
937
  && (nodeIn instanceof concepts_1.BatchAssignment || (nodeIn instanceof concepts_1.Assignment && nodeIn.left?.name))
1050
938
  && nodeIn.toJS().includes(`${node.name} = `)) {
1051
939
  used = true;
1052
- if (!nodeIn.tsErrorDetail) {
1053
- const diagnostic = {
1054
- node: nodeIn,
1055
- severity: 'error',
1056
- message: `${nodeIn.label}左边 ${node.name} 未设置类型,右边必须为有返回值的内容。`,
1057
- };
1058
- nodeIn.tsErrorDetail = diagnostic;
1059
- diagnostics.push(diagnostic);
1060
- }
1061
940
  }
1062
941
  });
1063
942
  const msg = used ? '必须赋值有返回值的内容。' : '未设置类型或未赋值。直接赋值系统可以自动推断类型。';
@@ -1073,56 +952,31 @@ class NaslServer {
1073
952
  node.tsErrorDetail = undefined;
1074
953
  }
1075
954
  }
1076
- this.checkNodeError(node, diagnostics);
955
+ this.checkMatchError(node, diagnostics);
1077
956
  });
1078
957
  }
1079
958
  return diagnostics;
1080
959
  }
1081
- checkNodeError(node, diagnostics) {
960
+ checkMatchError(node, diagnostics) {
1082
961
  if (!node)
1083
962
  return;
1084
963
  // 如果节点是match的看看节点里是不是有重复的
1085
964
  if (node instanceof concepts_1.Match) {
1086
965
  const typeMap = {};
1087
- if (node.expression?.__TypeAnnotation) {
1088
- const { typeName, typeNamespace } = node.expression.__TypeAnnotation;
1089
- if (typeName === 'Union' || typeName === 'Boolean' || typeNamespace?.endsWith('enums')) {
1090
- node.cases.forEach((item) => {
1091
- if (Array.isArray(item.patterns)) {
1092
- item.patterns.forEach((pattern) => {
1093
- if (pattern instanceof concepts_1.TypeAnnotation) {
1094
- if (typeMap[pattern.sortedTypeKey]) {
1095
- typeMap[pattern.sortedTypeKey].push(pattern);
1096
- }
1097
- else {
1098
- typeMap[pattern.sortedTypeKey] = [pattern];
1099
- }
1100
- }
1101
- else if (pattern instanceof concepts_1.MemberExpression) {
1102
- if (pattern.completeName && pattern.object?.namespace?.endsWith('enums')) {
1103
- const onlyKey = pattern.completeName;
1104
- if (typeMap[onlyKey]) {
1105
- typeMap[onlyKey].push(pattern);
1106
- }
1107
- else {
1108
- typeMap[onlyKey] = [pattern];
1109
- }
1110
- }
1111
- }
1112
- else if (pattern instanceof concepts_1.BooleanLiteral) {
1113
- const onlyKey = pattern.concept + pattern.value;
1114
- if (typeMap[onlyKey]) {
1115
- typeMap[onlyKey].push(pattern);
1116
- }
1117
- else {
1118
- typeMap[onlyKey] = [pattern];
1119
- }
1120
- }
1121
- });
966
+ node.cases.forEach((item) => {
967
+ if (Array.isArray(item.patterns)) {
968
+ item.patterns.forEach((pattern) => {
969
+ if (pattern instanceof concepts_1.TypeAnnotation) {
970
+ if (typeMap[pattern.sortedTypeKey]) {
971
+ typeMap[pattern.sortedTypeKey].push(pattern);
972
+ }
973
+ else {
974
+ typeMap[pattern.sortedTypeKey] = [pattern];
975
+ }
1122
976
  }
1123
977
  });
1124
978
  }
1125
- }
979
+ });
1126
980
  Object.keys(typeMap).forEach((item) => {
1127
981
  if (typeMap[item].length > 1) {
1128
982
  typeMap[item].forEach((nodeItem) => {
@@ -1139,7 +993,7 @@ class NaslServer {
1139
993
  });
1140
994
  }
1141
995
  // 如果节点是match的patterns 里的
1142
- if (node?.parentKey === 'patterns' && node.parentNode instanceof concepts_1.MatchCase) {
996
+ if (node.parentNode instanceof concepts_1.MatchCase && node.parentNode.patterns.includes(node)) {
1143
997
  const matchNode = node.getAncestor('Match');
1144
998
  const matchExpressionType = matchNode?.expression?.__TypeAnnotation;
1145
999
  // 判断union类型是不是重复
@@ -1158,6 +1012,7 @@ class NaslServer {
1158
1012
  }
1159
1013
  }
1160
1014
  if (node.tsErrorDetail) {
1015
+ // console.log(matchExpressionType);
1161
1016
  if (matchExpressionType?.typeNamespace?.includes('enums')) {
1162
1017
  node.tsErrorDetail.titleTip = '该枚举值已被删除';
1163
1018
  }
@@ -1166,16 +1021,6 @@ class NaslServer {
1166
1021
  }
1167
1022
  }
1168
1023
  }
1169
- // 如果forEach 中的each的内容是union类型就要提示报错
1170
- if (node?.parentKey === 'each' && node?.__TypeAnnotation?.typeKind === 'union') {
1171
- const diagnostic = {
1172
- node,
1173
- severity: 'error',
1174
- message: 'ForEach:参数类型不一致!传入类型:联合类型。接受类型:List类型。',
1175
- };
1176
- node.tsErrorDetail = diagnostic;
1177
- diagnostics.push(diagnostic);
1178
- }
1179
1024
  }
1180
1025
  /* 接口导入查找 */
1181
1026
  existStructureFix(semanticDiagnostics, node, that) {
@@ -1483,10 +1328,6 @@ class NaslServer {
1483
1328
  return null;
1484
1329
  const minRange = this._findMinRange(record, fileNode);
1485
1330
  if (minRange) {
1486
- // 节点上ts临时变量标识,如果有这个就不rename
1487
- if (minRange.node.noTsReName) {
1488
- return null;
1489
- }
1490
1331
  // 如果节点是TypeAnnotation类型,
1491
1332
  // 很复杂,可能是多级嵌套结构
1492
1333
  // 不一定只修改typeName
@@ -1573,16 +1414,10 @@ class NaslServer {
1573
1414
  minRange.newValue = newTextValue;
1574
1415
  }
1575
1416
  }
1576
- if (node instanceof concepts_1.Enum) {
1577
- // 如果是枚举修改,枚举的值刚好在Identifier 中选了 就修改值
1578
- if (minRange.node instanceof concepts_1.Identifier) {
1579
- minRange.newValue = newValue;
1580
- minRange.setTypeMethods = 'setName';
1581
- }
1582
- else if (minRange.node instanceof concepts_1.EntityProperty) {
1583
- // 如果枚举自己改名引用到了实体字段,而不是实体字段下的类型,就说明是默认值,默认值可以不处理
1584
- return null;
1585
- }
1417
+ // 如果是枚举修改,枚举的值刚好在Identifier 中选了 就修改值
1418
+ if (minRange.node instanceof concepts_1.Identifier && node instanceof concepts_1.Enum) {
1419
+ minRange.newValue = newValue;
1420
+ minRange.setTypeMethods = 'setName';
1586
1421
  }
1587
1422
  // 如果修改逻辑,改到了Identifier表达式,只能说明是在属性里有使用了
1588
1423
  if (minRange.node instanceof concepts_1.Identifier && node instanceof concepts_1.Logic) {
@@ -1801,7 +1636,7 @@ class NaslServer {
1801
1636
  minRange.newValue = newValue;
1802
1637
  }
1803
1638
  else if (minRange.node instanceof concepts_1.SqlQueryComponent || minRange.node instanceof concepts_1.OqlQueryComponent) {
1804
- minRange.setTypeMethods = 'renameDataSource';
1639
+ minRange.setTypeMethods = 'setDataSource';
1805
1640
  }
1806
1641
  }
1807
1642
  if (minRange.node instanceof concepts_1.QueryFieldExpression && node instanceof concepts_1.EntityProperty) {
@@ -1878,7 +1713,8 @@ class NaslServer {
1878
1713
  }
1879
1714
  }
1880
1715
  else {
1881
- console.log('没找到节点需要排查', record, fileNode.sourceMap);
1716
+ console.log('没找到节点需要排查');
1717
+ console.log(record, fileNode.sourceMap);
1882
1718
  }
1883
1719
  return minRange;
1884
1720
  })
@@ -1896,8 +1732,12 @@ class NaslServer {
1896
1732
  const minRange = this._findMinRange(record, fileNode);
1897
1733
  if (minRange) {
1898
1734
  // 如果找到节点是callLogic就去更新
1899
- if ((minRange.node instanceof concepts_1.CallLogic || minRange.node instanceof concepts_1.Destination) && node instanceof concepts_1.Param) {
1900
- minRange.node.addCalleeArg(parantNode);
1735
+ if (minRange.node instanceof concepts_1.CallLogic && node instanceof concepts_1.Param) {
1736
+ minRange.node.setCalleeArgName(parantNode);
1737
+ }
1738
+ // 如果节点参数增加页面也要更新
1739
+ if (minRange.node instanceof concepts_1.Destination && node instanceof concepts_1.Param) {
1740
+ minRange.node.setViewArgument(parantNode);
1901
1741
  }
1902
1742
  }
1903
1743
  });
@@ -2203,34 +2043,18 @@ class NaslServer {
2203
2043
  if (node instanceof concepts_1.BinaryExpression && (['==', '!=', '>', '<', '>=', '<='].includes(node.operator))) {
2204
2044
  return concepts_1.TypeAnnotation.createPrimitive('Boolean');
2205
2045
  }
2206
- // Convert和new都是自身携带类型的,就不进行修改
2207
- if (node instanceof concepts_1.CallFunction && node.calleeNamespace === 'nasl.util' && (node.calleeName === 'Convert' || node.calleeName === 'New')) {
2208
- if (node.typeArguments.length) {
2209
- return node.typeArguments[0];
2210
- }
2211
- }
2212
- // Convert和new都是自身携带类型的,就不进行修改
2213
- if (node instanceof concepts_1.CallLogic && node.calleeNamespace === 'nasl.util' && (node.calleeName === 'jsonDeserialize')) {
2046
+ // Convert
2047
+ if (node instanceof concepts_1.CallFunction && node.calleeNamespace === 'nasl.util' && node.calleeName === 'Convert') {
2214
2048
  if (node.typeArguments.length) {
2215
2049
  return node.typeArguments[0];
2216
2050
  }
2217
2051
  }
2218
- // 特殊处理param有类型错误的
2219
- if (node instanceof concepts_1.Param) {
2220
- // index在nasl foreach上有脏数据
2221
- if (node.parentKey === 'index' && node.parentNode instanceof concepts_1.ForEachStatement) {
2222
- return concepts_1.TypeAnnotation.createPrimitive('Integer');
2223
- }
2224
- }
2052
+ // --------------------------------下面的都是为了获取节点类型的, 全量标注走不进来------------------------------------------------------------------
2225
2053
  if (node instanceof concepts_1.CallQueryComponent || node instanceof concepts_1.SqlQueryComponent || node instanceof concepts_1.OqlQueryComponent) {
2226
2054
  return node.typeAnnotation;
2227
2055
  }
2228
- // 老数据可能typeKind 的primitive缺失
2229
- if (node instanceof concepts_1.NumericLiteral && node.typeAnnotation) {
2230
- return concepts_1.TypeAnnotation.from({
2231
- ...node.typeAnnotation?.toJSON(),
2232
- typeKind: 'primitive',
2233
- });
2056
+ if (node instanceof concepts_1.NumericLiteral) {
2057
+ return node.typeAnnotation;
2234
2058
  }
2235
2059
  }
2236
2060
  /**
@@ -2256,6 +2080,7 @@ class NaslServer {
2256
2080
  const nodeTypeAnnotation = this.getCurrentNodeKnownTypeAnnotation(node);
2257
2081
  if (nodeTypeAnnotation) {
2258
2082
  types.set(node, nodeTypeAnnotation);
2083
+ node.__TypeAnnotation = nodeTypeAnnotation;
2259
2084
  return;
2260
2085
  }
2261
2086
  // 要通过自己或者依赖关系拿的,二次遍历
@@ -2270,7 +2095,7 @@ class NaslServer {
2270
2095
  'Return',
2271
2096
  'Variable',
2272
2097
  ].includes(node.concept) && node.typeAnnotation) {
2273
- types.set(node, node.typeAnnotation);
2098
+ node.__TypeAnnotation = node.typeAnnotation;
2274
2099
  return;
2275
2100
  }
2276
2101
  if (![
@@ -2300,13 +2125,12 @@ class NaslServer {
2300
2125
  // 如果没有括号 ,括号就在外面,就 -1
2301
2126
  // 有括号就找到括号的位置 然后 -1
2302
2127
  let indexOf = 0;
2303
- if (!item.code.includes('(')) {
2128
+ if (item.code.indexOf('(') === -1) {
2304
2129
  indexOf = -1;
2305
2130
  }
2306
2131
  else {
2307
- // 如果有泛型先往前找一找
2308
- if (item.code.includes('<')) {
2309
- indexOf = Math.min(item.code.indexOf('<'), item.code.indexOf('('));
2132
+ if (item.code.includes('>(')) {
2133
+ indexOf = item.code.indexOf('<');
2310
2134
  }
2311
2135
  else {
2312
2136
  indexOf = item.code.indexOf('(');
@@ -2337,12 +2161,9 @@ class NaslServer {
2337
2161
  }
2338
2162
  args.push(fileDetail);
2339
2163
  });
2340
- console.time('请求');
2341
2164
  const resultMap = (await this.getNaslNodeTypeFull(args)).response;
2342
- console.timeEnd('请求');
2343
2165
  // console.log(resultMap);
2344
2166
  // const result = (await this.getNaslNodeQuickInfoFull(args)).response;
2345
- // console.log(result);
2346
2167
  args.forEach((arg, index) => {
2347
2168
  const { file, line, offset } = arg;
2348
2169
  const item = resultMap?.[file]?.[line]?.[offset];
@@ -2351,21 +2172,24 @@ class NaslServer {
2351
2172
  // console.log('原始:', displayString);
2352
2173
  // console.log('方案2:', item?.[0]?.nodeType);
2353
2174
  const nodeTypeAnnotation = (0, formatTsUtils_1.type2TypeAnnotation)(item?.[0]?.nodeType);
2354
- // console.log(newQuickInfoNodes[index].node, nodeTypeAnnotation, nodeTypeAnnotation?.typeKey);
2175
+ // console.log(newQuickInfoNodes[index].node, nodeTypeAnnotation, item?.[0]?.nodeType);
2355
2176
  types.set(newQuickInfoNodes[index].node, nodeTypeAnnotation);
2356
- newQuickInfoNodes[index].node.__nodeType = Object.freeze(item?.[0]?.nodeType);
2177
+ newQuickInfoNodes[index].node.__TypeAnnotation = nodeTypeAnnotation;
2178
+ newQuickInfoNodes[index].node.__nodeType = item?.[0]?.nodeType;
2357
2179
  // console.log('方案1:', displayString1);
2358
2180
  });
2359
2181
  getFromOthers.forEach((type, node) => {
2360
2182
  if (node instanceof concepts_1.Assignment) {
2361
2183
  if (!types.get(node.left)) {
2362
2184
  types.set(node.left, types.get(node.right));
2185
+ node.left.__TypeAnnotation = types.get(node.right);
2363
2186
  }
2364
2187
  }
2365
2188
  else if (node instanceof concepts_1.Argument) {
2366
2189
  // 如果Argument,但是没可以用的类型,就用原来logic的参数类型
2367
2190
  const argType = this.getArgumentTypeAnnotation(node, newQuickInfoNodes, types);
2368
2191
  types.set(node, argType);
2192
+ node.__TypeAnnotation = argType.typeAnnotation;
2369
2193
  }
2370
2194
  else if (node instanceof concepts_1.MatchCase) {
2371
2195
  // matchCase的类型
@@ -2374,30 +2198,11 @@ class NaslServer {
2374
2198
  const last = node.body[node.body.length - 1];
2375
2199
  if (last.__TypeAnnotation) {
2376
2200
  types.set(node, last.__TypeAnnotation);
2201
+ node.__TypeAnnotation = last.__TypeAnnotation;
2377
2202
  }
2378
2203
  }
2379
2204
  }
2380
2205
  });
2381
- // 重置类型状态, 并且赋值
2382
- types.forEach((value, node) => {
2383
- try {
2384
- // 因为node可能是经过处理的TypeAnnotation
2385
- node.__isCorrectTypeAnnotation = true;
2386
- if (value) {
2387
- if (value instanceof concepts_1.TypeAnnotation) {
2388
- node.__TypeAnnotation = Object.freeze(value);
2389
- }
2390
- else if (value.typeAnnotation) {
2391
- node.__TypeAnnotation = Object.freeze(value.typeAnnotation);
2392
- }
2393
- }
2394
- }
2395
- catch (err) {
2396
- if (globalThis.window) {
2397
- console.log(err);
2398
- }
2399
- }
2400
- });
2401
2206
  // newQuickInfoNodes.forEach((itemDetail, index) => {
2402
2207
  // const { node, filePath } = itemDetail;
2403
2208
  // if (!result[index] || node.concept === 'Argument')
@@ -2445,10 +2250,12 @@ class NaslServer {
2445
2250
  // types.set(node, argType);
2446
2251
  // }
2447
2252
  // });
2253
+ console.timeEnd('批量请求');
2448
2254
  return types;
2449
2255
  }
2450
- // 全量标注并且返回json
2256
+ // 全量标注
2451
2257
  async getNaslAnnotatedJSON(app, releaseFlag) {
2258
+ // 全量标注
2452
2259
  console.time('全量标注');
2453
2260
  const nodes = [];
2454
2261
  this.file2NodeMap.forEach((fileNode, filePath) => {
@@ -2470,13 +2277,14 @@ class NaslServer {
2470
2277
  const json = app.toJSON();
2471
2278
  if (releaseFlag) {
2472
2279
  // 全量标注后对json进行一些修改,为了服务端翻译处理
2473
- this.annotationToJson(typesMap, json);
2280
+ this.annitationToJson(typesMap, json);
2474
2281
  }
2475
2282
  return json;
2476
2283
  }
2477
2284
  // 加载全量nasl节点标注
2478
2285
  async createdNaslAnnotatedJSON(app) {
2479
2286
  // 全量标注
2287
+ console.time('全量标注');
2480
2288
  const nodes = [];
2481
2289
  this.file2NodeMap.forEach((fileNode, filePath) => {
2482
2290
  // 先不排除view,传递给后端的时候,去除views下的标注
@@ -2491,10 +2299,10 @@ class NaslServer {
2491
2299
  }
2492
2300
  });
2493
2301
  await this.getQuickInfoNodesTypeMap(nodes, true);
2302
+ console.timeEnd('全量标注');
2494
2303
  }
2495
2304
  // 增量标注
2496
2305
  async IncrementalAnnotationJSON(records) {
2497
- console.time('增量标注');
2498
2306
  const nodes = [];
2499
2307
  records.forEach((record) => {
2500
2308
  const fileNode = this.file2NodeMap.get(record.filePath);
@@ -2513,9 +2321,8 @@ class NaslServer {
2513
2321
  }
2514
2322
  });
2515
2323
  await this.getQuickInfoNodesTypeMap(nodes);
2516
- console.timeEnd('增量标注');
2517
2324
  }
2518
- annotationToJson(typesMap, json) {
2325
+ annitationToJson(typesMap, json) {
2519
2326
  typesMap.forEach((value, node) => {
2520
2327
  // 如果节点本身有类型就不去在塞一遍了
2521
2328
  // 有值而且没有类型再去设置
@@ -2532,8 +2339,8 @@ class NaslServer {
2532
2339
  }
2533
2340
  }
2534
2341
  }
2535
- // 旧版本数据查询需要确认是匿名数据结构的 ListTotal 类型
2536
- if (node instanceof concepts_1.CallQueryComponent && node.ideVersion !== '2.11') {
2342
+ if (node instanceof concepts_1.CallQueryComponent && node.ideVersion !== '2.11' && node.typeAnnotation.properties
2343
+ && (node.typeAnnotation.properties.length !== 2 || node.typeAnnotation.properties[0].name !== 'list')) {
2537
2344
  const jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
2538
2345
  jsonNode.typeAnnotation = {
2539
2346
  concept: 'TypeAnnotation',
@@ -2576,14 +2383,6 @@ class NaslServer {
2576
2383
  }],
2577
2384
  };
2578
2385
  }
2579
- // 特殊处理param有类型错误的
2580
- if (node instanceof concepts_1.Param) {
2581
- // index在nasl foreach上有脏数据
2582
- if (node.parentKey === 'index' && node.parentNode instanceof concepts_1.ForEachStatement) {
2583
- const jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
2584
- jsonNode.typeAnnotation = concepts_1.TypeAnnotation.createPrimitive('Integer').toJSON();
2585
- }
2586
- }
2587
2386
  if (node instanceof concepts_1.Match) {
2588
2387
  const matchExpression = node.expression;
2589
2388
  if (matchExpression?.__TypeAnnotation?.typeKind === 'union' && (matchExpression instanceof concepts_1.Identifier || matchExpression instanceof concepts_1.MemberExpression)) {
@@ -2596,14 +2395,6 @@ class NaslServer {
2596
2395
  });
2597
2396
  }
2598
2397
  }
2599
- // 特殊处理param有类型错误的
2600
- if (node instanceof concepts_1.Param && value) {
2601
- // index在nasl foreach上有脏数据
2602
- if (node.parentKey === 'index' && node.parentNode instanceof concepts_1.ForEachStatement) {
2603
- const jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
2604
- jsonNode.typeAnnotation = value.toJSON();
2605
- }
2606
- }
2607
2398
  });
2608
2399
  }
2609
2400
  /**
@@ -2642,7 +2433,7 @@ class NaslServer {
2642
2433
  // 用户自己声明的用用户的
2643
2434
  const callObj = App.findNodeByCompleteName(parent.calleeNamespace + '.' + parent.calleeName);
2644
2435
  const index = parent.arguments.indexOf(node);
2645
- const param = callObj?.params?.[index] || {};
2436
+ const param = callObj?.params[index] || {};
2646
2437
  // 取出参数的类型
2647
2438
  // 设置类型
2648
2439
  return {
@@ -2657,18 +2448,13 @@ class NaslServer {
2657
2448
  }
2658
2449
  return new Promise((resolve, reject) => {
2659
2450
  const myTimer = setTimeout(() => {
2660
- console.warn(node, '没有获取到类型');
2451
+ console.log(node, '没有获取到类型');
2661
2452
  clearTimeout(myTimer);
2662
2453
  clearInterval(mySetInterval);
2663
- if (node.__isCorrectTypeAnnotation) {
2664
- resolve(node.__TypeAnnotation);
2665
- }
2666
- else {
2667
- resolve(null);
2668
- }
2454
+ resolve(node.__TypeAnnotation);
2669
2455
  }, 600);
2670
2456
  const mySetInterval = setInterval(() => {
2671
- if (node.__isCorrectTypeAnnotation) {
2457
+ if (node.__TypeAnnotation) {
2672
2458
  resolve(node.__TypeAnnotation);
2673
2459
  clearInterval(mySetInterval);
2674
2460
  clearTimeout(myTimer);
@@ -2722,311 +2508,320 @@ class NaslServer {
2722
2508
  const result = await this._getTypeStrFull(args);
2723
2509
  return result;
2724
2510
  }
2511
+ }
2512
+ exports.NaslServer = NaslServer;
2513
+ const naslServer = new NaslServer();
2514
+ /**
2515
+ * 处理删除节点
2516
+ * @param fileNode 当前删除节点的文件级别节点
2517
+ * @param targetNode 当前操作的节点
2518
+ * @param result toTs生成的内容
2519
+ */
2520
+ async function handleDelete(fileNode, targetNode, result) {
2521
+ const filePath = fileNode.getEmbeddedFilePath();
2522
+ // 如果要删除,而且当前要删Logic就直接删除并且清除错误
2725
2523
  /**
2726
- * 处理删除节点
2727
- * @param fileNode 当前删除节点的文件级别节点
2728
- * @param targetNode 当前操作的节点
2729
- * @param result toTs生成的内容
2524
+ * 删除节点中的一个内容,删除了以后,就查一下引用的地方一起查一下异常
2730
2525
  */
2731
- async handleDelete(fileNode, targetNode, result) {
2732
- const filePath = fileNode.getEmbeddedFilePath();
2733
- // 如果要删除,而且当前要删Logic就直接删除并且清除错误
2734
- /**
2735
- * 删除节点中的一个内容,删除了以后,就查一下引用的地方一起查一下异常
2736
- */
2737
- let outputFiles = [];
2738
- // 删除之前先查一下内容的依赖
2739
- const newRefs = await this.references({
2740
- file: result.filePath,
2526
+ let outputFiles = [];
2527
+ // 删除之前先查一下内容的依赖
2528
+ const newRefs = await naslServer.references({
2529
+ file: result.filePath,
2530
+ line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
2531
+ offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
2532
+ });
2533
+ // 如果是要删除的内容,就是当前的file节点,要关闭当前文件,就把内容置为空
2534
+ if (fileNode === targetNode) {
2535
+ outputFiles = [{ file: filePath, fileContent: '' }];
2536
+ }
2537
+ else {
2538
+ // 如果是要删除logic一个小内容,要覆盖全部内容
2539
+ // 其余要删除的都是把原来的file节点的内容全部覆盖一把
2540
+ outputFiles = [{ file: result.filePath, fileContent: result.code }];
2541
+ }
2542
+ // 更新文件之后
2543
+ await naslServer.updateFiles({ outputFiles });
2544
+ newRefs.refs.forEach((ref) => filesToCheck.add(ref.file));
2545
+ }
2546
+ /**
2547
+ * 除去rename场景下的更新
2548
+ * @param fileNode 文件级别的节点
2549
+ * @param targetNode 触发修改的节点
2550
+ * @param result 生成代码的code 和位置信息
2551
+ */
2552
+ async function handleChange(fileNode, targetNode, result, action) {
2553
+ naslServer.file2NodeMap.set(result.filePath, fileNode);
2554
+ const outputFiles = [{ file: result.filePath, fileContent: result.code }];
2555
+ // 创建和更新都用update,内部会做判断
2556
+ await naslServer.updateFiles({ outputFiles });
2557
+ // 查一下新函数名的依赖
2558
+ const newRefs = await naslServer.references({
2559
+ file: result.filePath,
2560
+ line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
2561
+ offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
2562
+ });
2563
+ newRefs.refs.forEach((ref) => filesToCheck.add(ref.file));
2564
+ // 唤起建立连接弹框
2565
+ // 文件级别的建立连接采取提醒
2566
+ if (action === 'create' && targetNode.__init) {
2567
+ // 清除临时状态, 完成本次创建
2568
+ delete targetNode.__init;
2569
+ if (fileNode === targetNode && filesToCheck.size > 1) {
2570
+ const confirmParms = {
2571
+ actionType: 'createEstablishConnection',
2572
+ node: fileNode,
2573
+ icon: 'success',
2574
+ };
2575
+ (0, common_1.invokeCommand)('tsConfirm.open', confirmParms, () => { });
2576
+ }
2577
+ }
2578
+ }
2579
+ /**
2580
+ * 重命名的更新
2581
+ * @param fileNode 文件级别的节点
2582
+ * @param targetNode 触发修改的节点
2583
+ * @param result 生成代码的code 和位置信息
2584
+ * @param isRename 是不是修改名字
2585
+ * @param oldFilePath 如果是改名,文件级别的才会有这个参数,用于文件新增替换
2586
+ */
2587
+ async function handleRename(fileNode, targetNode, result, oldFilePath) {
2588
+ // rename 场景
2589
+ const outputFiles = [{ file: result.filePath, fileContent: result.code }];
2590
+ // 如果是要修改顶级文件名
2591
+ // file节点和当前改得是同一节点
2592
+ if (fileNode === targetNode) {
2593
+ naslServer.file2NodeMap.delete(oldFilePath);
2594
+ naslServer.file2NodeMap.set(result.filePath, fileNode);
2595
+ // 修改名字新的添加进去,旧的置为空
2596
+ outputFiles.unshift({ file: oldFilePath, fileContent: '' });
2597
+ // 查一下旧文件名的依赖
2598
+ const oldRefs = await naslServer.references({
2599
+ file: oldFilePath,
2741
2600
  line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
2742
2601
  offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
2743
2602
  });
2744
- // 如果是要删除的内容,就是当前的file节点,要关闭当前文件,就把内容置为空
2745
- if (fileNode === targetNode) {
2746
- outputFiles = [{ file: filePath, fileContent: '' }];
2747
- }
2748
- else {
2749
- // 如果是要删除logic一个小内容,要覆盖全部内容
2750
- // 其余要删除的都是把原来的file节点的内容全部覆盖一把
2751
- outputFiles = [{ file: result.filePath, fileContent: result.code }];
2752
- }
2603
+ oldRefs.refs.forEach((ref) => filesToCheck.add(ref.file));
2604
+ filesToCheck.delete(oldFilePath);
2753
2605
  // 更新文件之后
2754
- await this.updateFiles({ outputFiles });
2755
- newRefs.refs.forEach((ref) => filesToCheck.add(ref.file));
2756
- }
2757
- /**
2758
- * 除去rename场景下的更新
2759
- * @param fileNode 文件级别的节点
2760
- * @param targetNode 触发修改的节点
2761
- * @param result 生成代码的code 和位置信息
2762
- */
2763
- async handleChange(fileNode, targetNode, result, action) {
2764
- this.file2NodeMap.set(result.filePath, fileNode);
2765
- const outputFiles = [{ file: result.filePath, fileContent: result.code }];
2766
- // 创建和更新都用update,内部会做判断
2767
- await this.updateFiles({ outputFiles });
2606
+ await naslServer.updateFiles({ outputFiles });
2768
2607
  // 查一下新函数名的依赖
2769
- const newRefs = await this.references({
2608
+ const newRefs = await naslServer.references({
2770
2609
  file: result.filePath,
2771
2610
  line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
2772
2611
  offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
2773
2612
  });
2774
- newRefs.refs.forEach((ref) => filesToCheck.add(ref.file));
2775
- // 唤起建立连接弹框
2776
- // 文件级别的建立连接采取提醒
2777
- if (action === 'create' && targetNode.__init) {
2778
- // 清除临时状态, 完成本次创建
2779
- delete targetNode.__init;
2780
- if (fileNode === targetNode && filesToCheck.size > 1) {
2781
- const confirmParms = {
2782
- actionType: 'createEstablishConnection',
2783
- node: fileNode,
2784
- icon: 'success',
2785
- };
2786
- (0, common_1.invokeCommand)('tsConfirm.open', confirmParms, () => { });
2787
- }
2788
- }
2613
+ const newRefFileList = new Set();
2614
+ newRefs.refs.forEach((ref) => {
2615
+ filesToCheck.add(ref.file);
2616
+ newRefFileList.add(ref.file);
2617
+ });
2618
+ // 文件级别重命名,有依赖才唤起弹框
2619
+ // 唤起重命名,提示有连接弹框
2620
+ // 重命名建立连接先不展示弹框了
2621
+ // if (newRefFileList.size > 1) {
2622
+ // const confirmParms = {
2623
+ // actionType: 'renameEstablishConnection',
2624
+ // node: fileNode,
2625
+ // icon: 'success',
2626
+ // };
2627
+ // invokeCommand('tsConfirm.open', confirmParms, () => {});
2628
+ // }
2789
2629
  }
2790
- /**
2791
- * 重命名的更新
2792
- * @param fileNode 文件级别的节点
2793
- * @param targetNode 触发修改的节点
2794
- * @param result 生成代码的code 和位置信息
2795
- * @param isRename 是不是修改名字
2796
- * @param oldFilePath 如果是改名,文件级别的才会有这个参数,用于文件新增替换
2797
- */
2798
- async handleRename(fileNode, targetNode, result, oldFilePath) {
2799
- // rename 场景
2800
- const outputFiles = [{ file: result.filePath, fileContent: result.code }];
2801
- // 如果是要修改顶级文件名
2802
- // file节点和当前改得是同一节点
2803
- if (fileNode === targetNode) {
2804
- this.file2NodeMap.delete(oldFilePath);
2805
- this.file2NodeMap.set(result.filePath, fileNode);
2806
- // 修改名字新的添加进去,旧的置为空
2807
- outputFiles.unshift({ file: oldFilePath, fileContent: '' });
2808
- // 查一下旧文件名的依赖
2809
- const oldRefs = await this.references({
2810
- file: oldFilePath,
2811
- line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
2812
- offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
2813
- });
2814
- oldRefs.refs.forEach((ref) => filesToCheck.add(ref.file));
2815
- filesToCheck.delete(oldFilePath);
2816
- // 更新文件之后
2817
- await this.updateFiles({ outputFiles });
2818
- // 查一下新函数名的依赖
2819
- const newRefs = await this.references({
2820
- file: result.filePath,
2821
- line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
2822
- offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
2823
- });
2824
- const newRefFileList = new Set();
2825
- newRefs.refs.forEach((ref) => {
2826
- filesToCheck.add(ref.file);
2827
- newRefFileList.add(ref.file);
2828
- });
2829
- // 文件级别重命名,有依赖才唤起弹框
2830
- // 唤起重命名,提示有连接弹框
2831
- // 重命名建立连接先不展示弹框了
2832
- // if (newRefFileList.size > 1) {
2833
- // const confirmParms = {
2834
- // actionType: 'renameEstablishConnection',
2835
- // node: fileNode,
2836
- // icon: 'success',
2837
- // };
2838
- // invokeCommand('tsConfirm.open', confirmParms, () => {});
2839
- // }
2840
- }
2841
- else if (targetNode instanceof concepts_1.ViewElement) {
2630
+ else if (targetNode instanceof concepts_1.ViewElement) {
2631
+ /**
2632
+ * 因为页面组件比较特殊
2633
+ * 修改之后只用查页面本身就好了
2634
+ */
2635
+ // 更新文件之后
2636
+ await naslServer.updateFiles({ outputFiles });
2637
+ const newRefs2 = await naslServer.references({
2638
+ file: fileNode.getEmbeddedFilePath(),
2639
+ line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
2640
+ offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
2641
+ });
2642
+ newRefs2.refs.forEach((ref) => filesToCheck.add(ref.file));
2643
+ }
2644
+ else {
2645
+ // 查一下当前属性依赖的文件
2646
+ const { currentSource, fileNode } = naslServer.getCurrentSource(targetNode);
2647
+ // 如果当前节点存在
2648
+ if (currentSource) {
2842
2649
  /**
2843
- * 因为页面组件比较特殊
2844
- * 修改之后只用查页面本身就好了
2650
+ * 其余的节点修改之后直接查本身就可以了
2845
2651
  */
2652
+ const oldRefs = await naslServer.references({
2653
+ file: fileNode.getEmbeddedFilePath(),
2654
+ line: (0, translator_1.lsp2tspNumber)(currentSource.range.start.line),
2655
+ offset: (0, translator_1.lsp2tspNumber)(currentSource.range.start.character),
2656
+ });
2657
+ oldRefs.refs.forEach((ref) => filesToCheck.add(ref.file));
2846
2658
  // 更新文件之后
2847
- await this.updateFiles({ outputFiles });
2848
- const newRefs2 = await this.references({
2659
+ await naslServer.updateFiles({ outputFiles });
2660
+ const newRefs2 = await naslServer.references({
2849
2661
  file: fileNode.getEmbeddedFilePath(),
2850
- line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
2851
- offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
2662
+ line: (0, translator_1.lsp2tspNumber)(currentSource.range.start.line),
2663
+ offset: (0, translator_1.lsp2tspNumber)(currentSource.range.start.character),
2852
2664
  });
2853
2665
  newRefs2.refs.forEach((ref) => filesToCheck.add(ref.file));
2854
2666
  }
2855
- else {
2856
- // 查一下当前属性依赖的文件
2857
- const { currentSource, fileNode } = this.getCurrentSource(targetNode);
2858
- // 如果当前节点存在
2859
- if (currentSource) {
2860
- /**
2861
- * 其余的节点修改之后直接查本身就可以了
2862
- */
2863
- const oldRefs = await this.references({
2864
- file: fileNode.getEmbeddedFilePath(),
2865
- line: (0, translator_1.lsp2tspNumber)(currentSource.range.start.line),
2866
- offset: (0, translator_1.lsp2tspNumber)(currentSource.range.start.character),
2867
- });
2868
- oldRefs.refs.forEach((ref) => filesToCheck.add(ref.file));
2869
- // 更新文件之后
2870
- await this.updateFiles({ outputFiles });
2871
- const newRefs2 = await this.references({
2872
- file: fileNode.getEmbeddedFilePath(),
2873
- line: (0, translator_1.lsp2tspNumber)(currentSource.range.start.line),
2874
- offset: (0, translator_1.lsp2tspNumber)(currentSource.range.start.character),
2875
- });
2876
- newRefs2.refs.forEach((ref) => filesToCheck.add(ref.file));
2877
- }
2878
- }
2879
2667
  }
2880
- /**
2881
- * 处理一些节点操作,子节点需要更新并且check的场景
2882
- * 因为删除,新增父页面,或者重命名会一起
2883
- * 删除或者新增view而且他有子集 就要执行同样的操作
2884
- * @param action 当前操作类型
2885
- * @param fileNode 文件节点
2886
- * @param targetNode 操作节点 这里要两个相等才会走家去面对哦逻辑
2887
- * @param oldpath 触发内容的oldpath
2888
- */
2889
- async incidentalAction(action, fileNode, targetNode, oldpath) {
2890
- if ((action === 'create' || action === 'delete' || (action === 'update' && oldpath)) && fileNode === targetNode) {
2891
- // 删除或者新增页面
2892
- if (fileNode instanceof concepts_1.View && fileNode.children?.length) {
2893
- const fileNodeChildren = fileNode.children;
2894
- for (let i = 0; i < fileNodeChildren.length; i++) {
2895
- const fileNodeItem = fileNodeChildren[i];
2896
- const result = fileNodeItem.toEmbeddedTSFile();
2897
- fileNodeItem.sourceMap = result.sourceMap;
2898
- if (action === 'create') {
2899
- await this.handleChange(fileNodeItem, fileNodeItem, result, action);
2900
- await this.incidentalAction(action, fileNodeItem, fileNodeItem);
2901
- }
2902
- else if (action === 'delete') {
2903
- await this.handleDelete(fileNodeItem, fileNodeItem, result);
2904
- await this.incidentalAction(action, fileNodeItem, fileNodeItem);
2905
- }
2906
- else if (action === 'update' && oldpath) {
2907
- const parentPath = oldpath.replace('.ts', '/');
2908
- const currentOldPath = parentPath + fileNodeItem.name + '.ts';
2909
- // 因为重命名这里只有当前修改父级的 旧名称, 所以他的子集也要根据旧名称去查依赖 更新内容
2910
- await this.handleRename(fileNodeItem, fileNodeItem, result, currentOldPath);
2911
- await this.incidentalAction(action, fileNodeItem, fileNodeItem, currentOldPath);
2912
- }
2668
+ }
2669
+ /**
2670
+ * 处理一些节点操作,子节点需要更新并且check的场景
2671
+ * 因为删除,新增父页面,或者重命名会一起
2672
+ * 删除或者新增view而且他有子集 就要执行同样的操作
2673
+ * @param action 当前操作类型
2674
+ * @param fileNode 文件节点
2675
+ * @param targetNode 操作节点 这里要两个相等才会走家去面对哦逻辑
2676
+ * @param oldpath 触发内容的oldpath
2677
+ */
2678
+ async function incidentalAction(action, fileNode, targetNode, oldpath) {
2679
+ if ((action === 'create' || action === 'delete' || (action === 'update' && oldpath)) && fileNode === targetNode) {
2680
+ // 删除或者新增页面
2681
+ if (fileNode instanceof concepts_1.View && fileNode.children?.length) {
2682
+ const fileNodeChildren = fileNode.children;
2683
+ for (let i = 0; i < fileNodeChildren.length; i++) {
2684
+ const fileNodeItem = fileNodeChildren[i];
2685
+ const result = fileNodeItem.toEmbeddedTSFile();
2686
+ fileNodeItem.sourceMap = result.sourceMap;
2687
+ if (action === 'create') {
2688
+ await handleChange(fileNodeItem, fileNodeItem, result, action);
2689
+ await incidentalAction(action, fileNodeItem, fileNodeItem);
2690
+ }
2691
+ else if (action === 'delete') {
2692
+ await handleDelete(fileNodeItem, fileNodeItem, result);
2693
+ await incidentalAction(action, fileNodeItem, fileNodeItem);
2694
+ }
2695
+ else if (action === 'update' && oldpath) {
2696
+ const parentPath = oldpath.replace('.ts', '/');
2697
+ const currentOldPath = parentPath + fileNodeItem.name + '.ts';
2698
+ // 因为重命名这里只有当前修改父级的 旧名称, 所以他的子集也要根据旧名称去查依赖 更新内容
2699
+ await handleRename(fileNodeItem, fileNodeItem, result, currentOldPath);
2700
+ await incidentalAction(action, fileNodeItem, fileNodeItem, currentOldPath);
2701
+ }
2702
+ }
2703
+ }
2704
+ // 删除或新增模块
2705
+ // 需要把下面的哦内容全部都更新一遍
2706
+ if (fileNode instanceof concepts_1.Module) {
2707
+ if (fileNode.type === 'interface' && fileNode.isAdd && action === 'create') {
2708
+ isChangeInterface = true;
2709
+ }
2710
+ const module = targetNode;
2711
+ const results = [];
2712
+ naslServer.contentToFile(module, results);
2713
+ for (let i = 0; i < results.length; i++) {
2714
+ const result = results[i];
2715
+ const node = naslServer.file2NodeMap.get(result.filePath);
2716
+ if (action === 'create') {
2717
+ await handleChange(node, node, result, action);
2718
+ }
2719
+ else {
2720
+ await handleDelete(node, node, result);
2913
2721
  }
2914
2722
  }
2915
- // 删除或新增模块
2916
- // 需要把下面的哦内容全部都更新一遍
2917
- if (fileNode instanceof concepts_1.Module) {
2918
- if (fileNode.type === 'interface' && fileNode.isAdd && action === 'create') {
2919
- isChangeInterface = true;
2920
- }
2921
- const module = targetNode;
2922
- const results = [];
2923
- this.contentToFile(module, results);
2924
- for (let i = 0; i < results.length; i++) {
2925
- const result = results[i];
2926
- const node = this.file2NodeMap.get(result.filePath);
2927
- if (action === 'create') {
2928
- await this.handleChange(node, node, result, action);
2929
- }
2930
- else {
2931
- await this.handleDelete(node, node, result);
2932
- }
2723
+ // 删除模块通知更新列表
2724
+ if (action === 'delete') {
2725
+ try {
2726
+ // 如果已经
2727
+ (0, common_1.invokeCommand)('module.delete', true);
2933
2728
  }
2934
- // 删除模块通知更新列表
2935
- if (action === 'delete') {
2936
- try {
2937
- // 如果已经
2938
- (0, common_1.invokeCommand)('module.delete', true);
2939
- }
2940
- catch (err) {
2941
- console.log('module.delete', '组件销毁了,不用唤起了');
2942
- }
2729
+ catch (err) {
2730
+ console.log('module.delete', '组件销毁了,不用唤起了');
2943
2731
  }
2944
2732
  }
2945
- /**
2733
+ }
2734
+ /**
2946
2735
  * DataSource只会重命名时候,需要把子集全部重新生成一下
2947
2736
  */
2948
- if (fileNode instanceof concepts_1.DataSource) {
2949
- fileNode.entities.forEach(async (entity) => {
2950
- try {
2951
- const result = entity.toEmbeddedTSFile();
2952
- const parentPath = oldpath.replace('.ts', '/');
2953
- const currentOldPath = parentPath + '/entities/' + entity.name + '.ts';
2954
- // 因为重命名这里只有当前修改父级的 旧名称, 所以他的子集也要根据旧名称去查依赖 更新内容
2955
- await this.handleRename(entity, entity, result, currentOldPath);
2956
- }
2957
- catch (err) {
2958
- console.log(err);
2959
- }
2960
- });
2961
- }
2737
+ if (fileNode instanceof concepts_1.DataSource) {
2738
+ fileNode.entities.forEach(async (entity) => {
2739
+ try {
2740
+ const result = entity.toEmbeddedTSFile();
2741
+ const parentPath = oldpath.replace('.ts', '/');
2742
+ const currentOldPath = parentPath + '/entities/' + entity.name + '.ts';
2743
+ // 因为重命名这里只有当前修改父级的 旧名称, 所以他的子集也要根据旧名称去查依赖 更新内容
2744
+ await handleRename(entity, entity, result, currentOldPath);
2745
+ }
2746
+ catch (err) {
2747
+ console.log(err);
2748
+ }
2749
+ });
2962
2750
  }
2963
2751
  }
2964
- async receiveHandleChange($event) {
2965
- singleFileChangeIng = true;
2966
- // 行为
2967
- const action = $event.action;
2968
- const targetNode = $event.target;
2969
- // 当前操作的文件节点
2970
- const { fileNode } = this.getCurrentSource(targetNode);
2971
- // 如果是导入模块就,就引入对应模块,先不处理module和Configuration,下面的内容会自动创建
2972
- if (!fileNode || fileNode instanceof concepts_1.Module || fileNode instanceof concepts_1.Configuration) {
2973
- // module单独处理
2974
- if (fileNode instanceof concepts_1.Module) {
2975
- await this.incidentalAction(action, fileNode, targetNode);
2976
- }
2977
- return;
2752
+ }
2753
+ async function receiveHandleChange($event) {
2754
+ // 行为
2755
+ const action = $event.action;
2756
+ const targetNode = $event.target;
2757
+ // 当前操作的文件节点
2758
+ const { fileNode } = naslServer.getCurrentSource(targetNode);
2759
+ // 如果是导入模块就,就引入对应模块,先不处理module和Configuration,下面的内容会自动创建
2760
+ if (!fileNode || fileNode instanceof concepts_1.Module || fileNode instanceof concepts_1.Configuration) {
2761
+ // module单独处理
2762
+ if (fileNode instanceof concepts_1.Module) {
2763
+ await incidentalAction(action, fileNode, targetNode);
2764
+ }
2765
+ return;
2766
+ }
2767
+ const result = fileNode.toEmbeddedTSFile();
2768
+ // 当前操作的节点
2769
+ // 如果当前没有生成tsFile
2770
+ if (!result) {
2771
+ return;
2772
+ }
2773
+ // 修改触发修改文件
2774
+ naslServer._debugInFileStorage($event.currentTarget, [
2775
+ {
2776
+ file: result.filePath,
2777
+ fileContent: result.code,
2778
+ },
2779
+ ]);
2780
+ fileNode.sourceMap = result.sourceMap;
2781
+ if (action === 'update' || action === 'create') {
2782
+ if ($event?.field !== 'name') {
2783
+ await handleChange(fileNode, targetNode, result, action);
2784
+ await incidentalAction(action, fileNode, targetNode);
2978
2785
  }
2979
- const result = fileNode.toEmbeddedTSFile();
2980
- // 当前操作的节点
2981
- // 如果当前没有生成tsFile
2982
- if (!result) {
2983
- return;
2786
+ else {
2787
+ const oldpath = fileNode.getEmbeddedFilePath($event.oldObject.name);
2788
+ await handleRename(fileNode, targetNode, result, oldpath);
2789
+ await incidentalAction(action, fileNode, targetNode, oldpath);
2984
2790
  }
2985
- // 修改触发修改文件
2986
- this._debugInFileStorage(targetNode, [
2987
- {
2988
- file: result.filePath,
2989
- fileContent: result.code,
2990
- },
2991
- ]);
2992
- fileNode.sourceMap = result.sourceMap;
2993
- if (action === 'update' || action === 'create') {
2994
- if ($event?.field !== 'name') {
2995
- await this.handleChange(fileNode, targetNode, result, action);
2996
- await this.incidentalAction(action, fileNode, targetNode);
2791
+ }
2792
+ // 删除
2793
+ if (action === 'delete') {
2794
+ await incidentalAction(action, fileNode, targetNode);
2795
+ await handleDelete(fileNode, targetNode, result);
2796
+ }
2797
+ return true;
2798
+ }
2799
+ // 监听所有改变操作
2800
+ translator_1.embeddedTSEmitter.on('change', ($event) => {
2801
+ // 收集到一个行为集合
2802
+ const eventValue = $event.value;
2803
+ const stackList = [];
2804
+ eventValue.forEach(async (item) => {
2805
+ stackList.push(item.originEvent);
2806
+ });
2807
+ // 异步状态机,一个完成了在执行下一个
2808
+ function next() {
2809
+ const item = stackList.shift();
2810
+ receiveHandleChange(item).then(async () => {
2811
+ if (stackList.length) {
2812
+ next();
2997
2813
  }
2998
2814
  else {
2999
- const oldpath = fileNode.getEmbeddedFilePath($event.oldObject.name);
3000
- await this.handleRename(fileNode, targetNode, result, oldpath);
3001
- await this.incidentalAction(action, fileNode, targetNode, oldpath);
2815
+ await naslServer.getDiagnosticRecordsAndPushAll(Array.from(filesToCheck));
2816
+ filesToCheck.clear();
3002
2817
  }
3003
- }
3004
- // 删除
3005
- if (action === 'delete') {
3006
- await this.incidentalAction(action, fileNode, targetNode);
3007
- await this.handleDelete(fileNode, targetNode, result);
3008
- }
3009
- return true;
2818
+ });
3010
2819
  }
3011
- changeFileNext() {
3012
- if (!singleFileChangeIng) {
3013
- const item = this.changeStackList.shift();
3014
- this.receiveHandleChange(item).catch((err) => {
3015
- console.log(err, 'receiveHandleChangeErr');
3016
- }).finally(async () => {
3017
- // 每一个文件与change接触就把状态置为false,让下一个进入
3018
- singleFileChangeIng = false;
3019
- if (this.changeStackList.length) {
3020
- this.changeFileNext();
3021
- }
3022
- else {
3023
- console.log(Array.from(filesToCheck));
3024
- await this.getDiagnosticRecordsAndPushAll(Array.from(filesToCheck));
3025
- filesToCheck.clear();
3026
- }
3027
- });
3028
- }
2820
+ // 如果有长度开始执行状态机
2821
+ if (stackList.length) {
2822
+ next();
3029
2823
  }
3030
- }
3031
- exports.NaslServer = NaslServer;
2824
+ });
2825
+ // naslServer.messager.options.context = naslServer;
2826
+ exports.default = naslServer;
3032
2827
  //# sourceMappingURL=naslServer.js.map