@lcap/nasl 2.20.0-beta.2 → 2.20.0-beta.4

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 (323) hide show
  1. package/out/automate/engine/index.d.ts +1 -1
  2. package/out/automate/engine/index.js +2 -3
  3. package/out/automate/engine/index.js.map +1 -1
  4. package/out/automate/engine/uniqueName.d.ts +1 -1
  5. package/out/automate/engine/uniqueName.js +2 -2
  6. package/out/automate/engine/uniqueName.js.map +1 -1
  7. package/out/automate/engine/utils.js +4 -1
  8. package/out/automate/engine/utils.js.map +1 -1
  9. package/out/automate/template/myProcess.d.ts +1 -1
  10. package/out/automate/template/myProcess.js +2 -2
  11. package/out/automate/template/myProcess.js.map +1 -1
  12. package/out/bak/translator.js +14 -22
  13. package/out/bak/translator.js.map +1 -1
  14. package/out/common/BaseNode.js +4 -1
  15. package/out/common/BaseNode.js.map +1 -1
  16. package/out/common/Command.d.ts +1 -0
  17. package/out/common/Command.js +5 -1
  18. package/out/common/Command.js.map +1 -1
  19. package/out/concepts/App__.d.ts +4 -0
  20. package/out/concepts/App__.js +30 -6
  21. package/out/concepts/App__.js.map +1 -1
  22. package/out/concepts/Assignee__.js +4 -3
  23. package/out/concepts/Assignee__.js.map +1 -1
  24. package/out/concepts/BatchAssignment__.js +3 -3
  25. package/out/concepts/BatchAssignment__.js.map +1 -1
  26. package/out/concepts/BindAttribute__.d.ts +7 -0
  27. package/out/concepts/BindAttribute__.js +270 -39
  28. package/out/concepts/BindAttribute__.js.map +1 -1
  29. package/out/concepts/BindDirective__.d.ts +7 -0
  30. package/out/concepts/BindDirective__.js +215 -17
  31. package/out/concepts/BindDirective__.js.map +1 -1
  32. package/out/concepts/BindStyle__.d.ts +7 -0
  33. package/out/concepts/BindStyle__.js +194 -4
  34. package/out/concepts/BindStyle__.js.map +1 -1
  35. package/out/concepts/CallFunction__.js +22 -8
  36. package/out/concepts/CallFunction__.js.map +1 -1
  37. package/out/concepts/CallInterface__.js +3 -2
  38. package/out/concepts/CallInterface__.js.map +1 -1
  39. package/out/concepts/CallLogic__.d.ts +3 -0
  40. package/out/concepts/CallLogic__.js +78 -89
  41. package/out/concepts/CallLogic__.js.map +1 -1
  42. package/out/concepts/CallQueryComponent__.js +20 -3
  43. package/out/concepts/CallQueryComponent__.js.map +1 -1
  44. package/out/concepts/ConfigGroup__.d.ts +1 -0
  45. package/out/concepts/ConfigGroup__.js +13 -0
  46. package/out/concepts/ConfigGroup__.js.map +1 -1
  47. package/out/concepts/ConfigProperty__.d.ts +19 -0
  48. package/out/concepts/ConfigProperty__.js +61 -0
  49. package/out/concepts/ConfigProperty__.js.map +1 -1
  50. package/out/concepts/Configuration__.d.ts +1 -0
  51. package/out/concepts/Configuration__.js +13 -0
  52. package/out/concepts/Configuration__.js.map +1 -1
  53. package/out/concepts/DataSource__.js.map +1 -1
  54. package/out/concepts/Destination__.d.ts +1 -0
  55. package/out/concepts/Destination__.js +61 -7
  56. package/out/concepts/Destination__.js.map +1 -1
  57. package/out/concepts/EntityProperty__.js +9 -1
  58. package/out/concepts/EntityProperty__.js.map +1 -1
  59. package/out/concepts/EnumItem__.d.ts +5 -5
  60. package/out/concepts/EnumItem__.js +6 -6
  61. package/out/concepts/Enum__.d.ts +20 -19
  62. package/out/concepts/Enum__.js +28 -1
  63. package/out/concepts/Enum__.js.map +1 -1
  64. package/out/concepts/ExternalDestination__.d.ts +1 -0
  65. package/out/concepts/ExternalDestination__.js +21 -3
  66. package/out/concepts/ExternalDestination__.js.map +1 -1
  67. package/out/concepts/ForEachStatement__.js +2 -0
  68. package/out/concepts/ForEachStatement__.js.map +1 -1
  69. package/out/concepts/Frontend__.d.ts +2 -1
  70. package/out/concepts/Frontend__.js.map +1 -1
  71. package/out/concepts/Identifier__.js +16 -5
  72. package/out/concepts/Identifier__.js.map +1 -1
  73. package/out/concepts/InterfaceParam__.js +9 -1
  74. package/out/concepts/InterfaceParam__.js.map +1 -1
  75. package/out/concepts/JSBlock__.js +5 -1
  76. package/out/concepts/JSBlock__.js.map +1 -1
  77. package/out/concepts/Logic__.d.ts +79 -79
  78. package/out/concepts/Logic__.js +16 -3
  79. package/out/concepts/Logic__.js.map +1 -1
  80. package/out/concepts/Match__.d.ts +0 -3
  81. package/out/concepts/Match__.js +11 -66
  82. package/out/concepts/Match__.js.map +1 -1
  83. package/out/concepts/MemberExpression__.js +9 -0
  84. package/out/concepts/MemberExpression__.js.map +1 -1
  85. package/out/concepts/Module__.d.ts +16 -0
  86. package/out/concepts/Module__.js +43 -0
  87. package/out/concepts/Module__.js.map +1 -1
  88. package/out/concepts/NewComposite__.d.ts +2 -4
  89. package/out/concepts/NewComposite__.js +91 -126
  90. package/out/concepts/NewComposite__.js.map +1 -1
  91. package/out/concepts/NewList__.d.ts +1 -0
  92. package/out/concepts/NewList__.js +22 -2
  93. package/out/concepts/NewList__.js.map +1 -1
  94. package/out/concepts/NewMap__.d.ts +1 -0
  95. package/out/concepts/NewMap__.js +43 -11
  96. package/out/concepts/NewMap__.js.map +1 -1
  97. package/out/concepts/OqlQueryComponent__.js +40 -12
  98. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  99. package/out/concepts/Param__.js +10 -2
  100. package/out/concepts/Param__.js.map +1 -1
  101. package/out/concepts/ProcessElement__.js +2 -1
  102. package/out/concepts/ProcessElement__.js.map +1 -1
  103. package/out/concepts/ProcessOutcome__.js +1 -1
  104. package/out/concepts/ProcessOutcome__.js.map +1 -1
  105. package/out/concepts/ProcessOutcomes__.js +1 -1
  106. package/out/concepts/ProcessOutcomes__.js.map +1 -1
  107. package/out/concepts/Process__.js +1 -0
  108. package/out/concepts/Process__.js.map +1 -1
  109. package/out/concepts/Return__.js +10 -2
  110. package/out/concepts/Return__.js.map +1 -1
  111. package/out/concepts/StringInterpolation__.js +14 -2
  112. package/out/concepts/StringInterpolation__.js.map +1 -1
  113. package/out/concepts/StringLiteral__.js +6 -6
  114. package/out/concepts/StringLiteral__.js.map +1 -1
  115. package/out/concepts/StructureProperty__.js +9 -1
  116. package/out/concepts/StructureProperty__.js.map +1 -1
  117. package/out/concepts/TypeAnnotation__.d.ts +6 -3
  118. package/out/concepts/TypeAnnotation__.js +67 -13
  119. package/out/concepts/TypeAnnotation__.js.map +1 -1
  120. package/out/concepts/ValidationRule__.d.ts +1 -0
  121. package/out/concepts/ValidationRule__.js +53 -0
  122. package/out/concepts/ValidationRule__.js.map +1 -1
  123. package/out/concepts/Variable__.js +9 -1
  124. package/out/concepts/Variable__.js.map +1 -1
  125. package/out/concepts/ViewElement__.js +17 -1
  126. package/out/concepts/ViewElement__.js.map +1 -1
  127. package/out/concepts/View__.d.ts +1 -3
  128. package/out/concepts/View__.js +22 -11
  129. package/out/concepts/View__.js.map +1 -1
  130. package/out/concepts/basics/stdlib/nasl.collection.js +6 -1
  131. package/out/concepts/basics/stdlib/nasl.collection.js.map +1 -1
  132. package/out/concepts/basics/stdlib/nasl.configuration.js +3 -0
  133. package/out/concepts/basics/stdlib/nasl.configuration.js.map +1 -1
  134. package/out/concepts/basics/stdlib/nasl.core.d.ts +2 -0
  135. package/out/concepts/basics/stdlib/nasl.core.js +34 -0
  136. package/out/concepts/basics/stdlib/nasl.core.js.map +1 -1
  137. package/out/concepts/basics/stdlib/nasl.util.js +4 -2
  138. package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
  139. package/out/concepts/basics/types/index.d.ts +1 -0
  140. package/out/concepts/basics/types/index.js +3 -1
  141. package/out/concepts/basics/types/index.js.map +1 -1
  142. package/out/concepts/index__.d.ts +0 -1
  143. package/out/concepts/index__.js +0 -1
  144. package/out/concepts/index__.js.map +1 -1
  145. package/out/enums/KEYWORDS.js +8 -0
  146. package/out/enums/KEYWORDS.js.map +1 -1
  147. package/out/generator/genBundleFiles.js +24 -5
  148. package/out/generator/genBundleFiles.js.map +1 -1
  149. package/out/generator/genReleaseBody.d.ts +2 -3
  150. package/out/generator/genReleaseBody.js +97 -23
  151. package/out/generator/genReleaseBody.js.map +1 -1
  152. package/out/generator/permission.d.ts +2 -10
  153. package/out/generator/permission.js +27 -14
  154. package/out/generator/permission.js.map +1 -1
  155. package/out/server/entity2LogicNamespace.js +2 -20
  156. package/out/server/entity2LogicNamespace.js.map +1 -1
  157. package/out/server/extendBaseNode.js +16 -5
  158. package/out/server/extendBaseNode.js.map +1 -1
  159. package/out/server/formatTsUtils.d.ts +2 -1
  160. package/out/server/formatTsUtils.js +40 -10
  161. package/out/server/formatTsUtils.js.map +1 -1
  162. package/out/server/getLogics.d.ts +2 -2
  163. package/out/server/getLogics.js +3 -3
  164. package/out/server/getLogics.js.map +1 -1
  165. package/out/server/getMemberIdentifier.d.ts +1 -0
  166. package/out/server/getMemberIdentifier.js +27 -1
  167. package/out/server/getMemberIdentifier.js.map +1 -1
  168. package/out/server/index.js +1 -0
  169. package/out/server/index.js.map +1 -1
  170. package/out/server/naslServer.d.ts +7 -1
  171. package/out/server/naslServer.js +519 -46
  172. package/out/server/naslServer.js.map +1 -1
  173. package/out/server/translator.js +109 -33
  174. package/out/server/translator.js.map +1 -1
  175. package/out/service/storage/init.js +21 -1
  176. package/out/service/storage/init.js.map +1 -1
  177. package/out/templator/genCreateBlock.js +1 -3
  178. package/out/templator/genCreateBlock.js.map +1 -1
  179. package/out/templator/genCurdEditMultipleKeyBlock.js +1 -3
  180. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  181. package/out/templator/genCurdMultipleKeyBlock.js +2 -4
  182. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  183. package/out/templator/genGetBlock.js +1 -1
  184. package/out/templator/genGetBlock.js.map +1 -1
  185. package/out/templator/genGridViewBlock.js +2 -2
  186. package/out/templator/genGridViewBlock.js.map +1 -1
  187. package/out/templator/genListViewBlock.js +7 -1
  188. package/out/templator/genListViewBlock.js.map +1 -1
  189. package/out/templator/genSelectBlock.js +1 -1
  190. package/out/templator/genSelectBlock.js.map +1 -1
  191. package/out/templator/genTableBlock.js +2 -2
  192. package/out/templator/genTableBlock.js.map +1 -1
  193. package/out/templator/genUpdateBlock.js +2 -3
  194. package/out/templator/genUpdateBlock.js.map +1 -1
  195. package/out/utils/traverse.js +8 -2
  196. package/out/utils/traverse.js.map +1 -1
  197. package/package.json +2 -2
  198. package/sandbox/stdlib/dist/nasl.logging.js +0 -0
  199. package/sandbox/stdlib/dist/nasl.util.js +0 -0
  200. package/sandbox/stdlib/nasl.collection.ts +1 -0
  201. package/sandbox/stdlib/nasl.core.ts +34 -0
  202. package/sandbox/stdlib/nasl.oql.ts +71 -15
  203. package/sandbox/stdlib/nasl.util.ts +9 -3
  204. package/src/automate/engine/dist/index.dev.js +517 -0
  205. package/src/automate/engine/index.js +2 -3
  206. package/src/automate/engine/uniqueName.js +2 -2
  207. package/src/automate/engine/utils.js +4 -2
  208. package/src/automate/template/myProcess.js +2 -2
  209. package/src/bak/translator.js +16 -25
  210. package/src/common/BaseNode.ts +3 -1
  211. package/src/common/Command.ts +4 -0
  212. package/src/common/dist/BaseNode.js +1101 -0
  213. package/src/concepts/App__.ts +36 -7
  214. package/src/concepts/Assignee__.ts +4 -3
  215. package/src/concepts/BatchAssignment__.ts +3 -3
  216. package/src/concepts/BindAttribute__.ts +299 -38
  217. package/src/concepts/BindDirective__.ts +204 -31
  218. package/src/concepts/BindStyle__.ts +187 -24
  219. package/src/concepts/CallFunction__.ts +55 -10
  220. package/src/concepts/CallInterface__.ts +3 -2
  221. package/src/concepts/CallLogic__.ts +110 -90
  222. package/src/concepts/CallQueryComponent__.ts +18 -3
  223. package/src/concepts/ConfigGroup__.ts +17 -4
  224. package/src/concepts/ConfigProperty__.ts +70 -4
  225. package/src/concepts/Configuration__.ts +14 -5
  226. package/src/concepts/DataSource__.ts +4 -1
  227. package/src/concepts/Destination__.ts +61 -7
  228. package/src/concepts/EntityProperty__.ts +7 -1
  229. package/src/concepts/EnumItem__.ts +6 -6
  230. package/src/concepts/Enum__.ts +22 -19
  231. package/src/concepts/ExternalDestination__.ts +28 -8
  232. package/src/concepts/ForEachStatement__.ts +2 -0
  233. package/src/concepts/Frontend__.ts +2 -1
  234. package/src/concepts/Identifier__.ts +16 -5
  235. package/src/concepts/InterfaceParam__.ts +7 -1
  236. package/src/concepts/JSBlock__.ts +3 -2
  237. package/src/concepts/Logic__.ts +95 -83
  238. package/src/concepts/Match__.ts +31 -67
  239. package/src/concepts/MemberExpression__.ts +6 -0
  240. package/src/concepts/Module__.ts +57 -0
  241. package/src/concepts/NewComposite__.ts +95 -140
  242. package/src/concepts/NewList__.ts +23 -2
  243. package/src/concepts/NewMap__.ts +48 -24
  244. package/src/concepts/OqlQueryComponent__.ts +40 -20
  245. package/src/concepts/Param__.ts +178 -176
  246. package/src/concepts/ProcessElement__.ts +2 -1
  247. package/src/concepts/ProcessOutcome__.ts +1 -1
  248. package/src/concepts/ProcessOutcomes__.ts +1 -1
  249. package/src/concepts/Process__.ts +1 -0
  250. package/src/concepts/Return__.ts +8 -2
  251. package/src/concepts/StringInterpolation__.ts +19 -7
  252. package/src/concepts/StringLiteral__.ts +7 -6
  253. package/src/concepts/StructureProperty__.ts +7 -1
  254. package/src/concepts/TypeAnnotation__.ts +101 -14
  255. package/src/concepts/ValidationRule__.ts +58 -9
  256. package/src/concepts/Variable__.ts +11 -1
  257. package/src/concepts/ViewElement__.ts +39 -2
  258. package/src/concepts/View__.ts +26 -14
  259. package/src/concepts/basics/stdlib/dist/nasl.util.js +1602 -0
  260. package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +24 -0
  261. package/src/concepts/basics/stdlib/nasl.collection.ts +6 -1
  262. package/src/concepts/basics/stdlib/nasl.configuration.ts +3 -0
  263. package/src/concepts/basics/stdlib/nasl.core.ts +33 -2
  264. package/src/concepts/basics/stdlib/nasl.util.ts +4 -2
  265. package/src/concepts/basics/types/index.ts +1 -0
  266. package/src/concepts/dist/BindAttribute__.js +795 -0
  267. package/src/concepts/dist/BindEvent__.js +732 -0
  268. package/src/concepts/dist/CallFunction__.js +527 -0
  269. package/src/concepts/dist/CallLogic__.js +932 -0
  270. package/src/concepts/dist/Destination__.js +708 -0
  271. package/src/concepts/dist/ExternalDestination__.js +298 -0
  272. package/src/concepts/dist/Identifier__.js +311 -0
  273. package/src/concepts/dist/StringInterpolation__.js +231 -0
  274. package/src/concepts/dist/TypeAnnotation__.js +834 -0
  275. package/src/concepts/dist/ViewElement__.js +1692 -0
  276. package/src/concepts/dist/View__.js +1601 -0
  277. package/src/concepts/index__.ts +0 -1
  278. package/src/enums/KEYWORDS.ts +8 -0
  279. package/src/generator/dist/genBundleFiles.js +261 -0
  280. package/src/generator/dist/genMetaData.js +245 -0
  281. package/src/generator/dist/permission.js +405 -0
  282. package/src/generator/genBundleFiles.ts +24 -5
  283. package/src/generator/genReleaseBody.ts +75 -30
  284. package/src/generator/permission.ts +31 -15
  285. package/src/server/entity2LogicNamespace.ts +2 -20
  286. package/src/server/extendBaseNode.ts +15 -5
  287. package/src/server/formatTsUtils.ts +41 -10
  288. package/src/server/getLogics.ts +4 -4
  289. package/src/server/getMemberIdentifier.ts +27 -1
  290. package/src/server/index.ts +2 -0
  291. package/src/server/naslServer.ts +520 -48
  292. package/src/server/translator.ts +96 -34
  293. package/src/service/storage/dist/init.js +579 -0
  294. package/src/service/storage/init.ts +22 -2
  295. package/src/templator/dist/genEditTableBlock.js +204 -0
  296. package/src/templator/dist/genGridViewBlock.js +265 -0
  297. package/src/templator/dist/genListViewBlock.js +84 -0
  298. package/src/templator/dist/genTableBlock.js +209 -0
  299. package/src/templator/dist/utils.js +527 -0
  300. package/src/templator/genCreateBlock.ts +1 -3
  301. package/src/templator/genCurdEditMultipleKeyBlock.ts +1 -3
  302. package/src/templator/genCurdMultipleKeyBlock.ts +2 -4
  303. package/src/templator/genGetBlock.ts +1 -1
  304. package/src/templator/genGridViewBlock.ts +3 -4
  305. package/src/templator/genListViewBlock.ts +9 -3
  306. package/src/templator/genSelectBlock.ts +1 -1
  307. package/src/templator/genTableBlock.ts +3 -3
  308. package/src/templator/genUpdateBlock.ts +2 -3
  309. package/src/utils/traverse.ts +10 -2
  310. package/ts-worker/lib/tsserver.js +10 -2
  311. package/ts-worker/package.json +1 -0
  312. package/ts-worker/webpack.config.js +11 -2
  313. package/out/concepts/ConstructArgument__.d.ts +0 -40
  314. package/out/concepts/ConstructArgument__.js +0 -108
  315. package/out/concepts/ConstructArgument__.js.map +0 -1
  316. package/out/concepts/Construct__.d.ts +0 -189
  317. package/out/concepts/Construct__.js +0 -340
  318. package/out/concepts/Construct__.js.map +0 -1
  319. package/out/templator/sql-parser/index.d.ts +0 -1
  320. package/out/templator/sql-parser/index.js +0 -228
  321. package/out/templator/sql-parser/index.js.map +0 -1
  322. package/out/templator/sql-parser/parser.js +0 -26664
  323. package/out/templator/sql-parser/parser.js.map +0 -1
@@ -62,6 +62,14 @@ import {
62
62
  BatchAssignment,
63
63
  ForEachStatement,
64
64
  Frontend,
65
+ NewList,
66
+ NewMap,
67
+ ConfigProperty,
68
+ BindStyle,
69
+ BindDirective,
70
+ LogicItem,
71
+ JSBlock,
72
+ NewComposite,
65
73
  } from '../concepts';
66
74
  import { lsp2tspNumber, SourceMap, SourceMapItem } from '../translator';
67
75
  import axios from '../service/storage';
@@ -71,16 +79,20 @@ import { DiagnosticRecord, Diagnostic, DiagnosticManager } from '../manager/diag
71
79
  import formatUiTs from './createUiTs';
72
80
  import { primitiveTypeList } from '../concepts/basics/types/coreTypeList';
73
81
  import { getPlatformType, type2TypeAnnotation } from './formatTsUtils';
82
+ import * as utils from '../utils';
74
83
  import naslStdlibMap from './naslStdlibMap';
75
84
  import * as jsoner from '../service/storage/jsoner';
76
85
  import { EventEmitter } from '../common/EventEmitter';
77
86
 
87
+ import { traverse } from '../utils';
88
+
78
89
  const EmbeddedTSFileLineMap: { [name: string]: number } = {
79
90
  Entity: 3,
80
91
  };
81
92
 
82
93
  const EmbeddedTSFileOffsetMap: { [name: string]: number } = {
83
94
  Variable: 12,
95
+ ConfigProperty: 12,
84
96
  };
85
97
 
86
98
  export interface FileNode extends BaseNode {
@@ -169,6 +181,9 @@ export class NaslServer {
169
181
 
170
182
  singleFileChangeIng: Boolean;
171
183
 
184
+ // 包含组件逻辑调用的逻辑map
185
+ logicSetWithComponentLogic: Set<string> = new Set<string>();
186
+
172
187
  constructor() {
173
188
  /// #if process.env.BUILD_TARGET === 'node'
174
189
  if (globalThis.process) // For TS build
@@ -177,6 +192,7 @@ export class NaslServer {
177
192
  /// #endif
178
193
  /// #if process.env.BUILD_TARGET !== 'node'
179
194
  if (globalThis.window) // For TS build
195
+ /* !!!如果改动这里需要看下关联的对应文件:webpack/ts-worker/loader.js */
180
196
  this.worker = new Worker('/ts-worker.js');
181
197
  /// #endif
182
198
 
@@ -386,6 +402,21 @@ export class NaslServer {
386
402
  }
387
403
  });
388
404
  }
405
+
406
+ module.configuration?.groups?.forEach((_group) => {
407
+ if (_group.name === 'custom') {
408
+ _group.properties.forEach((_property) => {
409
+ try {
410
+ const result = _property.toEmbeddedTSFile();
411
+ results.push(result);
412
+ // sourceMap都存在目录级别内容下,在页面层级下去找
413
+ _property.sourceMap = result.sourceMap;
414
+ this.file2NodeMap.set(result.filePath, _property);
415
+ } catch (err) {
416
+ }
417
+ });
418
+ }
419
+ });
389
420
  }
390
421
 
391
422
  view2TSFile(viewsChildren: View[], results: Array<ReturnType<Structure['toEmbeddedTSFile']>>) {
@@ -788,6 +819,14 @@ export class NaslServer {
788
819
  // diagnosticManager.pushAll(records);
789
820
  }
790
821
 
822
+ /**
823
+ * 节点异常是只能挂载单个,如果已经了就不赋值了
824
+ */
825
+ baseNodeAssignmentTsError(node: BaseNode, tsErrorDetail: Diagnostic) {
826
+ if (node.tsErrorDetail)
827
+ return;
828
+ node.tsErrorDetail = tsErrorDetail;
829
+ }
791
830
  /**
792
831
  * 处理诊断结果
793
832
  * @param records 结果
@@ -846,6 +885,41 @@ export class NaslServer {
846
885
  .filter((diag) => !!diag);
847
886
  record.semanticDiagnostics.push(...this._attachDiagnostics(node));
848
887
 
888
+ // 报错降级逻辑
889
+ record.semanticDiagnostics = record.semanticDiagnostics
890
+ .map((diagnostic) => {
891
+ // 错误降级如果属于草稿态的就降级
892
+ if (diagnostic?.node) {
893
+ let currentNode = diagnostic.node;
894
+ while (currentNode?.parentNode?.concept !== 'App') {
895
+ if (currentNode.parentKey?.toLowerCase()?.includes('playground')) {
896
+ // 草稿区降级
897
+ // 重置 图标和错误等级
898
+ diagnostic.severity = 'warning';
899
+ if (diagnostic.node?.tsErrorDetail) {
900
+ // 重置组件节点上的错误信息
901
+ diagnostic.node.tsErrorDetail.severity = 'warning';
902
+ }
903
+ record.suggestionDiagnostics.push(diagnostic);
904
+ return null;
905
+ } else if (currentNode.concept === 'OqlQueryComponent') {
906
+ // OQL别名错误降级为警告
907
+ if (diagnostic.originalDiagnostic && diagnostic.originalDiagnostic?.text.includes('__OQL_ALIAS_WARNING__')) {
908
+ // 重置 图标和错误等级
909
+ diagnostic.severity = 'warning';
910
+ if (diagnostic.node?.tsErrorDetail) {
911
+ // 重置组件节点上的错误信息
912
+ diagnostic.node.tsErrorDetail.severity = 'warning';
913
+ }
914
+ record.suggestionDiagnostics.push(diagnostic);
915
+ return null;
916
+ }
917
+ }
918
+ currentNode = currentNode.parentNode;
919
+ }
920
+ }
921
+ return diagnostic;
922
+ }).filter((diag) => !!diag);
849
923
  // 建议诊断
850
924
  // 实体下的建议不用展示,因为都是平台自己写的逻辑
851
925
  // if (node instanceof Entity) {
@@ -859,11 +933,49 @@ export class NaslServer {
859
933
  // // logic在for循环中,不展示any提示
860
934
  // record.suggestionDiagnostics = record.suggestionDiagnostics.filter((item) => !item.text.includes(`implicitly has an 'any' type, but a better type may be inferred from usage.`));
861
935
  // }
862
- record.suggestionDiagnostics = record.suggestionDiagnostics
863
- .filter((item) => [`'__LogicEmpty' is declared but its value is never read.`, `'__destinationEmpty__' is declared but its value is never read.`,
864
- `'__UpdateNoProperty__' is declared but its value is never read.`].includes(item.text))
865
- .map((diag) => this._resolveDiagnostic(diag as unknown as tsProtocol.DiagnosticWithFileName, node as FileNode, record))
866
- .filter((diag) => !!diag);
936
+
937
+ // 处理后的警告异常提示信息
938
+ record.suggestionDiagnostics = record.suggestionDiagnostics.map((diag) => {
939
+ // 上面错误降级下来的
940
+ if (diag?.node) {
941
+ return diag;
942
+ // 一些已知警告的单独处理
943
+ } else if ([`'__LogicEmpty' is declared but its value is never read.`,
944
+ `'__destinationEmpty__' is declared but its value is never read.`,
945
+ `'__devConfigValueEmpty' is declared but its value is never read.`,
946
+ `'__onlineConfigValueEmpty' is declared but its value is never read.`,
947
+ `'__UpdateNoProperty__' is declared but its value is never read.`].includes(diag.text)) {
948
+ return this._resolveDiagnostic(diag as unknown as tsProtocol.DiagnosticWithFileName, node as FileNode, record);
949
+ } else if ((diag.text).includes(` is declared but its value is never read.`)) {
950
+ // 局部变量和输入变量未使用的警告
951
+ if ((node.concept === 'View' || node.concept === 'Logic') && node.parentNode.concept !== 'Module') {
952
+ const minRange = this._findMinRange(diag as unknown as tsProtocol.DiagnosticWithFileName, node as FileNode);
953
+ if (minRange) {
954
+ /**
955
+ * 如果节点是入参类型
956
+ * 而且不是foreach中
957
+ * 而且不是事件逻辑的入参
958
+ */
959
+ if (minRange.node instanceof Param && minRange.node.parentNode.concept !== 'ForEachStatement' && !minRange.node.getAncestor('BindEvent')) {
960
+ const diagnostic = {
961
+ node: minRange.node,
962
+ severity: 'warning',
963
+ message: `未使用的输入参数${minRange.node.name}`,
964
+ };
965
+ return diagnostic;
966
+ } else if (minRange.node instanceof Variable) {
967
+ const diagnostic = {
968
+ node: minRange.node,
969
+ severity: 'warning',
970
+ message: `未使用的变量${minRange.node.name}`,
971
+ };
972
+ return diagnostic;
973
+ }
974
+ }
975
+ }
976
+ }
977
+ return null;
978
+ }).filter((diag) => !!diag);
867
979
 
868
980
  record.suggestionDiagnostics.push(...this._attachSuggestionDiagnostics(node));
869
981
  });
@@ -878,22 +990,6 @@ export class NaslServer {
878
990
  _attachSuggestionDiagnostics(fileNode: BaseNode): Diagnostic[] {
879
991
  const diagnostics: Diagnostic[] = [];
880
992
  if (fileNode instanceof Logic || fileNode instanceof View) {
881
- // 判断逻辑是否已经删除
882
- if (fileNode instanceof Logic && fileNode.parentNode instanceof App && !fileNode.parentNode.logics.includes(fileNode))
883
- return diagnostics;
884
- // 判断页面是否已经删除
885
- let removed = false;
886
- let curNode: Logic | View | App | Frontend = fileNode;
887
- // 递归检查,防止从顶层页面开始删除影响子页面内容检查
888
- while (curNode instanceof View && !removed) {
889
- if (curNode.parentNode instanceof View && !curNode.parentNode.children.includes(curNode)
890
- || curNode.parentNode instanceof Frontend && !curNode.parentNode.views.includes(curNode)) {
891
- removed = true;
892
- }
893
- curNode = curNode.parentNode as View | Frontend;
894
- }
895
- if (removed)
896
- return diagnostics;
897
993
  fileNode?.sourceMap.forEach((value, node) => {
898
994
  if (node instanceof Match) {
899
995
  const { cases, expression } = node || {};
@@ -1009,41 +1105,237 @@ export class NaslServer {
1009
1105
  const lastExpression = body[body.length - 1];
1010
1106
  diagnostic.node = lastExpression;
1011
1107
  diagnostic.message = `${lastExpression?.toUI()}期望的类型是${maxTypeAnnotation?.headTitle}`;
1012
- lastExpression.tsErrorDetail = diagnostic;
1108
+ this.baseNodeAssignmentTsError(lastExpression, diagnostic);
1013
1109
  diagnostics.push(diagnostic);
1014
1110
  }
1015
1111
  });
1016
1112
  }
1017
1113
  }
1018
1114
  }
1115
+ } else if (node instanceof NewList && !node.typeAnnotation) {
1116
+ // 匿名函数返回值有可能是newList,需要过滤。代码来源:AnonymousFunction.__ts
1117
+ const grandParent = node.parentNode?.parentNode?.parentNode;
1118
+ if (grandParent instanceof CallLogic
1119
+ && /dataSources\.[^.]+\.entities\.[^.]+\.logics/.test(grandParent.calleeNamespace)
1120
+ && ['update', 'updateBy', 'createOrUpdate', 'batchUpdate'].includes(grandParent.calleeName)) {
1121
+ return;
1122
+ }
1123
+ const { items } = node || {};
1124
+ const typeAnnotationMap: any = {};
1125
+ // 最多数的类型
1126
+ let maxTypeAnnotationInfo: any = {
1127
+ typeAnnotation: null,
1128
+ count: 0,
1129
+ };
1130
+ if (Array.isArray(items)) {
1131
+ items.forEach((item) => {
1132
+ const typeAnnotation = item.__TypeAnnotation;
1133
+ // 仅处理有类型的情况,返回类型为void的情况由其他地方处理成报错
1134
+ if (typeAnnotation) {
1135
+ const sortedTypeKey = typeAnnotation.sortedTypeKey;
1136
+ if (!typeAnnotationMap[sortedTypeKey]) {
1137
+ typeAnnotationMap[sortedTypeKey] = {
1138
+ typeAnnotation,
1139
+ items: [],
1140
+ count: 0,
1141
+ };
1142
+ }
1143
+ const typeAnnotationInfo = typeAnnotationMap[sortedTypeKey];
1144
+ typeAnnotationInfo.items.push(item);
1145
+ typeAnnotationInfo.count++;
1146
+ const { count } = typeAnnotationInfo;
1147
+ if (maxTypeAnnotationInfo.count < count) {
1148
+ maxTypeAnnotationInfo = {
1149
+ typeAnnotation,
1150
+ count,
1151
+ };
1152
+ }
1153
+ }
1154
+ });
1155
+ }
1156
+ const {
1157
+ typeAnnotation: maxTypeAnnotation,
1158
+ } = maxTypeAnnotationInfo;
1159
+ for (const sortedTypeKey in typeAnnotationMap) {
1160
+ const { typeAnnotation, items } = typeAnnotationMap[sortedTypeKey];
1161
+ if (maxTypeAnnotation?.sortedTypeKey !== typeAnnotation?.sortedTypeKey) {
1162
+ if (Array.isArray(items)) {
1163
+ items.forEach((item) => {
1164
+ const diagnostic = {
1165
+ node: item,
1166
+ severity: 'warning',
1167
+ message: `NewList期望的类型是${maxTypeAnnotation?.headTitle}`,
1168
+ };
1169
+ this.baseNodeAssignmentTsError(item, diagnostic);
1170
+ diagnostics.push(diagnostic);
1171
+ });
1172
+ }
1173
+ }
1174
+ }
1175
+ } else if (node instanceof NewMap && !node.typeAnnotation) {
1176
+ const { values } = node || {};
1177
+ const typeAnnotationMap: any = {};
1178
+ // 最多数的类型
1179
+ let maxTypeAnnotationInfo: any = {
1180
+ typeAnnotation: null,
1181
+ count: 0,
1182
+ };
1183
+ if (Array.isArray(values)) {
1184
+ values.forEach((value) => {
1185
+ if (!value)
1186
+ return;
1187
+ const typeAnnotation = value.__TypeAnnotation;
1188
+ // 仅处理有类型的情况,返回类型为void的情况由其他地方处理成报错
1189
+ if (typeAnnotation) {
1190
+ const sortedTypeKey = typeAnnotation.sortedTypeKey;
1191
+ if (!typeAnnotationMap[sortedTypeKey]) {
1192
+ typeAnnotationMap[sortedTypeKey] = {
1193
+ typeAnnotation,
1194
+ values: [],
1195
+ count: 0,
1196
+ };
1197
+ }
1198
+ const typeAnnotationInfo = typeAnnotationMap[sortedTypeKey];
1199
+ typeAnnotationInfo.values.push(value);
1200
+ typeAnnotationInfo.count++;
1201
+ const { count } = typeAnnotationInfo;
1202
+ if (maxTypeAnnotationInfo.count < count) {
1203
+ maxTypeAnnotationInfo = {
1204
+ typeAnnotation,
1205
+ count,
1206
+ };
1207
+ }
1208
+ }
1209
+ });
1210
+ }
1211
+ const {
1212
+ typeAnnotation: maxTypeAnnotation,
1213
+ } = maxTypeAnnotationInfo;
1214
+ for (const sortedTypeKey in typeAnnotationMap) {
1215
+ const { typeAnnotation, values } = typeAnnotationMap[sortedTypeKey];
1216
+ if (maxTypeAnnotation?.sortedTypeKey !== typeAnnotation?.sortedTypeKey) {
1217
+ if (Array.isArray(values)) {
1218
+ values.forEach((value) => {
1219
+ const diagnostic = {
1220
+ node: value,
1221
+ severity: 'warning',
1222
+ message: `NewMap中values值所期望的类型是${maxTypeAnnotation?.headTitle}`,
1223
+ };
1224
+ this.baseNodeAssignmentTsError(value, diagnostic);
1225
+ diagnostics.push(diagnostic);
1226
+ });
1227
+ }
1228
+ }
1229
+ }
1230
+ } else if (node.concept === 'JSBlock') {
1231
+ // 初始js代码块先屏蔽掉
1232
+ if ((node as JSBlock).code === `location.href = '/';`) {
1233
+ return null;
1234
+ }
1235
+ const diagnostic = {
1236
+ node,
1237
+ severity: 'warning',
1238
+ message: '不建议使用js代码块',
1239
+ };
1240
+ diagnostics.push(diagnostic);
1241
+ } else if (node.concept === 'Unparsed') {
1242
+ const diagnostic = {
1243
+ node,
1244
+ severity: 'warning',
1245
+ message: '不建议使用自定义表达式',
1246
+ };
1247
+ diagnostics.push(diagnostic);
1248
+ } else if (node instanceof CallQueryComponent) {
1249
+ // 可视化查询中不允许有复杂的数据结构
1250
+ const contentVariables: Array<Identifier | MemberExpression> = [];
1251
+ utils.traverse(({ node }) => {
1252
+ if ((node as any)?.parentNode?.concept !== 'MemberExpression') {
1253
+ if ((node as any)?.concept === 'MemberExpression') {
1254
+ contentVariables.push(node as any);
1255
+ } else if ((node as any)?.concept === 'Identifier') {
1256
+ // 因为要是父级是MemberExpression, 就放入了父级,子级就不需要了
1257
+ contentVariables.push(node as any);
1258
+ // QueryFromExpression QueryJoinExpression
1259
+ } else if ((node as any)?.concept === 'QueryFieldExpression' || (node as any)?.concept === 'QueryGroupByExpression') {
1260
+ contentVariables.push(node as any);
1261
+ }
1262
+ }
1263
+ }, { node }, {
1264
+ mode: 'anyObject',
1265
+ excludedKeySet: new Set(['parentNode', '_events', 'globalDataMap', 'havingPlayground', 'wherePlayground']),
1266
+ });
1267
+ contentVariables?.forEach((variable) => {
1268
+ // 如果是复杂数据结构
1269
+ if (variable.__TypeAnnotation?.isComplexType()) {
1270
+ const diagnostic = {
1271
+ node,
1272
+ severity: 'warning',
1273
+ message: `数据查询中不可以使用复杂类型!当前类型:${variable.__TypeAnnotation?.typeChineseTitle}。`,
1274
+ };
1275
+ this.baseNodeAssignmentTsError(variable, diagnostic);
1276
+ diagnostics.push(diagnostic);
1277
+ }
1278
+ });
1019
1279
  }
1020
1280
  });
1021
1281
  }
1022
1282
  return diagnostics;
1023
1283
  }
1024
1284
 
1285
+ // 是否包含组件逻辑
1286
+ hasComponentLogics(expression: BaseNode) {
1287
+ let flag = false;
1288
+ traverse((current: any) => {
1289
+ const { node } = current || {};
1290
+ const { concept } = node || {};
1291
+ if (concept === 'CallLogic') {
1292
+ // 调用组件逻辑
1293
+ if (node.isComponentLogic) {
1294
+ flag = true;
1295
+ } else if (node.isViewLogic) { // 调用页面逻辑
1296
+ const logicNode = node.view?.logics?.find?.((viewLogic: Logic) => viewLogic.name === node.calleeName);
1297
+ if (logicNode) {
1298
+ if (this.logicSetWithComponentLogic.has(logicNode.nodePath)) {
1299
+ flag = true;
1300
+ } else {
1301
+ const logicItem = logicNode.body?.find?.((logicItem: LogicItem) => this.hasComponentLogics(logicItem));
1302
+ if (logicItem) {
1303
+ flag = true;
1304
+ this.logicSetWithComponentLogic.add(logicNode.nodePath);
1305
+ }
1306
+ }
1307
+ }
1308
+ }
1309
+ }
1310
+ }, {
1311
+ node: expression,
1312
+ }, {
1313
+ mode: 'anyObject',
1314
+ excludedKeySet: new Set([
1315
+ 'parentNode',
1316
+ 'sourceMap',
1317
+ 'storageJSON',
1318
+ 'tsErrorDetail',
1319
+ 'NaslAnnotatedJSON',
1320
+ 'calledFrom',
1321
+ '_events',
1322
+ '_collectingList',
1323
+ '_historyList',
1324
+ ]),
1325
+ });
1326
+ return flag;
1327
+ }
1328
+
1025
1329
  /**
1026
1330
  * 额外的诊断
1027
1331
  * @param fileNode 文件级别的节点
1028
1332
  * @returns 诊断结果
1029
1333
  */
1030
1334
  _attachDiagnostics(fileNode: BaseNode): Diagnostic[] {
1335
+ // 每次诊断前先清空这个Set
1336
+ this.logicSetWithComponentLogic = new Set<string>();
1031
1337
  const diagnostics: Diagnostic[] = [];
1032
1338
  if (fileNode instanceof View) {
1033
- // 判断页面是否已经删除
1034
- let removed = false;
1035
- let curNode: View | App | Frontend = fileNode;
1036
- // 递归检查,防止从顶层页面开始删除影响子页面内容检查
1037
- while (curNode instanceof View && !removed) {
1038
- if (curNode.parentNode instanceof View && !curNode.parentNode.children.includes(curNode)
1039
- || curNode.parentNode instanceof Frontend && !curNode.parentNode.views.includes(curNode)) {
1040
- removed = true;
1041
- }
1042
- curNode = curNode.parentNode as View | Frontend;
1043
- }
1044
- if (removed)
1045
- return diagnostics;
1046
-
1047
1339
  fileNode?.sourceMap.forEach((value, node) => {
1048
1340
  if (node instanceof ViewElement && node.view === fileNode) {
1049
1341
  if (node.tag) {
@@ -1123,7 +1415,7 @@ export class NaslServer {
1123
1415
  }
1124
1416
  });
1125
1417
  if (!msg)
1126
- msg = '未设置类型或未赋值,直接赋值系统会自动推断类型。';
1418
+ msg = '未设置类型或未赋值。直接赋值系统可以自动推断类型。';
1127
1419
  const diagnostic = {
1128
1420
  node,
1129
1421
  severity: 'error',
@@ -1132,6 +1424,30 @@ export class NaslServer {
1132
1424
  node.tsErrorDetail = diagnostic;
1133
1425
  diagnostics.push(diagnostic);
1134
1426
  }
1427
+ } else if (node instanceof BindAttribute || node instanceof BindDirective || node instanceof BindStyle) {
1428
+ if (Array.isArray(node.bindExpressions)) {
1429
+ const exp = node.bindExpressions.find((bindExpression) => this.hasComponentLogics(bindExpression));
1430
+ if (exp) {
1431
+ //const element: any = node.getAncestor('ViewElement');
1432
+ //const api = config.allNodesAPI[element?.tag];
1433
+ //const attr = api?.attrs?.find?.((attr) => {
1434
+ // return attr.name === node.name;
1435
+ //});
1436
+ const map = {
1437
+ BindAttribute: '属性',
1438
+ BindDirective: '指令',
1439
+ BindStyle: '样式属性',
1440
+ };
1441
+ //“${attr?.title || node.title || node.name}”
1442
+ const diagnostic = {
1443
+ node,
1444
+ severity: 'error',
1445
+ message: `${map[node.concept]}表达式不能绑定组件逻辑`,
1446
+ };
1447
+ node.tsErrorDetail = diagnostic;
1448
+ diagnostics.push(diagnostic);
1449
+ }
1450
+ }
1135
1451
  } else {
1136
1452
  this.checkNodeError(node, diagnostics);
1137
1453
  }
@@ -1198,10 +1514,6 @@ export class NaslServer {
1198
1514
  }
1199
1515
  }
1200
1516
  if (fileNode instanceof Logic) {
1201
- // 判断逻辑是否已经删除
1202
- if (fileNode.parentNode instanceof App && !fileNode.parentNode.logics.includes(fileNode))
1203
- return diagnostics;
1204
-
1205
1517
  fileNode?.sourceMap.forEach((value, node) => {
1206
1518
  //OQL支持返回复合类型数据了
1207
1519
  // SqlQueryComponent内部返回值类型,如果是嵌套的就需要报错
@@ -1214,6 +1526,24 @@ export class NaslServer {
1214
1526
  // node.tsErrorDetail = diagnostic;
1215
1527
  // diagnostics.push(diagnostic);
1216
1528
  // }
1529
+ if (node instanceof OqlQueryComponent) {
1530
+ // 自动推导情况
1531
+ const typeAnnotation = type2TypeAnnotation((node as any).__nodeType);
1532
+ if (!node.typeAnnotation && typeAnnotation) {
1533
+ if (typeAnnotation.typeName === 'List' && typeAnnotation.typeKind === 'generic') {
1534
+ const typeArguments = typeAnnotation.typeArguments;
1535
+ if (typeArguments.length && typeArguments[0].isComplexType()) {
1536
+ const diagnostic = {
1537
+ node,
1538
+ severity: 'error',
1539
+ message: `SQL查询:返回类型不支持单个复杂类型 ${typeArguments[0].headTitle}。`,
1540
+ };
1541
+ node.tsErrorDetail = diagnostic;
1542
+ diagnostics.push(diagnostic);
1543
+ }
1544
+ }
1545
+ }
1546
+ }
1217
1547
  if (node instanceof Return || node instanceof Variable) {
1218
1548
  if (!node.typeAnnotation && !node.__TypeAnnotation) {
1219
1549
  const nodeTypeName = node.concept === 'Return' ? '输出参数' : '局部变量';
@@ -1257,7 +1587,7 @@ export class NaslServer {
1257
1587
  return diagnostics;
1258
1588
  }
1259
1589
 
1260
- checkNodeError(node: BaseNode, diagnostics: Diagnostic[]) {
1590
+ checkNodeError(node: BaseNode, diagnostics: Diagnostic[]): any {
1261
1591
  if (!node)
1262
1592
  return;
1263
1593
  // 如果节点是match的看看节点里是不是有重复的
@@ -1313,6 +1643,19 @@ export class NaslServer {
1313
1643
  }
1314
1644
  });
1315
1645
  }
1646
+ if (node instanceof MatchCase && (node.getAncestor('Match') as Match)?.isExpression && node.body.length === 0) {
1647
+ // 如果不是其他就标红
1648
+ if ((node?.getIndexOfParent() !== ((node.getAncestor('Match') as Match)?.cases?.length || 0) - 1)) {
1649
+ const diagnostic = {
1650
+ node,
1651
+ severity: 'error',
1652
+ message: '匹配分支:表达式不能为空',
1653
+ titleTip: '表达式不能为空',
1654
+ };
1655
+ node.tsErrorDetail = diagnostic;
1656
+ diagnostics.push(diagnostic);
1657
+ }
1658
+ }
1316
1659
  // 如果节点是match的patterns 里的
1317
1660
  if (node?.parentKey === 'patterns' && node.parentNode instanceof MatchCase) {
1318
1661
  const matchNode = node.getAncestor('Match');
@@ -1385,11 +1728,55 @@ export class NaslServer {
1385
1728
  const diagnostic = {
1386
1729
  node,
1387
1730
  severity: 'error',
1388
- message: `类型不一致,当前内置函数${node.calleeName || ''}无返回值。`,
1731
+ message: `类型不匹配,传入类型:void`,
1389
1732
  };
1390
1733
  node.tsErrorDetail = diagnostic;
1391
1734
  diagnostics.push(diagnostic);
1392
1735
  }
1736
+ // newMap key或者value没填都要有报错
1737
+ if (node instanceof NewMap) {
1738
+ // 如果一项没有key 或者没有 value 就报错
1739
+ const findFlag = node.keys?.some((key, index) => !key || !node.values?.[index]);
1740
+ if (findFlag) {
1741
+ const diagnostic = {
1742
+ node,
1743
+ severity: 'error',
1744
+ message: `新建Map的key和value应该都必填`,
1745
+ };
1746
+ node.tsErrorDetail = diagnostic;
1747
+ diagnostics.push(diagnostic);
1748
+ }
1749
+ }
1750
+ // 赋值语句左右list 和 map等可以 必须都一样
1751
+ if (node instanceof Assignment && !node.tsErrorDetail) {
1752
+ const leftType = node.left?.__TypeAnnotation || {} as TypeAnnotation;
1753
+ const rightType = node.right?.__TypeAnnotation || {} as TypeAnnotation;
1754
+ // 如果左边节点是 泛型,而且 左边泛型的名字 和 右边一样, 而且是list 或者map 就强制报错
1755
+ // 而且右边原来没有报错
1756
+ if (leftType.typeKind === 'generic' && leftType.typeKind === rightType.typeKind && leftType.typeName === rightType.typeName && ['Map', 'List'].includes(leftType.typeName)) {
1757
+ if (!(node.right.tsErrorDetail) && leftType.sortedTypeKey !== rightType.sortedTypeKey) {
1758
+ const excludeList = [
1759
+ 'nasl.collection.List<nasl.core.String>',
1760
+ 'nasl.collection.List<nasl.core.Text>',
1761
+ 'nasl.collection.List<nasl.core.Email>',
1762
+ 'nasl.collection.Map<nasl.core.String, nasl.core.String>',
1763
+ 'nasl.collection.Map<nasl.core.String, nasl.core.Text>',
1764
+ 'nasl.collection.Map<nasl.core.String, nasl.core.Email>',
1765
+ ];
1766
+ // 先特殊处理等 类型合并后就可以去掉了
1767
+ if (excludeList.includes(leftType.sortedTypeKey) && excludeList.includes(rightType.sortedTypeKey)) {
1768
+ return null;
1769
+ }
1770
+ const diagnostic = {
1771
+ node: node.right,
1772
+ severity: 'error',
1773
+ message: `左右参数类型不一致!左边类型:${leftType.typeChineseTitle},右边类型:${rightType.typeChineseTitle}。`,
1774
+ };
1775
+ node.right.tsErrorDetail = diagnostic;
1776
+ diagnostics.push(diagnostic);
1777
+ }
1778
+ }
1779
+ }
1393
1780
  }
1394
1781
 
1395
1782
  /* 接口导入查找 */
@@ -1457,7 +1844,7 @@ export class NaslServer {
1457
1844
  */
1458
1845
  _resolveDiagnostic(diagnostic: tsProtocol.DiagnosticWithFileName, fileNode: FileNode, record: DiagnosticRecord): Diagnostic {
1459
1846
  // 拓展模块中的翻译先过滤掉,因为有错用户也不能修改
1460
- if ((fileNode as any).module)
1847
+ if ((fileNode as any).module && !(fileNode instanceof ConfigProperty))
1461
1848
  return;
1462
1849
 
1463
1850
  const minRange = this._findMinRange(diagnostic, fileNode);
@@ -1684,6 +2071,53 @@ export class NaslServer {
1684
2071
  refsList = [...methodRefs];
1685
2072
  }
1686
2073
  }
2074
+ if (node instanceof Process) {
2075
+ if (currentSource) {
2076
+ const code = currentSource.code;
2077
+ const prefix = '__ProcessIdentification__';
2078
+ let positions = [];
2079
+ let pos = code.indexOf(prefix);
2080
+ while (pos !== -1) {
2081
+ positions.push(pos);
2082
+ pos = code.indexOf(prefix, pos + prefix.length);
2083
+ }
2084
+ positions.shift();
2085
+ // 拿到标识下定义的const process = {...}
2086
+ positions = positions.map((position) => code.indexOf('const', position + prefix.length));
2087
+ const promises = positions.map((item) => this.references({
2088
+ file: (fileNode as FileNode).getEmbeddedFilePath(),
2089
+ line: lsp2tspNumber(currentSource.range.start.line),
2090
+ offset: lsp2tspNumber(currentSource.range.start.character + item),
2091
+ }));
2092
+ const results = await Promise.all(promises);
2093
+ results.forEach((constRefs) => {
2094
+ refsList = [...refsList, ...constRefs.refs];
2095
+ });
2096
+ }
2097
+ }
2098
+ if (node instanceof ProcessElement) {
2099
+ if (currentSource) {
2100
+ const code = currentSource.code;
2101
+ const prefix = '__ProcessIdentification__';
2102
+ let positions = [];
2103
+ let pos = code.indexOf(prefix);
2104
+ while (pos !== -1) {
2105
+ positions.push(pos);
2106
+ pos = code.indexOf(prefix, pos + prefix.length);
2107
+ }
2108
+ // 拿到标识下定义的const process = {...}
2109
+ positions = positions.map((position) => code.indexOf(`${node.name}:`, position + prefix.length));
2110
+ const promises = positions.map((item) => this.references({
2111
+ file: (fileNode as FileNode).getEmbeddedFilePath(),
2112
+ line: lsp2tspNumber(currentSource.range.start.line),
2113
+ offset: lsp2tspNumber(currentSource.range.start.character + item),
2114
+ }));
2115
+ const results = await Promise.all(promises);
2116
+ results.forEach((constRefs) => {
2117
+ refsList = [...refsList, ...constRefs.refs];
2118
+ });
2119
+ }
2120
+ }
1687
2121
  // console.log(refsList, 'refsList');
1688
2122
  return refsList;
1689
2123
  }
@@ -2334,6 +2768,7 @@ export class NaslServer {
2334
2768
  // 如果没有sourceMap,就继续向上找 ,或者到module结束
2335
2769
  // 如果 节点找到 app 或者module 停止 或者entity找到DataSource为止
2336
2770
  // 如果当前节点是view就不要向上查找了
2771
+ // 配置参数的ConfigProperty也不需要向上找
2337
2772
  while (
2338
2773
  !sourceMap
2339
2774
  && fileNode
@@ -2341,6 +2776,7 @@ export class NaslServer {
2341
2776
  && !(fileNode.parentNode instanceof Module)
2342
2777
  && !(fileNode.parentNode instanceof DataSource)
2343
2778
  && !(fileNode instanceof View)
2779
+ && !(fileNode instanceof ConfigProperty)
2344
2780
  ) {
2345
2781
  fileNode = fileNode.parentNode;
2346
2782
  sourceMap = fileNode?.sourceMap;
@@ -2434,7 +2870,7 @@ export class NaslServer {
2434
2870
  * @returns 不需要去查就可以返回类型的节点
2435
2871
  */
2436
2872
  getCurrentNodeKnownTypeAnnotation(node: BaseNode) {
2437
- if (node.concept === 'StringLiteral' || node.concept === 'BooleanLiteral' || node.concept === 'NullLiteral') {
2873
+ if (node.concept === 'StringLiteral' || node.concept === 'StringInterpolation' || node.concept === 'BooleanLiteral' || node.concept === 'NullLiteral') {
2438
2874
  let type = 'String';
2439
2875
  switch (node.concept) {
2440
2876
  case 'NullLiteral':
@@ -2544,6 +2980,9 @@ export class NaslServer {
2544
2980
  'NewComposite',
2545
2981
  'NewList',
2546
2982
  'NewMap',
2983
+ 'OqlQueryComponent',
2984
+ 'QueryFieldExpression',
2985
+ 'QueryGroupByExpression',
2547
2986
  ].includes(node.concept))
2548
2987
  return;
2549
2988
  // 要去ls那边获取的
@@ -2575,7 +3014,7 @@ export class NaslServer {
2575
3014
  indexOf = subStr.length - lastLen;
2576
3015
  }
2577
3016
  fileDetail.offset = fileDetail.offset + indexOf;
2578
- } else if (node.concept === 'MemberExpression' || node.concept === 'Identifier') {
3017
+ } else if (node.concept === 'MemberExpression' || node.concept === 'Identifier' || node.concept === 'QueryFieldExpression' || node.concept === 'QueryGroupByExpression') {
2579
3018
  if (item.code.includes('.')) {
2580
3019
  const codeArr = item.code?.split('.');
2581
3020
  const lastLen = codeArr?.[codeArr.length - 1]?.length;
@@ -2596,6 +3035,8 @@ export class NaslServer {
2596
3035
  let newCode = item.code.substring(0, indexOf);
2597
3036
  newCode = newCode.substring(newCode.lastIndexOf('\n'), indexOf);
2598
3037
  fileDetail.offset = newCode.length + 'return '.length;
3038
+ } else if (['OqlQueryComponent'].includes(node.concept)) {
3039
+ fileDetail.offset += 10;
2599
3040
  }
2600
3041
  args.push(fileDetail);
2601
3042
  });
@@ -2648,11 +3089,27 @@ export class NaslServer {
2648
3089
  // 因为node可能是经过处理的TypeAnnotation
2649
3090
  node.__isCorrectTypeAnnotation = true;
2650
3091
  if (value) {
3092
+ if (node instanceof OqlQueryComponent) {
3093
+ // 自动推导情况
3094
+ const typeAnnotation = value as TypeAnnotation;
3095
+ if (!node.typeAnnotation && typeAnnotation) {
3096
+ if (typeAnnotation.typeName === 'List' && typeAnnotation.typeKind === 'generic') {
3097
+ const typeArguments = typeAnnotation.typeArguments;
3098
+ if (typeArguments.length && typeArguments[0].isComplexType()) {
3099
+ node.__TypeAnnotation = null;
3100
+ return;
3101
+ }
3102
+ }
3103
+ }
3104
+ }
2651
3105
  if (value instanceof TypeAnnotation) {
2652
3106
  node.__TypeAnnotation = (Object.freeze(value) as TypeAnnotation);
2653
3107
  } else if (value.typeAnnotation) {
2654
3108
  node.__TypeAnnotation = (Object.freeze(value.typeAnnotation) as TypeAnnotation);
2655
3109
  }
3110
+ } else {
3111
+ // 清空原来已经赋值上去的类型,可能原来有现在没有了
3112
+ node.__TypeAnnotation = null;
2656
3113
  }
2657
3114
  } catch (err) {
2658
3115
  if (globalThis.window) {
@@ -2878,6 +3335,10 @@ export class NaslServer {
2878
3335
  jsonNode.typeAnnotation = (value as TypeAnnotation).toJSON();
2879
3336
  }
2880
3337
  }
3338
+ if (node instanceof NewComposite && node.typeAnnotation.typeKind === 'anonymousStructure') {
3339
+ const jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
3340
+ jsonNode.typeAnnotation = (value as TypeAnnotation).toJSON();
3341
+ }
2881
3342
  });
2882
3343
  }
2883
3344
 
@@ -3023,6 +3484,13 @@ export class NaslServer {
3023
3484
  // 如果是要删除的内容,就是当前的file节点,要关闭当前文件,就把内容置为空
3024
3485
  if (fileNode === targetNode) {
3025
3486
  outputFiles = [{ file: filePath, fileContent: '' }];
3487
+
3488
+ // 去掉原来存储的当前节点的nasl内存的存储,和错误的存储
3489
+ // 已经删除的就不用在去check错误了
3490
+ // check就会去取类型啥的,没有必要
3491
+ this.diagnosticManager.deleteOwn(fileNode.id);
3492
+ // 删除文件同时删除ls存储nasl 的引用
3493
+ this.file2NodeMap.delete(filePath);
3026
3494
  } else {
3027
3495
  // 如果是要删除logic一个小内容,要覆盖全部内容
3028
3496
  // 其余要删除的都是把原来的file节点的内容全部覆盖一把
@@ -3054,13 +3522,17 @@ export class NaslServer {
3054
3522
  offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
3055
3523
  });
3056
3524
 
3057
- newRefs.refs.forEach((ref) => this.filesToCheck.add(ref.file));
3525
+ const files = new Set();
3526
+ newRefs.refs.forEach((ref) => {
3527
+ this.filesToCheck.add(ref.file);
3528
+ files.add(ref.file);
3529
+ });
3058
3530
  // 唤起建立连接弹框
3059
3531
  // 文件级别的建立连接采取提醒
3060
3532
  if (action === 'create' && (targetNode as any).__init) {
3061
3533
  // 清除临时状态, 完成本次创建
3062
3534
  delete (targetNode as any).__init;
3063
- if (fileNode === targetNode && this.filesToCheck.size > 1) {
3535
+ if (fileNode === targetNode && files.size > 1) {
3064
3536
  const confirmParms = {
3065
3537
  actionType: 'createEstablishConnection',
3066
3538
  node: fileNode,