@lcap/nasl-language-server-core 4.1.0-rc.7 → 4.1.0-rc.9

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 (107) hide show
  1. package/out/checker.d.ts +1 -1
  2. package/out/checker.d.ts.map +1 -1
  3. package/out/checker.js +87 -121
  4. package/out/checker.js.map +1 -1
  5. package/out/index.d.ts +2 -2
  6. package/out/index.d.ts.map +1 -1
  7. package/out/index.js +4 -3
  8. package/out/index.js.map +1 -1
  9. package/out/reference-manager/builtin-q-name.d.ts +1 -2
  10. package/out/reference-manager/builtin-q-name.d.ts.map +1 -1
  11. package/out/reference-manager/builtin-q-name.js +1 -5
  12. package/out/reference-manager/builtin-q-name.js.map +1 -1
  13. package/out/reference-manager/collect-q-name.d.ts.map +1 -1
  14. package/out/reference-manager/collect-q-name.js +8 -7
  15. package/out/reference-manager/collect-q-name.js.map +1 -1
  16. package/out/reference-manager/helper.d.ts +1 -1
  17. package/out/reference-manager/helper.d.ts.map +1 -1
  18. package/out/reference-manager/helper.js +11 -1
  19. package/out/reference-manager/helper.js.map +1 -1
  20. package/out/reference-manager/reference-manager.d.ts +64 -7
  21. package/out/reference-manager/reference-manager.d.ts.map +1 -1
  22. package/out/reference-manager/reference-manager.js +198 -56
  23. package/out/reference-manager/reference-manager.js.map +1 -1
  24. package/out/reference-manager/remove-q-name.js +8 -8
  25. package/out/reference-manager/remove-q-name.js.map +1 -1
  26. package/out/reference-manager/rename-q-name.d.ts.map +1 -1
  27. package/out/reference-manager/rename-q-name.js +6 -6
  28. package/out/reference-manager/rename-q-name.js.map +1 -1
  29. package/out/reference-manager/update-nasl-fragment.d.ts +0 -1
  30. package/out/reference-manager/update-nasl-fragment.d.ts.map +1 -1
  31. package/out/reference-manager/update-nasl-fragment.js +2 -33
  32. package/out/reference-manager/update-nasl-fragment.js.map +1 -1
  33. package/out/typer/component-def-manager/utils.js +1 -1
  34. package/out/typer/component-def-manager/utils.js.map +1 -1
  35. package/out/typer/dispatch-all.d.ts +10 -3
  36. package/out/typer/dispatch-all.d.ts.map +1 -1
  37. package/out/typer/dispatch-all.js +44 -7
  38. package/out/typer/dispatch-all.js.map +1 -1
  39. package/out/typer/dispatch-call.d.ts +14 -0
  40. package/out/typer/dispatch-call.d.ts.map +1 -0
  41. package/out/typer/dispatch-call.js +637 -0
  42. package/out/typer/dispatch-call.js.map +1 -0
  43. package/out/typer/dispatch-def.d.ts +9 -3
  44. package/out/typer/dispatch-def.d.ts.map +1 -1
  45. package/out/typer/dispatch-def.js +101 -91
  46. package/out/typer/dispatch-def.js.map +1 -1
  47. package/out/typer/dispatch-expr.d.ts +3 -15
  48. package/out/typer/dispatch-expr.d.ts.map +1 -1
  49. package/out/typer/dispatch-expr.js +94 -677
  50. package/out/typer/dispatch-expr.js.map +1 -1
  51. package/out/typer/dispatch-process.d.ts.map +1 -1
  52. package/out/typer/dispatch-process.js +28 -11
  53. package/out/typer/dispatch-process.js.map +1 -1
  54. package/out/typer/dispatch-stmt.d.ts.map +1 -1
  55. package/out/typer/dispatch-stmt.js +39 -38
  56. package/out/typer/dispatch-stmt.js.map +1 -1
  57. package/out/typer/dispatch-view.d.ts.map +1 -1
  58. package/out/typer/dispatch-view.js +22 -16
  59. package/out/typer/dispatch-view.js.map +1 -1
  60. package/out/typer/get-oql-files.d.ts +13 -0
  61. package/out/typer/get-oql-files.d.ts.map +1 -0
  62. package/out/typer/get-oql-files.js +136 -0
  63. package/out/typer/get-oql-files.js.map +1 -0
  64. package/out/typer/helper.d.ts +2 -2
  65. package/out/typer/helper.d.ts.map +1 -1
  66. package/out/typer/helper.js +5 -5
  67. package/out/typer/helper.js.map +1 -1
  68. package/out/typer/incremental-update.d.ts +0 -12
  69. package/out/typer/incremental-update.d.ts.map +1 -1
  70. package/out/typer/incremental-update.js +99 -193
  71. package/out/typer/incremental-update.js.map +1 -1
  72. package/out/typer/index.d.ts +6 -4
  73. package/out/typer/index.d.ts.map +1 -1
  74. package/out/typer/index.js +9 -10
  75. package/out/typer/index.js.map +1 -1
  76. package/out/typer/subster.d.ts +0 -1
  77. package/out/typer/subster.d.ts.map +1 -1
  78. package/out/typer/subster.js +3 -23
  79. package/out/typer/subster.js.map +1 -1
  80. package/out/typer/topo-sort.d.ts +4 -4
  81. package/out/typer/topo-sort.d.ts.map +1 -1
  82. package/out/typer/topo-sort.js +5 -1
  83. package/out/typer/topo-sort.js.map +1 -1
  84. package/out/typer/type-manager.d.ts +2 -2
  85. package/out/typer/type-manager.d.ts.map +1 -1
  86. package/out/typer/type-manager.js +32 -9
  87. package/out/typer/type-manager.js.map +1 -1
  88. package/out/typer/type-predicate.d.ts +6 -1
  89. package/out/typer/type-predicate.d.ts.map +1 -1
  90. package/out/typer/type-predicate.js +22 -4
  91. package/out/typer/type-predicate.js.map +1 -1
  92. package/out/typer/typer.d.ts +27 -6
  93. package/out/typer/typer.d.ts.map +1 -1
  94. package/out/typer/typer.js +69 -18
  95. package/out/typer/typer.js.map +1 -1
  96. package/out/typer/unifier.d.ts +1 -1
  97. package/out/typer/unifier.d.ts.map +1 -1
  98. package/out/typer/unifier.js +48 -69
  99. package/out/typer/unifier.js.map +1 -1
  100. package/out/utils/string.d.ts.map +1 -1
  101. package/out/utils/string.js +1 -0
  102. package/out/utils/string.js.map +1 -1
  103. package/package.json +5 -5
  104. package/out/typer/nasl-predicate.d.ts +0 -8
  105. package/out/typer/nasl-predicate.d.ts.map +0 -1
  106. package/out/typer/nasl-predicate.js +0 -25
  107. package/out/typer/nasl-predicate.js.map +0 -1
package/out/checker.d.ts CHANGED
@@ -54,7 +54,7 @@ export interface DiagnosticRecord {
54
54
  semanticDiagnostics: Array<Diagnostic>;
55
55
  suggestionDiagnostics: Array<Diagnostic>;
56
56
  }
57
- export declare const transformDiagnosticsToRecords: (fileNode: SyntaxNode, diagnostics: NodeDiagnosticsMap) => Array<DiagnosticRecord>;
57
+ export declare const transformDiagnosticsToRecords: (fileNode: SyntaxNode, diagnostics: NodeDiagnosticsMap, deduplication?: boolean) => Array<DiagnosticRecord>;
58
58
  export type ErrorDiagnoser = ReturnType<typeof createErrorDiagnoser>;
59
59
  export {};
60
60
  //# sourceMappingURL=checker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../src/checker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EAU0F,GAAG,EAMvG,QAAQ,EACT,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACgE,cAAc,EAGpF,MAAM,qBAAqB,CAAC;AAS7B,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAK5C,OAAO,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAMpE,oBAAY,QAAQ;IAClB,IAAI,YAAY;IAChB,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,UAAU,GAAG,kBAAkB,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;AAEnE,KAAK,YAAY,GAAG;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAMF,MAAM,MAAM,kBAAkB,GAAG,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AAEpE,MAAM,MAAM,kBAAkB,GAAG,GAAG,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;AAMrE,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAqBF,KAAK,eAAe,GAAG;IACrB,GAAG,EAAE,GAAG,CAAC;IACT,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,OAAO,CAAC;IACf,yBAAyB,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC/C,CAAC,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AAO,MAAM,6BAA6B,aAC9B,UAAU,+DAGnB,MAAM,gBAAgB,CAyCxB,CAAC;AAMF,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
package/out/checker.js CHANGED
@@ -10,7 +10,7 @@ const sem_diag_1 = require("./typer/sem-diag");
10
10
  const type_predicate_1 = require("./typer/type-predicate");
11
11
  const type_manager_1 = require("./typer/type-manager");
12
12
  const service_2 = require("@lcap/nasl-concepts/service");
13
- const get_q_name_1 = require("./reference-manager/get-q-name");
13
+ const lodash_1 = require("lodash");
14
14
  const helper_1 = require("./typer/helper");
15
15
  var Severity;
16
16
  (function (Severity) {
@@ -1127,6 +1127,7 @@ function createErrorDiagnoser(context) {
1127
1127
  * @param node
1128
1128
  */
1129
1129
  function* checkConnector(node) {
1130
+ env.enterScope(node);
1130
1131
  yield* checkModule(node);
1131
1132
  if (node.triggerLaunchers?.length) {
1132
1133
  yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.triggerLaunchers, function* (node) {
@@ -1153,6 +1154,7 @@ function createErrorDiagnoser(context) {
1153
1154
  yield* checkNode(node);
1154
1155
  });
1155
1156
  }
1157
+ env.exitScope();
1156
1158
  }
1157
1159
  /**
1158
1160
  * 检查 连接器触发器
@@ -1267,11 +1269,14 @@ function createErrorDiagnoser(context) {
1267
1269
  * @param node
1268
1270
  */
1269
1271
  function* checkStructure(node) {
1272
+ const pConn = node.getAncestor('Connector');
1273
+ pConn && env.enterScope(pConn);
1270
1274
  if (node.properties?.length) {
1271
1275
  yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.properties, function* (node) {
1272
1276
  yield* checkNode(node);
1273
1277
  });
1274
1278
  }
1279
+ pConn && env.exitScope();
1275
1280
  }
1276
1281
  /**
1277
1282
  * 检查 数据结构属性
@@ -1746,11 +1751,9 @@ function createErrorDiagnoser(context) {
1746
1751
  * @param node
1747
1752
  */
1748
1753
  function* checkInterface(node) {
1749
- const unbindVariables = env.temporarilyBindVariables([
1750
- ...(node.params || []),
1751
- ...(node.returns || []),
1752
- ...(node.protocolParams || [])
1753
- ]);
1754
+ const pConn = node.getAncestor('Connector');
1755
+ pConn && env.enterScope(pConn);
1756
+ env.enterScope(node);
1754
1757
  if (node.params?.length) {
1755
1758
  yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.params, function* (node) {
1756
1759
  yield* checkNode(node);
@@ -1768,18 +1771,17 @@ function createErrorDiagnoser(context) {
1768
1771
  }
1769
1772
  yield* checkNode(node.validation);
1770
1773
  yield* checkTimeout(node);
1771
- unbindVariables();
1774
+ env.exitScope();
1775
+ pConn && env.exitScope();
1772
1776
  }
1773
1777
  /**
1774
1778
  * 检查 鉴权接口
1775
1779
  * @param node
1776
1780
  */
1777
1781
  function* checkAuthInterface(node) {
1778
- const unbindVariables = env.temporarilyBindVariables([
1779
- ...(node.params || []),
1780
- ...(node.returns || []),
1781
- ...(node.protocolParams || [])
1782
- ]);
1782
+ const pConn = node.getAncestor('Connector');
1783
+ pConn && env.enterScope(pConn);
1784
+ env.enterScope(node);
1783
1785
  if (node.params?.length) {
1784
1786
  yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.params, function* (node) {
1785
1787
  yield* checkNode(node);
@@ -1797,7 +1799,8 @@ function createErrorDiagnoser(context) {
1797
1799
  }
1798
1800
  yield* checkNode(node.validation);
1799
1801
  yield* checkTimeout(node);
1800
- unbindVariables();
1802
+ env.exitScope();
1803
+ pConn && env.exitScope();
1801
1804
  }
1802
1805
  /**
1803
1806
  * 检查 接口参数
@@ -1858,7 +1861,7 @@ function createErrorDiagnoser(context) {
1858
1861
  * @param node
1859
1862
  */
1860
1863
  function* checkFrontend(node) {
1861
- const unbindVariables = env.temporarilyBindVariables(node.variables);
1864
+ env.enterScope(node);
1862
1865
  if (node.variables?.length) {
1863
1866
  yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.variables, function* (node) {
1864
1867
  yield* checkNode(node);
@@ -1874,18 +1877,14 @@ function createErrorDiagnoser(context) {
1874
1877
  yield* checkNode(node);
1875
1878
  });
1876
1879
  }
1877
- unbindVariables();
1880
+ env.exitScope();
1878
1881
  }
1879
1882
  /**
1880
1883
  * 检查 页面
1881
1884
  * @param node
1882
1885
  */
1883
1886
  function* checkView(node) {
1884
- const unbindVariables = env.temporarilyBindVariables([
1885
- ...(node.params || []),
1886
- ...(node.variables || []),
1887
- ...(node.logics || []),
1888
- ]);
1887
+ env.enterScope(node);
1889
1888
  checkVariableAndReturnTypeAnnotations(node.variables, [], false);
1890
1889
  const module = node.getAncestor('Module');
1891
1890
  if (!(module?.parentKey === 'dependencies')) {
@@ -1928,18 +1927,14 @@ function createErrorDiagnoser(context) {
1928
1927
  yield* checkNode(node);
1929
1928
  });
1930
1929
  }
1931
- unbindVariables();
1930
+ env.exitScope();
1932
1931
  }
1933
1932
  /**
1934
1933
  * 检查 业务组件
1935
1934
  * @param node
1936
1935
  */
1937
1936
  function* checkBusinessComponent(node) {
1938
- const unbindVariables = env.temporarilyBindVariables([
1939
- ...(node.params || []),
1940
- ...(node.variables || []),
1941
- ...(node.logics || []),
1942
- ]);
1937
+ env.enterScope(node);
1943
1938
  // 组件元素
1944
1939
  if (node.elements?.length) {
1945
1940
  yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.elements, function* (node) {
@@ -1964,7 +1959,7 @@ function createErrorDiagnoser(context) {
1964
1959
  yield* checkNode(node);
1965
1960
  });
1966
1961
  }
1967
- unbindVariables();
1962
+ env.exitScope();
1968
1963
  }
1969
1964
  /**
1970
1965
  * 检查 页面元素
@@ -1976,18 +1971,14 @@ function createErrorDiagnoser(context) {
1976
1971
  return;
1977
1972
  }
1978
1973
  const shouldProvideCurrentCtx = !!(node.slotScope);
1979
- let unbindVariables;
1974
+ let scopeEntered = false;
1980
1975
  if (shouldProvideCurrentCtx) {
1981
1976
  const name = curVarCounter > 0 ? node.slotScope + curVarCounter : node.slotScope;
1982
- const variable = new nasl_concepts_1.Variable({
1983
- name,
1984
- });
1977
+ const variable = new nasl_concepts_1.Variable({ name });
1985
1978
  curVarCounter++;
1986
- unbindVariables = env.temporarilyBindVariables([
1987
- variable,
1988
- ], () => {
1989
- curVarCounter--;
1990
- });
1979
+ // @ts-expect-error ViewElement 引入的 current 目前没有加入 refMgr,VE 也没当做 ScopeNode
1980
+ env.enterScope(node, [variable]);
1981
+ scopeEntered = true;
1991
1982
  }
1992
1983
  if (node.bindAttrs?.length) {
1993
1984
  yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.bindAttrs, function* (node) {
@@ -2032,7 +2023,10 @@ function createErrorDiagnoser(context) {
2032
2023
  if (!dsFilled && !hasSubComponents) {
2033
2024
  error(errNode, '数据源不能为空');
2034
2025
  }
2035
- unbindVariables?.();
2026
+ if (scopeEntered) {
2027
+ env.exitScope();
2028
+ curVarCounter--;
2029
+ }
2036
2030
  }
2037
2031
  /**
2038
2032
  * 检查 元素绑定属性
@@ -2190,10 +2184,7 @@ function createErrorDiagnoser(context) {
2190
2184
  if (node.includeTypeArgs) {
2191
2185
  error(node, '流程暂不支持泛型参数');
2192
2186
  }
2193
- const unbindVariables = env.temporarilyBindVariables([
2194
- ...(node?.params || []),
2195
- ...(node?.returns || []),
2196
- ]);
2187
+ // env.enterScope(node); 尚不支持流程 1.0
2197
2188
  if (node.params?.length) {
2198
2189
  yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.params, function* (node) {
2199
2190
  yield* checkNode(node);
@@ -2219,17 +2210,14 @@ function createErrorDiagnoser(context) {
2219
2210
  yield* checkNode(node);
2220
2211
  });
2221
2212
  }
2222
- unbindVariables();
2213
+ // env.exitScope();
2223
2214
  }
2224
2215
  /**
2225
2216
  * 检查 流程元素
2226
2217
  * @param node
2227
2218
  */
2228
2219
  function* checkProcessElement(node) {
2229
- const unbindVariables = env.temporarilyBindVariables([
2230
- ...(node?.variables || []),
2231
- ...(node?.returns || []),
2232
- ]);
2220
+ // env.enterScope(node); 尚不支持流程1.0
2233
2221
  if (node.returns?.length) {
2234
2222
  yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.returns, function* (node) {
2235
2223
  yield* checkNode(node);
@@ -2274,7 +2262,7 @@ function createErrorDiagnoser(context) {
2274
2262
  yield* checkNode(node);
2275
2263
  });
2276
2264
  }
2277
- unbindVariables();
2265
+ // env.exitScope();
2278
2266
  }
2279
2267
  /**
2280
2268
  * 检查 常量
@@ -2289,6 +2277,7 @@ function createErrorDiagnoser(context) {
2289
2277
  * @param node
2290
2278
  */
2291
2279
  function* checkProcessV2(node) {
2280
+ env.enterScope(node);
2292
2281
  yield* checkNode(node.bind);
2293
2282
  if (node.processDefinitions?.length) {
2294
2283
  yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.processDefinitions, function* (node) {
@@ -2305,6 +2294,7 @@ function createErrorDiagnoser(context) {
2305
2294
  if (node.includeTypeArgs) {
2306
2295
  error(node, '流程暂不支持泛型参数');
2307
2296
  }
2297
+ env.exitScope();
2308
2298
  }
2309
2299
  /**
2310
2300
  * 检查 绑定实体或数据结构
@@ -2318,14 +2308,7 @@ function createErrorDiagnoser(context) {
2318
2308
  * @param node
2319
2309
  */
2320
2310
  function* checkProcessDefinitionV2(node) {
2321
- const unbindVariables = env.temporarilyBindVariables([
2322
- ...(node.variables || []),
2323
- ...['custom', 'processSystem'].map((name) => {
2324
- return new nasl_concepts_1.Variable({
2325
- name,
2326
- });
2327
- }),
2328
- ]);
2311
+ env.enterScope(node);
2329
2312
  if (node.variables?.length) {
2330
2313
  yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.variables, function* (node) {
2331
2314
  yield* checkNode(node);
@@ -2341,20 +2324,14 @@ function createErrorDiagnoser(context) {
2341
2324
  yield* checkNode(node);
2342
2325
  });
2343
2326
  }
2344
- unbindVariables();
2327
+ env.exitScope();
2345
2328
  }
2346
2329
  /**
2347
2330
  * 检查 流程元素
2348
2331
  * @param node
2349
2332
  */
2350
2333
  function* checkProcessElementV2(node) {
2351
- const unbindVariables = env.temporarilyBindVariables([
2352
- ...['custom', 'processSystem'].map((name) => {
2353
- return new nasl_concepts_1.Variable({
2354
- name,
2355
- });
2356
- }),
2357
- ]);
2334
+ env.enterScope(node);
2358
2335
  yield* checkNode(node.logic);
2359
2336
  yield* checkNode(node.flowCondition);
2360
2337
  if (node.bindEvents?.length) {
@@ -2409,7 +2386,7 @@ function createErrorDiagnoser(context) {
2409
2386
  else if (!service_1.ProcessesV2.isFromStartNode(node)) {
2410
2387
  error(node, '节点未关联到流程图');
2411
2388
  }
2412
- unbindVariables();
2389
+ env.exitScope();
2413
2390
  }
2414
2391
  /**
2415
2392
  * 检查 无人时,自动转派审批策略
@@ -2491,16 +2468,8 @@ function createErrorDiagnoser(context) {
2491
2468
  * @param node
2492
2469
  */
2493
2470
  function* checkLogic(node) {
2494
- const unbindVariables = env.temporarilyBindVariables([
2495
- ...(node.params || []),
2496
- ...(node.returns || []),
2497
- ...(node.variables || []),
2498
- ...(node.virtualParams || [])
2499
- ]);
2500
- // 仅检查用户写的逻辑
2501
- // if (node.nodePath?.startsWith('app.logics')) {
2471
+ env.enterScope(node);
2502
2472
  checkVariableAndReturnTypeAnnotations(node.variables ?? [], node.returns ?? []);
2503
- // }
2504
2473
  const module = node.getAncestor('Module');
2505
2474
  if (!(module?.parentKey === 'dependencies')) {
2506
2475
  if (node.params?.length) {
@@ -2591,34 +2560,38 @@ function createErrorDiagnoser(context) {
2591
2560
  if (!likeComponent) {
2592
2561
  yield* checkTrigger(node);
2593
2562
  }
2594
- unbindVariables();
2563
+ env.exitScope();
2595
2564
  }
2596
2565
  /**
2597
2566
  * 检查 鉴权逻辑
2598
2567
  * @param node
2599
2568
  */
2600
2569
  function* checkAuthLogic(node) {
2570
+ const pConn = node.getAncestor('Connector');
2571
+ pConn && env.enterScope(pConn);
2601
2572
  inAuthLogic = true;
2573
+ // checkLogic 会 enter scope
2602
2574
  yield* checkLogic(node);
2603
2575
  inAuthLogic = false;
2576
+ pConn && env.exitScope();
2604
2577
  }
2605
2578
  /**
2606
2579
  * 检查 调用接口的鉴权逻辑
2607
2580
  * @param node
2608
2581
  */
2609
2582
  function* checkAuthLogicForCallInterface(node) {
2610
- const unbindVariables = env.temporarilyBindVariables([
2611
- ...(node.authParams || []),
2612
- ]);
2583
+ // authLogic 会打开 Connector 的局部-全局变量
2613
2584
  yield* checkAuthLogic(node);
2614
- unbindVariables();
2615
2585
  }
2616
2586
  /**
2617
2587
  * 检查 调用接口的鉴权逻辑
2618
2588
  * @param node
2619
2589
  */
2620
2590
  function* checkConnectorLogic(node) {
2591
+ const pConn = node.getAncestor('Connector');
2592
+ pConn && env.enterScope(pConn);
2621
2593
  yield* checkLogic(node);
2594
+ pConn && env.exitScope();
2622
2595
  }
2623
2596
  /**
2624
2597
  * 检查 业务组件逻辑
@@ -2632,12 +2605,7 @@ function createErrorDiagnoser(context) {
2632
2605
  * @param node
2633
2606
  */
2634
2607
  function* checkOverriddenLogic(node) {
2635
- const unbindVariables = env.temporarilyBindVariables([
2636
- ...(node.params || []),
2637
- ...(node.returns || []),
2638
- ...(node.variables || []),
2639
- ...(node.virtualParams || [])
2640
- ]);
2608
+ env.enterScope(node);
2641
2609
  const module = node.getAncestor('Module');
2642
2610
  if (!(module?.parentKey === 'dependencies')) {
2643
2611
  if (node.params?.length) {
@@ -2663,7 +2631,7 @@ function createErrorDiagnoser(context) {
2663
2631
  });
2664
2632
  }
2665
2633
  yield* checkPlayground(node.playground);
2666
- unbindVariables();
2634
+ env.exitScope();
2667
2635
  yield* checkTrigger(node);
2668
2636
  }
2669
2637
  /**
@@ -2676,14 +2644,8 @@ function createErrorDiagnoser(context) {
2676
2644
  * @param node
2677
2645
  */
2678
2646
  function* checkSubLogic(node) {
2679
- const unbindVariables = env.temporarilyBindVariables([
2680
- ...(node.params || []),
2681
- ...(node.returns || []),
2682
- ...(node.variables || []),
2683
- ]);
2684
- // if (nd.nodePath?.startsWith('app.logics')) {
2647
+ env.enterScope(node);
2685
2648
  checkVariableAndReturnTypeAnnotations(node.variables, node.returns);
2686
- // }
2687
2649
  const module = node.getAncestor('Module');
2688
2650
  if (!(module?.parentKey === 'dependencies')) {
2689
2651
  if (node.params?.length) {
@@ -2709,7 +2671,7 @@ function createErrorDiagnoser(context) {
2709
2671
  });
2710
2672
  }
2711
2673
  yield* checkPlayground(node.playground);
2712
- unbindVariables();
2674
+ env.exitScope();
2713
2675
  return env.getType(node);
2714
2676
  }
2715
2677
  /**
@@ -3244,10 +3206,7 @@ function createErrorDiagnoser(context) {
3244
3206
  * @param node
3245
3207
  */
3246
3208
  function* checkForEachStatement(node) {
3247
- const unbindVariables = env.temporarilyBindVariables([
3248
- node.item,
3249
- node.index,
3250
- ]);
3209
+ env.enterScope(node);
3251
3210
  if (ensureNodeKeyExists(node, 'each')) {
3252
3211
  yield* checkNode(node.each);
3253
3212
  }
@@ -3269,7 +3228,7 @@ function createErrorDiagnoser(context) {
3269
3228
  error(node, `ForEach:循环列表:参数类型不匹配!结束值自动推导失败。`);
3270
3229
  }
3271
3230
  }
3272
- unbindVariables();
3231
+ env.exitScope();
3273
3232
  }
3274
3233
  /**
3275
3234
  * 检查 循环分支
@@ -3903,14 +3862,14 @@ function createErrorDiagnoser(context) {
3903
3862
  */
3904
3863
  function* checkFunction(node) {
3905
3864
  if (ensureNodeKeyExists(node, 'returnExpression')) {
3906
- const unbindVariables = env.temporarilyBindVariables(node.params);
3865
+ env.enterScope(node);
3907
3866
  if (node.params?.length) {
3908
3867
  yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.params, function* (node) {
3909
3868
  yield* checkNode(node);
3910
3869
  });
3911
3870
  }
3912
3871
  yield* checkNode(node.returnExpression);
3913
- unbindVariables();
3872
+ env.exitScope();
3914
3873
  }
3915
3874
  }
3916
3875
  /**
@@ -3918,7 +3877,7 @@ function createErrorDiagnoser(context) {
3918
3877
  * @param node
3919
3878
  */
3920
3879
  function* checkAnonymousFunction(node) {
3921
- const unbindVariables = env.temporarilyBindVariables(node.params);
3880
+ env.enterScope(node);
3922
3881
  if (node.params?.length) {
3923
3882
  yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.params, function* (node) {
3924
3883
  yield* checkNode(node);
@@ -3927,7 +3886,7 @@ function createErrorDiagnoser(context) {
3927
3886
  if (ensureNodeKeyExists(node, 'body')) {
3928
3887
  yield* checkNode(node.body);
3929
3888
  }
3930
- unbindVariables();
3889
+ env.exitScope();
3931
3890
  }
3932
3891
  /**
3933
3892
  * 检查 验证规则
@@ -3963,8 +3922,7 @@ function createErrorDiagnoser(context) {
3963
3922
  ensureNodeKeyExists(node, 'typeKind');
3964
3923
  if (['primitive', 'reference', 'generic'].includes(node.typeKind)) {
3965
3924
  if (ensureNodeKeyExists(node, 'typeName') && node.typeKind === 'reference') {
3966
- const qName = (0, get_q_name_1.getTokenQualifiedName)(node);
3967
- const ref = env.refMgr.gQNameDefs.get(qName);
3925
+ const ref = env.resolveRef(node);
3968
3926
  if (!ref) {
3969
3927
  error(node, `找不到类型 ${node.typeName}`);
3970
3928
  }
@@ -4409,8 +4367,10 @@ function createErrorDiagnoser(context) {
4409
4367
  };
4410
4368
  }
4411
4369
  exports.createErrorDiagnoser = createErrorDiagnoser;
4412
- const transformDiagnosticsToRecords = (fileNode, diagnostics) => {
4413
- const records = [];
4370
+ function deduplicateDiagnostics(diagnostics) {
4371
+ return (0, lodash_1.uniqWith)(diagnostics, (a, b) => a.node === b.node && a.message === b.message);
4372
+ }
4373
+ const transformDiagnosticsToRecords = (fileNode, diagnostics, deduplication = true) => {
4414
4374
  let filePath;
4415
4375
  try {
4416
4376
  filePath = fileNode.concept !== 'App' ? fileNode.getEmbeddedFilePath() : undefined;
@@ -4418,10 +4378,8 @@ const transformDiagnosticsToRecords = (fileNode, diagnostics) => {
4418
4378
  catch (err) {
4419
4379
  nasl_utils_1.isDebugMode && console.error(err);
4420
4380
  }
4421
- const semanticDiagnostics = [];
4422
- const suggestionDiagnostics = [];
4423
- const syntaxDiagnostics = [];
4424
- //
4381
+ let semanticDiagnostics = [];
4382
+ let suggestionDiagnostics = [];
4425
4383
  diagnostics.forEach((err, node) => {
4426
4384
  if (err.length) {
4427
4385
  err.forEach((item) => {
@@ -4434,17 +4392,25 @@ const transformDiagnosticsToRecords = (fileNode, diagnostics) => {
4434
4392
  }
4435
4393
  });
4436
4394
  if (filePath) {
4437
- records.push({
4438
- filePath,
4439
- id: fileNode.id,
4440
- node: fileNode,
4441
- semanticDiagnostics,
4442
- suggestionDiagnostics,
4443
- syntaxDiagnostics,
4444
- message: '',
4445
- });
4446
- }
4447
- return records;
4395
+ if (deduplication) {
4396
+ if (semanticDiagnostics.length) {
4397
+ semanticDiagnostics = deduplicateDiagnostics(semanticDiagnostics);
4398
+ }
4399
+ if (suggestionDiagnostics.length) {
4400
+ suggestionDiagnostics = deduplicateDiagnostics(suggestionDiagnostics);
4401
+ }
4402
+ }
4403
+ return [{
4404
+ filePath,
4405
+ id: fileNode.id,
4406
+ node: fileNode,
4407
+ semanticDiagnostics,
4408
+ suggestionDiagnostics,
4409
+ syntaxDiagnostics: [],
4410
+ message: '',
4411
+ }];
4412
+ }
4413
+ return [];
4448
4414
  };
4449
4415
  exports.transformDiagnosticsToRecords = transformDiagnosticsToRecords;
4450
4416
  // @ts-expect-error