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/README.md +1 -1
- package/dist/{chunk-SXRYJV32.js → chunk-HJ2C3OFZ.js} +43 -11
- package/dist/chunk-HJ2C3OFZ.js.map +1 -0
- package/dist/cli.cjs +38 -7
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +38 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-SXRYJV32.js.map +0 -1
package/dist/cli.cjs
CHANGED
|
@@ -799,6 +799,9 @@ function describe(analysis, path, index) {
|
|
|
799
799
|
case "DeclareStatement":
|
|
800
800
|
if (parent.id === node) return declareText(analysis, parent);
|
|
801
801
|
break;
|
|
802
|
+
case "DeclareClassStatement":
|
|
803
|
+
if (parent.name === node) return classText(analysis, name);
|
|
804
|
+
break;
|
|
802
805
|
case "TableTypeProperty":
|
|
803
806
|
if (parent.key === node) {
|
|
804
807
|
const type2 = typeOfNode(parent.valueType);
|
|
@@ -855,9 +858,11 @@ function describe(analysis, path, index) {
|
|
|
855
858
|
if (parameter) return typeParameterText(analysis, parameter);
|
|
856
859
|
if (PRIMITIVES.has(base)) return `type ${base}`;
|
|
857
860
|
}
|
|
858
|
-
if (!node.
|
|
859
|
-
const
|
|
860
|
-
|
|
861
|
+
if (!node.typeArguments.length) {
|
|
862
|
+
const qualified = node.namespace ? `${node.namespace}.${base}` : base;
|
|
863
|
+
const alias = types.aliases.get(qualified);
|
|
864
|
+
if (alias && (0, import_luaut_parser4.isClassType)(alias)) return classText(analysis, qualified);
|
|
865
|
+
if (alias) return `type ${qualified} = ${pretty(alias)}`;
|
|
861
866
|
}
|
|
862
867
|
const type2 = typeOfNode(node);
|
|
863
868
|
return type2 && `type ${referenceText(analysis, node)} = ${pretty(type2)}`;
|
|
@@ -886,6 +891,19 @@ function declareText(analysis, statement) {
|
|
|
886
891
|
const overloads = others > 0 ? ` (+${others} overload${others > 1 ? "s" : ""})` : "";
|
|
887
892
|
return `declare function ${name}${(0, import_luaut_parser4.formatType)(own)}${overloads}`;
|
|
888
893
|
}
|
|
894
|
+
function classText(analysis, name) {
|
|
895
|
+
const type = analysis.types.aliases.get(name);
|
|
896
|
+
if (!type || !(0, import_luaut_parser4.isClassType)(type)) return void 0;
|
|
897
|
+
const superclass = type.class.superclass;
|
|
898
|
+
const inherited = superclass ? analysis.types.aliases.get(superclass) : void 0;
|
|
899
|
+
const own = [...type.properties].filter(([key, property]) => inherited?.kind !== "object" || inherited.properties.get(key) !== property);
|
|
900
|
+
const head = `declare class ${name}${superclass ? ` extends ${superclass}` : ""}`;
|
|
901
|
+
if (!own.length) return `${head} {}`;
|
|
902
|
+
const lines = own.map(([key, property]) => ` ${property.readonly ? "readonly " : ""}${key}${property.optional ? "?" : ""}: ${(0, import_luaut_parser4.formatType)(property.type)},`);
|
|
903
|
+
return `${head} {
|
|
904
|
+
${lines.join("\n")}
|
|
905
|
+
}`;
|
|
906
|
+
}
|
|
889
907
|
function typeParameterText(analysis, parameter) {
|
|
890
908
|
return `(type parameter) ${typeParameterSignature(analysis, parameter)}`;
|
|
891
909
|
}
|
|
@@ -1050,10 +1068,10 @@ function completion(analyzer, document, position) {
|
|
|
1050
1068
|
}
|
|
1051
1069
|
if (operator || !first) return [];
|
|
1052
1070
|
if (inTypePosition(first.path)) {
|
|
1053
|
-
const named = [...first.analysis.types.aliases
|
|
1071
|
+
const named = [...first.analysis.types.aliases].map(([name, type]) => ({
|
|
1054
1072
|
label: name,
|
|
1055
|
-
kind: import_vscode_languageserver4.CompletionItemKind.Interface,
|
|
1056
|
-
detail: "type"
|
|
1073
|
+
kind: (0, import_luaut_parser5.isClassType)(type) ? import_vscode_languageserver4.CompletionItemKind.Class : import_vscode_languageserver4.CompletionItemKind.Interface,
|
|
1074
|
+
detail: (0, import_luaut_parser5.isClassType)(type) ? "class" : "type"
|
|
1057
1075
|
}));
|
|
1058
1076
|
const primitives = PRIMITIVES2.map((name) => ({
|
|
1059
1077
|
label: name,
|
|
@@ -1185,7 +1203,7 @@ function kindOf(type, bindingKind) {
|
|
|
1185
1203
|
}
|
|
1186
1204
|
function inTypePosition(path) {
|
|
1187
1205
|
return path.some(
|
|
1188
|
-
(n) => !!n.type && (n.type.endsWith("TypeNode") || n.type === "TypeReference" || n.type === "TypeAliasStatement" || n.type === "ExportTypeAliasStatement")
|
|
1206
|
+
(n) => !!n.type && (n.type.endsWith("TypeNode") || n.type === "TypeReference" || n.type === "TypeAliasStatement" || n.type === "ExportTypeAliasStatement" || n.type === "DeclareClassStatement")
|
|
1189
1207
|
);
|
|
1190
1208
|
}
|
|
1191
1209
|
var PRIMITIVES2 = [
|
|
@@ -1326,6 +1344,12 @@ function documentSymbols(analysis) {
|
|
|
1326
1344
|
}
|
|
1327
1345
|
break;
|
|
1328
1346
|
}
|
|
1347
|
+
case "DeclareClassStatement": {
|
|
1348
|
+
const name = node.name.name;
|
|
1349
|
+
const superclass = node.superclass?.base;
|
|
1350
|
+
out.push(symbol(name, import_vscode_languageserver5.SymbolKind.Class, node, superclass && `extends ${superclass}`));
|
|
1351
|
+
break;
|
|
1352
|
+
}
|
|
1329
1353
|
case "VariableDeclaration": {
|
|
1330
1354
|
for (const target of node.names ?? []) {
|
|
1331
1355
|
const name = target.name;
|
|
@@ -1367,6 +1391,7 @@ var import_luaut_parser7 = require("luaut-parser");
|
|
|
1367
1391
|
var TOKEN_TYPES = [
|
|
1368
1392
|
"namespace",
|
|
1369
1393
|
"type",
|
|
1394
|
+
"class",
|
|
1370
1395
|
"typeParameter",
|
|
1371
1396
|
"parameter",
|
|
1372
1397
|
"variable",
|
|
@@ -1383,6 +1408,7 @@ var semanticTokensLegend = {
|
|
|
1383
1408
|
var SOFT_KEYWORDS = /* @__PURE__ */ new Set([
|
|
1384
1409
|
"type",
|
|
1385
1410
|
"declare",
|
|
1411
|
+
"class",
|
|
1386
1412
|
"extends",
|
|
1387
1413
|
"keyof",
|
|
1388
1414
|
"infer",
|
|
@@ -1449,6 +1475,8 @@ function classify(analysis, spanned, ancestors, identifiers, add) {
|
|
|
1449
1475
|
if (!baseToken) return;
|
|
1450
1476
|
if (!namespace && typeParameterInScope2(ancestors, base)) {
|
|
1451
1477
|
add(baseToken, base.length, "typeParameter");
|
|
1478
|
+
} else if ((0, import_luaut_parser7.isClassType)(analysis.types.aliases.get(namespace ? `${namespace}.${base}` : base) ?? import_luaut_parser7.unknownType)) {
|
|
1479
|
+
add(baseToken, base.length, "class");
|
|
1452
1480
|
} else {
|
|
1453
1481
|
add(baseToken, base.length, "type", PRIMITIVES3.has(base) ? ["defaultLibrary"] : []);
|
|
1454
1482
|
}
|
|
@@ -1476,6 +1504,9 @@ function identifier(analysis, node, parent, add) {
|
|
|
1476
1504
|
case "ExportTypeAliasStatement":
|
|
1477
1505
|
if (parent.name === node) return as("type", ["declaration"]);
|
|
1478
1506
|
break;
|
|
1507
|
+
case "DeclareClassStatement":
|
|
1508
|
+
if (parent.name === node) return as("class", ["declaration"]);
|
|
1509
|
+
break;
|
|
1479
1510
|
case "DeclareStatement":
|
|
1480
1511
|
if (parent.id === node) return as(isFunction(typeOfNode(parent.valueType)) ? "function" : "variable", ["declaration"]);
|
|
1481
1512
|
break;
|