luaut-language-server 2.0.0 → 2.1.0

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/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  startServer
4
- } from "./chunk-SXRYJV32.js";
4
+ } from "./chunk-HJ2C3OFZ.js";
5
5
 
6
6
  // src/cli.ts
7
7
  startServer();
package/dist/index.cjs CHANGED
@@ -865,6 +865,9 @@ function describe(analysis, path, index) {
865
865
  case "DeclareStatement":
866
866
  if (parent.id === node) return declareText(analysis, parent);
867
867
  break;
868
+ case "DeclareClassStatement":
869
+ if (parent.name === node) return classText(analysis, name);
870
+ break;
868
871
  case "TableTypeProperty":
869
872
  if (parent.key === node) {
870
873
  const type2 = typeOfNode(parent.valueType);
@@ -921,9 +924,11 @@ function describe(analysis, path, index) {
921
924
  if (parameter) return typeParameterText(analysis, parameter);
922
925
  if (PRIMITIVES.has(base)) return `type ${base}`;
923
926
  }
924
- if (!node.namespace && !node.typeArguments.length) {
925
- const alias = types.aliases.get(base);
926
- if (alias) return `type ${base} = ${pretty(alias)}`;
927
+ if (!node.typeArguments.length) {
928
+ const qualified = node.namespace ? `${node.namespace}.${base}` : base;
929
+ const alias = types.aliases.get(qualified);
930
+ if (alias && (0, import_luaut_parser4.isClassType)(alias)) return classText(analysis, qualified);
931
+ if (alias) return `type ${qualified} = ${pretty(alias)}`;
927
932
  }
928
933
  const type2 = typeOfNode(node);
929
934
  return type2 && `type ${referenceText(analysis, node)} = ${pretty(type2)}`;
@@ -952,6 +957,19 @@ function declareText(analysis, statement) {
952
957
  const overloads = others > 0 ? ` (+${others} overload${others > 1 ? "s" : ""})` : "";
953
958
  return `declare function ${name}${(0, import_luaut_parser4.formatType)(own)}${overloads}`;
954
959
  }
960
+ function classText(analysis, name) {
961
+ const type = analysis.types.aliases.get(name);
962
+ if (!type || !(0, import_luaut_parser4.isClassType)(type)) return void 0;
963
+ const superclass = type.class.superclass;
964
+ const inherited = superclass ? analysis.types.aliases.get(superclass) : void 0;
965
+ const own = [...type.properties].filter(([key, property]) => inherited?.kind !== "object" || inherited.properties.get(key) !== property);
966
+ const head = `declare class ${name}${superclass ? ` extends ${superclass}` : ""}`;
967
+ if (!own.length) return `${head} {}`;
968
+ const lines = own.map(([key, property]) => ` ${property.readonly ? "readonly " : ""}${key}${property.optional ? "?" : ""}: ${(0, import_luaut_parser4.formatType)(property.type)},`);
969
+ return `${head} {
970
+ ${lines.join("\n")}
971
+ }`;
972
+ }
955
973
  function typeParameterText(analysis, parameter) {
956
974
  return `(type parameter) ${typeParameterSignature(analysis, parameter)}`;
957
975
  }
@@ -1116,10 +1134,10 @@ function completion(analyzer, document, position) {
1116
1134
  }
1117
1135
  if (operator || !first) return [];
1118
1136
  if (inTypePosition(first.path)) {
1119
- const named = [...first.analysis.types.aliases.keys()].map((name) => ({
1137
+ const named = [...first.analysis.types.aliases].map(([name, type]) => ({
1120
1138
  label: name,
1121
- kind: import_vscode_languageserver4.CompletionItemKind.Interface,
1122
- detail: "type"
1139
+ kind: (0, import_luaut_parser5.isClassType)(type) ? import_vscode_languageserver4.CompletionItemKind.Class : import_vscode_languageserver4.CompletionItemKind.Interface,
1140
+ detail: (0, import_luaut_parser5.isClassType)(type) ? "class" : "type"
1123
1141
  }));
1124
1142
  const primitives = PRIMITIVES2.map((name) => ({
1125
1143
  label: name,
@@ -1251,7 +1269,7 @@ function kindOf(type, bindingKind) {
1251
1269
  }
1252
1270
  function inTypePosition(path) {
1253
1271
  return path.some(
1254
- (n) => !!n.type && (n.type.endsWith("TypeNode") || n.type === "TypeReference" || n.type === "TypeAliasStatement" || n.type === "ExportTypeAliasStatement")
1272
+ (n) => !!n.type && (n.type.endsWith("TypeNode") || n.type === "TypeReference" || n.type === "TypeAliasStatement" || n.type === "ExportTypeAliasStatement" || n.type === "DeclareClassStatement")
1255
1273
  );
1256
1274
  }
1257
1275
  var PRIMITIVES2 = [
@@ -1392,6 +1410,12 @@ function documentSymbols(analysis) {
1392
1410
  }
1393
1411
  break;
1394
1412
  }
1413
+ case "DeclareClassStatement": {
1414
+ const name = node.name.name;
1415
+ const superclass = node.superclass?.base;
1416
+ out.push(symbol(name, import_vscode_languageserver5.SymbolKind.Class, node, superclass && `extends ${superclass}`));
1417
+ break;
1418
+ }
1395
1419
  case "VariableDeclaration": {
1396
1420
  for (const target of node.names ?? []) {
1397
1421
  const name = target.name;
@@ -1433,6 +1457,7 @@ var import_luaut_parser7 = require("luaut-parser");
1433
1457
  var TOKEN_TYPES = [
1434
1458
  "namespace",
1435
1459
  "type",
1460
+ "class",
1436
1461
  "typeParameter",
1437
1462
  "parameter",
1438
1463
  "variable",
@@ -1449,6 +1474,7 @@ var semanticTokensLegend = {
1449
1474
  var SOFT_KEYWORDS = /* @__PURE__ */ new Set([
1450
1475
  "type",
1451
1476
  "declare",
1477
+ "class",
1452
1478
  "extends",
1453
1479
  "keyof",
1454
1480
  "infer",
@@ -1515,6 +1541,8 @@ function classify(analysis, spanned, ancestors, identifiers, add) {
1515
1541
  if (!baseToken) return;
1516
1542
  if (!namespace && typeParameterInScope2(ancestors, base)) {
1517
1543
  add(baseToken, base.length, "typeParameter");
1544
+ } else if ((0, import_luaut_parser7.isClassType)(analysis.types.aliases.get(namespace ? `${namespace}.${base}` : base) ?? import_luaut_parser7.unknownType)) {
1545
+ add(baseToken, base.length, "class");
1518
1546
  } else {
1519
1547
  add(baseToken, base.length, "type", PRIMITIVES3.has(base) ? ["defaultLibrary"] : []);
1520
1548
  }
@@ -1542,6 +1570,9 @@ function identifier(analysis, node, parent, add) {
1542
1570
  case "ExportTypeAliasStatement":
1543
1571
  if (parent.name === node) return as("type", ["declaration"]);
1544
1572
  break;
1573
+ case "DeclareClassStatement":
1574
+ if (parent.name === node) return as("class", ["declaration"]);
1575
+ break;
1545
1576
  case "DeclareStatement":
1546
1577
  if (parent.id === node) return as(isFunction(typeOfNode(parent.valueType)) ? "function" : "variable", ["declaration"]);
1547
1578
  break;