luaut-language-server 1.1.0 → 1.1.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/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  startServer
4
- } from "./chunk-HK7PKBDB.js";
4
+ } from "./chunk-OQWE7ISD.js";
5
5
 
6
6
  // src/cli.ts
7
7
  startServer();
package/dist/index.cjs CHANGED
@@ -889,6 +889,8 @@ var IDENTIFIER_CHAR = /[A-Za-z0-9_]/;
889
889
  function completion(analyzer, document, position) {
890
890
  const inImport = importCompletion(analyzer, document, position);
891
891
  if (inImport) return inImport;
892
+ const inString = stringCompletion(analyzer, document, position);
893
+ if (inString) return inString;
892
894
  const source = document.getText();
893
895
  const offset = document.offsetAt(position);
894
896
  let start = offset;
@@ -929,6 +931,43 @@ function completion(analyzer, document, position) {
929
931
  }
930
932
  return valueItems(first.analysis, at);
931
933
  }
934
+ function stringCompletion(analyzer, document, position) {
935
+ const analysis = analyzer.get(document);
936
+ const path = pathAt(analysis.program, position, false);
937
+ const literal = [...path].reverse().find((n) => n.type === "StringLiteral");
938
+ if (!literal) return void 0;
939
+ const expected = analysis.types.expectedTypeOf.get(literal);
940
+ const values = stringLiterals(expected, analysis.types.aliases);
941
+ if (!values.length) return [];
942
+ const line = literal.line.start - 1;
943
+ const range = literal.line.start === literal.line.end ? {
944
+ start: { line, character: literal.column.start },
945
+ end: { line, character: literal.column.end - 2 }
946
+ } : void 0;
947
+ return values.map((value) => ({
948
+ label: value,
949
+ kind: import_vscode_languageserver4.CompletionItemKind.Constant,
950
+ ...range ? { textEdit: { range, newText: value } } : {}
951
+ }));
952
+ }
953
+ function stringLiterals(type, aliases, seen = /* @__PURE__ */ new Set()) {
954
+ if (!type || seen.has(type)) return [];
955
+ seen.add(type);
956
+ switch (type.kind) {
957
+ case "literal":
958
+ return typeof type.value === "string" ? [type.value] : [];
959
+ case "union":
960
+ return [...new Set(type.types.flatMap((t) => stringLiterals(t, aliases, seen)))];
961
+ case "genericRef": {
962
+ const alias = aliases.get(type.name);
963
+ return alias ? stringLiterals(alias, aliases, seen) : [];
964
+ }
965
+ case "typeParam":
966
+ return stringLiterals(type.constraint, aliases, seen);
967
+ default:
968
+ return [];
969
+ }
970
+ }
932
971
  function memberOperator(source, wordStart) {
933
972
  const ch = source[wordStart - 1];
934
973
  if (ch === ":") return source[wordStart - 2] === ":" ? void 0 : ":";
@@ -1203,7 +1242,7 @@ var TOKEN_TYPES = [
1203
1242
  "method",
1204
1243
  "keyword"
1205
1244
  ];
1206
- var TOKEN_MODIFIERS = ["declaration", "readonly", "defaultLibrary"];
1245
+ var TOKEN_MODIFIERS = ["declaration", "readonly", "defaultLibrary", "control"];
1207
1246
  var semanticTokensLegend = {
1208
1247
  tokenTypes: [...TOKEN_TYPES],
1209
1248
  tokenModifiers: [...TOKEN_MODIFIERS]
@@ -1218,8 +1257,10 @@ var SOFT_KEYWORDS = /* @__PURE__ */ new Set([
1218
1257
  "is",
1219
1258
  "asserts",
1220
1259
  "satisfies",
1221
- "typeof"
1260
+ "typeof",
1261
+ "default"
1222
1262
  ]);
1263
+ var CONTROL_KEYWORDS = /* @__PURE__ */ new Set(["default"]);
1223
1264
  var PRIMITIVES3 = /* @__PURE__ */ new Set(["any", "unknown", "never", "nil", "boolean", "number", "string", "thread", "buffer"]);
1224
1265
  function semanticTokens(analysis) {
1225
1266
  const entries = /* @__PURE__ */ new Map();
@@ -1245,12 +1286,8 @@ function semanticTokens(analysis) {
1245
1286
  walk2(analysis.program);
1246
1287
  for (const token of tokens) {
1247
1288
  const value = token.value;
1248
- if (typeof value !== "string") continue;
1249
- if (token.type === "Keyword" && value !== "true" && value !== "false" && value !== "nil") {
1250
- add(token, value.length, "keyword");
1251
- } else if (token.type === "Identifier" && SOFT_KEYWORDS.has(value)) {
1252
- add(token, value.length, "keyword");
1253
- }
1289
+ if (token.type !== "Identifier" || typeof value !== "string" || !SOFT_KEYWORDS.has(value)) continue;
1290
+ add(token, value.length, "keyword", CONTROL_KEYWORDS.has(value) ? ["control"] : []);
1254
1291
  }
1255
1292
  return { data: encode([...entries.values()]) };
1256
1293
  }