luaut-language-server 2.1.0 → 3.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-HJ2C3OFZ.js";
4
+ } from "./chunk-X2GHHRWT.js";
5
5
 
6
6
  // src/cli.ts
7
7
  startServer();
package/dist/index.cjs CHANGED
@@ -819,11 +819,28 @@ var import_luaut_parser4 = require("luaut-parser");
819
819
  function hover(analysis, position) {
820
820
  const path = pathAt(analysis.program, position, true);
821
821
  for (let i = path.length - 1; i >= 0; i--) {
822
+ if (UNNAMED.has(path[i].type)) return null;
822
823
  const text = describe(analysis, path, i);
823
824
  if (text) return { contents: { kind: "markdown", value: code(text) }, range: toRange(path[i]) };
824
825
  }
825
826
  return null;
826
827
  }
828
+ var UNNAMED = /* @__PURE__ */ new Set([
829
+ "BinaryExpression",
830
+ "UnaryExpression",
831
+ "CallExpression",
832
+ "MethodCallExpression",
833
+ "MemberExpression",
834
+ "IndexExpression",
835
+ "ParenthesizedExpression",
836
+ "IfElseExpression",
837
+ "TableExpression",
838
+ "ArrayExpression",
839
+ "TypeAssertionExpression",
840
+ "SatisfiesExpression",
841
+ "AsConstExpression",
842
+ "InterpolatedStringExpression"
843
+ ]);
827
844
  var PRIMITIVES = /* @__PURE__ */ new Set(["any", "unknown", "never", "nil", "boolean", "number", "string", "thread", "buffer"]);
828
845
  function describe(analysis, path, index) {
829
846
  const { types } = analysis;
@@ -899,7 +916,7 @@ function describe(analysis, path, index) {
899
916
  const binding = bindingOfNode(analysis, identifier2);
900
917
  if (binding) {
901
918
  const type2 = types.bindingType.get(binding.id);
902
- if (type2) return `${keyword(binding)} ${binding.name}: ${pretty(type2)}`;
919
+ if (type2) return bindingText(binding, type2);
903
920
  }
904
921
  if (parent?.type === "MemberExpression" || parent?.type === "MethodCallExpression") {
905
922
  const type2 = types.typeOf.get(parent);
@@ -907,13 +924,13 @@ function describe(analysis, path, index) {
907
924
  }
908
925
  return void 0;
909
926
  }
910
- // Declarations: `const x`, a parameter, `const function f`.
927
+ // Declarations: `const x`, a parameter.
911
928
  case "IdentifierPattern":
912
929
  case "FunctionParameter":
913
930
  case "TypedIdentifier": {
914
931
  const binding = bindingOfNode(analysis, node);
915
932
  const type2 = binding && types.bindingType.get(binding.id);
916
- return type2 ? `${keyword(binding)} ${binding.name}: ${pretty(type2)}` : void 0;
933
+ return type2 ? bindingText(binding, type2) : void 0;
917
934
  }
918
935
  // A type written by name: `number`, `Shape`, `Partial<User>`, or a type
919
936
  // parameter in scope.
@@ -1029,10 +1046,19 @@ ${lines.join("\n")}
1029
1046
  }
1030
1047
  return flat;
1031
1048
  }
1049
+ function bindingText(binding, type) {
1050
+ if (binding.declaredBy === "function" && type.kind === "function") {
1051
+ return `function ${binding.name}${(0, import_luaut_parser4.formatType)(type)}`;
1052
+ }
1053
+ return `${keyword(binding)} ${binding.name}: ${pretty(type)}`;
1054
+ }
1032
1055
  function keyword(binding) {
1033
1056
  if (binding.kind === "param" || binding.kind === "self") return "(parameter)";
1034
1057
  if (binding.kind === "global") return "(global)";
1035
1058
  if (binding.kind.startsWith("for-")) return "(loop variable)";
1059
+ if (binding.declaredBy === "import" || binding.declaredBy === "namespace") return "(import)";
1060
+ if (binding.declaredBy === "type") return "(type import)";
1061
+ if (binding.declaredBy === "function") return "function";
1036
1062
  return binding.isConst ? "const" : "let";
1037
1063
  }
1038
1064
  function code(text) {
@@ -1228,6 +1254,7 @@ function valueItems(analysis, at) {
1228
1254
  const seen = /* @__PURE__ */ new Set();
1229
1255
  for (const binding of analysis.scopes.bindings.values()) {
1230
1256
  if (binding.name === PLACEHOLDER || seen.has(binding.name)) continue;
1257
+ if (binding.declaredBy === "type") continue;
1231
1258
  const declaration = binding.declarationNode;
1232
1259
  if (declaration && declaration.line.start - 1 > at.line) continue;
1233
1260
  seen.add(binding.name);
@@ -1596,10 +1623,14 @@ function identifier(analysis, node, parent, add) {
1596
1623
  break;
1597
1624
  case "ImportSpecifier": {
1598
1625
  const binding2 = bindingOfNode(analysis, node);
1626
+ if (binding2?.declaredBy === "type") return as("type", ["declaration"]);
1599
1627
  const value = binding2 && analysis.types.bindingType.get(binding2.id);
1600
1628
  if (analysis.types.aliases.has(name) && (!value || value.kind === "any")) return as("type", ["declaration"]);
1601
1629
  break;
1602
1630
  }
1631
+ case "ImportStatement":
1632
+ if (parent.namespaceImport === node) return as("namespace", ["declaration"]);
1633
+ break;
1603
1634
  case "ExportSpecifier":
1604
1635
  if (!bindingOfNode(analysis, node) && analysis.types.aliases.has(name)) return as("type");
1605
1636
  break;
@@ -1615,6 +1646,7 @@ function identifier(analysis, node, parent, add) {
1615
1646
  function valueKind(analysis, binding) {
1616
1647
  if (!binding) return "variable";
1617
1648
  if (binding.kind === "param" || binding.kind === "self") return "parameter";
1649
+ if (binding.declaredBy === "namespace") return "namespace";
1618
1650
  return isFunction(analysis.types.bindingType.get(binding.id)) ? "function" : "variable";
1619
1651
  }
1620
1652
  function modifiersOf(binding, isDeclaration) {