dot-language-support 4.1.4 → 4.2.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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # dot-language-support [![CD](https://github.com/nikeee/dot-language-support/actions/workflows/CD.yml/badge.svg)](https://github.com/nikeee/dot-language-support/actions/workflows/CD.yml) [![CI](https://github.com/nikeee/dot-language-support/actions/workflows/CI.yml/badge.svg)](https://github.com/nikeee/dot-language-support/actions/workflows/CI.yml) ![Dependencies](https://img.shields.io/librariesio/release/npm/dot-language-support) [![npm version](https://img.shields.io/npm/v/dot-language-support)](https://www.npmjs.com/package/dot-language-support)
1
+ # dot-language-support [![CD](https://github.com/nikeee/dot-language-support/actions/workflows/CD.yaml/badge.svg)](https://github.com/nikeee/dot-language-support/actions/workflows/CD.yaml) [![CI](https://github.com/nikeee/dot-language-support/actions/workflows/CI.yaml/badge.svg)](https://github.com/nikeee/dot-language-support/actions/workflows/CI.yaml) ![Dependencies](https://img.shields.io/librariesio/release/npm/dot-language-support) [![npm version](https://img.shields.io/npm/v/dot-language-support)](https://www.npmjs.com/package/dot-language-support)
2
2
 
3
3
  A language service library, written in TypeScript. Used by [dot-language-server](https://github.com/nikeee/dot-language-server) and [edotor.net](https://edotor.net).
4
4
 
package/dist/index.mjs CHANGED
@@ -295,6 +295,13 @@ const characterCodes = {
295
295
  };
296
296
  //#endregion
297
297
  //#region src/service/util.ts
298
+ function posRangeToRange(doc, sourceFile, pos, end) {
299
+ const start = pos === end ? pos : skipTrivia(sourceFile.content, pos);
300
+ return {
301
+ start: doc.positionAt(start),
302
+ end: doc.positionAt(end)
303
+ };
304
+ }
298
305
  function getStart(sourceFile, node) {
299
306
  return getTokenPosOfNode(sourceFile, node);
300
307
  }
@@ -3185,6 +3192,7 @@ function getCompletions(doc, sourceFile, position) {
3185
3192
  if (p) switch (p.kind) {
3186
3193
  case syntaxKind.NodeId: return getNodeCompletions(symbols);
3187
3194
  case syntaxKind.Assignment: return getAssignmentCompletion(p);
3195
+ case syntaxKind.IdEqualsIdStatement: return getAssignmentCompletion(p);
3188
3196
  }
3189
3197
  }
3190
3198
  if (node.flags & syntaxNodeFlags.ContainsErrors || node.end === node.pos) {
@@ -3193,6 +3201,7 @@ function getCompletions(doc, sourceFile, position) {
3193
3201
  if (!attribute.parent) throw "sourceFile is not bound";
3194
3202
  const parent = attribute.parent;
3195
3203
  if (parent.kind === syntaxKind.Assignment) return getAssignmentCompletion(parent);
3204
+ if (parent.kind === syntaxKind.IdEqualsIdStatement) return getAssignmentCompletion(parent);
3196
3205
  }
3197
3206
  return [];
3198
3207
  }
@@ -3266,11 +3275,17 @@ function hover(doc, sourceFile, position) {
3266
3275
  return getNodeHover(doc, sourceFile, node);
3267
3276
  }
3268
3277
  function getNodeHover(doc, sf, n) {
3269
- const contents = getHoverContents(n);
3270
- if (contents) return {
3271
- contents,
3272
- range: syntaxNodeToRange(doc, sf, n)
3273
- };
3278
+ const result = getHoverContents(n);
3279
+ if (result) {
3280
+ const { pos, end } = result.range ?? {
3281
+ pos: n.pos,
3282
+ end: n.end
3283
+ };
3284
+ return {
3285
+ contents: result.contents,
3286
+ range: posRangeToRange(doc, sf, pos, end)
3287
+ };
3288
+ }
3274
3289
  }
3275
3290
  function getAssignedLabel(statement) {
3276
3291
  const assignedLabel = statement.attributes.flatMap((a) => a.assignments)?.find((a) => getIdentifierText(a.leftId) === "label");
@@ -3286,37 +3301,63 @@ function getHoverContents(n) {
3286
3301
  const labelMentions = (n.symbol?.references).map((e) => e.symbol?.members?.get("label")?.firstMention.parent);
3287
3302
  for (let i = labelMentions.length; i >= 0; i--) {
3288
3303
  const s = labelMentions[i];
3289
- if (s?.rightId) return `(node) ${getIdentifierText(n)}: ${getIdentifierText(s.rightId)}`;
3304
+ if (s?.rightId) return { contents: `(node) ${getIdentifierText(n)}: ${getIdentifierText(s.rightId)}` };
3290
3305
  }
3291
3306
  } else if (parent.parent?.kind === syntaxKind.NodeStatement) {
3292
3307
  const label = getAssignedLabel(parent.parent);
3293
- if (label) return `(node) ${getIdentifierText(n)}: ${label}`;
3308
+ if (label) return { contents: `(node) ${getIdentifierText(n)}: ${label}` };
3294
3309
  }
3295
- return `(node) ${getIdentifierText(n)}`;
3310
+ return { contents: `(node) ${getIdentifierText(n)}` };
3296
3311
  case syntaxKind.Assignment: {
3297
3312
  const assignment = parent;
3298
- return `(assignment) \`${getIdentifierText(assignment.leftId)}\` = \`${getIdentifierText(assignment.rightId)}\``;
3313
+ return {
3314
+ contents: `(assignment) \`${getIdentifierText(assignment.leftId)}\` = \`${getIdentifierText(assignment.rightId)}\``,
3315
+ range: {
3316
+ pos: assignment.pos,
3317
+ end: assignment.end
3318
+ }
3319
+ };
3299
3320
  }
3300
3321
  case syntaxKind.DirectedGraph: return getGraphHover(parent);
3301
3322
  case syntaxKind.UndirectedGraph: return getGraphHover(parent);
3302
3323
  case syntaxKind.SubGraphStatement: {
3303
- const sg = parent.subgraph;
3304
- return sg.id ? `(sub graph) ${getIdentifierText(sg.id)}` : "(sub graph)";
3324
+ const sgs = parent;
3325
+ const sg = sgs.subgraph;
3326
+ return {
3327
+ contents: sg.id ? `(sub graph) ${getIdentifierText(sg.id)}` : "(sub graph)",
3328
+ range: {
3329
+ pos: sgs.pos,
3330
+ end: sgs.end
3331
+ }
3332
+ };
3305
3333
  }
3306
3334
  case syntaxKind.SubGraph: {
3307
3335
  const sg = parent;
3308
- return sg.id ? `(sub graph) ${getIdentifierText(sg.id)}` : "(sub graph)";
3336
+ return {
3337
+ contents: sg.id ? `(sub graph) ${getIdentifierText(sg.id)}` : "(sub graph)",
3338
+ range: {
3339
+ pos: sg.pos,
3340
+ end: sg.end
3341
+ }
3342
+ };
3309
3343
  }
3310
3344
  case syntaxKind.IdEqualsIdStatement: {
3311
3345
  const idEqId = parent;
3312
- return `(graph property) \`${getIdentifierText(idEqId.leftId)}\` = \`${getIdentifierText(idEqId.rightId)}\``;
3346
+ return {
3347
+ contents: `(graph property) \`${getIdentifierText(idEqId.leftId)}\` = \`${getIdentifierText(idEqId.rightId)}\``,
3348
+ range: {
3349
+ pos: idEqId.pos,
3350
+ end: idEqId.end
3351
+ }
3352
+ };
3313
3353
  }
3314
3354
  case syntaxKind.EdgeRhs: return getEdgeHover(parent);
3315
3355
  }
3316
- return syntaxKindNames[parent.kind];
3356
+ const fallbackParent = syntaxKindNames[parent.kind];
3357
+ return fallbackParent ? { contents: fallbackParent } : void 0;
3317
3358
  }
3318
3359
  const fallback = syntaxKindNames[n.kind];
3319
- return fallback ? `(${fallback.toLowerCase()})` : void 0;
3360
+ return fallback ? { contents: `(${fallback.toLowerCase()})` } : void 0;
3320
3361
  }
3321
3362
  switch (n.kind) {
3322
3363
  case syntaxKind.GraphKeyword:
@@ -3333,7 +3374,13 @@ function getGraphHover(g) {
3333
3374
  const direction = g.kind === syntaxKind.DirectedGraph ? "directed" : "undirected";
3334
3375
  const graphId = g.id;
3335
3376
  const strict = g.strict ? "strict " : "";
3336
- return graphId ? `(${strict}${direction} graph) ${getIdentifierText(graphId)}` : `(${strict}${direction} graph)`;
3377
+ return {
3378
+ contents: graphId ? `(${strict}${direction} graph) ${getIdentifierText(graphId)}` : `(${strict}${direction} graph)`,
3379
+ range: {
3380
+ pos: g.pos,
3381
+ end: g.end
3382
+ }
3383
+ };
3337
3384
  }
3338
3385
  function getEdgeHover(n) {
3339
3386
  const p = n.parent;
@@ -3344,8 +3391,15 @@ function getEdgeHover(n) {
3344
3391
  source = curr.target;
3345
3392
  }
3346
3393
  if (source === void 0) source = p.source;
3394
+ if (source === void 0) return void 0;
3347
3395
  const edgeOpStr = getEdgeStr(n.operation.kind);
3348
- return source === void 0 ? void 0 : `(edge) ${getEdgeSourceOrTargetText(source)} ${edgeOpStr} ${getEdgeSourceOrTargetText(n.target)}`;
3396
+ return {
3397
+ contents: `(edge) ${getEdgeSourceOrTargetText(source)} ${edgeOpStr} ${getEdgeSourceOrTargetText(n.target)}`,
3398
+ range: {
3399
+ pos: source.pos,
3400
+ end: n.target.end
3401
+ }
3402
+ };
3349
3403
  }
3350
3404
  function getEdgeSourceOrTargetText(n) {
3351
3405
  return n.kind === syntaxKind.NodeId ? getIdentifierText(n.id) : n.id !== void 0 ? `${getIdentifierText(n.id)}` : "sub graph";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dot-language-support",
3
- "version": "4.1.4",
3
+ "version": "4.2.1",
4
4
  "description": "Parser and language service for graphviz (dot) files",
5
5
  "keywords": [
6
6
  "dot",
@@ -38,9 +38,9 @@
38
38
  "expect": "^30.3.0",
39
39
  "oxfmt": "^0.45.0",
40
40
  "oxlint": "^1.60.0",
41
- "oxlint-tsgolint": "^0.20.0",
42
- "tsdown": "^0.21.8",
43
- "typescript": "^6.0.2"
41
+ "oxlint-tsgolint": "^0.21.1",
42
+ "tsdown": "^0.21.9",
43
+ "typescript": "^6.0.3"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=22"