@lcap/nasl-language-server-core 4.3.0-rc.4 → 4.4.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.
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,E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UAAU,WAAW,MAAM,YAAY,YAAY;EAg5IzE;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");
@@ -3518,7 +3519,26 @@ function createErrorDiagnoser(context) {
3518
3519
  });
3519
3520
  }
3520
3521
  }
3521
- return env.getType(node);
3522
+ const ty = env.getType(node);
3523
+ function isConcreteTy(ty) {
3524
+ if (ty.typeKind === 'generic') {
3525
+ return !!ty.typeArguments?.every(x => isConcreteTy(x));
3526
+ }
3527
+ else if (ty.typeKind === 'primitive') {
3528
+ return ty !== type_manager_1.naslAnyTy;
3529
+ }
3530
+ return true;
3531
+ }
3532
+ if (!ty || !isConcreteTy(ty)) {
3533
+ const p = node.parentNode;
3534
+ if (p && p.name === 'dataSourceWatch' && (0, asserts_1.isBindAttribute)(p)) {
3535
+ // 🐮
3536
+ }
3537
+ else {
3538
+ error(node, `NewList 无法推导类型,请添加手动类型标注或添加元素`);
3539
+ }
3540
+ }
3541
+ return ty;
3522
3542
  }
3523
3543
  /**
3524
3544
  * 检查 Map 构造器
@@ -3607,6 +3627,37 @@ function createErrorDiagnoser(context) {
3607
3627
  if (ensureNodeKeyExists(node, 'right')) {
3608
3628
  yield* checkNode(node.right);
3609
3629
  }
3630
+ // 检查左侧为 Decimal,右侧为 Union<Decimal, Integer> 的情况
3631
+ const leftType = env.getType(node.left);
3632
+ const rightType = env.getType(node.right);
3633
+ // 检查左右两侧同为匿名结构体时,对每个字段,都增加 Decimal 和 Union<Decimal, Long> 的检查
3634
+ if (leftType && rightType && (0, type_predicate_1.isAnonymousTy)(leftType) && (0, type_predicate_1.isAnonymousTy)(rightType)) {
3635
+ const leftProps = leftType.properties ?? [];
3636
+ const rightProps = rightType.properties ?? [];
3637
+ for (const leftProp of leftProps) {
3638
+ const rightProp = rightProps.find(p => p.name === leftProp.name);
3639
+ if (rightProp) {
3640
+ if (leftProp.typeAnnotation && rightProp.typeAnnotation) {
3641
+ if ((0, type_predicate_1.isDecimalTy)(leftProp.typeAnnotation) && (0, type_predicate_1.isDecimalUnionLongTy)(rightProp.typeAnnotation)) {
3642
+ error(node, `赋值:字段 ${leftProp.name} 类型不匹配,不能将 ${(0, type_manager_1.showUserLevelType)(rightProp.typeAnnotation)} 赋值给 ${(0, type_manager_1.showUserLevelType)(leftProp.typeAnnotation)} 类型。`);
3643
+ }
3644
+ }
3645
+ }
3646
+ }
3647
+ }
3648
+ if (leftType && rightType) {
3649
+ // 检查左侧是否为 Decimal
3650
+ const isLeftDecimal = leftType.typeKind === 'primitive' && leftType.typeName === 'Decimal';
3651
+ // 检查右侧是否为 Union<Decimal, Long> 或 Union<Long, Decimal>
3652
+ if (isLeftDecimal && rightType.typeKind === 'union' && rightType.typeArguments) {
3653
+ const typeArgs = rightType.typeArguments;
3654
+ const hasDecimal = typeArgs.some((arg) => arg.typeKind === 'primitive' && arg.typeName === 'Decimal');
3655
+ const hasLong = typeArgs.some((arg) => arg.typeKind === 'primitive' && arg.typeName === 'Long');
3656
+ if (hasDecimal && hasLong && typeArgs.length === 2) {
3657
+ error(node, `赋值:类型不匹配,不能将联合类型 ${(0, type_manager_1.showUserLevelType)(rightType)} 赋值给 ${(0, type_manager_1.showUserLevelType)(leftType)} 类型。`);
3658
+ }
3659
+ }
3660
+ }
3610
3661
  }
3611
3662
  /**
3612
3663
  * 检查 批量赋值语句
@@ -3851,7 +3902,9 @@ function createErrorDiagnoser(context) {
3851
3902
  * @param node
3852
3903
  */
3853
3904
  function* checkQueryOrderByExpression(node) {
3854
- yield* checkNode(node.orderElement);
3905
+ if (ensureNodeKeyExists(node, 'orderElement')) {
3906
+ yield* checkNode(node.orderElement);
3907
+ }
3855
3908
  yield* checkPlayground(node.orderElementPlayground);
3856
3909
  }
3857
3910
  /**
@@ -3880,13 +3933,20 @@ function createErrorDiagnoser(context) {
3880
3933
  function* checkOqlQueryComponent(node) {
3881
3934
  ensureNodeKeyExists(node, 'code');
3882
3935
  yield* checkSameSource(node);
3883
- // 自动推导情况
3884
- const typeAnnotation = env.getType(node);
3885
- if (!node.typeAnnotation && typeAnnotation) {
3886
- if (typeAnnotation.typeName === 'List' && typeAnnotation.typeKind === 'generic') {
3887
- const { typeArguments = [] } = typeAnnotation;
3888
- if (typeArguments.length && typeArguments[0].isComplexType()) {
3889
- error(node, `SQL查询:返回类型不支持单个复杂类型 ${typeArguments[0].headTitle}。`);
3936
+ if (node.typeAnnotation) { // 手动设置
3937
+ const IMPOSSIBLE_TOPLEVEL_TYPES = ['Map'];
3938
+ if (IMPOSSIBLE_TOPLEVEL_TYPES.includes(node.typeAnnotation.typeName || "")) {
3939
+ error(node, `SQL查询:返回类型不支持设置为 ${node.typeAnnotation.headTitle}。`);
3940
+ }
3941
+ }
3942
+ else { // 自动推导
3943
+ const typeAnnotation = env.getType(node);
3944
+ if (typeAnnotation) {
3945
+ if (typeAnnotation.typeName === 'List' && typeAnnotation.typeKind === 'generic') {
3946
+ const { typeArguments = [] } = typeAnnotation;
3947
+ if (typeArguments.length && typeArguments[0].isComplexType()) {
3948
+ error(node, `SQL查询:返回类型不支持单个复杂类型 ${typeArguments[0].headTitle}。`);
3949
+ }
3890
3950
  }
3891
3951
  }
3892
3952
  }
@@ -4482,6 +4542,8 @@ function createErrorDiagnoser(context) {
4482
4542
  }
4483
4543
  });
4484
4544
  diagnostics?.clear();
4545
+ // 删除 diagnosticMap 中的 key,避免内存泄漏和冗余报错
4546
+ diagnosticMap.delete(node);
4485
4547
  }
4486
4548
  else {
4487
4549
  diagnosticMap.clear();
@@ -4497,7 +4559,7 @@ function createErrorDiagnoser(context) {
4497
4559
  function getAllDiagnostics() {
4498
4560
  return diagnosticMap;
4499
4561
  }
4500
- function getDebugDiagnostics() {
4562
+ function getDebugDiagnostics(normalize = false) {
4501
4563
  const diagMap = getAllDiagnostics();
4502
4564
  const flattenedDiags = [];
4503
4565
  diagMap.forEach((item) => {
@@ -4506,11 +4568,12 @@ function createErrorDiagnoser(context) {
4506
4568
  if (!x.message || !x.severity) {
4507
4569
  return [];
4508
4570
  }
4571
+ const msg = normalize ? (0, lodash_1.sortBy)(x.message).join('') : x.message;
4509
4572
  return [{
4510
- message: x.message,
4573
+ message: msg,
4511
4574
  severity: x.severity,
4512
4575
  nodePath: node.nodePath,
4513
- nodeConcept: node.concept,
4576
+ nodeConcept: node.concept
4514
4577
  }];
4515
4578
  });
4516
4579
  })));