sysml-diagram 0.31.1 → 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
@@ -162710,6 +162710,11 @@ var FeaturePathResolver = class {
162710
162710
  linker;
162711
162711
  scopeProvider;
162712
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();
162713
162718
  propertySegments = /* @__PURE__ */ new WeakMap();
162714
162719
  resolvingSpecializations = /* @__PURE__ */ new Set();
162715
162720
  enumerationPathDepth = 0;
@@ -162720,9 +162725,12 @@ var FeaturePathResolver = class {
162720
162725
  this.locator = services?.workspace.AstNodeLocator;
162721
162726
  this.linker = services?.references.Linker;
162722
162727
  this.scopeProvider = services?.references.ScopeProvider;
162723
- services?.shared.workspace.DocumentBuilder.onBuildPhase(DocumentState.IndexedContent, () => {
162724
- this.snapshots = /* @__PURE__ */ new WeakMap();
162725
- });
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;
162726
162734
  }
162727
162735
  // REQ-220/317 — resolve every independently clickable/diagnosable segment.
162728
162736
  resolve(node) {
@@ -163187,10 +163195,22 @@ var FeaturePathResolver = class {
163187
163195
  }
163188
163196
  return {};
163189
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.
163190
163205
  typedAndSpecializedOwners(node, snapshot) {
163191
163206
  const syntax = inheritanceSyntax(node);
163192
163207
  if (!syntax.hasSources)
163193
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;
163194
163214
  const result = [];
163195
163215
  const seen = /* @__PURE__ */ new Set();
163196
163216
  const visit = (candidate) => {
@@ -163221,6 +163241,8 @@ var FeaturePathResolver = class {
163221
163241
  visit(this.isEnumUsage(node) ? this.enumerationTypingTarget(node) : this.typingTarget(node, snapshot));
163222
163242
  for (const specialized of this.specializationTargets(node, snapshot))
163223
163243
  visit(specialized);
163244
+ if (cacheable)
163245
+ this.owners.set(node, { snapshot, depthZero, owners: result });
163224
163246
  return result;
163225
163247
  }
163226
163248
  inferredEnumerationTarget(node) {
@@ -163379,8 +163401,9 @@ var FeaturePathResolver = class {
163379
163401
  segment.target = target.node;
163380
163402
  segment.description = target.description;
163381
163403
  }
163404
+ // REQ-361/410 - One indexed workspace snapshot, or one per parse-only root.
163382
163405
  snapshot(root4) {
163383
- const cached = this.snapshots.get(root4);
163406
+ const cached = this.indexManager ? this.indexedSnapshot : this.snapshots.get(root4);
163384
163407
  if (cached)
163385
163408
  return cached;
163386
163409
  const byName = /* @__PURE__ */ new Map();
@@ -163412,7 +163435,10 @@ var FeaturePathResolver = class {
163412
163435
  }
163413
163436
  }
163414
163437
  const snapshot = { byName };
163415
- this.snapshots.set(root4, snapshot);
163438
+ if (this.indexManager)
163439
+ this.indexedSnapshot = snapshot;
163440
+ else
163441
+ this.snapshots.set(root4, snapshot);
163416
163442
  return snapshot;
163417
163443
  }
163418
163444
  };
@@ -185822,10 +185848,26 @@ var SysmlCodeLensProvider = class {
185822
185848
  constructor(services) {
185823
185849
  this.services = services;
185824
185850
  }
185825
- // TSK_023 — A "N references" lens above a definition (find-references on click).
185826
- 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
+ });
185827
185863
  const refProvider = this.services.lsp.ReferencesProvider;
185828
- 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;
185829
185871
  return {
185830
185872
  range,
185831
185873
  command: {
@@ -185844,6 +185886,7 @@ var SysmlCodeLensProvider = class {
185844
185886
  const uri = document2.uri.toString();
185845
185887
  const requirements = indexByName(root4, "RequirementDecl");
185846
185888
  const parts = indexByName(root4, "PartDecl");
185889
+ const counts = this.referenceCounts(root4);
185847
185890
  walkAst(root4, (node) => {
185848
185891
  const cst = node.$cstNode;
185849
185892
  if (!cst)
@@ -185877,7 +185920,7 @@ var SysmlCodeLensProvider = class {
185877
185920
  });
185878
185921
  }
185879
185922
  if (isRequirementDecl(node) && node.isDef && node.name) {
185880
- lenses.push(this.referencesLens(node, uri, range));
185923
+ lenses.push(this.referencesLens(node, uri, range, counts));
185881
185924
  }
185882
185925
  if (isVerificationCaseDecl(node) && node.isDef && node.name) {
185883
185926
  const result = evaluateVerificationCase(node, (name) => requirements.get(name), (name) => parts.get(name));
@@ -185897,7 +185940,7 @@ var SysmlCodeLensProvider = class {
185897
185940
  arguments: [uri, node.name]
185898
185941
  }
185899
185942
  });
185900
- lenses.push(this.referencesLens(node, uri, range));
185943
+ lenses.push(this.referencesLens(node, uri, range, counts));
185901
185944
  }
185902
185945
  });
185903
185946
  return lenses;
@@ -186113,6 +186156,14 @@ var SysmlReferencesProvider = class extends DefaultReferencesProvider {
186113
186156
  referenceCount(target) {
186114
186157
  return this.references.findReferences(target, { includeDeclaration: false }).count();
186115
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
+ }
186116
186167
  };
186117
186168
 
186118
186169
  // ../language-server/out/src/services/written-path-references.js
@@ -186128,6 +186179,53 @@ var WrittenPathReferences = class extends DefaultReferences {
186128
186179
  const segment = this.paths.segmentAt(source);
186129
186180
  return segment ? segment.target : super.findDeclaration(source);
186130
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
+ }
186131
186229
  findReferences(target, options) {
186132
186230
  const result = super.findReferences(target, options).toArray();
186133
186231
  const targetUri = ast_utils_exports.getDocument(target).uri;
@@ -209624,7 +209722,7 @@ async function runExport(command) {
209624
209722
  }
209625
209723
 
209626
209724
  // src/main.ts
209627
- var VERSION2 = true ? "0.31.1" : "dev";
209725
+ var VERSION2 = true ? "0.31.2" : "dev";
209628
209726
  function display(file) {
209629
209727
  const rel2 = path9.relative(process.cwd(), file);
209630
209728
  return rel2 && !rel2.startsWith("..") ? rel2.split(path9.sep).join("/") : file;