dot-language-support 2.2.2 → 2.2.3
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/.github/workflows/CD.yml +4 -1
- package/.github/workflows/CI.yml +4 -1
- package/.github/workflows/auto-merge.yaml +1 -1
- package/biome.json +50 -0
- package/lib/cjs/binder.d.ts +1 -1
- package/lib/cjs/binder.js +2 -5
- package/lib/cjs/checker.d.ts +1 -1
- package/lib/cjs/checker.js +34 -30
- package/lib/cjs/core.js +2 -3
- package/lib/cjs/error.js +3 -5
- package/lib/cjs/parser.d.ts +4 -61
- package/lib/cjs/parser.js +580 -616
- package/lib/cjs/scanner.d.ts +2 -13
- package/lib/cjs/scanner.js +316 -317
- package/lib/cjs/service/codeAction.d.ts +3 -3
- package/lib/cjs/service/codeAction.js +28 -32
- package/lib/cjs/service/colorProvider.d.ts +3 -3
- package/lib/cjs/service/colorProvider.js +13 -24
- package/lib/cjs/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.d.ts +4 -4
- package/lib/cjs/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.js +5 -6
- package/lib/cjs/service/command/ChangeEdgeOpCommand.d.ts +3 -3
- package/lib/cjs/service/command/ChangeEdgeOpCommand.js +5 -8
- package/lib/cjs/service/command/ConsolidateDescendantsCommand.d.ts +4 -4
- package/lib/cjs/service/command/ConsolidateDescendantsCommand.js +12 -13
- package/lib/cjs/service/command/RemoveSemicolons.d.ts +4 -4
- package/lib/cjs/service/command/RemoveSemicolons.js +8 -11
- package/lib/cjs/service/command/common.d.ts +4 -4
- package/lib/cjs/service/command/common.js +12 -10
- package/lib/cjs/service/completion.d.ts +2 -2
- package/lib/cjs/service/completion.js +17 -18
- package/lib/cjs/service/hover.d.ts +2 -2
- package/lib/cjs/service/hover.js +12 -16
- package/lib/cjs/service/languageFacts.js +1 -6
- package/lib/cjs/service/reference.d.ts +2 -2
- package/lib/cjs/service/reference.js +4 -8
- package/lib/cjs/service/rename.d.ts +3 -3
- package/lib/cjs/service/rename.js +10 -8
- package/lib/cjs/service/service.d.ts +3 -3
- package/lib/cjs/service/service.js +7 -8
- package/lib/cjs/service/util.d.ts +1 -1
- package/lib/cjs/service/util.js +10 -13
- package/lib/cjs/service/validation.d.ts +3 -3
- package/lib/cjs/service/validation.js +1 -2
- package/lib/cjs/tester.js +1 -1
- package/lib/cjs/visitor.d.ts +1 -1
- package/lib/cjs/visitor.js +32 -34
- package/lib/esm/binder.d.ts +1 -1
- package/lib/esm/binder.js +1 -3
- package/lib/esm/checker.d.ts +1 -1
- package/lib/esm/checker.js +21 -16
- package/lib/esm/core.js +1 -1
- package/lib/esm/error.js +1 -3
- package/lib/esm/parser.d.ts +4 -61
- package/lib/esm/parser.js +320 -306
- package/lib/esm/scanner.d.ts +2 -13
- package/lib/esm/scanner.js +153 -152
- package/lib/esm/service/codeAction.d.ts +3 -3
- package/lib/esm/service/codeAction.js +26 -29
- package/lib/esm/service/colorProvider.d.ts +3 -3
- package/lib/esm/service/colorProvider.js +11 -21
- package/lib/esm/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.d.ts +4 -4
- package/lib/esm/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.js +4 -4
- package/lib/esm/service/command/ChangeEdgeOpCommand.d.ts +3 -3
- package/lib/esm/service/command/ChangeEdgeOpCommand.js +3 -5
- package/lib/esm/service/command/ConsolidateDescendantsCommand.d.ts +4 -4
- package/lib/esm/service/command/ConsolidateDescendantsCommand.js +11 -11
- package/lib/esm/service/command/RemoveSemicolons.d.ts +4 -4
- package/lib/esm/service/command/RemoveSemicolons.js +6 -8
- package/lib/esm/service/command/common.d.ts +4 -4
- package/lib/esm/service/command/common.js +7 -4
- package/lib/esm/service/completion.d.ts +2 -2
- package/lib/esm/service/completion.js +16 -16
- package/lib/esm/service/hover.d.ts +2 -2
- package/lib/esm/service/hover.js +8 -14
- package/lib/esm/service/languageFacts.js +1 -6
- package/lib/esm/service/reference.d.ts +2 -2
- package/lib/esm/service/reference.js +3 -6
- package/lib/esm/service/rename.d.ts +3 -3
- package/lib/esm/service/rename.js +9 -6
- package/lib/esm/service/service.d.ts +3 -3
- package/lib/esm/service/service.js +7 -7
- package/lib/esm/service/util.d.ts +1 -1
- package/lib/esm/service/util.js +5 -7
- package/lib/esm/service/validation.d.ts +3 -3
- package/lib/esm/service/validation.js +1 -1
- package/lib/esm/tester.js +1 -1
- package/lib/esm/visitor.d.ts +1 -1
- package/lib/esm/visitor.js +32 -33
- package/package.json +15 -10
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type * as lst from "vscode-languageserver-types";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { DocumentLike } from "../index.js";
|
|
3
|
+
import { type SourceFile } from "../types.js";
|
|
4
4
|
export declare function hover(doc: DocumentLike, sourceFile: SourceFile, position: lst.Position): lst.Hover | undefined;
|
package/lib/cjs/service/hover.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hover =
|
|
4
|
-
const types_js_1 = require("../types.js");
|
|
3
|
+
exports.hover = hover;
|
|
5
4
|
const checker_js_1 = require("../checker.js");
|
|
6
5
|
const parser_js_1 = require("../parser.js");
|
|
7
|
-
const
|
|
6
|
+
const types_js_1 = require("../types.js");
|
|
8
7
|
const common_js_1 = require("./command/common.js");
|
|
8
|
+
const util_js_1 = require("./util.js");
|
|
9
9
|
function hover(doc, sourceFile, position) {
|
|
10
10
|
const offset = doc.offsetAt(position);
|
|
11
11
|
const g = sourceFile.graph;
|
|
@@ -16,7 +16,6 @@ function hover(doc, sourceFile, position) {
|
|
|
16
16
|
return undefined;
|
|
17
17
|
return getNodeHover(doc, sourceFile, node);
|
|
18
18
|
}
|
|
19
|
-
exports.hover = hover;
|
|
20
19
|
function getNodeHover(doc, sf, n) {
|
|
21
20
|
const contents = getHoverContents(n);
|
|
22
21
|
if (contents) {
|
|
@@ -41,7 +40,10 @@ function getHoverContents(n) {
|
|
|
41
40
|
case types_js_1.SyntaxKind.NodeId: {
|
|
42
41
|
if ((_a = n.symbol) === null || _a === void 0 ? void 0 : _a.references) {
|
|
43
42
|
const nodeIdentifierRefs = (_b = n.symbol) === null || _b === void 0 ? void 0 : _b.references;
|
|
44
|
-
const labelMentions = nodeIdentifierRefs.map(e => {
|
|
43
|
+
const labelMentions = nodeIdentifierRefs.map(e => {
|
|
44
|
+
var _a, _b, _c;
|
|
45
|
+
return (_c = (_b = (_a = e.symbol) === null || _a === void 0 ? void 0 : _a.members) === null || _b === void 0 ? void 0 : _b.get("label")) === null || _c === void 0 ? void 0 : _c.firstMention.parent;
|
|
46
|
+
});
|
|
45
47
|
for (let i = labelMentions.length; i >= 0; i--) {
|
|
46
48
|
const s = labelMentions[i];
|
|
47
49
|
if (s === null || s === void 0 ? void 0 : s.rightId) {
|
|
@@ -70,15 +72,11 @@ function getHoverContents(n) {
|
|
|
70
72
|
case types_js_1.SyntaxKind.SubGraphStatement: {
|
|
71
73
|
const sgs = parent;
|
|
72
74
|
const sg = sgs.subgraph;
|
|
73
|
-
return
|
|
74
|
-
? `(sub graph) ${(0, checker_js_1.getIdentifierText)(sg.id)}`
|
|
75
|
-
: `(sub graph)`;
|
|
75
|
+
return sg.id ? `(sub graph) ${(0, checker_js_1.getIdentifierText)(sg.id)}` : "(sub graph)";
|
|
76
76
|
}
|
|
77
77
|
case types_js_1.SyntaxKind.SubGraph: {
|
|
78
78
|
const sg = parent;
|
|
79
|
-
return
|
|
80
|
-
? `(sub graph) ${(0, checker_js_1.getIdentifierText)(sg.id)}`
|
|
81
|
-
: `(sub graph)`;
|
|
79
|
+
return sg.id ? `(sub graph) ${(0, checker_js_1.getIdentifierText)(sg.id)}` : "(sub graph)";
|
|
82
80
|
}
|
|
83
81
|
case types_js_1.SyntaxKind.IdEqualsIdStatement: {
|
|
84
82
|
const idEqId = parent;
|
|
@@ -92,9 +90,7 @@ function getHoverContents(n) {
|
|
|
92
90
|
return types_js_1.SyntaxKind[parent.kind];
|
|
93
91
|
}
|
|
94
92
|
const fallback = types_js_1.SyntaxKind[n.kind];
|
|
95
|
-
return fallback
|
|
96
|
-
? "(" + fallback.toLowerCase() + ")"
|
|
97
|
-
: undefined;
|
|
93
|
+
return fallback ? `(${fallback.toLowerCase()})` : undefined;
|
|
98
94
|
}
|
|
99
95
|
switch (n.kind) {
|
|
100
96
|
case types_js_1.SyntaxKind.GraphKeyword:
|
|
@@ -115,8 +111,8 @@ function getGraphHover(g) {
|
|
|
115
111
|
const direction = g.kind === types_js_1.SyntaxKind.DirectedGraph ? "directed" : "undirected";
|
|
116
112
|
const graphId = g.id;
|
|
117
113
|
const strict = g.strict ? "strict " : "";
|
|
118
|
-
return
|
|
119
|
-
? `(${strict}${direction} graph) ${(
|
|
114
|
+
return graphId
|
|
115
|
+
? `(${strict}${direction} graph) ${(0, checker_js_1.getIdentifierText)(graphId)}`
|
|
120
116
|
: `(${strict}${direction} graph)`;
|
|
121
117
|
}
|
|
122
118
|
function getEdgeHover(n) {
|
|
@@ -310,12 +310,7 @@ const clusterAttributes = Object.freeze([
|
|
|
310
310
|
"target",
|
|
311
311
|
"tooltip",
|
|
312
312
|
]);
|
|
313
|
-
exports.attributes = Array.from(new Set([
|
|
314
|
-
...nodeAttributes,
|
|
315
|
-
...edgeAttributes,
|
|
316
|
-
...graphAttributes,
|
|
317
|
-
...clusterAttributes,
|
|
318
|
-
])).sort();
|
|
313
|
+
exports.attributes = Array.from(new Set([...nodeAttributes, ...edgeAttributes, ...graphAttributes, ...clusterAttributes])).sort();
|
|
319
314
|
exports.colors = Object.freeze({
|
|
320
315
|
aliceblue: "#f0f8ff",
|
|
321
316
|
antiquewhite: "#faebd7",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Position, ReferenceContext
|
|
2
|
-
import type { SourceFile } from "../types.js";
|
|
1
|
+
import type { Location, Position, ReferenceContext } from "vscode-languageserver-types";
|
|
3
2
|
import { type DocumentLike } from "../index.js";
|
|
3
|
+
import type { SourceFile } from "../types.js";
|
|
4
4
|
export declare function findReferences(doc: DocumentLike, sourceFile: SourceFile, position: Position, context: ReferenceContext): Location[];
|
|
5
5
|
export declare function findDefinition(doc: DocumentLike, sourceFile: SourceFile, position: Position): Location | undefined;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.findReferences = findReferences;
|
|
4
|
+
exports.findDefinition = findDefinition;
|
|
5
5
|
const checker_js_1 = require("../checker.js");
|
|
6
|
+
const index_js_1 = require("../index.js");
|
|
6
7
|
const util_js_1 = require("./util.js");
|
|
7
8
|
function findReferences(doc, sourceFile, position, context) {
|
|
8
9
|
if (!sourceFile.symbols)
|
|
@@ -28,10 +29,7 @@ function findReferences(doc, sourceFile, position, context) {
|
|
|
28
29
|
symbolRefs = refs;
|
|
29
30
|
}
|
|
30
31
|
else {
|
|
31
|
-
symbolRefs = [
|
|
32
|
-
nodeSymbol.firstMention,
|
|
33
|
-
...refs.filter(r => r !== node),
|
|
34
|
-
];
|
|
32
|
+
symbolRefs = [nodeSymbol.firstMention, ...refs.filter(r => r !== node)];
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
const ranges = (0, util_js_1.syntaxNodesToRanges)(doc, sourceFile, symbolRefs);
|
|
@@ -43,7 +41,6 @@ function findReferences(doc, sourceFile, position, context) {
|
|
|
43
41
|
debugger;
|
|
44
42
|
return [];
|
|
45
43
|
}
|
|
46
|
-
exports.findReferences = findReferences;
|
|
47
44
|
function findDefinition(doc, sourceFile, position) {
|
|
48
45
|
if (!sourceFile.symbols)
|
|
49
46
|
throw "sourceFile is not bound";
|
|
@@ -67,5 +64,4 @@ function findDefinition(doc, sourceFile, position) {
|
|
|
67
64
|
debugger;
|
|
68
65
|
return undefined;
|
|
69
66
|
}
|
|
70
|
-
exports.findDefinition = findDefinition;
|
|
71
67
|
//# sourceMappingURL=reference.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Position, WorkspaceEdit } from "vscode-languageserver-types";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { type Position, type WorkspaceEdit } from "vscode-languageserver-types";
|
|
2
|
+
import { type DocumentLike } from "../index.js";
|
|
3
|
+
import { type SourceFile } from "../types.js";
|
|
4
4
|
export declare function renameSymbol(doc: DocumentLike, sourceFile: SourceFile, position: Position, newName: string): WorkspaceEdit | undefined;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.renameSymbol =
|
|
3
|
+
exports.renameSymbol = renameSymbol;
|
|
4
4
|
const vscode_languageserver_types_1 = require("vscode-languageserver-types");
|
|
5
|
-
const types_js_1 = require("../types.js");
|
|
6
5
|
const checker_js_1 = require("../checker.js");
|
|
7
6
|
const index_js_1 = require("../index.js");
|
|
7
|
+
const types_js_1 = require("../types.js");
|
|
8
8
|
const util_js_1 = require("./util.js");
|
|
9
9
|
function renameSymbol(doc, sourceFile, position, newName) {
|
|
10
10
|
if (!sourceFile.symbols)
|
|
@@ -19,7 +19,10 @@ function renameSymbol(doc, sourceFile, position, newName) {
|
|
|
19
19
|
if (!node)
|
|
20
20
|
return undefined;
|
|
21
21
|
const parent = node.parent;
|
|
22
|
-
if ((0, index_js_1.isIdentifierNode)(node) &&
|
|
22
|
+
if ((0, index_js_1.isIdentifierNode)(node) &&
|
|
23
|
+
isRenamableIdentifier(node) &&
|
|
24
|
+
!!parent &&
|
|
25
|
+
isRenameableNode(parent)) {
|
|
23
26
|
const nodeSymbol = node.symbol;
|
|
24
27
|
if (!nodeSymbol)
|
|
25
28
|
throw "node.symbol is not bound";
|
|
@@ -30,18 +33,17 @@ function renameSymbol(doc, sourceFile, position, newName) {
|
|
|
30
33
|
const res = {
|
|
31
34
|
changes: {
|
|
32
35
|
[uri]: ranges.map(r => vscode_languageserver_types_1.TextEdit.replace(r, newName)),
|
|
33
|
-
}
|
|
36
|
+
},
|
|
34
37
|
};
|
|
35
38
|
return res;
|
|
36
39
|
}
|
|
37
40
|
debugger;
|
|
38
41
|
return undefined;
|
|
39
42
|
}
|
|
40
|
-
exports.renameSymbol = renameSymbol;
|
|
41
43
|
function isRenameableNode(node) {
|
|
42
|
-
return node.kind === types_js_1.SyntaxKind.NodeId
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
return (node.kind === types_js_1.SyntaxKind.NodeId ||
|
|
45
|
+
node.kind === types_js_1.SyntaxKind.DirectedGraph ||
|
|
46
|
+
node.kind === types_js_1.SyntaxKind.UndirectedGraph);
|
|
45
47
|
}
|
|
46
48
|
function isRenamableIdentifier(node) {
|
|
47
49
|
return node.kind !== types_js_1.SyntaxKind.QuotedTextIdentifier;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type * as lst from "vscode-languageserver-types";
|
|
2
|
-
import type { ColorInformation, Color, ColorPresentation } from "vscode-languageserver-types";
|
|
3
1
|
import type { TextDocument } from "vscode-languageserver-textdocument";
|
|
4
|
-
import
|
|
2
|
+
import type * as lst from "vscode-languageserver-types";
|
|
3
|
+
import type { Color, ColorInformation, ColorPresentation } from "vscode-languageserver-types";
|
|
4
|
+
import type { Omit, SourceFile } from "../types.js";
|
|
5
5
|
export interface DocumentLike {
|
|
6
6
|
positionAt(offset: number): lst.Position;
|
|
7
7
|
offsetAt(position: lst.Position): number;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createService =
|
|
4
|
-
const index_js_1 = require("../index.js");
|
|
3
|
+
exports.createService = createService;
|
|
5
4
|
const binder_js_1 = require("../binder.js");
|
|
6
|
-
const hover_js_1 = require("./hover.js");
|
|
7
|
-
const validation_js_1 = require("./validation.js");
|
|
8
|
-
const reference_js_1 = require("./reference.js");
|
|
9
|
-
const rename_js_1 = require("./rename.js");
|
|
10
|
-
const completion_js_1 = require("./completion.js");
|
|
11
5
|
const checker_js_1 = require("../checker.js");
|
|
6
|
+
const index_js_1 = require("../index.js");
|
|
12
7
|
const codeAction_js_1 = require("./codeAction.js");
|
|
13
8
|
const colorProvider_js_1 = require("./colorProvider.js");
|
|
9
|
+
const completion_js_1 = require("./completion.js");
|
|
10
|
+
const hover_js_1 = require("./hover.js");
|
|
11
|
+
const reference_js_1 = require("./reference.js");
|
|
12
|
+
const rename_js_1 = require("./rename.js");
|
|
13
|
+
const validation_js_1 = require("./validation.js");
|
|
14
14
|
function parseDocument(doc) {
|
|
15
15
|
const parser = new index_js_1.Parser();
|
|
16
16
|
const content = typeof doc === "string" ? doc : doc.getText();
|
|
@@ -35,5 +35,4 @@ function createService() {
|
|
|
35
35
|
getAvailableCommands: codeAction_js_1.getAvailableCommands,
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
exports.createService = createService;
|
|
39
38
|
//# sourceMappingURL=service.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Range } from "vscode-languageserver-types";
|
|
2
|
-
import { SourceFile, SyntaxNode } from "../types.js";
|
|
3
2
|
import type { DocumentLike } from "../index.js";
|
|
3
|
+
import { type SourceFile, type SyntaxNode } from "../types.js";
|
|
4
4
|
export declare function getStart(sourceFile: SourceFile, node: SyntaxNode): number;
|
|
5
5
|
export declare function syntaxNodesToRanges(doc: DocumentLike, sourceFile: SourceFile, nodes: SyntaxNode[]): Range[];
|
|
6
6
|
export declare function syntaxNodeToRange(doc: DocumentLike, sourceFile: SourceFile, node: SyntaxNode): {
|
package/lib/cjs/service/util.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.getStart = getStart;
|
|
4
|
+
exports.syntaxNodesToRanges = syntaxNodesToRanges;
|
|
5
|
+
exports.syntaxNodeToRange = syntaxNodeToRange;
|
|
6
|
+
exports.escapeIdentifierText = escapeIdentifierText;
|
|
7
|
+
exports.assertNever = assertNever;
|
|
5
8
|
const scanner_js_1 = require("../scanner.js");
|
|
9
|
+
const types_js_1 = require("../types.js");
|
|
6
10
|
function getStart(sourceFile, node) {
|
|
7
11
|
return getTokenPosOfNode(sourceFile, node);
|
|
8
12
|
}
|
|
9
|
-
exports.getStart = getStart;
|
|
10
13
|
function getTokenPosOfNode(sourceFile, node) {
|
|
11
14
|
if (nodeIsMissing(node))
|
|
12
15
|
return node.pos;
|
|
@@ -20,7 +23,6 @@ function nodeIsMissing(node) {
|
|
|
20
23
|
function syntaxNodesToRanges(doc, sourceFile, nodes) {
|
|
21
24
|
return nodes.map(node => syntaxNodeToRange(doc, sourceFile, node));
|
|
22
25
|
}
|
|
23
|
-
exports.syntaxNodesToRanges = syntaxNodesToRanges;
|
|
24
26
|
function syntaxNodeToRange(doc, sourceFile, node) {
|
|
25
27
|
const start = getStart(sourceFile, node);
|
|
26
28
|
return {
|
|
@@ -28,14 +30,11 @@ function syntaxNodeToRange(doc, sourceFile, node) {
|
|
|
28
30
|
end: doc.positionAt(node.end),
|
|
29
31
|
};
|
|
30
32
|
}
|
|
31
|
-
exports.syntaxNodeToRange = syntaxNodeToRange;
|
|
32
33
|
function escapeIdentifierText(text) {
|
|
33
34
|
if (text === "")
|
|
34
35
|
return quote("");
|
|
35
|
-
if (text.includes("
|
|
36
|
-
const esc = text
|
|
37
|
-
.replace(/"/, "\\\"")
|
|
38
|
-
.replace(/\n/, "\\\n");
|
|
36
|
+
if (text.includes('"') || text.includes("\n")) {
|
|
37
|
+
const esc = text.replace(/"/, '\\"').replace(/\n/, "\\\n");
|
|
39
38
|
return quote(esc);
|
|
40
39
|
}
|
|
41
40
|
const ch = text.charCodeAt(0);
|
|
@@ -43,10 +42,8 @@ function escapeIdentifierText(text) {
|
|
|
43
42
|
return quote(text);
|
|
44
43
|
return text;
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
const quote = (s) => "\"" + s + "\"";
|
|
45
|
+
const quote = (s) => `"${s}"`;
|
|
48
46
|
function assertNever(v) {
|
|
49
|
-
throw new Error(
|
|
47
|
+
throw new Error(`Should not have reached this. Value: ${v !== null && v !== void 0 ? v : ""}`);
|
|
50
48
|
}
|
|
51
|
-
exports.assertNever = assertNever;
|
|
52
49
|
//# sourceMappingURL=util.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as lst from "vscode-languageserver-types";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type * as lst from "vscode-languageserver-types";
|
|
2
|
+
import type { DocumentLike } from "../index.js";
|
|
3
|
+
import type { SourceFile } from "../types.js";
|
|
4
4
|
export declare function validateDocument(doc: DocumentLike, sourceFile: SourceFile): lst.Diagnostic[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateDocument =
|
|
3
|
+
exports.validateDocument = validateDocument;
|
|
4
4
|
const error_js_1 = require("../error.js");
|
|
5
5
|
function convertDiagnostic(document, source) {
|
|
6
6
|
return {
|
|
@@ -20,5 +20,4 @@ function validateDocument(doc, sourceFile) {
|
|
|
20
20
|
return [];
|
|
21
21
|
return diagnostics.map(d => convertDiagnostic(doc, d));
|
|
22
22
|
}
|
|
23
|
-
exports.validateDocument = validateDocument;
|
|
24
23
|
//# sourceMappingURL=validation.js.map
|
package/lib/cjs/tester.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
4
|
-
const parser_js_1 = require("./parser.js");
|
|
5
4
|
const binder_js_1 = require("./binder.js");
|
|
6
5
|
const checker_js_1 = require("./checker.js");
|
|
6
|
+
const parser_js_1 = require("./parser.js");
|
|
7
7
|
const completion_js_1 = require("./service/completion.js");
|
|
8
8
|
const text = `graph {
|
|
9
9
|
node_name_a -- node_name_b [color=blue,
|
package/lib/cjs/visitor.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SyntaxNode, SyntaxNodeArray } from "./types.js";
|
|
1
|
+
import { type SyntaxNode, type SyntaxNodeArray } from "./types.js";
|
|
2
2
|
export declare function forEachChild<TReturn>(node: SyntaxNode, cbNode: (node: SyntaxNode) => TReturn, cbNodes?: (nodes: SyntaxNodeArray<SyntaxNode>) => TReturn): TReturn | undefined;
|
package/lib/cjs/visitor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.forEachChild =
|
|
3
|
+
exports.forEachChild = forEachChild;
|
|
4
4
|
const types_js_1 = require("./types.js");
|
|
5
5
|
function visitNode(cbNode, node) {
|
|
6
6
|
return node && cbNode(node);
|
|
@@ -23,56 +23,54 @@ function forEachChild(node, cbNode, cbNodes) {
|
|
|
23
23
|
switch (node.kind) {
|
|
24
24
|
case types_js_1.SyntaxKind.DirectedGraph:
|
|
25
25
|
case types_js_1.SyntaxKind.UndirectedGraph:
|
|
26
|
-
return visitNodes(cbNode, cbNodes, node.statements)
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
return (visitNodes(cbNode, cbNodes, node.statements) ||
|
|
27
|
+
visitNode(cbNode, node.strict) ||
|
|
28
|
+
visitNode(cbNode, node.id));
|
|
29
29
|
case types_js_1.SyntaxKind.AttributeStatement:
|
|
30
|
-
return visitNodes(cbNode, cbNodes, node.attributes)
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
return (visitNodes(cbNode, cbNodes, node.attributes) ||
|
|
31
|
+
visitNode(cbNode, node.subject) ||
|
|
32
|
+
visitNode(cbNode, node.terminator));
|
|
33
33
|
case types_js_1.SyntaxKind.EdgeStatement:
|
|
34
|
-
return visitNodes(cbNode, cbNodes, node.attributes)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
return (visitNodes(cbNode, cbNodes, node.attributes) ||
|
|
35
|
+
visitNodes(cbNode, cbNodes, node.rhs) ||
|
|
36
|
+
visitNode(cbNode, node.source) ||
|
|
37
|
+
visitNode(cbNode, node.terminator));
|
|
38
38
|
case types_js_1.SyntaxKind.NodeStatement:
|
|
39
|
-
return visitNodes(cbNode, cbNodes, node.attributes)
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
return (visitNodes(cbNode, cbNodes, node.attributes) ||
|
|
40
|
+
visitNode(cbNode, node.id) ||
|
|
41
|
+
visitNode(cbNode, node.terminator));
|
|
42
42
|
case types_js_1.SyntaxKind.SubGraph:
|
|
43
|
-
return visitNodes(cbNode, cbNodes, node.statements)
|
|
44
|
-
|
|
43
|
+
return (visitNodes(cbNode, cbNodes, node.statements) ||
|
|
44
|
+
visitNode(cbNode, node.id));
|
|
45
45
|
case types_js_1.SyntaxKind.SubGraphStatement:
|
|
46
|
-
return visitNode(cbNode, node.subgraph)
|
|
47
|
-
|
|
46
|
+
return (visitNode(cbNode, node.subgraph) ||
|
|
47
|
+
visitNode(cbNode, node.terminator));
|
|
48
48
|
case types_js_1.SyntaxKind.IdEqualsIdStatement:
|
|
49
|
-
return visitNode(cbNode, node.leftId)
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
return (visitNode(cbNode, node.leftId) ||
|
|
50
|
+
visitNode(cbNode, node.rightId) ||
|
|
51
|
+
visitNode(cbNode, node.terminator));
|
|
52
52
|
case types_js_1.SyntaxKind.QuotedTextIdentifier:
|
|
53
53
|
return visitNodes(cbNode, cbNodes, node.values);
|
|
54
54
|
case types_js_1.SyntaxKind.EdgeRhs:
|
|
55
|
-
return visitNode(cbNode, node.operation)
|
|
56
|
-
|
|
55
|
+
return (visitNode(cbNode, node.operation) ||
|
|
56
|
+
visitNode(cbNode, node.target));
|
|
57
57
|
case types_js_1.SyntaxKind.AttributeContainer:
|
|
58
58
|
return visitNodes(cbNode, cbNodes, node.assignments);
|
|
59
59
|
case types_js_1.SyntaxKind.Assignment:
|
|
60
|
-
return visitNode(cbNode, node.leftId)
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
return (visitNode(cbNode, node.leftId) ||
|
|
61
|
+
visitNode(cbNode, node.rightId) ||
|
|
62
|
+
visitNode(cbNode, node.terminator));
|
|
63
63
|
case types_js_1.SyntaxKind.NormalPortDeclaration:
|
|
64
|
-
return visitNode(cbNode, node.colon)
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
return (visitNode(cbNode, node.colon) ||
|
|
65
|
+
visitNode(cbNode, node.id) ||
|
|
66
|
+
visitNode(cbNode, node.compassPt));
|
|
67
67
|
case types_js_1.SyntaxKind.CompassPortDeclaration:
|
|
68
|
-
return visitNode(cbNode, node.colon)
|
|
69
|
-
|
|
68
|
+
return (visitNode(cbNode, node.colon) ||
|
|
69
|
+
visitNode(cbNode, node.compassPt));
|
|
70
70
|
case types_js_1.SyntaxKind.NodeId:
|
|
71
|
-
return visitNode(cbNode, node.port)
|
|
72
|
-
|| visitNode(cbNode, node.id);
|
|
71
|
+
return (visitNode(cbNode, node.port) || visitNode(cbNode, node.id));
|
|
73
72
|
default:
|
|
74
73
|
return undefined;
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
|
-
exports.forEachChild = forEachChild;
|
|
78
76
|
//# sourceMappingURL=visitor.js.map
|
package/lib/esm/binder.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SourceFile } from "./types.js";
|
|
1
|
+
import { type SourceFile } from "./types.js";
|
|
2
2
|
export declare function bindSourceFile(file: SourceFile): void;
|
package/lib/esm/binder.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SyntaxKind, } from "./types.js";
|
|
2
1
|
import { getIdentifierText, nodeContainsErrors } from "./checker.js";
|
|
3
2
|
import { isIdentifierNode } from "./parser.js";
|
|
3
|
+
import { SyntaxKind, } from "./types.js";
|
|
4
4
|
const binder = createBinder();
|
|
5
5
|
export function bindSourceFile(file) {
|
|
6
6
|
binder.bind(file);
|
|
@@ -74,7 +74,6 @@ function createBinder() {
|
|
|
74
74
|
ensureGlobalSymbol(node.id);
|
|
75
75
|
bind(node.id);
|
|
76
76
|
}
|
|
77
|
-
;
|
|
78
77
|
if (node.strict)
|
|
79
78
|
bind(node.strict);
|
|
80
79
|
bindChildren(node.statements);
|
|
@@ -102,7 +101,6 @@ function createBinder() {
|
|
|
102
101
|
if (node.id) {
|
|
103
102
|
bind(node.id);
|
|
104
103
|
}
|
|
105
|
-
;
|
|
106
104
|
bindChildren(node.statements);
|
|
107
105
|
}
|
|
108
106
|
function bindSubGraphStatement(node) {
|
package/lib/esm/checker.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type AttributeStatement, type EdgeRhs, type EdgeStatement, type Graph, type Identifier, type NodeId, type SourceFile, type Statement, type StatementOf, type SubGraphStatement, SyntaxKind, type SyntaxNode, type Token } from "./types.js";
|
|
2
2
|
export declare function checkSourceFile(file: SourceFile): void;
|
|
3
3
|
export declare function findNodeAtOffset(root: SyntaxNode, offset: number, inclusiveEnd?: boolean): SyntaxNode | undefined;
|
|
4
4
|
export declare function getAllowedEdgeOperation(graph: Graph): SyntaxKind.DirectedEdgeOp | SyntaxKind.UndirectedEdgeOp;
|
package/lib/esm/checker.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { shapes as validShapes } from "./service/languageFacts.js";
|
|
2
2
|
import { assertNever, getStart } from "./service/util.js";
|
|
3
|
+
import { DiagnosticCategory, SyntaxKind, } from "./types.js";
|
|
3
4
|
import { forEachChild } from "./visitor.js";
|
|
4
|
-
import { shapes as validShapes } from "./service/languageFacts.js";
|
|
5
5
|
export function checkSourceFile(file) {
|
|
6
6
|
const g = file.graph;
|
|
7
7
|
if (g) {
|
|
@@ -14,7 +14,7 @@ export function checkSourceFile(file) {
|
|
|
14
14
|
function getNarrowerNode(offset, prev, toCheck) {
|
|
15
15
|
const prevRange = prev.end - prev.pos;
|
|
16
16
|
if (toCheck.pos <= offset && offset <= toCheck.end) {
|
|
17
|
-
|
|
17
|
+
const nrange = toCheck.end - toCheck.pos;
|
|
18
18
|
if (nrange < prevRange) {
|
|
19
19
|
return toCheck;
|
|
20
20
|
}
|
|
@@ -44,7 +44,7 @@ function checkGraphSemantics(file, root) {
|
|
|
44
44
|
const expectedEdgeOp = getAllowedEdgeOperation(root);
|
|
45
45
|
const invalidEdgeRhses = findEdgeErrors(expectedEdgeOp, root);
|
|
46
46
|
const invalidShapes = checkShapeLabelValues(root);
|
|
47
|
-
const invalidEdgeDiagnostics = invalidEdgeRhses
|
|
47
|
+
const invalidEdgeDiagnostics = invalidEdgeRhses === undefined || invalidEdgeRhses.length === 0
|
|
48
48
|
? []
|
|
49
49
|
: createEdgeViolationDiagnostics(file, expectedEdgeOp, invalidEdgeRhses);
|
|
50
50
|
return [...invalidEdgeDiagnostics, ...invalidShapes];
|
|
@@ -62,7 +62,8 @@ function checkShapeLabelValues(root) {
|
|
|
62
62
|
const invalidShapes = [];
|
|
63
63
|
forEachAssignmentTransitive(root, assignment => {
|
|
64
64
|
const { leftId, rightId } = assignment;
|
|
65
|
-
if (leftId.kind !== SyntaxKind.TextIdentifier ||
|
|
65
|
+
if (leftId.kind !== SyntaxKind.TextIdentifier ||
|
|
66
|
+
rightId.kind !== SyntaxKind.TextIdentifier) {
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
68
69
|
const leftText = leftId.text.trim();
|
|
@@ -105,16 +106,16 @@ export function findOptionalSemicolons(node) {
|
|
|
105
106
|
return terminators.filter(t => !!t);
|
|
106
107
|
}
|
|
107
108
|
function isStatement(node) {
|
|
108
|
-
return node.kind === SyntaxKind.SubGraphStatement
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
109
|
+
return (node.kind === SyntaxKind.SubGraphStatement ||
|
|
110
|
+
node.kind === SyntaxKind.EdgeStatement ||
|
|
111
|
+
node.kind === SyntaxKind.NodeStatement ||
|
|
112
|
+
node.kind === SyntaxKind.IdEqualsIdStatement ||
|
|
113
|
+
node.kind === SyntaxKind.AttributeStatement);
|
|
113
114
|
}
|
|
114
115
|
export function findAllStatements(node, kind) {
|
|
115
116
|
const allStatements = [];
|
|
116
117
|
forEachChild(node, child => {
|
|
117
|
-
if ((kind === undefined && isStatement(child)) ||
|
|
118
|
+
if ((kind === undefined && isStatement(child)) || child.kind === kind) {
|
|
118
119
|
allStatements.push(child);
|
|
119
120
|
}
|
|
120
121
|
const childStatements = findAllStatements(child, kind);
|
|
@@ -129,7 +130,9 @@ function findEdgeErrors(expectedEdgeOp, node) {
|
|
|
129
130
|
? edges.filter(e => e.operation.kind !== expectedEdgeOp)
|
|
130
131
|
: undefined;
|
|
131
132
|
if (wrongEdges && wrongEdges.length > 0) {
|
|
132
|
-
|
|
133
|
+
for (const edge of wrongEdges) {
|
|
134
|
+
edge.operation.flags |= 2;
|
|
135
|
+
}
|
|
133
136
|
return wrongEdges;
|
|
134
137
|
}
|
|
135
138
|
return undefined;
|
|
@@ -140,7 +143,9 @@ function createEdgeViolationDiagnostics(file, expectedEdgeOp, violators) {
|
|
|
140
143
|
const message = `Invalid edge operation, use "${op}" in ${graphType} graph`;
|
|
141
144
|
const code = createCheckerError(0);
|
|
142
145
|
const category = DiagnosticCategory.Error;
|
|
143
|
-
|
|
146
|
+
for (const edge of violators) {
|
|
147
|
+
edge.operation.flags |= 2;
|
|
148
|
+
}
|
|
144
149
|
return violators.map(edge => {
|
|
145
150
|
const start = getStart(file, edge.operation);
|
|
146
151
|
const end = edge.operation.end;
|
|
@@ -177,9 +182,9 @@ export function isNodeId(node) {
|
|
|
177
182
|
return node.kind === SyntaxKind.NodeId;
|
|
178
183
|
}
|
|
179
184
|
export function edgeStatementHasAttributes(es) {
|
|
180
|
-
return es.attributes
|
|
181
|
-
|
|
182
|
-
|
|
185
|
+
return (es.attributes &&
|
|
186
|
+
es.attributes.length > 0 &&
|
|
187
|
+
es.attributes.some(a => a.assignments && a.assignments.length > 0));
|
|
183
188
|
}
|
|
184
189
|
export function getIdentifierText(n) {
|
|
185
190
|
switch (n.kind) {
|
package/lib/esm/core.js
CHANGED
package/lib/esm/error.js
CHANGED
|
@@ -2,9 +2,7 @@ export const diagnosicSource = "DOT";
|
|
|
2
2
|
const errorCodeLength = 4;
|
|
3
3
|
const subErrorCodeLength = errorCodeLength - 1;
|
|
4
4
|
export function formatError(error) {
|
|
5
|
-
const subCode = (error.sub | 0)
|
|
6
|
-
.toString()
|
|
7
|
-
.padStart(subErrorCodeLength, "0");
|
|
5
|
+
const subCode = (error.sub | 0).toString().padStart(subErrorCodeLength, "0");
|
|
8
6
|
return diagnosicSource + error.source + subCode;
|
|
9
7
|
}
|
|
10
8
|
//# sourceMappingURL=error.js.map
|