luaut-language-server 3.1.0 → 4.0.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-SCZTSX3Y.js";
4
+ } from "./chunk-XK3KS3T4.js";
5
5
 
6
6
  // src/cli.ts
7
7
  startServer();
package/dist/index.cjs CHANGED
@@ -116,6 +116,20 @@ function membersOf(type, aliases, seen = /* @__PURE__ */ new Set()) {
116
116
  }
117
117
  case "typeParam":
118
118
  return membersOf(type.constraint, aliases, seen);
119
+ // An array and a string answer to the methods the language gives them
120
+ // — `names:filter(f)`, `text:trim()`. They are written in the parser's
121
+ // prelude as `ArrayMethods<T>` and `StringMethods`, so the element
122
+ // type goes in where `T` stands.
123
+ case "array":
124
+ case "tuple": {
125
+ const element = type.kind === "array" ? type.element : (0, import_luaut_parser.union)(type.elements);
126
+ const methods = aliases.get("ArrayMethods");
127
+ return methods ? membersOf((0, import_luaut_parser.substitute)(methods, /* @__PURE__ */ new Map([["T", element]])), aliases, seen) : [];
128
+ }
129
+ case "primitive":
130
+ return type.name === "string" ? membersOf(aliases.get("StringMethods"), aliases, seen) : [];
131
+ case "literal":
132
+ return type.base === "string" ? membersOf(aliases.get("StringMethods"), aliases, seen) : [];
119
133
  default:
120
134
  return [];
121
135
  }
@@ -1538,12 +1552,7 @@ function memberItems(analysis, access) {
1538
1552
  const object = access.object;
1539
1553
  const type = withoutNil(analysis.types.typeOf.get(object));
1540
1554
  const colon = access.type === "MethodCallExpression";
1541
- if (isStringLike(type)) {
1542
- if (!colon) return [];
1543
- const id = analysis.scopes.globalsByName.get("string");
1544
- const library = id === void 0 ? void 0 : analysis.types.bindingType.get(id);
1545
- return membersOf(library, analysis.types.aliases).filter((member) => signaturesOf(member.property.type).length > 0).map((member) => memberItem(member.name, member.property.type, member.property.readonly));
1546
- }
1555
+ if (isMethodOnly(type) && !colon) return [];
1547
1556
  return membersOf(type, analysis.types.aliases).filter((member) => colon ? member.isMethod : true).map((member) => memberItem(member.name, member.property.type, member.property.readonly));
1548
1557
  }
1549
1558
  function withoutNil(type) {
@@ -1551,17 +1560,19 @@ function withoutNil(type) {
1551
1560
  const kept = type.types.filter((t) => !(t.kind === "primitive" && t.name === "nil"));
1552
1561
  return kept.length === 1 ? kept[0] : { ...type, types: kept };
1553
1562
  }
1554
- function isStringLike(type) {
1563
+ function isMethodOnly(type) {
1555
1564
  if (!type) return false;
1556
1565
  switch (type.kind) {
1566
+ case "array":
1567
+ case "tuple":
1568
+ case "templateLiteral":
1569
+ return true;
1557
1570
  case "primitive":
1558
1571
  return type.name === "string";
1559
1572
  case "literal":
1560
1573
  return typeof type.value === "string";
1561
- case "templateLiteral":
1562
- return true;
1563
1574
  case "union":
1564
- return type.types.length > 0 && type.types.every(isStringLike);
1575
+ return type.types.length > 0 && type.types.every(isMethodOnly);
1565
1576
  default:
1566
1577
  return false;
1567
1578
  }
@@ -2129,7 +2140,7 @@ function createServer(connection, options = {}) {
2129
2140
  severity: import_node.DiagnosticSeverity.Information,
2130
2141
  source: "luaut",
2131
2142
  code: "no-config",
2132
- message: 'No luaut.config.json applies to this file, so no types are loaded \u2014 not even `print`. Add one to this folder or a folder above, such as { "types": ["luau"], "paths": {}, "sourceMap": null }'
2143
+ message: 'No luaut.config.json applies to this file, so no types are loaded \u2014 not even `print`. Add one to this folder or a folder above: { "types": [], "paths": {}, "sourceMap": null }, listing in `types` the type libraries the project has installed.'
2133
2144
  }];
2134
2145
  };
2135
2146
  documents.onDidOpen(publishAll);