@lcap/nasl-language-server-core 4.0.0-beta.26 → 4.0.0-beta.28

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 (126) hide show
  1. package/README.md +85 -0
  2. package/out/checker.d.ts.map +1 -1
  3. package/out/checker.js +28 -13
  4. package/out/checker.js.map +1 -1
  5. package/out/index.d.ts +2 -1
  6. package/out/index.d.ts.map +1 -1
  7. package/out/index.js +2 -1
  8. package/out/index.js.map +1 -1
  9. package/out/query/context-variable-query.d.ts +31 -0
  10. package/out/query/context-variable-query.d.ts.map +1 -0
  11. package/out/query/context-variable-query.js +105 -0
  12. package/out/query/context-variable-query.js.map +1 -0
  13. package/out/query/index.d.ts +2 -0
  14. package/out/query/index.d.ts.map +1 -0
  15. package/out/query/index.js +18 -0
  16. package/out/query/index.js.map +1 -0
  17. package/out/reference-manager/builtin-q-name.d.ts +1 -1
  18. package/out/reference-manager/builtin-q-name.d.ts.map +1 -1
  19. package/out/reference-manager/builtin-q-name.js +2 -2
  20. package/out/reference-manager/builtin-q-name.js.map +1 -1
  21. package/out/reference-manager/collect-q-name.d.ts +2 -1
  22. package/out/reference-manager/collect-q-name.d.ts.map +1 -1
  23. package/out/reference-manager/collect-q-name.js +8 -4
  24. package/out/reference-manager/collect-q-name.js.map +1 -1
  25. package/out/reference-manager/get-q-name.d.ts +1 -1
  26. package/out/reference-manager/get-q-name.d.ts.map +1 -1
  27. package/out/reference-manager/get-q-name.js +35 -31
  28. package/out/reference-manager/get-q-name.js.map +1 -1
  29. package/out/reference-manager/reference-manager.d.ts +6 -7
  30. package/out/reference-manager/reference-manager.d.ts.map +1 -1
  31. package/out/reference-manager/reference-manager.js +7 -6
  32. package/out/reference-manager/reference-manager.js.map +1 -1
  33. package/out/reference-manager/remove-q-name.d.ts +30 -28
  34. package/out/reference-manager/remove-q-name.d.ts.map +1 -1
  35. package/out/reference-manager/remove-q-name.js +54 -47
  36. package/out/reference-manager/remove-q-name.js.map +1 -1
  37. package/out/reference-manager/rename-q-name.d.ts +2 -1
  38. package/out/reference-manager/rename-q-name.d.ts.map +1 -1
  39. package/out/reference-manager/rename-q-name.js +31 -36
  40. package/out/reference-manager/rename-q-name.js.map +1 -1
  41. package/out/reference-manager/symbol-type.d.ts +2 -2
  42. package/out/reference-manager/symbol-type.d.ts.map +1 -1
  43. package/out/reference-manager/symbol-type.js +1 -1
  44. package/out/reference-manager/symbol-type.js.map +1 -1
  45. package/out/reference-manager/update-nasl-fragment.d.ts +2 -1
  46. package/out/reference-manager/update-nasl-fragment.d.ts.map +1 -1
  47. package/out/reference-manager/update-nasl-fragment.js +9 -1
  48. package/out/reference-manager/update-nasl-fragment.js.map +1 -1
  49. package/out/typer/collectGlobalDefs.d.ts.map +1 -1
  50. package/out/typer/collectGlobalDefs.js.map +1 -1
  51. package/out/typer/component-def-manager/component-def-manager.d.ts +32 -5
  52. package/out/typer/component-def-manager/component-def-manager.d.ts.map +1 -1
  53. package/out/typer/component-def-manager/component-def-manager.js +96 -19
  54. package/out/typer/component-def-manager/component-def-manager.js.map +1 -1
  55. package/out/typer/component-def-manager/utils.d.ts.map +1 -1
  56. package/out/typer/component-def-manager/utils.js +39 -12
  57. package/out/typer/component-def-manager/utils.js.map +1 -1
  58. package/out/typer/dispatch-all.d.ts +1 -1
  59. package/out/typer/dispatch-all.d.ts.map +1 -1
  60. package/out/typer/dispatch-all.js +3 -7
  61. package/out/typer/dispatch-all.js.map +1 -1
  62. package/out/typer/dispatch-def.d.ts +1 -1
  63. package/out/typer/dispatch-def.d.ts.map +1 -1
  64. package/out/typer/dispatch-def.js +7 -5
  65. package/out/typer/dispatch-def.js.map +1 -1
  66. package/out/typer/dispatch-expr.d.ts +4 -1
  67. package/out/typer/dispatch-expr.d.ts.map +1 -1
  68. package/out/typer/dispatch-expr.js +34 -14
  69. package/out/typer/dispatch-expr.js.map +1 -1
  70. package/out/typer/dispatch-stmt.d.ts.map +1 -1
  71. package/out/typer/dispatch-stmt.js +20 -8
  72. package/out/typer/dispatch-stmt.js.map +1 -1
  73. package/out/typer/dispatch-view.d.ts.map +1 -1
  74. package/out/typer/dispatch-view.js +109 -112
  75. package/out/typer/dispatch-view.js.map +1 -1
  76. package/out/typer/helper.js +3 -3
  77. package/out/typer/helper.js.map +1 -1
  78. package/out/typer/incremental-update.d.ts +15 -13
  79. package/out/typer/incremental-update.d.ts.map +1 -1
  80. package/out/typer/incremental-update.js +89 -42
  81. package/out/typer/incremental-update.js.map +1 -1
  82. package/out/typer/index.d.ts +2 -2
  83. package/out/typer/index.d.ts.map +1 -1
  84. package/out/typer/index.js +1 -2
  85. package/out/typer/index.js.map +1 -1
  86. package/out/typer/nasl-predicate.d.ts +1 -1
  87. package/out/typer/nasl-predicate.d.ts.map +1 -1
  88. package/out/typer/solver.d.ts +37 -24
  89. package/out/typer/solver.d.ts.map +1 -1
  90. package/out/typer/solver.js +205 -426
  91. package/out/typer/solver.js.map +1 -1
  92. package/out/typer/subster.d.ts +2 -4
  93. package/out/typer/subster.d.ts.map +1 -1
  94. package/out/typer/subster.js +29 -35
  95. package/out/typer/subster.js.map +1 -1
  96. package/out/typer/topo-sort.d.ts.map +1 -1
  97. package/out/typer/topo-sort.js +9 -2
  98. package/out/typer/topo-sort.js.map +1 -1
  99. package/out/typer/type-hint-manager/type-hint-manager.d.ts +3 -0
  100. package/out/typer/type-hint-manager/type-hint-manager.d.ts.map +1 -1
  101. package/out/typer/type-hint-manager/type-hint-manager.js +2 -0
  102. package/out/typer/type-hint-manager/type-hint-manager.js.map +1 -1
  103. package/out/typer/type-manager.d.ts +6 -2
  104. package/out/typer/type-manager.d.ts.map +1 -1
  105. package/out/typer/type-manager.js.map +1 -1
  106. package/out/typer/type-predicate.d.ts.map +1 -1
  107. package/out/typer/type-predicate.js +61 -6
  108. package/out/typer/type-predicate.js.map +1 -1
  109. package/out/typer/typer.d.ts +7 -4
  110. package/out/typer/typer.d.ts.map +1 -1
  111. package/out/typer/typer.js +26 -47
  112. package/out/typer/typer.js.map +1 -1
  113. package/out/typer/unifier.d.ts +0 -3
  114. package/out/typer/unifier.d.ts.map +1 -1
  115. package/out/typer/unifier.js +28 -27
  116. package/out/typer/unifier.js.map +1 -1
  117. package/out/utils/nasl-type-manipulation.d.ts +1 -0
  118. package/out/utils/nasl-type-manipulation.d.ts.map +1 -1
  119. package/out/utils/nasl-type-manipulation.js +3 -1
  120. package/out/utils/nasl-type-manipulation.js.map +1 -1
  121. package/out/utils/parseTsClassType.d.ts.map +1 -1
  122. package/out/utils/parseTsClassType.js +7 -3
  123. package/out/utils/parseTsClassType.js.map +1 -1
  124. package/out/utils/type-operator.d.ts.map +1 -1
  125. package/out/utils/type-operator.js.map +1 -1
  126. package/package.json +13 -6
package/README.md CHANGED
@@ -1,3 +1,88 @@
1
1
  # Nasl Language Server
2
2
 
3
3
  Nasl 语言服务
4
+
5
+ ## 描述
6
+
7
+ NetEase Application Specific Language (NASL) 语言服务器核心包,提供 NASL 语言的类型检查、语法分析和其他语言服务功能。
8
+
9
+ ## 技术栈
10
+
11
+ ### 核心技术
12
+ - **TypeScript 5.4.4** - 主要开发语言
13
+ - **Node.js 18+** - 运行环境
14
+
15
+ ### 主要依赖
16
+ - **@lcap/nasl-concepts** - NASL 概念定义
17
+ - **@lcap/nasl-types** - NASL 类型系统
18
+ - **@lcap/nasl-utils** - NASL 工具库
19
+ - **decimal.js** - 精确数值计算
20
+ - **json5** - JSON5 格式支持
21
+ - **lodash** - 实用工具库
22
+ - **mnemonist** - 数据结构库
23
+
24
+ ### 开发工具
25
+ - **Vitest 3.2.4** - 现代测试框架
26
+ - **Chai 4.3.7** - 断言库
27
+ - **Mocha** - 传统测试框架(通过 @lcap/nasl-test-toolkit)
28
+
29
+ ## 开发
30
+
31
+ ### 构建
32
+ ```bash
33
+ # 清理输出目录
34
+ npm run clear
35
+
36
+ # 构建项目
37
+ npm run build
38
+
39
+ # 监听模式构建
40
+ npm run watch
41
+ ```
42
+
43
+ ### 测试
44
+
45
+ #### Vitest 测试(推荐)
46
+ ```bash
47
+ # 运行所有 Vitest 测试
48
+ npm run test:vite
49
+
50
+ # 监听模式运行测试
51
+ npm run test:watch
52
+
53
+ # 启动测试 UI 界面
54
+ npm run test:ui
55
+ ```
56
+
57
+ #### Mocha 测试 (遗留)
58
+
59
+ 注意:
60
+ - Mocha 测试框架已经废弃,对于新的单元测试的编写,请使用 Vitest 测试框架。
61
+ - Mocha 测试框架的测试用例,请迁移到 Vitest 测试框架。请参考 [TESTING_MIGRATION.md](./tests/TESTING_MIGRATION.md) 文件,让LLM自动化地完成迁移。
62
+
63
+ ```bash
64
+ # 运行标准 Mocha 测试套件
65
+ npm run test
66
+
67
+ # 运行应用测试
68
+ npm run test:apps
69
+
70
+ # 运行 CI 测试
71
+ npm run test:ci
72
+
73
+ # 更新测试快照
74
+ npm run test:update
75
+
76
+ # 运行性能测试
77
+ npm run test:perf
78
+ ```
79
+
80
+ ### 其他工具
81
+ ```bash
82
+ # 压缩测试数据
83
+ npm run compress-test-data
84
+ ```
85
+
86
+ ## 许可证
87
+
88
+ MIT
@@ -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,EAA4B,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAIhE,OAAO,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAGpE,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,E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gB,oBAAoB,CAAC,OAAO,EAAE,eAAe;oCAmmIpB,OAAO;sDAPW,gBAAgB,EAAE;;;;sBAhBjD,UAAU,GAAG,SAAS;;;8BA4Df,UAAU;2BAuBb,UAAU;;kBAvmInB,UAAU,WAAW,MAAM,YAAY,YAAY;EAynIzE;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;AAED,eAAO,MAAM,6BAA6B,aAAc,UAAU,sCAAoC,MAAM,gBAAgB,CAmC3H,CAAA;AAMD,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
package/out/checker.js CHANGED
@@ -338,6 +338,15 @@ function createErrorDiagnoser(context) {
338
338
  }
339
339
  else { }
340
340
  }
341
+ function scopedError(node, message, context) {
342
+ const scope = node?.constructor?.nodeTitle;
343
+ if (scope) {
344
+ error(node, `${scope}:${message}`, context);
345
+ }
346
+ else {
347
+ error(node, message, context);
348
+ }
349
+ }
341
350
  /**
342
351
  * 获取当前错误信息
343
352
  * @param node
@@ -691,7 +700,7 @@ function createErrorDiagnoser(context) {
691
700
  * @returns
692
701
  */
693
702
  function isNonRequiredParam(param) {
694
- return param?.defaultValue?.expression || param?.defaultExpression || param?.optional || param?.spread || (nasl_concepts_1.asserts.isInterfaceParam(param) && !param.required);
703
+ return param?.defaultValue?.expression || param?.defaultExpression || param?.optional || (nasl_concepts_1.asserts.isInterfaceParam(param) && !param.required);
695
704
  }
696
705
  /**
697
706
  * 确定函数签名中所需的最小参数数量
@@ -701,6 +710,9 @@ function createErrorDiagnoser(context) {
701
710
  let minArgsCount = 0;
702
711
  for (let i = 0; i < paramLen; i++) {
703
712
  const param = params[i];
713
+ if (param?.spread) {
714
+ continue;
715
+ }
704
716
  if (!isNonRequiredParam(param)) {
705
717
  minArgsCount++; // 如果参数有默认值,则跳过
706
718
  }
@@ -823,13 +835,17 @@ function createErrorDiagnoser(context) {
823
835
  }
824
836
  yield* (0, nasl_utils_1.wrapForEachToGenerator)(args, function* (arg, index) {
825
837
  const param = params?.[index];
826
- if (!param)
827
- return;
828
- const isParamRequired = !(hasSpreadParam && index > spreadParamIndex) && !isNonRequiredParam(param);
838
+ // param 的定义不存在,则默认是必填的。
839
+ const isParamRequired = param ? !isNonRequiredParam(param) : true;
829
840
  arg.paramRequired = isParamRequired;
841
+ // 即便是 param 的定义不存在,也需要检查 arg。这样可以检查出 arg 是否引用了一些未定义的变量
842
+ const argType = yield* checkNode(arg);
843
+ if (!param) {
844
+ return;
845
+ }
830
846
  const paramType = param.typeAnnotation ??
831
847
  (nasl_concepts_1.asserts.isTypeAnnotation(param) ? param : env.getType(param));
832
- const argType = yield* checkNode(arg);
848
+ // 检查高阶函数参数个数是否匹配
833
849
  if (paramType?.typeKind === 'function' && argType?.typeKind === 'function') {
834
850
  const argTypeArgs = argType?.typeArguments || [];
835
851
  const paramTypeArgs = paramType?.typeArguments || [];
@@ -3268,14 +3284,6 @@ function createErrorDiagnoser(context) {
3268
3284
  }
3269
3285
  else {
3270
3286
  const { name } = node;
3271
- // 之前有一些脏数据,先兼容
3272
- // if (['true', 'false'].includes(name)) {
3273
- // return new TypeAnnotation({
3274
- // typeKind: 'primitive',
3275
- // typeName: 'Boolean',
3276
- // typeNamespace: 'nasl.core',
3277
- // });
3278
- // }
3279
3287
  if (
3280
3288
  // name 是 A.B.C
3281
3289
  name?.split('.')?.length > 1
@@ -3290,6 +3298,13 @@ function createErrorDiagnoser(context) {
3290
3298
  return errorType;
3291
3299
  }
3292
3300
  }
3301
+ if (node.namespace === 'app.enums' &&
3302
+ node.parentNode?.concept !== 'MemberExpression' &&
3303
+ node.parentNode?.concept !== 'SelectMembers') {
3304
+ // 判断枚举类是否直接被使用
3305
+ scopedError(node, `${node.toNaturalTS()} 枚举类不能直接使用,请取它的枚举项`);
3306
+ return errorType;
3307
+ }
3293
3308
  // 检查使用范围
3294
3309
  yield* checkScopeOfUse(node, ref);
3295
3310
  return env.getType(node);