@lcap/nasl-language-server-core 4.3.0-rc.5 → 4.4.0-beta.3

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 (38) hide show
  1. package/out/checker.d.ts +1 -1
  2. package/out/checker.d.ts.map +1 -1
  3. package/out/checker.js +74 -5
  4. package/out/checker.js.map +1 -1
  5. package/out/reference-manager/collect-q-name.d.ts.map +1 -1
  6. package/out/reference-manager/collect-q-name.js +6 -3
  7. package/out/reference-manager/collect-q-name.js.map +1 -1
  8. package/out/reference-manager/reference-manager.d.ts.map +1 -1
  9. package/out/reference-manager/reference-manager.js +10 -1
  10. package/out/reference-manager/reference-manager.js.map +1 -1
  11. package/out/typer/component-def-manager/component-def-manager.js +1 -1
  12. package/out/typer/component-def-manager/component-def-manager.js.map +1 -1
  13. package/out/typer/dispatch-expr.d.ts.map +1 -1
  14. package/out/typer/dispatch-expr.js +7 -2
  15. package/out/typer/dispatch-expr.js.map +1 -1
  16. package/out/typer/dispatch-view.d.ts.map +1 -1
  17. package/out/typer/dispatch-view.js +72 -24
  18. package/out/typer/dispatch-view.js.map +1 -1
  19. package/out/typer/oql-checker/ts-parser.d.ts.map +1 -1
  20. package/out/typer/oql-checker/ts-parser.js +16 -2
  21. package/out/typer/oql-checker/ts-parser.js.map +1 -1
  22. package/out/typer/overload-helper.d.ts.map +1 -1
  23. package/out/typer/overload-helper.js +7 -15
  24. package/out/typer/overload-helper.js.map +1 -1
  25. package/out/typer/type-predicate.d.ts +1 -0
  26. package/out/typer/type-predicate.d.ts.map +1 -1
  27. package/out/typer/type-predicate.js +3 -1
  28. package/out/typer/type-predicate.js.map +1 -1
  29. package/out/typer/typer.d.ts +5 -0
  30. package/out/typer/typer.d.ts.map +1 -1
  31. package/out/typer/typer.js +7 -0
  32. package/out/typer/typer.js.map +1 -1
  33. package/out/typer/unifier.js +5 -1
  34. package/out/typer/unifier.js.map +1 -1
  35. package/out/utils/parseTsClassType.d.ts.map +1 -1
  36. package/out/utils/parseTsClassType.js +0 -2
  37. package/out/utils/parseTsClassType.js.map +1 -1
  38. package/package.json +5 -5
package/out/checker.d.ts CHANGED
@@ -42,7 +42,7 @@ export declare function createErrorDiagnoser(context: DiagnoseContext): {
42
42
  clearDiagnostics: (node?: SyntaxNode) => void;
43
43
  getDiagnostics: (node: SyntaxNode) => NodeDiagnosticsMap | undefined;
44
44
  getAllDiagnostics: () => FileDiagnosticsMap;
45
- getDebugDiagnostics: () => {
45
+ getDebugDiagnostics: (normalize?: boolean) => {
46
46
  message: string;
47
47
  severity: string;
48
48
  nodePath: string;
@@ -1 +1 @@
1
- {"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../src/checker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EAU2G,GAAG,EAMxH,QAAQ,EAET,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,C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AAGD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IAEX,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IACrC,mBAAmB,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IACvC,qBAAqB,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;CAC1C;AAMD,eAAO,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,6 +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 asserts_1 = require("@lcap/nasl-concepts/asserts");
13
14
  const lodash_1 = require("lodash");
14
15
  const helper_1 = require("./typer/helper");
15
16
  const semantic_rules_1 = require("./semantic-rules");
@@ -1970,6 +1971,17 @@ function createErrorDiagnoser(context) {
1970
1971
  */
1971
1972
  function* checkBusinessComponent(node) {
1972
1973
  env.enterScope(node);
1974
+ if (node.params?.length) {
1975
+ yield* checkParams(node.params);
1976
+ yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.params, function* (node) {
1977
+ yield* checkNode(node);
1978
+ });
1979
+ }
1980
+ if (node.variables?.length) {
1981
+ yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.variables, function* (node) {
1982
+ yield* checkNode(node);
1983
+ });
1984
+ }
1973
1985
  // 组件元素
1974
1986
  if (node.elements?.length) {
1975
1987
  yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.elements, function* (node) {
@@ -3518,7 +3530,26 @@ function createErrorDiagnoser(context) {
3518
3530
  });
3519
3531
  }
3520
3532
  }
3521
- return env.getType(node);
3533
+ const ty = env.getType(node);
3534
+ function isConcreteTy(ty) {
3535
+ if (ty.typeKind === 'generic') {
3536
+ return !!ty.typeArguments?.every(x => isConcreteTy(x));
3537
+ }
3538
+ else if (ty.typeKind === 'primitive') {
3539
+ return ty !== type_manager_1.naslAnyTy;
3540
+ }
3541
+ return true;
3542
+ }
3543
+ if (!ty || !isConcreteTy(ty)) {
3544
+ const p = node.parentNode;
3545
+ if (p && p.name === 'dataSourceWatch' && (0, asserts_1.isBindAttribute)(p)) {
3546
+ // 🐮
3547
+ }
3548
+ else {
3549
+ error(node, `NewList 无法推导类型,请添加手动类型标注或添加元素`);
3550
+ }
3551
+ }
3552
+ return ty;
3522
3553
  }
3523
3554
  /**
3524
3555
  * 检查 Map 构造器
@@ -3607,6 +3638,37 @@ function createErrorDiagnoser(context) {
3607
3638
  if (ensureNodeKeyExists(node, 'right')) {
3608
3639
  yield* checkNode(node.right);
3609
3640
  }
3641
+ // 检查左侧为 Decimal,右侧为 Union<Decimal, Integer> 的情况
3642
+ const leftType = env.getType(node.left);
3643
+ const rightType = env.getType(node.right);
3644
+ // 检查左右两侧同为匿名结构体时,对每个字段,都增加 Decimal 和 Union<Decimal, Long> 的检查
3645
+ if (leftType && rightType && (0, type_predicate_1.isAnonymousTy)(leftType) && (0, type_predicate_1.isAnonymousTy)(rightType)) {
3646
+ const leftProps = leftType.properties ?? [];
3647
+ const rightProps = rightType.properties ?? [];
3648
+ for (const leftProp of leftProps) {
3649
+ const rightProp = rightProps.find(p => p.name === leftProp.name);
3650
+ if (rightProp) {
3651
+ if (leftProp.typeAnnotation && rightProp.typeAnnotation) {
3652
+ if ((0, type_predicate_1.isDecimalTy)(leftProp.typeAnnotation) && (0, type_predicate_1.isDecimalUnionLongTy)(rightProp.typeAnnotation)) {
3653
+ error(node, `赋值:字段 ${leftProp.name} 类型不匹配,不能将 ${(0, type_manager_1.showUserLevelType)(rightProp.typeAnnotation)} 赋值给 ${(0, type_manager_1.showUserLevelType)(leftProp.typeAnnotation)} 类型。`);
3654
+ }
3655
+ }
3656
+ }
3657
+ }
3658
+ }
3659
+ if (leftType && rightType) {
3660
+ // 检查左侧是否为 Decimal
3661
+ const isLeftDecimal = leftType.typeKind === 'primitive' && leftType.typeName === 'Decimal';
3662
+ // 检查右侧是否为 Union<Decimal, Long> 或 Union<Long, Decimal>
3663
+ if (isLeftDecimal && rightType.typeKind === 'union' && rightType.typeArguments) {
3664
+ const typeArgs = rightType.typeArguments;
3665
+ const hasDecimal = typeArgs.some((arg) => arg.typeKind === 'primitive' && arg.typeName === 'Decimal');
3666
+ const hasLong = typeArgs.some((arg) => arg.typeKind === 'primitive' && arg.typeName === 'Long');
3667
+ if (hasDecimal && hasLong && typeArgs.length === 2) {
3668
+ error(node, `赋值:类型不匹配,不能将联合类型 ${(0, type_manager_1.showUserLevelType)(rightType)} 赋值给 ${(0, type_manager_1.showUserLevelType)(leftType)} 类型。`);
3669
+ }
3670
+ }
3671
+ }
3610
3672
  }
3611
3673
  /**
3612
3674
  * 检查 批量赋值语句
@@ -3851,7 +3913,9 @@ function createErrorDiagnoser(context) {
3851
3913
  * @param node
3852
3914
  */
3853
3915
  function* checkQueryOrderByExpression(node) {
3854
- yield* checkNode(node.orderElement);
3916
+ if (ensureNodeKeyExists(node, 'orderElement')) {
3917
+ yield* checkNode(node.orderElement);
3918
+ }
3855
3919
  yield* checkPlayground(node.orderElementPlayground);
3856
3920
  }
3857
3921
  /**
@@ -4180,6 +4244,8 @@ function createErrorDiagnoser(context) {
4180
4244
  return yield* checkBackendVariable(node);
4181
4245
  case 'Param':
4182
4246
  return yield* checkParam(node);
4247
+ case 'ParamWithGroup':
4248
+ return yield* checkParam(node);
4183
4249
  case 'Return':
4184
4250
  return yield* checkReturn(node);
4185
4251
  case 'DefaultValue':
@@ -4489,6 +4555,8 @@ function createErrorDiagnoser(context) {
4489
4555
  }
4490
4556
  });
4491
4557
  diagnostics?.clear();
4558
+ // 删除 diagnosticMap 中的 key,避免内存泄漏和冗余报错
4559
+ diagnosticMap.delete(node);
4492
4560
  }
4493
4561
  else {
4494
4562
  diagnosticMap.clear();
@@ -4504,7 +4572,7 @@ function createErrorDiagnoser(context) {
4504
4572
  function getAllDiagnostics() {
4505
4573
  return diagnosticMap;
4506
4574
  }
4507
- function getDebugDiagnostics() {
4575
+ function getDebugDiagnostics(normalize = false) {
4508
4576
  const diagMap = getAllDiagnostics();
4509
4577
  const flattenedDiags = [];
4510
4578
  diagMap.forEach((item) => {
@@ -4513,11 +4581,12 @@ function createErrorDiagnoser(context) {
4513
4581
  if (!x.message || !x.severity) {
4514
4582
  return [];
4515
4583
  }
4584
+ const msg = normalize ? (0, lodash_1.sortBy)(x.message).join('') : x.message;
4516
4585
  return [{
4517
- message: x.message,
4586
+ message: msg,
4518
4587
  severity: x.severity,
4519
4588
  nodePath: node.nodePath,
4520
- nodeConcept: node.concept,
4589
+ nodeConcept: node.concept
4521
4590
  }];
4522
4591
  });
4523
4592
  })));