sysml-v2-lsp 0.34.0 → 0.36.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.
@@ -10545,8 +10545,8 @@ var require_main2 = __commonJS({
10545
10545
  }
10546
10546
  uinteger2.is = is;
10547
10547
  })(uinteger || (exports3.uinteger = uinteger = {}));
10548
- var Position;
10549
- (function(Position2) {
10548
+ var Position2;
10549
+ (function(Position3) {
10550
10550
  function create(line, character) {
10551
10551
  if (line === Number.MAX_VALUE) {
10552
10552
  line = uinteger.MAX_VALUE;
@@ -10556,31 +10556,31 @@ var require_main2 = __commonJS({
10556
10556
  }
10557
10557
  return { line, character };
10558
10558
  }
10559
- Position2.create = create;
10559
+ Position3.create = create;
10560
10560
  function is(value) {
10561
10561
  var candidate = value;
10562
10562
  return Is.objectLiteral(candidate) && Is.uinteger(candidate.line) && Is.uinteger(candidate.character);
10563
10563
  }
10564
- Position2.is = is;
10565
- })(Position || (exports3.Position = Position = {}));
10566
- var Range;
10567
- (function(Range2) {
10564
+ Position3.is = is;
10565
+ })(Position2 || (exports3.Position = Position2 = {}));
10566
+ var Range2;
10567
+ (function(Range3) {
10568
10568
  function create(one, two, three, four) {
10569
10569
  if (Is.uinteger(one) && Is.uinteger(two) && Is.uinteger(three) && Is.uinteger(four)) {
10570
- return { start: Position.create(one, two), end: Position.create(three, four) };
10571
- } else if (Position.is(one) && Position.is(two)) {
10570
+ return { start: Position2.create(one, two), end: Position2.create(three, four) };
10571
+ } else if (Position2.is(one) && Position2.is(two)) {
10572
10572
  return { start: one, end: two };
10573
10573
  } else {
10574
10574
  throw new Error("Range#create called with invalid arguments[".concat(one, ", ").concat(two, ", ").concat(three, ", ").concat(four, "]"));
10575
10575
  }
10576
10576
  }
10577
- Range2.create = create;
10577
+ Range3.create = create;
10578
10578
  function is(value) {
10579
10579
  var candidate = value;
10580
- return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end);
10580
+ return Is.objectLiteral(candidate) && Position2.is(candidate.start) && Position2.is(candidate.end);
10581
10581
  }
10582
- Range2.is = is;
10583
- })(Range || (exports3.Range = Range = {}));
10582
+ Range3.is = is;
10583
+ })(Range2 || (exports3.Range = Range2 = {}));
10584
10584
  var Location;
10585
10585
  (function(Location2) {
10586
10586
  function create(uri, range) {
@@ -10589,7 +10589,7 @@ var require_main2 = __commonJS({
10589
10589
  Location2.create = create;
10590
10590
  function is(value) {
10591
10591
  var candidate = value;
10592
- return Is.objectLiteral(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
10592
+ return Is.objectLiteral(candidate) && Range2.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
10593
10593
  }
10594
10594
  Location2.is = is;
10595
10595
  })(Location || (exports3.Location = Location = {}));
@@ -10601,7 +10601,7 @@ var require_main2 = __commonJS({
10601
10601
  LocationLink2.create = create;
10602
10602
  function is(value) {
10603
10603
  var candidate = value;
10604
- return Is.objectLiteral(candidate) && Range.is(candidate.targetRange) && Is.string(candidate.targetUri) && Range.is(candidate.targetSelectionRange) && (Range.is(candidate.originSelectionRange) || Is.undefined(candidate.originSelectionRange));
10604
+ return Is.objectLiteral(candidate) && Range2.is(candidate.targetRange) && Is.string(candidate.targetUri) && Range2.is(candidate.targetSelectionRange) && (Range2.is(candidate.originSelectionRange) || Is.undefined(candidate.originSelectionRange));
10605
10605
  }
10606
10606
  LocationLink2.is = is;
10607
10607
  })(LocationLink || (exports3.LocationLink = LocationLink = {}));
@@ -10633,7 +10633,7 @@ var require_main2 = __commonJS({
10633
10633
  ColorInformation2.create = create;
10634
10634
  function is(value) {
10635
10635
  var candidate = value;
10636
- return Is.objectLiteral(candidate) && Range.is(candidate.range) && Color.is(candidate.color);
10636
+ return Is.objectLiteral(candidate) && Range2.is(candidate.range) && Color.is(candidate.color);
10637
10637
  }
10638
10638
  ColorInformation2.is = is;
10639
10639
  })(ColorInformation || (exports3.ColorInformation = ColorInformation = {}));
@@ -10744,7 +10744,7 @@ var require_main2 = __commonJS({
10744
10744
  function is(value) {
10745
10745
  var _a3;
10746
10746
  var candidate = value;
10747
- return Is.defined(candidate) && Range.is(candidate.range) && Is.string(candidate.message) && (Is.number(candidate.severity) || Is.undefined(candidate.severity)) && (Is.integer(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code)) && (Is.undefined(candidate.codeDescription) || Is.string((_a3 = candidate.codeDescription) === null || _a3 === void 0 ? void 0 : _a3.href)) && (Is.string(candidate.source) || Is.undefined(candidate.source)) && (Is.undefined(candidate.relatedInformation) || Is.typedArray(candidate.relatedInformation, DiagnosticRelatedInformation.is));
10747
+ return Is.defined(candidate) && Range2.is(candidate.range) && Is.string(candidate.message) && (Is.number(candidate.severity) || Is.undefined(candidate.severity)) && (Is.integer(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code)) && (Is.undefined(candidate.codeDescription) || Is.string((_a3 = candidate.codeDescription) === null || _a3 === void 0 ? void 0 : _a3.href)) && (Is.string(candidate.source) || Is.undefined(candidate.source)) && (Is.undefined(candidate.relatedInformation) || Is.typedArray(candidate.relatedInformation, DiagnosticRelatedInformation.is));
10748
10748
  }
10749
10749
  Diagnostic3.is = is;
10750
10750
  })(Diagnostic2 || (exports3.Diagnostic = Diagnostic2 = {}));
@@ -10784,7 +10784,7 @@ var require_main2 = __commonJS({
10784
10784
  TextEdit2.del = del;
10785
10785
  function is(value) {
10786
10786
  var candidate = value;
10787
- return Is.objectLiteral(candidate) && Is.string(candidate.newText) && Range.is(candidate.range);
10787
+ return Is.objectLiteral(candidate) && Is.string(candidate.newText) && Range2.is(candidate.range);
10788
10788
  }
10789
10789
  TextEdit2.is = is;
10790
10790
  })(TextEdit || (exports3.TextEdit = TextEdit = {}));
@@ -11328,7 +11328,7 @@ var require_main2 = __commonJS({
11328
11328
  InsertReplaceEdit2.create = create;
11329
11329
  function is(value) {
11330
11330
  var candidate = value;
11331
- return candidate && Is.string(candidate.newText) && Range.is(candidate.insert) && Range.is(candidate.replace);
11331
+ return candidate && Is.string(candidate.newText) && Range2.is(candidate.insert) && Range2.is(candidate.replace);
11332
11332
  }
11333
11333
  InsertReplaceEdit2.is = is;
11334
11334
  })(InsertReplaceEdit || (exports3.InsertReplaceEdit = InsertReplaceEdit = {}));
@@ -11375,7 +11375,7 @@ var require_main2 = __commonJS({
11375
11375
  (function(Hover2) {
11376
11376
  function is(value) {
11377
11377
  var candidate = value;
11378
- return !!candidate && Is.objectLiteral(candidate) && (MarkupContent.is(candidate.contents) || MarkedString.is(candidate.contents) || Is.typedArray(candidate.contents, MarkedString.is)) && (value.range === void 0 || Range.is(value.range));
11378
+ return !!candidate && Is.objectLiteral(candidate) && (MarkupContent.is(candidate.contents) || MarkedString.is(candidate.contents) || Is.typedArray(candidate.contents, MarkedString.is)) && (value.range === void 0 || Range2.is(value.range));
11379
11379
  }
11380
11380
  Hover2.is = is;
11381
11381
  })(Hover || (exports3.Hover = Hover = {}));
@@ -11496,7 +11496,7 @@ var require_main2 = __commonJS({
11496
11496
  DocumentSymbol2.create = create;
11497
11497
  function is(value) {
11498
11498
  var candidate = value;
11499
- return candidate && Is.string(candidate.name) && Is.number(candidate.kind) && Range.is(candidate.range) && Range.is(candidate.selectionRange) && (candidate.detail === void 0 || Is.string(candidate.detail)) && (candidate.deprecated === void 0 || Is.boolean(candidate.deprecated)) && (candidate.children === void 0 || Array.isArray(candidate.children)) && (candidate.tags === void 0 || Array.isArray(candidate.tags));
11499
+ return candidate && Is.string(candidate.name) && Is.number(candidate.kind) && Range2.is(candidate.range) && Range2.is(candidate.selectionRange) && (candidate.detail === void 0 || Is.string(candidate.detail)) && (candidate.deprecated === void 0 || Is.boolean(candidate.deprecated)) && (candidate.children === void 0 || Array.isArray(candidate.children)) && (candidate.tags === void 0 || Array.isArray(candidate.tags));
11500
11500
  }
11501
11501
  DocumentSymbol2.is = is;
11502
11502
  })(DocumentSymbol || (exports3.DocumentSymbol = DocumentSymbol = {}));
@@ -11573,7 +11573,7 @@ var require_main2 = __commonJS({
11573
11573
  CodeLens2.create = create;
11574
11574
  function is(value) {
11575
11575
  var candidate = value;
11576
- return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.command) || Command.is(candidate.command));
11576
+ return Is.defined(candidate) && Range2.is(candidate.range) && (Is.undefined(candidate.command) || Command.is(candidate.command));
11577
11577
  }
11578
11578
  CodeLens2.is = is;
11579
11579
  })(CodeLens || (exports3.CodeLens = CodeLens = {}));
@@ -11597,7 +11597,7 @@ var require_main2 = __commonJS({
11597
11597
  DocumentLink2.create = create;
11598
11598
  function is(value) {
11599
11599
  var candidate = value;
11600
- return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.target) || Is.string(candidate.target));
11600
+ return Is.defined(candidate) && Range2.is(candidate.range) && (Is.undefined(candidate.target) || Is.string(candidate.target));
11601
11601
  }
11602
11602
  DocumentLink2.is = is;
11603
11603
  })(DocumentLink || (exports3.DocumentLink = DocumentLink = {}));
@@ -11609,7 +11609,7 @@ var require_main2 = __commonJS({
11609
11609
  SelectionRange2.create = create;
11610
11610
  function is(value) {
11611
11611
  var candidate = value;
11612
- return Is.objectLiteral(candidate) && Range.is(candidate.range) && (candidate.parent === void 0 || SelectionRange2.is(candidate.parent));
11612
+ return Is.objectLiteral(candidate) && Range2.is(candidate.range) && (candidate.parent === void 0 || SelectionRange2.is(candidate.parent));
11613
11613
  }
11614
11614
  SelectionRange2.is = is;
11615
11615
  })(SelectionRange || (exports3.SelectionRange = SelectionRange = {}));
@@ -11668,7 +11668,7 @@ var require_main2 = __commonJS({
11668
11668
  InlineValueText2.create = create;
11669
11669
  function is(value) {
11670
11670
  var candidate = value;
11671
- return candidate !== void 0 && candidate !== null && Range.is(candidate.range) && Is.string(candidate.text);
11671
+ return candidate !== void 0 && candidate !== null && Range2.is(candidate.range) && Is.string(candidate.text);
11672
11672
  }
11673
11673
  InlineValueText2.is = is;
11674
11674
  })(InlineValueText || (exports3.InlineValueText = InlineValueText = {}));
@@ -11680,7 +11680,7 @@ var require_main2 = __commonJS({
11680
11680
  InlineValueVariableLookup2.create = create;
11681
11681
  function is(value) {
11682
11682
  var candidate = value;
11683
- return candidate !== void 0 && candidate !== null && Range.is(candidate.range) && Is.boolean(candidate.caseSensitiveLookup) && (Is.string(candidate.variableName) || candidate.variableName === void 0);
11683
+ return candidate !== void 0 && candidate !== null && Range2.is(candidate.range) && Is.boolean(candidate.caseSensitiveLookup) && (Is.string(candidate.variableName) || candidate.variableName === void 0);
11684
11684
  }
11685
11685
  InlineValueVariableLookup2.is = is;
11686
11686
  })(InlineValueVariableLookup || (exports3.InlineValueVariableLookup = InlineValueVariableLookup = {}));
@@ -11692,7 +11692,7 @@ var require_main2 = __commonJS({
11692
11692
  InlineValueEvaluatableExpression2.create = create;
11693
11693
  function is(value) {
11694
11694
  var candidate = value;
11695
- return candidate !== void 0 && candidate !== null && Range.is(candidate.range) && (Is.string(candidate.expression) || candidate.expression === void 0);
11695
+ return candidate !== void 0 && candidate !== null && Range2.is(candidate.range) && (Is.string(candidate.expression) || candidate.expression === void 0);
11696
11696
  }
11697
11697
  InlineValueEvaluatableExpression2.is = is;
11698
11698
  })(InlineValueEvaluatableExpression || (exports3.InlineValueEvaluatableExpression = InlineValueEvaluatableExpression = {}));
@@ -11704,7 +11704,7 @@ var require_main2 = __commonJS({
11704
11704
  InlineValueContext2.create = create;
11705
11705
  function is(value) {
11706
11706
  var candidate = value;
11707
- return Is.defined(candidate) && Range.is(value.stoppedLocation);
11707
+ return Is.defined(candidate) && Range2.is(value.stoppedLocation);
11708
11708
  }
11709
11709
  InlineValueContext2.is = is;
11710
11710
  })(InlineValueContext || (exports3.InlineValueContext = InlineValueContext = {}));
@@ -11741,7 +11741,7 @@ var require_main2 = __commonJS({
11741
11741
  InlayHint2.create = create;
11742
11742
  function is(value) {
11743
11743
  var candidate = value;
11744
- return Is.objectLiteral(candidate) && Position.is(candidate.position) && (Is.string(candidate.label) || Is.typedArray(candidate.label, InlayHintLabelPart.is)) && (candidate.kind === void 0 || InlayHintKind.is(candidate.kind)) && candidate.textEdits === void 0 || Is.typedArray(candidate.textEdits, TextEdit.is) && (candidate.tooltip === void 0 || Is.string(candidate.tooltip) || MarkupContent.is(candidate.tooltip)) && (candidate.paddingLeft === void 0 || Is.boolean(candidate.paddingLeft)) && (candidate.paddingRight === void 0 || Is.boolean(candidate.paddingRight));
11744
+ return Is.objectLiteral(candidate) && Position2.is(candidate.position) && (Is.string(candidate.label) || Is.typedArray(candidate.label, InlayHintLabelPart.is)) && (candidate.kind === void 0 || InlayHintKind.is(candidate.kind)) && candidate.textEdits === void 0 || Is.typedArray(candidate.textEdits, TextEdit.is) && (candidate.tooltip === void 0 || Is.string(candidate.tooltip) || MarkupContent.is(candidate.tooltip)) && (candidate.paddingLeft === void 0 || Is.boolean(candidate.paddingLeft)) && (candidate.paddingRight === void 0 || Is.boolean(candidate.paddingRight));
11745
11745
  }
11746
11746
  InlayHint2.is = is;
11747
11747
  })(InlayHint || (exports3.InlayHint = InlayHint = {}));
@@ -11930,7 +11930,7 @@ var require_main2 = __commonJS({
11930
11930
  var lineOffsets = this.getLineOffsets();
11931
11931
  var low = 0, high = lineOffsets.length;
11932
11932
  if (high === 0) {
11933
- return Position.create(0, offset);
11933
+ return Position2.create(0, offset);
11934
11934
  }
11935
11935
  while (low < high) {
11936
11936
  var mid = Math.floor((low + high) / 2);
@@ -11941,7 +11941,7 @@ var require_main2 = __commonJS({
11941
11941
  }
11942
11942
  }
11943
11943
  var line = low - 1;
11944
- return Position.create(line, offset - lineOffsets[line]);
11944
+ return Position2.create(line, offset - lineOffsets[line]);
11945
11945
  };
11946
11946
  FullTextDocument2.prototype.offsetAt = function(position) {
11947
11947
  var lineOffsets = this.getLineOffsets();
@@ -42741,6 +42741,9 @@ var Protocol = class {
42741
42741
  this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
42742
42742
  const handleTaskResult = async () => {
42743
42743
  const taskId = request.params.taskId;
42744
+ if (!await this._taskStore.getTask(taskId, extra.sessionId)) {
42745
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
42746
+ }
42744
42747
  if (this._taskMessageQueue) {
42745
42748
  let queuedMessage;
42746
42749
  while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
@@ -42771,12 +42774,12 @@ var Protocol = class {
42771
42774
  throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
42772
42775
  }
42773
42776
  if (!isTerminal(task.status)) {
42774
- await this._waitForTaskUpdate(taskId, extra.signal);
42777
+ await this._waitForTaskUpdate(taskId, extra.signal, extra.sessionId);
42775
42778
  return await handleTaskResult();
42776
42779
  }
42777
42780
  if (isTerminal(task.status)) {
42778
42781
  const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
42779
- this._clearTaskQueue(taskId);
42782
+ this._clearTaskQueue(taskId, extra.sessionId);
42780
42783
  return {
42781
42784
  ...result,
42782
42785
  _meta: {
@@ -42813,7 +42816,7 @@ var Protocol = class {
42813
42816
  throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
42814
42817
  }
42815
42818
  await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
42816
- this._clearTaskQueue(request.params.taskId);
42819
+ this._clearTaskQueue(request.params.taskId, extra.sessionId);
42817
42820
  const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
42818
42821
  if (!cancelledTask) {
42819
42822
  throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
@@ -42941,6 +42944,19 @@ var Protocol = class {
42941
42944
  const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
42942
42945
  const capturedTransport = this._transport;
42943
42946
  const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
42947
+ const sessionId = capturedTransport?.sessionId;
42948
+ const store = this._taskStore;
42949
+ let relatedTaskFound = true;
42950
+ let relatedTaskLookup;
42951
+ if (relatedTaskId && store && this._taskMessageQueue && sessionId !== void 0) {
42952
+ relatedTaskFound = false;
42953
+ relatedTaskLookup = (async () => {
42954
+ if (!await store.getTask(relatedTaskId, sessionId)) {
42955
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${relatedTaskId}`);
42956
+ }
42957
+ relatedTaskFound = true;
42958
+ })();
42959
+ }
42944
42960
  if (handler === void 0) {
42945
42961
  const errorResponse = {
42946
42962
  jsonrpc: "2.0",
@@ -42950,7 +42966,10 @@ var Protocol = class {
42950
42966
  message: "Method not found"
42951
42967
  }
42952
42968
  };
42953
- if (relatedTaskId && this._taskMessageQueue) {
42969
+ if (relatedTaskId && relatedTaskLookup) {
42970
+ const queuedError = { type: "error", message: errorResponse, timestamp: Date.now() };
42971
+ relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((error62) => this._onerror(new Error(`Failed to send an error response: ${error62}`)));
42972
+ } else if (relatedTaskId && this._taskMessageQueue) {
42954
42973
  this._enqueueTaskMessage(relatedTaskId, {
42955
42974
  type: "error",
42956
42975
  message: errorResponse,
@@ -43001,7 +43020,10 @@ var Protocol = class {
43001
43020
  closeSSEStream: extra?.closeSSEStream,
43002
43021
  closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
43003
43022
  };
43004
- Promise.resolve().then(() => {
43023
+ (relatedTaskLookup ?? Promise.resolve()).then(() => {
43024
+ if (relatedTaskLookup && abortController.signal.aborted) {
43025
+ throw new McpError(ErrorCode.ConnectionClosed, "Request was cancelled");
43026
+ }
43005
43027
  if (taskCreationParams) {
43006
43028
  this.assertTaskHandlerCapability(request.method);
43007
43029
  }
@@ -43036,7 +43058,7 @@ var Protocol = class {
43036
43058
  ...error62["data"] !== void 0 && { data: error62["data"] }
43037
43059
  }
43038
43060
  };
43039
- if (relatedTaskId && this._taskMessageQueue) {
43061
+ if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
43040
43062
  await this._enqueueTaskMessage(relatedTaskId, {
43041
43063
  type: "error",
43042
43064
  message: errorResponse,
@@ -43516,7 +43538,7 @@ var Protocol = class {
43516
43538
  throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
43517
43539
  }
43518
43540
  const maxQueueSize = this._options?.maxTaskQueueSize;
43519
- await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
43541
+ await this._taskMessageQueue.enqueue(taskId, message, sessionId ?? this._transport?.sessionId, maxQueueSize);
43520
43542
  }
43521
43543
  /**
43522
43544
  * Clears the message queue for a task and rejects any pending request resolvers.
@@ -43545,12 +43567,13 @@ var Protocol = class {
43545
43567
  * Uses polling to check for updates at the task's configured poll interval.
43546
43568
  * @param taskId The task ID to wait for
43547
43569
  * @param signal Abort signal to cancel the wait
43570
+ * @param sessionId Session of the request that waits, passed to the task store
43548
43571
  * @returns Promise that resolves when an update occurs or rejects if aborted
43549
43572
  */
43550
- async _waitForTaskUpdate(taskId, signal) {
43573
+ async _waitForTaskUpdate(taskId, signal, sessionId) {
43551
43574
  let interval = this._options?.defaultTaskPollInterval ?? 1e3;
43552
43575
  try {
43553
- const task = await this._taskStore?.getTask(taskId);
43576
+ const task = await this._taskStore?.getTask(taskId, sessionId);
43554
43577
  if (task?.pollInterval) {
43555
43578
  interval = task.pollInterval;
43556
43579
  }
@@ -44429,6 +44452,42 @@ var ExperimentalMcpServerTasks = class {
44429
44452
  };
44430
44453
 
44431
44454
  // node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js
44455
+ function toolInputElementCount(value, max) {
44456
+ let count = 0;
44457
+ const stack = [value];
44458
+ while (stack.length > 0) {
44459
+ const node2 = stack.pop();
44460
+ if (node2 === null || typeof node2 !== "object")
44461
+ continue;
44462
+ if (Array.isArray(node2)) {
44463
+ for (const child of node2) {
44464
+ if (++count > max)
44465
+ return count;
44466
+ if (child !== null && typeof child === "object")
44467
+ stack.push(child);
44468
+ }
44469
+ } else {
44470
+ for (const key in node2) {
44471
+ if (!Object.prototype.hasOwnProperty.call(node2, key))
44472
+ continue;
44473
+ if (++count > max)
44474
+ return count;
44475
+ const child = node2[key];
44476
+ if (child !== null && typeof child === "object")
44477
+ stack.push(child);
44478
+ }
44479
+ }
44480
+ }
44481
+ return count;
44482
+ }
44483
+ function resolveMaxToolInputElements(value) {
44484
+ if (value === void 0 || value === Infinity)
44485
+ return void 0;
44486
+ if (typeof value !== "number" || Number.isNaN(value) || value < 1) {
44487
+ throw new RangeError(`maxToolInputElements must be a number of at least 1, or Infinity, got ${String(value)}`);
44488
+ }
44489
+ return value;
44490
+ }
44432
44491
  var McpServer = class {
44433
44492
  constructor(serverInfo, options) {
44434
44493
  this._registeredResources = {};
@@ -44440,6 +44499,7 @@ var McpServer = class {
44440
44499
  this._resourceHandlersInitialized = false;
44441
44500
  this._promptHandlersInitialized = false;
44442
44501
  this.server = new Server(serverInfo, options);
44502
+ this._maxToolInputElements = resolveMaxToolInputElements(options?.maxToolInputElements);
44443
44503
  }
44444
44504
  /**
44445
44505
  * Access experimental features.
@@ -44570,12 +44630,15 @@ var McpServer = class {
44570
44630
  * Validates tool input arguments against the tool's input schema.
44571
44631
  */
44572
44632
  async validateToolInput(tool, args, toolName) {
44633
+ if (this._maxToolInputElements !== void 0 && toolInputElementCount(args, this._maxToolInputElements) > this._maxToolInputElements) {
44634
+ throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for tool ${toolName}: arguments contain more than the maximum of ${this._maxToolInputElements} elements`);
44635
+ }
44573
44636
  if (!tool.inputSchema) {
44574
44637
  return void 0;
44575
44638
  }
44576
44639
  const inputObj = normalizeObjectSchema(tool.inputSchema);
44577
44640
  const schemaToParse = inputObj ?? tool.inputSchema;
44578
- const parseResult = await safeParseAsync2(schemaToParse, args);
44641
+ const parseResult = await safeParseAsync2(schemaToParse, args ?? {});
44579
44642
  if (!parseResult.success) {
44580
44643
  const error62 = "error" in parseResult ? parseResult.error : "Unknown error";
44581
44644
  const errorMessage = getParseErrorMessage(error62);
@@ -44813,7 +44876,7 @@ var McpServer = class {
44813
44876
  }
44814
44877
  if (prompt.argsSchema) {
44815
44878
  const argsObj = normalizeObjectSchema(prompt.argsSchema);
44816
- const parseResult = await safeParseAsync2(argsObj, request.params.arguments);
44879
+ const parseResult = await safeParseAsync2(argsObj, request.params.arguments ?? {});
44817
44880
  if (!parseResult.success) {
44818
44881
  const error62 = "error" in parseResult ? parseResult.error : "Unknown error";
44819
44882
  const errorMessage = getParseErrorMessage(error62);
@@ -45355,6 +45418,8 @@ var SysMLElementKind = /* @__PURE__ */ ((SysMLElementKind2) => {
45355
45418
  SysMLElementKind2["TransitionUsage"] = "transition";
45356
45419
  SysMLElementKind2["RequirementDef"] = "requirement def";
45357
45420
  SysMLElementKind2["RequirementUsage"] = "requirement";
45421
+ SysMLElementKind2["ConcernDef"] = "concern def";
45422
+ SysMLElementKind2["ConcernUsage"] = "concern";
45358
45423
  SysMLElementKind2["ConstraintDef"] = "constraint def";
45359
45424
  SysMLElementKind2["ConstraintUsage"] = "constraint";
45360
45425
  SysMLElementKind2["ItemDef"] = "item def";
@@ -45466,6 +45531,10 @@ function toMetaclassName(kind) {
45466
45531
  return "RequirementDefinition";
45467
45532
  case "requirement" /* RequirementUsage */:
45468
45533
  return "RequirementUsage";
45534
+ case "concern def" /* ConcernDef */:
45535
+ return "ConcernDefinition";
45536
+ case "concern" /* ConcernUsage */:
45537
+ return "ConcernUsage";
45469
45538
  case "constraint def" /* ConstraintDef */:
45470
45539
  return "ConstraintDefinition";
45471
45540
  case "constraint" /* ConstraintUsage */:
@@ -158884,6 +158953,10 @@ function getLibraryPackageNames() {
158884
158953
  function canonicalUri(uri) {
158885
158954
  return uri.replace(/^file:\/\/\/([A-Za-z])(?::|%3[Aa])(?=\/|$)/, (_m, drive) => `file:///${drive.toLowerCase()}:`);
158886
158955
  }
158956
+ function isInFolder(uri, folderUri) {
158957
+ const folder = canonicalUri(folderUri);
158958
+ return canonicalUri(uri).startsWith(folder.endsWith("/") ? folder : `${folder}/`);
158959
+ }
158887
158960
  function isSameDocumentUri(a, b) {
158888
158961
  return a === b || canonicalUri(a) === canonicalUri(b);
158889
158962
  }
@@ -159062,14 +159135,21 @@ var NamespaceResolver = class {
159062
159135
  * namespace.
159063
159136
  */
159064
159137
  isLocallyVisible(symbol2, name, indexes) {
159065
- return this.resolveQualifiedNameFrom(ownerKeyOf(symbol2, indexes.byId), name, indexes) !== void 0;
159138
+ return this.resolveNameFrom(symbol2, name, indexes) !== void 0;
159139
+ }
159140
+ /**
159141
+ * Resolve a (possibly qualified) name from the namespace containing
159142
+ * `symbol`, respecting namespace membership and visibility.
159143
+ */
159144
+ resolveNameFrom(symbol2, name, indexes) {
159145
+ return this.resolveQualifiedNameFrom(ownerKeyOf(symbol2, indexes.byId), name, indexes);
159066
159146
  }
159067
159147
  /**
159068
159148
  * Resolve a (possibly qualified) name to its symbol per §7.5.1, searching
159069
159149
  * outward from namespace `start` and its enclosing namespaces (its own resolved
159070
159150
  * members first, then its parent's, ...). Shared by `isLocallyVisible` (an
159071
- * ordinary reference resolving relative to its own enclosing namespace) and
159072
- * import-target resolution (an `import` declaration's target is itself a
159151
+ * ordinary reference resolving relative to its own enclosing namespace),
159152
+ * `resolveNameFrom`, and import-target resolution (an `import` declaration's target is itself a
159073
159153
  * qualifiedName, resolved the same relative way -- not as an absolute/global
159074
159154
  * name -- so a bare `import C;` inside a nested package can pick up a `C`
159075
159155
  * its own enclosing package already imported, per §7.5.1/§7.5.3).
@@ -159474,6 +159554,7 @@ var NAMESPACE_URL = v5_default.URL;
159474
159554
  var DEFAULT_URL_PREFIX = "https://github.com/daltskin/sysml-v2-lsp/";
159475
159555
  var PROJECT_ID_ENV_VAR = "SYSML_PROJECT_ID";
159476
159556
  var urlPrefix = DEFAULT_URL_PREFIX;
159557
+ var folderPrefixes = [];
159477
159558
  function setProjectId(projectId2) {
159478
159559
  if (projectId2 === void 0) {
159479
159560
  urlPrefix = DEFAULT_URL_PREFIX;
@@ -159483,8 +159564,9 @@ function setProjectId(projectId2) {
159483
159564
  urlPrefix = `urn:uuid:${projectId2.toLowerCase()}/`;
159484
159565
  return true;
159485
159566
  }
159486
- function getUrlPrefix() {
159487
- return urlPrefix;
159567
+ function getUrlPrefix(uri) {
159568
+ const match = uri === void 0 ? void 0 : folderPrefixes.find((f) => isInFolder(uri, f.folderUri));
159569
+ return match?.prefix ?? urlPrefix;
159488
159570
  }
159489
159571
  function uuidV5(namespace, name) {
159490
159572
  return v5_default(name, namespace);
@@ -159544,7 +159626,7 @@ var IdRegistry = class {
159544
159626
  declaration.parentId = owner?.symbolId;
159545
159627
  const path = declaration.qualifiedName !== void 0 ? this.qualifiedNameAsWritten(declaration) : owner ? `${this.paths.get(owner)}/${segmentOf(declaration)}` : segmentOf(declaration);
159546
159628
  const namespace = owner ? this.topLevelOf(owner).symbolId : NAMESPACE_URL;
159547
- const key = owner ? path : getUrlPrefix() + encodeURIComponent(path);
159629
+ const key = owner ? path : getUrlPrefix(declaration.uri) + encodeURIComponent(path);
159548
159630
  const groupId = this.uuidOf(namespace, key);
159549
159631
  this.groupKeys.set(groupId, { namespace, key, path });
159550
159632
  this.groupOf.set(declaration, groupId);
@@ -159729,6 +159811,12 @@ var RULE_INDEX_TO_KIND = /* @__PURE__ */ new Map([
159729
159811
  // 343
159730
159812
  [SysMLv2Parser.RULE_requirementDefinition, "requirement def" /* RequirementDef */],
159731
159813
  // 384
159814
+ [SysMLv2Parser.RULE_concernDefinition, "concern def" /* ConcernDef */],
159815
+ // 405
159816
+ [SysMLv2Parser.RULE_concernUsage, "concern" /* ConcernUsage */],
159817
+ // 406
159818
+ [SysMLv2Parser.RULE_framedConcernUsage, "concern" /* ConcernUsage */],
159819
+ // 394
159732
159820
  [SysMLv2Parser.RULE_constraintDefinition, "constraint def" /* ConstraintDef */],
159733
159821
  // 380
159734
159822
  [SysMLv2Parser.RULE_itemDefinition, "item def" /* ItemDef */],
@@ -159801,6 +159889,10 @@ var RULE_INDEX_TO_KIND = /* @__PURE__ */ new Map([
159801
159889
  // 268
159802
159890
  [SysMLv2Parser.RULE_performActionUsage, "perform action" /* PerformActionUsage */],
159803
159891
  // 298
159892
+ // A state's `entry`/`do`/`exit` action (`exit action a : A;`, `exit a;`): the
159893
+ // StatePerformActionUsage production, a PerformActionUsage without `perform`.
159894
+ [SysMLv2Parser.RULE_statePerformActionUsage, "perform action" /* PerformActionUsage */],
159895
+ // 352
159804
159896
  [SysMLv2Parser.RULE_exhibitStateUsage, "exhibit state" /* ExhibitStateUsage */],
159805
159897
  // 359
159806
159898
  [SysMLv2Parser.RULE_transitionUsage, "transition" /* TransitionUsage */],
@@ -159924,8 +160016,10 @@ var TYPE_RECURSE_RULE_INDICES = /* @__PURE__ */ new Set([
159924
160016
  // 210
159925
160017
  SysMLv2Parser.RULE_definition,
159926
160018
  // 192
159927
- SysMLv2Parser.RULE_usage
160019
+ SysMLv2Parser.RULE_usage,
159928
160020
  // 208
160021
+ SysMLv2Parser.RULE_payloadFeatureSpecializationPart
160022
+ // 157
159929
160023
  ]);
159930
160024
  var DOC_RULE_INDICES = /* @__PURE__ */ new Set([
159931
160025
  SysMLv2Parser.RULE_comment,
@@ -160550,8 +160644,9 @@ var SymbolTable = class {
160550
160644
  const shortName = transition || isFlowUsage(kind) && !declaredName ? void 0 : this.extractShortName(ctx2);
160551
160645
  const qualifiedName = anonymous || owner && owner.qualifiedName === void 0 ? void 0 : owner ? `${owner.qualifiedName}::${name}` : name;
160552
160646
  const selectionRange = anonymous ? ctx2.start ? tokenToRange(ctx2.start) : range : this.extractNameRange(ctx2) ?? range;
160553
- const typeNames = isFlowUsage(kind) ? this.extractFlowTypeNames(ctx2) : this.extractTypeNames(ctx2);
160647
+ const typeNames = isFlowUsage(kind) ? this.extractFlowTypeNames(ctx2) : transition ? this.extractTransitionTypeNames(ctx2) : this.extractTypeNames(ctx2);
160554
160648
  const specializationNames = this.extractSpecializationNames(ctx2);
160649
+ const redefinedFeatureTargets = this.extractRedefinedFeatureTargets(ctx2);
160555
160650
  const typeName = typeNames[0];
160556
160651
  const documentation = this.extractDocumentation(ctx2);
160557
160652
  const visibility = this.extractVisibility(ctx2);
@@ -160582,6 +160677,7 @@ var SymbolTable = class {
160582
160677
  typeName,
160583
160678
  typeNames,
160584
160679
  specializationNames,
160680
+ redefinedFeatureTargets: redefinedFeatureTargets.length > 0 ? redefinedFeatureTargets : void 0,
160585
160681
  documentation,
160586
160682
  visibility,
160587
160683
  source: transition?.source,
@@ -160665,6 +160761,25 @@ var SymbolTable = class {
160665
160761
  const typeDeclaration = declaration && (this.findOwnHeaderRule(declaration, SysMLv2Parser.RULE_featureDeclaration) ?? this.findOwnHeaderRule(declaration, SysMLv2Parser.RULE_usageDeclaration));
160666
160762
  return typeDeclaration ? this.extractTypeNames(typeDeclaration) : [];
160667
160763
  }
160764
+ /**
160765
+ * A transition's own typing, then the types of the payload its trigger
160766
+ * accepts (`accept cmd : Command`, `accept Command`; TriggerAction ->
160767
+ * AcceptParameterPart -> PayloadParameter). Read from the parse tree only:
160768
+ * the regex fallback of `extractTypeNames` runs on whitespace-free text, where
160769
+ * the payload type runs into the guard, effect or target that follows it
160770
+ * (`Commandifcmd`, `Commandthenbusy`).
160771
+ */
160772
+ extractTransitionTypeNames(ctx2) {
160773
+ const names = [];
160774
+ this.collectTypeNamesFromTree(ctx2, names, 0);
160775
+ const trigger = this.findOwnHeaderRule(ctx2, SysMLv2Parser.RULE_triggerActionMember);
160776
+ const parameter = trigger && this.findRuleContext(trigger, SysMLv2Parser.RULE_payloadParameter);
160777
+ if (parameter) {
160778
+ const payload = this.findRuleContext(parameter, SysMLv2Parser.RULE_payloadFeature) ?? parameter;
160779
+ this.collectTypeNamesFromTree(payload, names, 0);
160780
+ }
160781
+ return names;
160782
+ }
160668
160783
  /** Find the first descendant of `ctx` with rule `ruleIndex`, in source order. */
160669
160784
  findRuleContext(ctx2, ruleIndex) {
160670
160785
  const matches = [];
@@ -160790,7 +160905,7 @@ var SymbolTable = class {
160790
160905
  */
160791
160906
  anonymousDeclaration(ctx2, kind, transition) {
160792
160907
  if (!isDefinition(kind) && !isUsage(kind)) return void 0;
160793
- if (transition && !(transition.source && transition.target) && this.extractTypeNames(ctx2).length === 0) return void 0;
160908
+ if (transition && !(transition.source && transition.target) && this.extractTransitionTypeNames(ctx2).length === 0) return void 0;
160794
160909
  return this.declarationText(ctx2);
160795
160910
  }
160796
160911
  /**
@@ -160814,15 +160929,28 @@ var SymbolTable = class {
160814
160929
  * such as `#metadata`.
160815
160930
  */
160816
160931
  findOwnHeaderRule(ctx2, ruleIndex) {
160932
+ const matches = [];
160933
+ this.findOwnHeaderRules(ctx2, ruleIndex, matches, true);
160934
+ return matches[0];
160935
+ }
160936
+ findOwnHeaderRules(ctx2, ruleIndex, matches, firstOnly = false) {
160817
160937
  for (let i = 0; i < ctx2.getChildCount(); i++) {
160818
160938
  const child = ctx2.getChild(i);
160819
160939
  if (!(child instanceof ParserRuleContext)) continue;
160820
- if (child.ruleIndex === ruleIndex) return child;
160940
+ if (child.ruleIndex === ruleIndex) {
160941
+ matches.push(child);
160942
+ if (firstOnly) return;
160943
+ continue;
160944
+ }
160821
160945
  if (RULE_INDEX_TO_KIND.has(child.ruleIndex) || BODY_RULE_INDICES.has(child.ruleIndex) || child.ruleIndex === SysMLv2Parser.RULE_valuePart || FLOW_PART_RULE_INDICES.has(child.ruleIndex) || child.ruleIndex === SysMLv2Parser.RULE_ownedCrossMultiplicityMember || this.isPrefixOrExtensionContext(child)) continue;
160822
- const found = this.findOwnHeaderRule(child, ruleIndex);
160823
- if (found) return found;
160946
+ this.findOwnHeaderRules(child, ruleIndex, matches, firstOnly);
160947
+ if (firstOnly && matches.length > 0) return;
160824
160948
  }
160825
- return void 0;
160949
+ }
160950
+ extractRedefinedFeatureTargets(ctx2) {
160951
+ const targets = [];
160952
+ this.findOwnHeaderRules(ctx2, SysMLv2Parser.RULE_ownedRedefinition, targets);
160953
+ return targets.map((target) => target.getText());
160826
160954
  }
160827
160955
  /**
160828
160956
  * A connection, interface or allocation usage's end reference paths, in
@@ -160850,13 +160978,7 @@ var SymbolTable = class {
160850
160978
  const segment = reference.getText().split(/::|\./).pop();
160851
160979
  return segment ? this.unquoteName(segment) : void 0;
160852
160980
  }
160853
- /**
160854
- * An element's declaration as written, without its body: its tokens up to
160855
- * its body or closing `;`, each exactly as written (a quoted name keeps its
160856
- * spaces), with one space wherever the source has whitespace or a comment
160857
- * between two of them (`connect a.p to b.p`, `connection : Conn`).
160858
- */
160859
- declarationText(ctx2) {
160981
+ declarationTokens(ctx2) {
160860
160982
  const tokens = [];
160861
160983
  const visit2 = (node2) => {
160862
160984
  for (let i = 0; i < node2.getChildCount(); i++) {
@@ -160871,6 +160993,16 @@ var SymbolTable = class {
160871
160993
  return false;
160872
160994
  };
160873
160995
  visit2(ctx2);
160996
+ return tokens;
160997
+ }
160998
+ /**
160999
+ * An element's declaration as written, without its body: its tokens up to
161000
+ * its body or closing `;`, each exactly as written (a quoted name keeps its
161001
+ * spaces), with one space wherever the source has whitespace or a comment
161002
+ * between two of them (`connect a.p to b.p`, `connection : Conn`).
161003
+ */
161004
+ declarationText(ctx2) {
161005
+ const tokens = this.declarationTokens(ctx2);
160874
161006
  let text = "";
160875
161007
  tokens.forEach((token, i) => {
160876
161008
  if (i > 0 && token.start > tokens[i - 1].stop + 1) text += " ";
@@ -161011,17 +161143,16 @@ var SymbolTable = class {
161011
161143
  const names = [];
161012
161144
  this.collectTypeNamesFromTree(ctx2, names, 0);
161013
161145
  if (names.length > 0) return names;
161014
- const fullText = ctx2.getText();
161015
- const braceIdx = fullText.indexOf("{");
161016
- let text = braceIdx >= 0 ? fullText.substring(0, braceIdx) : fullText;
161146
+ const { text: declarationText, quotedName } = this.maskedDeclaration(ctx2);
161147
+ let text = declarationText;
161017
161148
  text = text.replace(RE_KEYWORD_TRUNCATE, "");
161018
161149
  const specMatch = text.match(RE_SPEC);
161019
161150
  if (specMatch) {
161020
161151
  const specStr = text.substring(text.indexOf(specMatch[0]) + specMatch[0].indexOf(specMatch[1]));
161021
161152
  for (const part of specStr.split(",")) {
161022
- const qm = part.match(RE_QUOTED_NAME);
161023
- if (qm) {
161024
- names.push(qm[1]);
161153
+ const quoted = quotedName(part);
161154
+ if (quoted !== void 0) {
161155
+ names.push(quoted);
161025
161156
  continue;
161026
161157
  }
161027
161158
  const m2 = part.trim().match(RE_IDENT_START);
@@ -161042,9 +161173,9 @@ var SymbolTable = class {
161042
161173
  const fullMatchIdx = text.indexOf(typingMatch[0]);
161043
161174
  const afterColon = text.substring(fullMatchIdx + 1).trim();
161044
161175
  for (const part of afterColon.split(",")) {
161045
- const qm = part.match(RE_QUOTED_NAME);
161046
- if (qm) {
161047
- names.push(qm[1]);
161176
+ const quoted = quotedName(part);
161177
+ if (quoted !== void 0) {
161178
+ names.push(quoted);
161048
161179
  continue;
161049
161180
  }
161050
161181
  const m2 = part.trim().match(RE_IDENT_START);
@@ -161054,6 +161185,28 @@ var SymbolTable = class {
161054
161185
  }
161055
161186
  return names;
161056
161187
  }
161188
+ /**
161189
+ * The declaration tokens before the body, with each lexer STRING token
161190
+ * replaced by a numbered placeholder (`'0'`, `'1'`, ...), and
161191
+ * `quotedName`, which turns a placeholder in a part of that text back into
161192
+ * the name. SysML 2.0 section 7.2.2 permits punctuation in unrestricted
161193
+ * names (the STRING lexer production), so fallback regexes must never see
161194
+ * their `:`, `:>`, `{` or keywords. Documentation is not a name token.
161195
+ */
161196
+ maskedDeclaration(ctx2) {
161197
+ const quoted = [];
161198
+ const masked = this.declarationTokens(ctx2).map((token) => {
161199
+ const text = token.text ?? "";
161200
+ return token.type === SysMLv2Lexer.STRING ? `'${quoted.push(text.slice(1, -1)) - 1}'` : text;
161201
+ }).join("");
161202
+ return {
161203
+ text: masked,
161204
+ quotedName: (part) => {
161205
+ const qm = part.match(RE_QUOTED_NAME);
161206
+ return qm ? quoted[Number(qm[1])] : void 0;
161207
+ }
161208
+ };
161209
+ }
161057
161210
  /**
161058
161211
  * Extract only the specialization names (:> / specializes / subsets) from a context.
161059
161212
  * Uses the same tree-walk as extractTypeNames but restricted to
@@ -161064,17 +161217,15 @@ var SymbolTable = class {
161064
161217
  const names = [];
161065
161218
  this.collectNamesFromTree(ctx2, names, 0, TYPE_SPECIALIZATION_RULE_INDICES);
161066
161219
  if (names.length > 0) return names;
161067
- const fullText = ctx2.getText();
161068
- const braceIdx = fullText.indexOf("{");
161069
- let text = braceIdx >= 0 ? fullText.substring(0, braceIdx) : fullText;
161070
- text = text.replace(RE_KEYWORD_TRUNCATE_SPEC, "");
161220
+ const { text: declarationText, quotedName } = this.maskedDeclaration(ctx2);
161221
+ const text = declarationText.replace(RE_KEYWORD_TRUNCATE_SPEC, "");
161071
161222
  const specMatch = text.match(RE_SPEC_WITH_SUBSETS);
161072
161223
  if (specMatch) {
161073
161224
  const specStr = text.substring(text.indexOf(specMatch[0]) + specMatch[0].indexOf(specMatch[1]));
161074
161225
  for (const part of specStr.split(",")) {
161075
- const qm = part.match(RE_QUOTED_NAME);
161076
- if (qm) {
161077
- names.push(qm[1]);
161226
+ const quoted = quotedName(part);
161227
+ if (quoted !== void 0) {
161228
+ names.push(quoted);
161078
161229
  continue;
161079
161230
  }
161080
161231
  const m2 = part.trim().match(RE_IDENT_START);
@@ -163253,6 +163404,13 @@ var CONSTRAINT_KEYWORDS = /* @__PURE__ */ new Set([
163253
163404
  "assert",
163254
163405
  "assume"
163255
163406
  ]);
163407
+ var CONNECTOR_KINDS = /* @__PURE__ */ new Set([
163408
+ "connection" /* ConnectionUsage */,
163409
+ "interface" /* InterfaceUsage */,
163410
+ "allocation" /* AllocationUsage */,
163411
+ "flow" /* FlowUsage */,
163412
+ "succession flow" /* SuccessionFlowUsage */
163413
+ ]);
163256
163414
  var SemanticValidator = class _SemanticValidator {
163257
163415
  constructor(documentManager) {
163258
163416
  this.documentManager = documentManager;
@@ -163329,7 +163487,7 @@ var SemanticValidator = class _SemanticValidator {
163329
163487
  diagnostics.push(...this.checkAmbiguousNamespaceName(symbols, allSymbols));
163330
163488
  diagnostics.push(...this.checkUnusedDefinitions(allSymbols, uri));
163331
163489
  diagnostics.push(...this.checkRedefinitionMultiplicity(symbols, indexes, text));
163332
- diagnostics.push(...this.checkPortCompatibility(text, uri, indexes));
163490
+ diagnostics.push(...this.checkPortCompatibility(text, uri, symbols, indexes));
163333
163491
  diagnostics.push(...this.checkConstraintBodyReferences(text, uri, symbols, indexes));
163334
163492
  diagnostics.push(...this.checkCircularSpecialization(symbols, indexes));
163335
163493
  diagnostics.push(...this.checkUnsatisfiedRequirements(symbols, indexes));
@@ -163550,7 +163708,7 @@ var SemanticValidator = class _SemanticValidator {
163550
163708
  opts?.text ? [opts.text] : []
163551
163709
  ));
163552
163710
  if (opts?.text && opts.uri) {
163553
- diagnostics.push(...instance.checkPortCompatibility(opts.text, opts.uri, indexes));
163711
+ diagnostics.push(...instance.checkPortCompatibility(opts.text, opts.uri, symbolsInUri, indexes));
163554
163712
  diagnostics.push(...instance.checkConstraintBodyReferences(opts.text, opts.uri, symbolsInUri, indexes));
163555
163713
  }
163556
163714
  return instance.dedupeDiagnostics(diagnostics);
@@ -163913,17 +164071,20 @@ var SemanticValidator = class _SemanticValidator {
163913
164071
  * - The connection is within an interface usage
163914
164072
  * - Both ports are untyped (empty port defs with no features)
163915
164073
  */
163916
- checkPortCompatibility(text, uri, indexes) {
164074
+ checkPortCompatibility(text, uri, symbolsInUri, indexes) {
163917
164075
  if (!text) return [];
163918
164076
  const diagnostics = [];
163919
164077
  const lines = text.split("\n");
163920
164078
  const re = /\bconnect\s+([A-Za-z_][\w.]*)\s+to\s+([A-Za-z_][\w.]*)/g;
163921
164079
  let m2;
163922
164080
  while ((m2 = re.exec(text)) !== null) {
163923
- const left = m2[1].split(".").pop();
163924
- const right = m2[2].split(".").pop();
163925
- const lSym = (indexes.portsByName.get(left) ?? [])[0];
163926
- const rSym = (indexes.portsByName.get(right) ?? [])[0];
164081
+ const leftPath = m2[1].split(".");
164082
+ const rightPath = m2[2].split(".");
164083
+ const left = leftPath[leftPath.length - 1];
164084
+ const right = rightPath[rightPath.length - 1];
164085
+ const scope = this.connectorScope(symbolsInUri, this.indexToRange(text, m2.index, 0).start, indexes);
164086
+ const lSym = this.resolveConnectorEnd(leftPath, scope, indexes);
164087
+ const rSym = this.resolveConnectorEnd(rightPath, scope, indexes);
163927
164088
  if (!lSym || !rSym) continue;
163928
164089
  const lType = lSym.typeNames[0] ?? lSym.typeName;
163929
164090
  const rType = rSym.typeNames[0] ?? rSym.typeName;
@@ -163973,6 +164134,55 @@ var SemanticValidator = class _SemanticValidator {
163973
164134
  }
163974
164135
  return diagnostics;
163975
164136
  }
164137
+ /**
164138
+ * The innermost element around `position` that owns a connector declared
164139
+ * there: the connector's own symbol, when it has one, is skipped.
164140
+ */
164141
+ connectorScope(symbols, position, indexes) {
164142
+ const before = (a, b) => a.line < b.line || a.line === b.line && a.character <= b.character;
164143
+ const size = (r) => (r.end.line - r.start.line) * 1e6 + (r.end.character - r.start.character);
164144
+ let scope;
164145
+ for (const s of symbols) {
164146
+ if (!before(s.range.start, position) || !before(position, s.range.end)) continue;
164147
+ if (!scope || size(s.range) < size(scope.range)) scope = s;
164148
+ }
164149
+ while (scope && CONNECTOR_KINDS.has(scope.kind)) scope = ownerOf2(scope, indexes);
164150
+ return scope;
164151
+ }
164152
+ /**
164153
+ * The port that a connector end (`a.p`, `a.p.q`) names, resolved from
164154
+ * `scope` outward: its first segment is a feature of `scope` or of one of
164155
+ * its owners, each next one a feature of the one before. Two parts can each
164156
+ * have a port of the same name, so an end is never matched by its last
164157
+ * segment alone, except when the path does not resolve and the workspace
164158
+ * has only one port of that name.
164159
+ */
164160
+ resolveConnectorEnd(path, scope, indexes) {
164161
+ let feature;
164162
+ for (let namespace = scope; namespace && !feature; namespace = ownerOf2(namespace, indexes)) {
164163
+ feature = this.findFeature(namespace, path[0], indexes);
164164
+ }
164165
+ for (const name of path.slice(1)) {
164166
+ feature = feature && this.findFeature(feature, name, indexes);
164167
+ }
164168
+ if (feature) return feature.kind === "port" /* PortUsage */ ? feature : void 0;
164169
+ const sameName = indexes.portsByName.get(path[path.length - 1]) ?? [];
164170
+ return sameName.length === 1 ? sameName[0] : void 0;
164171
+ }
164172
+ /** The feature `name` of `owner`: its own member, else a member of one of its types or their supertypes. */
164173
+ findFeature(owner, name, indexes) {
164174
+ const own2 = (indexes.byParent.get(namespaceKeyOf(owner)) ?? []).find((s) => s.name === name);
164175
+ if (own2) return own2;
164176
+ for (const typeName of owner.typeNames) {
164177
+ const type = this.namespaceResolver.resolveNameFrom(owner, typeName, indexes);
164178
+ if (!type || !isDefinition(type.kind)) continue;
164179
+ for (const definition of this.getSpecializationHierarchy(type, indexes).flat()) {
164180
+ const member = (indexes.byParent.get(namespaceKeyOf(definition)) ?? []).find((s) => s.name === name);
164181
+ if (member) return member;
164182
+ }
164183
+ }
164184
+ return void 0;
164185
+ }
163976
164186
  /**
163977
164187
  * Resolve the full type hierarchy for a type name by following
163978
164188
  * specialization chains transitively (max depth 10).
@@ -164020,7 +164230,7 @@ var SemanticValidator = class _SemanticValidator {
164020
164230
  }
164021
164231
  const parent = this.findConstraintScopeSymbol(symbolsInUri, indexes, b.startLine);
164022
164232
  if (!parent) continue;
164023
- const parentMembers = indexes.byParent.get(namespaceKeyOf(parent)) ?? [];
164233
+ const parentMembers = this.getConstraintScopeMembers(parent, indexes);
164024
164234
  if (parentMembers.length === 0) continue;
164025
164235
  const ignoredRanges = this.getIgnoredBodyRanges(b.body);
164026
164236
  const idRe = /\b([A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*)*)\b/g;
@@ -164079,18 +164289,135 @@ var SemanticValidator = class _SemanticValidator {
164079
164289
  const root = parentMembers.find((s) => s.name === path[0]);
164080
164290
  if (!root) return false;
164081
164291
  if (path.length === 1) return true;
164082
- let typeName = root.typeNames[0] ?? root.typeName;
164292
+ let current = root;
164083
164293
  for (let i = 1; i < path.length; i++) {
164294
+ const typeName = current.typeNames[0] ?? current.typeName;
164084
164295
  if (!typeName) return false;
164085
- const typeDefs = indexes.definitionsByName.get(typeName) ?? [];
164086
- const typeDef = typeDefs[0];
164087
- if (!typeDef) return false;
164088
- const member = (indexes.byParent.get(namespaceKeyOf(typeDef)) ?? []).find((s) => s.name === path[i]);
164296
+ const typeDef = this.namespaceResolver.resolveNameFrom(current, typeName, indexes);
164297
+ if (!typeDef || !isDefinition(typeDef.kind)) return false;
164298
+ const member = this.getConstraintScopeMembers(typeDef, indexes, true).find((s) => s.name === path[i]);
164089
164299
  if (!member) return false;
164090
- typeName = member.typeNames[0] ?? member.typeName;
164300
+ current = member;
164091
164301
  }
164092
164302
  return true;
164093
164303
  }
164304
+ getConstraintScopeMembers(scope, indexes, publicOnly = false) {
164305
+ const hierarchy = [[scope]];
164306
+ const visited = /* @__PURE__ */ new Set([scope]);
164307
+ let frontier = [scope];
164308
+ while (frontier.length > 0) {
164309
+ const next = [];
164310
+ for (const current of frontier) {
164311
+ for (const typeName of current.typeNames) {
164312
+ const supertype = this.namespaceResolver.resolveNameFrom(current, typeName, indexes);
164313
+ if (!supertype || !isDefinition(supertype.kind) || visited.has(supertype)) continue;
164314
+ visited.add(supertype);
164315
+ next.push(supertype);
164316
+ }
164317
+ }
164318
+ if (next.length > 0) hierarchy.push(next);
164319
+ frontier = next;
164320
+ }
164321
+ const membersByLevel = hierarchy.map((level) => level.flatMap((namespace) => indexes.byParent.get(namespaceKeyOf(namespace)) ?? []));
164322
+ const hiddenMembers = /* @__PURE__ */ new Set();
164323
+ for (let level = membersByLevel.length - 1; level >= 0; level--) {
164324
+ for (const redefining of membersByLevel[level]) {
164325
+ for (const target of redefining.redefinedFeatureTargets ?? []) {
164326
+ const owner = ownerOf2(redefining, indexes);
164327
+ if (!owner) continue;
164328
+ for (const candidate of this.resolveInheritedRedefinitionTarget(owner, target, hiddenMembers, indexes)) {
164329
+ hiddenMembers.add(candidate.symbolId);
164330
+ }
164331
+ }
164332
+ if (redefining.kind === "subject" /* SubjectUsage */) {
164333
+ const owner = ownerOf2(redefining, indexes);
164334
+ if (!owner) continue;
164335
+ for (const ancestor of this.getSpecializationHierarchy(owner, indexes).slice(1).flat()) {
164336
+ for (const candidate of indexes.byParent.get(namespaceKeyOf(ancestor)) ?? []) {
164337
+ if (candidate.kind === "subject" /* SubjectUsage */) hiddenMembers.add(candidate.symbolId);
164338
+ }
164339
+ }
164340
+ }
164341
+ }
164342
+ }
164343
+ const membersByName = /* @__PURE__ */ new Map();
164344
+ for (let level = 0; level < membersByLevel.length; level++) {
164345
+ for (const member of membersByLevel[level]) {
164346
+ if (level > 0 && member.visibility === "private") continue;
164347
+ if (publicOnly && member.visibility !== void 0 && member.visibility !== "public") continue;
164348
+ if (hiddenMembers.has(member.symbolId) || membersByName.has(member.name)) continue;
164349
+ membersByName.set(member.name, member);
164350
+ }
164351
+ }
164352
+ return [...membersByName.values()];
164353
+ }
164354
+ resolveInheritedRedefinitionTarget(owner, target, alreadyRedefined, indexes) {
164355
+ if (target.includes(".")) return [];
164356
+ const segments = target.split("::");
164357
+ const targetName = segments.pop()?.replace(/^'|'$/g, "");
164358
+ if (!targetName) return [];
164359
+ const qualifier = segments.join("::").replace(/^'|'$/g, "");
164360
+ const matches = /* @__PURE__ */ new Map();
164361
+ for (const supertype of this.resolveDirectSupertypes(owner, indexes)) {
164362
+ const branch = this.getSpecializationHierarchy(supertype, indexes);
164363
+ const anchors = qualifier ? branch.flat().filter((type) => this.matchesSpecializationQualifier(type, qualifier)) : [supertype];
164364
+ for (const anchor2 of anchors) {
164365
+ let frontier = [anchor2];
164366
+ const visited = new Set(frontier);
164367
+ const candidates = [];
164368
+ while (frontier.length > 0 && candidates.length === 0) {
164369
+ for (const type of frontier) {
164370
+ for (const member of indexes.byParent.get(namespaceKeyOf(type)) ?? []) {
164371
+ if (member.name === targetName && member.visibility !== "private" && !alreadyRedefined.has(member.symbolId)) {
164372
+ candidates.push(member);
164373
+ }
164374
+ }
164375
+ }
164376
+ if (candidates.length > 0) break;
164377
+ const next = /* @__PURE__ */ new Map();
164378
+ for (const type of frontier) {
164379
+ for (const parent of this.resolveDirectSupertypes(type, indexes)) {
164380
+ if (visited.has(parent)) continue;
164381
+ visited.add(parent);
164382
+ next.set(parent.symbolId, parent);
164383
+ }
164384
+ }
164385
+ frontier = [...next.values()];
164386
+ }
164387
+ for (const candidate of candidates) matches.set(candidate.symbolId, candidate);
164388
+ }
164389
+ }
164390
+ return matches.size === 1 ? [...matches.values()] : [];
164391
+ }
164392
+ resolveDirectSupertypes(scope, indexes) {
164393
+ const supertypes = /* @__PURE__ */ new Map();
164394
+ for (const typeName of scope.typeNames) {
164395
+ const supertype = this.namespaceResolver.resolveNameFrom(scope, typeName, indexes);
164396
+ if (supertype && isDefinition(supertype.kind)) supertypes.set(supertype.symbolId, supertype);
164397
+ }
164398
+ return [...supertypes.values()];
164399
+ }
164400
+ getSpecializationHierarchy(scope, indexes) {
164401
+ const levels = [[scope]];
164402
+ const visited = /* @__PURE__ */ new Set([scope]);
164403
+ let frontier = [scope];
164404
+ while (frontier.length > 0) {
164405
+ const next = [];
164406
+ for (const type of frontier) {
164407
+ for (const parent of this.resolveDirectSupertypes(type, indexes)) {
164408
+ if (visited.has(parent)) continue;
164409
+ visited.add(parent);
164410
+ next.push(parent);
164411
+ }
164412
+ }
164413
+ if (next.length > 0) levels.push(next);
164414
+ frontier = next;
164415
+ }
164416
+ return levels;
164417
+ }
164418
+ matchesSpecializationQualifier(type, qualifier) {
164419
+ return type.name === qualifier || type.qualifiedName === qualifier || type.qualifiedName?.endsWith(`::${qualifier}`) === true;
164420
+ }
164094
164421
  findContainingSymbolByLine(symbols, line) {
164095
164422
  return symbols.filter((s) => s.range.start.line <= line && s.range.end.line >= line).sort((a, b) => {
164096
164423
  const ar = (a.range.end.line - a.range.start.line) * 1e3 + (a.range.end.character - a.range.start.character);
@@ -164101,7 +164428,7 @@ var SemanticValidator = class _SemanticValidator {
164101
164428
  findConstraintScopeSymbol(symbolsInUri, indexes, line) {
164102
164429
  let scope = this.findContainingSymbolByLine(symbolsInUri, line);
164103
164430
  while (scope) {
164104
- const members2 = indexes.byParent.get(namespaceKeyOf(scope)) ?? [];
164431
+ const members2 = this.getConstraintScopeMembers(scope, indexes);
164105
164432
  if (members2.length > 0) return scope;
164106
164433
  if (!scope.parentId) return scope;
164107
164434
  scope = ownerOf2(scope, indexes);