sysml-diagram 0.31.0 → 0.31.2

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/out/main.js CHANGED
@@ -162534,6 +162534,26 @@ function isPublic(node) {
162534
162534
  return true;
162535
162535
  }
162536
162536
  var SPECIALIZATION_KINDS = /* @__PURE__ */ new Set([":>", ":>>", "specializes", "subsets", "redefines"]);
162537
+ var inheritanceByNode = /* @__PURE__ */ new WeakMap();
162538
+ function inheritanceSyntax(node) {
162539
+ const cached = inheritanceByNode.get(node);
162540
+ if (cached)
162541
+ return cached;
162542
+ const shape = node;
162543
+ const relationships = [...shape.preRelationships ?? [], ...shape.relationships ?? []].filter((relation) => relation.kind && SPECIALIZATION_KINDS.has(relation.kind));
162544
+ const implicitVariant = implicitVariantSpecialization(node)?.target;
162545
+ const externalVariant = !!externalVariantPath(node);
162546
+ const enumUsage = node.$type === "EnumDecl" && shape.isDef !== true;
162547
+ const result = {
162548
+ relationships,
162549
+ implicitVariant,
162550
+ externalVariant,
162551
+ enumUsage,
162552
+ hasSources: !!shape.typing || relationships.length > 0 || !!implicitVariant || externalVariant || enumUsage
162553
+ };
162554
+ inheritanceByNode.set(node, result);
162555
+ return result;
162556
+ }
162537
162557
  function nameOf(node) {
162538
162558
  if (node) {
162539
162559
  const external = externalVariantName(node);
@@ -162690,6 +162710,11 @@ var FeaturePathResolver = class {
162690
162710
  linker;
162691
162711
  scopeProvider;
162692
162712
  snapshots = /* @__PURE__ */ new WeakMap();
162713
+ indexedSnapshot;
162714
+ // REQ-361 - Inheritance walks memoized against the snapshot they were read
162715
+ // from; a new snapshot answers fresh. Keyed weakly, so a re-parsed document
162716
+ // drops its entries with its nodes.
162717
+ owners = /* @__PURE__ */ new WeakMap();
162693
162718
  propertySegments = /* @__PURE__ */ new WeakMap();
162694
162719
  resolvingSpecializations = /* @__PURE__ */ new Set();
162695
162720
  enumerationPathDepth = 0;
@@ -162700,9 +162725,12 @@ var FeaturePathResolver = class {
162700
162725
  this.locator = services?.workspace.AstNodeLocator;
162701
162726
  this.linker = services?.references.Linker;
162702
162727
  this.scopeProvider = services?.references.ScopeProvider;
162703
- services?.shared.workspace.DocumentBuilder.onBuildPhase(DocumentState.IndexedContent, () => {
162704
- this.snapshots = /* @__PURE__ */ new WeakMap();
162705
- });
162728
+ services?.shared.workspace.DocumentBuilder.onBuildPhase(DocumentState.IndexedContent, () => this.dropSnapshots());
162729
+ services?.shared.workspace.DocumentBuilder.onUpdate(() => this.dropSnapshots());
162730
+ }
162731
+ dropSnapshots() {
162732
+ this.snapshots = /* @__PURE__ */ new WeakMap();
162733
+ this.indexedSnapshot = void 0;
162706
162734
  }
162707
162735
  // REQ-220/317 — resolve every independently clickable/diagnosable segment.
162708
162736
  resolve(node) {
@@ -163167,7 +163195,22 @@ var FeaturePathResolver = class {
163167
163195
  }
163168
163196
  return {};
163169
163197
  }
163198
+ // REQ-361 - The inheritance walk is the hot path of every written-path
163199
+ // resolution, and a document resolves the same owners over and over: once per
163200
+ // path that mentions them, and again for every reference tally a CodeLens
163201
+ // pass asks for. The answer only changes with the syntax (fixed for a parse)
163202
+ // and the index generation, so it is memoized against the snapshot that
163203
+ // produced it. A walk that ran INSIDE a specialization cycle sees the cycle
163204
+ // guard's empty answer, so only a top-level walk is cached.
163170
163205
  typedAndSpecializedOwners(node, snapshot) {
163206
+ const syntax = inheritanceSyntax(node);
163207
+ if (!syntax.hasSources)
163208
+ return [];
163209
+ const cacheable = this.resolvingSpecializations.size === 0;
163210
+ const depthZero = this.enumerationPathDepth === 0;
163211
+ const cached = this.owners.get(node);
163212
+ if (cached && cached.snapshot === snapshot && cached.depthZero === depthZero)
163213
+ return cached.owners;
163171
163214
  const result = [];
163172
163215
  const seen = /* @__PURE__ */ new Set();
163173
163216
  const visit = (candidate) => {
@@ -163175,15 +163218,20 @@ var FeaturePathResolver = class {
163175
163218
  return;
163176
163219
  seen.add(candidate);
163177
163220
  result.push(candidate);
163178
- visit(this.externalVariantTarget(candidate));
163179
- visit(implicitVariantSpecialization(candidate)?.target);
163221
+ const inheritedSyntax = inheritanceSyntax(candidate);
163222
+ if (!inheritedSyntax.hasSources)
163223
+ return;
163224
+ if (inheritedSyntax.externalVariant)
163225
+ visit(this.externalVariantTarget(candidate));
163226
+ visit(inheritedSyntax.implicitVariant);
163180
163227
  visit(this.inferredEnumerationTarget(candidate));
163181
163228
  visit(this.isEnumUsage(candidate) ? this.enumerationTypingTarget(candidate) : this.typingTarget(candidate, snapshot));
163182
163229
  for (const specialized of this.specializationTargets(candidate, snapshot))
163183
163230
  visit(specialized);
163184
163231
  };
163185
- visit(this.externalVariantTarget(node));
163186
- visit(implicitVariantSpecialization(node)?.target);
163232
+ if (syntax.externalVariant)
163233
+ visit(this.externalVariantTarget(node));
163234
+ visit(syntax.implicitVariant);
163187
163235
  visit(this.inferredEnumerationTarget(node));
163188
163236
  const enumNode = node;
163189
163237
  if (this.enumerationPathDepth === 0 && enumNode.$type === "EnumDecl" && enumNode.isDef !== true && enumNode.value?.$type === "PathExpr" && isEnumerationUsage(enumNode)) {
@@ -163193,6 +163241,8 @@ var FeaturePathResolver = class {
163193
163241
  visit(this.isEnumUsage(node) ? this.enumerationTypingTarget(node) : this.typingTarget(node, snapshot));
163194
163242
  for (const specialized of this.specializationTargets(node, snapshot))
163195
163243
  visit(specialized);
163244
+ if (cacheable)
163245
+ this.owners.set(node, { snapshot, depthZero, owners: result });
163196
163246
  return result;
163197
163247
  }
163198
163248
  inferredEnumerationTarget(node) {
@@ -163253,15 +163303,13 @@ var FeaturePathResolver = class {
163253
163303
  return typed;
163254
163304
  }
163255
163305
  specializationTargets(node, snapshot) {
163256
- if (this.resolvingSpecializations.has(node))
163306
+ const { relationships } = inheritanceSyntax(node);
163307
+ if (relationships.length === 0 || this.resolvingSpecializations.has(node))
163257
163308
  return [];
163258
163309
  this.resolvingSpecializations.add(node);
163259
- const relNode = node;
163260
163310
  const result = [];
163261
163311
  try {
163262
- for (const relation of [...relNode.preRelationships ?? [], ...relNode.relationships ?? []]) {
163263
- if (!relation.kind || !SPECIALIZATION_KINDS.has(relation.kind))
163264
- continue;
163312
+ for (const relation of relationships) {
163265
163313
  for (const [index2, target] of (relation.targets ?? []).entries()) {
163266
163314
  const simple = simpleRelationName(target);
163267
163315
  const scoped = simple ? this.scopedSpecializationTarget(node, simple, snapshot) : void 0;
@@ -163353,8 +163401,9 @@ var FeaturePathResolver = class {
163353
163401
  segment.target = target.node;
163354
163402
  segment.description = target.description;
163355
163403
  }
163404
+ // REQ-361/410 - One indexed workspace snapshot, or one per parse-only root.
163356
163405
  snapshot(root4) {
163357
- const cached = this.snapshots.get(root4);
163406
+ const cached = this.indexManager ? this.indexedSnapshot : this.snapshots.get(root4);
163358
163407
  if (cached)
163359
163408
  return cached;
163360
163409
  const byName = /* @__PURE__ */ new Map();
@@ -163386,7 +163435,10 @@ var FeaturePathResolver = class {
163386
163435
  }
163387
163436
  }
163388
163437
  const snapshot = { byName };
163389
- this.snapshots.set(root4, snapshot);
163438
+ if (this.indexManager)
163439
+ this.indexedSnapshot = snapshot;
163440
+ else
163441
+ this.snapshots.set(root4, snapshot);
163390
163442
  return snapshot;
163391
163443
  }
163392
163444
  };
@@ -167203,7 +167255,7 @@ var SysmlDiagramModelProvider = class _SysmlDiagramModelProvider {
167203
167255
  multiplicity: this.multText(n2),
167204
167256
  type: typeText(n2) ?? (usageDefinitions.get(n2) ? nameOf2(usageDefinitions.get(n2)) : void 0),
167205
167257
  ...attributeUsages.has(n2) ? { value: attributeValue(n2) } : {},
167206
- compartments: this.compartmentsFor(n2, uri, index2, shape === "box"),
167258
+ compartments: extra?.compartments ?? this.compartmentsFor(n2, uri, index2, shape === "box"),
167207
167259
  ...packageOf2(n2),
167208
167260
  source: sourceOf2(n2, uri),
167209
167261
  ...extra
@@ -185796,10 +185848,26 @@ var SysmlCodeLensProvider = class {
185796
185848
  constructor(services) {
185797
185849
  this.services = services;
185798
185850
  }
185799
- // TSK_023 — A "N references" lens above a definition (find-references on click).
185800
- referencesLens(node, uri, range) {
185851
+ // TSK_023 — Every reference tally this pass needs, from one workspace sweep.
185852
+ // A sweep resolves every written path in every document, so one per lens made
185853
+ // a file with a dozen requirement definitions take seconds and the lenses
185854
+ // never reached the editor.
185855
+ referenceCounts(root4) {
185856
+ const targets = [];
185857
+ walkAst(root4, (node) => {
185858
+ if (isRequirementDecl(node) && node.isDef && node.name)
185859
+ targets.push(node);
185860
+ if (isVerificationCaseDecl(node) && node.isDef && node.name)
185861
+ targets.push(node);
185862
+ });
185801
185863
  const refProvider = this.services.lsp.ReferencesProvider;
185802
- const count = typeof refProvider?.referenceCount === "function" ? refProvider.referenceCount(node) : 0;
185864
+ if (typeof refProvider?.referenceCounts !== "function")
185865
+ return /* @__PURE__ */ new Map();
185866
+ return refProvider.referenceCounts(targets);
185867
+ }
185868
+ // TSK_023 — A "N references" lens above a definition (find-references on click).
185869
+ referencesLens(node, uri, range, counts) {
185870
+ const count = counts.get(node) ?? 0;
185803
185871
  return {
185804
185872
  range,
185805
185873
  command: {
@@ -185818,6 +185886,7 @@ var SysmlCodeLensProvider = class {
185818
185886
  const uri = document2.uri.toString();
185819
185887
  const requirements = indexByName(root4, "RequirementDecl");
185820
185888
  const parts = indexByName(root4, "PartDecl");
185889
+ const counts = this.referenceCounts(root4);
185821
185890
  walkAst(root4, (node) => {
185822
185891
  const cst = node.$cstNode;
185823
185892
  if (!cst)
@@ -185851,7 +185920,7 @@ var SysmlCodeLensProvider = class {
185851
185920
  });
185852
185921
  }
185853
185922
  if (isRequirementDecl(node) && node.isDef && node.name) {
185854
- lenses.push(this.referencesLens(node, uri, range));
185923
+ lenses.push(this.referencesLens(node, uri, range, counts));
185855
185924
  }
185856
185925
  if (isVerificationCaseDecl(node) && node.isDef && node.name) {
185857
185926
  const result = evaluateVerificationCase(node, (name) => requirements.get(name), (name) => parts.get(name));
@@ -185871,7 +185940,7 @@ var SysmlCodeLensProvider = class {
185871
185940
  arguments: [uri, node.name]
185872
185941
  }
185873
185942
  });
185874
- lenses.push(this.referencesLens(node, uri, range));
185943
+ lenses.push(this.referencesLens(node, uri, range, counts));
185875
185944
  }
185876
185945
  });
185877
185946
  return lenses;
@@ -186087,6 +186156,14 @@ var SysmlReferencesProvider = class extends DefaultReferencesProvider {
186087
186156
  referenceCount(target) {
186088
186157
  return this.references.findReferences(target, { includeDeclaration: false }).count();
186089
186158
  }
186159
+ // TSK_023 - One sweep answers every tally a CodeLens pass needs. Counting them
186160
+ // one at a time repeats the whole written-path scan per lens.
186161
+ referenceCounts(targets) {
186162
+ const references = this.references;
186163
+ if (typeof references?.referenceCounts === "function")
186164
+ return references.referenceCounts(targets);
186165
+ return new Map(targets.map((target) => [target, this.referenceCount(target)]));
186166
+ }
186090
186167
  };
186091
186168
 
186092
186169
  // ../language-server/out/src/services/written-path-references.js
@@ -186102,6 +186179,53 @@ var WrittenPathReferences = class extends DefaultReferences {
186102
186179
  const segment = this.paths.segmentAt(source);
186103
186180
  return segment ? segment.target : super.findDeclaration(source);
186104
186181
  }
186182
+ /**
186183
+ * TSK_023 - How many references each target has, in ONE workspace sweep.
186184
+ *
186185
+ * `findReferences` resolves every written path in every document, so asking
186186
+ * it per target multiplies that sweep by the number of targets. A CodeLens
186187
+ * pass over a file with a dozen requirement definitions paid it a dozen
186188
+ * times and took seconds, which reads in the editor as lenses that never
186189
+ * appear. The tally below answers all of them from a single sweep.
186190
+ */
186191
+ referenceCounts(targets) {
186192
+ const counts = new Map(targets.map((target) => [target, 0]));
186193
+ if (targets.length === 0)
186194
+ return counts;
186195
+ const seen = new Map(targets.map((target) => [target, /* @__PURE__ */ new Set()]));
186196
+ const byIdentity = /* @__PURE__ */ new Map();
186197
+ for (const target of targets) {
186198
+ const targetUri = ast_utils_exports.getDocument(target).uri.toString();
186199
+ byIdentity.set(`${targetUri}|${this.nodeLocator.getAstNodePath(target)}`, target);
186200
+ const found = seen.get(target);
186201
+ for (const reference of super.findReferences(target, { includeDeclaration: false })) {
186202
+ const key2 = `${reference.sourceUri}|${reference.segment.offset}`;
186203
+ if (found.has(key2))
186204
+ continue;
186205
+ found.add(key2);
186206
+ counts.set(target, (counts.get(target) ?? 0) + 1);
186207
+ }
186208
+ }
186209
+ for (const document2 of this.documents.all) {
186210
+ for (const node of ast_utils_exports.streamAllContents(document2.parseResult.value)) {
186211
+ for (const path10 of this.paths.writtenPaths(node)) {
186212
+ for (const segment of path10.segments) {
186213
+ const description = segment.description;
186214
+ const target = segment.target && counts.has(segment.target) ? segment.target : description ? byIdentity.get(`${description.documentUri.toString()}|${description.path}`) : void 0;
186215
+ if (!target)
186216
+ continue;
186217
+ const found = seen.get(target);
186218
+ const key2 = `${document2.uri}|${segment.cst.offset}`;
186219
+ if (found.has(key2))
186220
+ continue;
186221
+ found.add(key2);
186222
+ counts.set(target, (counts.get(target) ?? 0) + 1);
186223
+ }
186224
+ }
186225
+ }
186226
+ }
186227
+ return counts;
186228
+ }
186105
186229
  findReferences(target, options) {
186106
186230
  const result = super.findReferences(target, options).toArray();
186107
186231
  const targetUri = ast_utils_exports.getDocument(target).uri;
@@ -209598,7 +209722,7 @@ async function runExport(command) {
209598
209722
  }
209599
209723
 
209600
209724
  // src/main.ts
209601
- var VERSION2 = true ? "0.31.0" : "dev";
209725
+ var VERSION2 = true ? "0.31.2" : "dev";
209602
209726
  function display(file) {
209603
209727
  const rel2 = path9.relative(process.cwd(), file);
209604
209728
  return rel2 && !rel2.startsWith("..") ? rel2.split(path9.sep).join("/") : file;