dot-language-support 1.6.2 → 2.0.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/.github/workflows/CD.yml +3 -3
- package/.github/workflows/CI.yml +2 -2
- package/README.md +5 -4
- package/jest.config.mjs +19 -0
- package/lib/{binder.d.ts → cjs/binder.d.ts} +1 -1
- package/lib/{binder.js → cjs/binder.js} +34 -34
- package/lib/{checker.d.ts → cjs/checker.d.ts} +1 -1
- package/lib/{checker.js → cjs/checker.js} +28 -28
- package/lib/{core.d.ts → cjs/core.d.ts} +0 -0
- package/lib/{core.js → cjs/core.js} +0 -0
- package/lib/{error.d.ts → cjs/error.d.ts} +1 -1
- package/lib/{error.js → cjs/error.js} +0 -0
- package/lib/cjs/index.d.ts +5 -0
- package/lib/{index.js → cjs/index.js} +5 -5
- package/lib/{parser.d.ts → cjs/parser.d.ts} +2 -2
- package/lib/{parser.js → cjs/parser.js} +14 -12
- package/lib/{scanner.d.ts → cjs/scanner.d.ts} +1 -1
- package/lib/{scanner.js → cjs/scanner.js} +67 -67
- package/lib/{service → cjs/service}/codeAction.d.ts +3 -3
- package/lib/cjs/service/codeAction.js +237 -0
- package/lib/cjs/service/colorProvider.d.ts +5 -0
- package/lib/cjs/service/colorProvider.js +92 -0
- package/lib/{service → cjs/service}/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.d.ts +4 -4
- package/lib/{service → cjs/service}/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.js +7 -7
- package/lib/{service → cjs/service}/command/ChangeEdgeOpCommand.d.ts +4 -4
- package/lib/cjs/service/command/ChangeEdgeOpCommand.js +60 -0
- package/lib/{service → cjs/service}/command/ConsolidateDescendantsCommand.d.ts +3 -3
- package/lib/{service → cjs/service}/command/ConsolidateDescendantsCommand.js +7 -25
- package/lib/{service → cjs/service}/command/RemoveSemicolons.d.ts +3 -3
- package/lib/{service → cjs/service}/command/RemoveSemicolons.js +4 -4
- package/lib/{service → cjs/service}/command/common.d.ts +4 -4
- package/lib/cjs/service/command/common.js +31 -0
- package/lib/{service → cjs/service}/completion.d.ts +2 -2
- package/lib/{service → cjs/service}/completion.js +49 -26
- package/lib/{service → cjs/service}/hover.d.ts +2 -2
- package/lib/{service → cjs/service}/hover.js +38 -38
- package/lib/{service → cjs/service}/languageFacts.d.ts +0 -0
- package/lib/{service → cjs/service}/languageFacts.js +0 -0
- package/lib/{service → cjs/service}/reference.d.ts +2 -2
- package/lib/{service → cjs/service}/reference.js +9 -11
- package/lib/{service → cjs/service}/rename.d.ts +2 -2
- package/lib/{service → cjs/service}/rename.js +11 -11
- package/lib/{service → cjs/service}/service.d.ts +2 -2
- package/lib/cjs/service/service.js +39 -0
- package/lib/cjs/service/util.d.ts +11 -0
- package/lib/{service → cjs/service}/util.js +7 -7
- package/lib/{service → cjs/service}/validation.d.ts +2 -2
- package/lib/{service → cjs/service}/validation.js +3 -3
- package/lib/cjs/tester.d.ts +1 -0
- package/lib/cjs/tester.js +23 -0
- package/lib/{types.d.ts → cjs/types.d.ts} +0 -0
- package/lib/{types.js → cjs/types.js} +0 -0
- package/lib/{visitor.d.ts → cjs/visitor.d.ts} +1 -1
- package/lib/{visitor.js → cjs/visitor.js} +17 -17
- package/lib/esm/binder.d.ts +2 -0
- package/lib/esm/binder.js +296 -0
- package/lib/esm/checker.d.ts +14 -0
- package/lib/esm/checker.js +169 -0
- package/lib/esm/core.d.ts +1 -0
- package/lib/esm/core.js +10 -0
- package/lib/esm/error.d.ts +3 -0
- package/lib/esm/error.js +10 -0
- package/lib/esm/index.d.ts +5 -0
- package/lib/esm/index.js +6 -0
- package/lib/esm/parser.d.ts +84 -0
- package/lib/esm/parser.js +700 -0
- package/lib/esm/scanner.d.ts +52 -0
- package/lib/esm/scanner.js +581 -0
- package/lib/esm/service/codeAction.d.ts +12 -0
- package/lib/{service → esm/service}/codeAction.js +40 -46
- package/lib/esm/service/colorProvider.d.ts +5 -0
- package/lib/{service → esm/service}/colorProvider.js +8 -18
- package/lib/esm/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.d.ts +10 -0
- package/lib/esm/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.js +38 -0
- package/lib/esm/service/command/ChangeEdgeOpCommand.d.ts +10 -0
- package/lib/{service → esm/service}/command/ChangeEdgeOpCommand.js +6 -11
- package/lib/esm/service/command/ConsolidateDescendantsCommand.d.ts +10 -0
- package/lib/esm/service/command/ConsolidateDescendantsCommand.js +83 -0
- package/lib/esm/service/command/RemoveSemicolons.d.ts +10 -0
- package/lib/esm/service/command/RemoveSemicolons.js +37 -0
- package/lib/esm/service/command/common.d.ts +31 -0
- package/lib/esm/service/command/common.js +22 -0
- package/lib/esm/service/completion.d.ts +4 -0
- package/lib/esm/service/completion.js +137 -0
- package/lib/esm/service/hover.d.ts +4 -0
- package/lib/esm/service/hover.js +119 -0
- package/lib/esm/service/languageFacts.d.ts +683 -0
- package/lib/esm/service/languageFacts.js +997 -0
- package/lib/esm/service/reference.d.ts +5 -0
- package/lib/esm/service/reference.js +66 -0
- package/lib/esm/service/rename.d.ts +4 -0
- package/lib/esm/service/rename.js +45 -0
- package/lib/esm/service/service.d.ts +28 -0
- package/lib/esm/service/service.js +35 -0
- package/lib/esm/service/util.d.ts +11 -0
- package/lib/esm/service/util.js +44 -0
- package/lib/esm/service/validation.d.ts +4 -0
- package/lib/esm/service/validation.js +20 -0
- package/lib/esm/tester.d.ts +1 -0
- package/lib/esm/tester.js +21 -0
- package/lib/esm/types.d.ts +396 -0
- package/lib/esm/types.js +71 -0
- package/lib/esm/visitor.d.ts +2 -0
- package/lib/esm/visitor.js +74 -0
- package/package.json +13 -11
- package/lib/index.d.ts +0 -5
- package/lib/service/colorProvider.d.ts +0 -6
- package/lib/service/command/common.js +0 -31
- package/lib/service/polyfill.d.ts +0 -16
- package/lib/service/polyfill.js +0 -3
- package/lib/service/service.js +0 -39
- package/lib/service/util.d.ts +0 -11
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SyntaxNode, Identifier, SyntaxKind, Graph, EdgeStatement, EdgeRhs, SourceFile, SubGraphStatement, NodeId, AttributeStatement, Statement, StatementOf, Token } from "./types.js";
|
|
2
|
+
export declare function checkSourceFile(file: SourceFile): void;
|
|
3
|
+
export declare function findNodeAtOffset(root: SyntaxNode, offset: number, inclusiveEnd?: boolean): SyntaxNode | undefined;
|
|
4
|
+
export declare function getAllowedEdgeOperation(graph: Graph): SyntaxKind.DirectedEdgeOp | SyntaxKind.UndirectedEdgeOp;
|
|
5
|
+
export declare function findAllEdges(node: SyntaxNode): EdgeRhs[];
|
|
6
|
+
export declare function findOptionalSemicolons(node: SyntaxNode): Token<SyntaxKind.SemicolonToken>[];
|
|
7
|
+
export declare function findAllStatements<T extends Statement["kind"]>(node: SyntaxNode, kind?: T): StatementOf<T>[];
|
|
8
|
+
export declare function isAttrStatement(node: SyntaxNode): node is AttributeStatement;
|
|
9
|
+
export declare function isEdgeStatement(node: SyntaxNode): node is EdgeStatement;
|
|
10
|
+
export declare function isSubGraphStatement(node: SyntaxNode): node is SubGraphStatement;
|
|
11
|
+
export declare function isNodeId(node: SyntaxNode): node is NodeId;
|
|
12
|
+
export declare function edgeStatementHasAttributes(es: EdgeStatement): boolean;
|
|
13
|
+
export declare function getIdentifierText(n: Identifier): string;
|
|
14
|
+
export declare function nodeContainsErrors(node: SyntaxNode): boolean;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { SyntaxKind, DiagnosticCategory, } from "./types.js";
|
|
2
|
+
import { assertNever, getStart } from "./service/util.js";
|
|
3
|
+
import { forEachChild } from "./visitor.js";
|
|
4
|
+
export function checkSourceFile(file) {
|
|
5
|
+
const g = file.graph;
|
|
6
|
+
if (g) {
|
|
7
|
+
const messages = checkGraphSemantics(file, g);
|
|
8
|
+
if (messages) {
|
|
9
|
+
file.diagnostics.push.apply(file.diagnostics, messages);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function getNarrowerNode(offset, prev, toCheck) {
|
|
14
|
+
const prevRange = prev.end - prev.pos;
|
|
15
|
+
if (toCheck.pos <= offset && offset <= toCheck.end) {
|
|
16
|
+
let nrange = toCheck.end - toCheck.pos;
|
|
17
|
+
if (nrange < prevRange) {
|
|
18
|
+
return toCheck;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return prev;
|
|
22
|
+
}
|
|
23
|
+
function rangeContainsOffset(range, offset, inclusiveEnd) {
|
|
24
|
+
return inclusiveEnd
|
|
25
|
+
? range.pos <= offset && offset <= range.end
|
|
26
|
+
: range.pos <= offset && offset < range.end;
|
|
27
|
+
}
|
|
28
|
+
export function findNodeAtOffset(root, offset, inclusiveEnd = false) {
|
|
29
|
+
if (root.pos === offset && root.pos === root.end)
|
|
30
|
+
return root;
|
|
31
|
+
if (rangeContainsOffset(root, offset, inclusiveEnd)) {
|
|
32
|
+
const narrowerChild = forEachChild(root, child => findNodeAtOffset(child, offset, inclusiveEnd));
|
|
33
|
+
return narrowerChild ? narrowerChild : root;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
export function getAllowedEdgeOperation(graph) {
|
|
38
|
+
return graph.kind === SyntaxKind.DirectedGraph
|
|
39
|
+
? SyntaxKind.DirectedEdgeOp
|
|
40
|
+
: SyntaxKind.UndirectedEdgeOp;
|
|
41
|
+
}
|
|
42
|
+
function checkGraphSemantics(file, root) {
|
|
43
|
+
const expectedEdgeOp = getAllowedEdgeOperation(root);
|
|
44
|
+
const invalidEdgeRhses = findEdgeErrors(expectedEdgeOp, root);
|
|
45
|
+
return invalidEdgeRhses == undefined || invalidEdgeRhses.length === 0
|
|
46
|
+
? undefined
|
|
47
|
+
: createEdgeViolationDiagnostics(file, expectedEdgeOp, invalidEdgeRhses);
|
|
48
|
+
}
|
|
49
|
+
export function findAllEdges(node) {
|
|
50
|
+
const allEdges = [];
|
|
51
|
+
forEachChild(node, child => {
|
|
52
|
+
if (isEdgeStatement(child)) {
|
|
53
|
+
if (child.rhs && child.rhs.length > 0) {
|
|
54
|
+
for (const edgeRhs of child.rhs)
|
|
55
|
+
allEdges.push(edgeRhs);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const childEdges = findAllEdges(child);
|
|
59
|
+
if (childEdges && childEdges.length > 0)
|
|
60
|
+
allEdges.push.apply(allEdges, childEdges);
|
|
61
|
+
});
|
|
62
|
+
return allEdges;
|
|
63
|
+
}
|
|
64
|
+
export function findOptionalSemicolons(node) {
|
|
65
|
+
const statements = findAllStatements(node);
|
|
66
|
+
const terminators = statements.map(p => p.terminator);
|
|
67
|
+
return terminators.filter(t => !!t);
|
|
68
|
+
}
|
|
69
|
+
function isStatement(node) {
|
|
70
|
+
return node.kind === SyntaxKind.SubGraphStatement
|
|
71
|
+
|| node.kind === SyntaxKind.EdgeStatement
|
|
72
|
+
|| node.kind === SyntaxKind.NodeStatement
|
|
73
|
+
|| node.kind === SyntaxKind.IdEqualsIdStatement
|
|
74
|
+
|| node.kind === SyntaxKind.AttributeStatement;
|
|
75
|
+
}
|
|
76
|
+
export function findAllStatements(node, kind) {
|
|
77
|
+
const allStatements = [];
|
|
78
|
+
forEachChild(node, child => {
|
|
79
|
+
if ((kind === undefined && isStatement(child)) || (child.kind === kind)) {
|
|
80
|
+
allStatements.push(child);
|
|
81
|
+
}
|
|
82
|
+
const childStatements = findAllStatements(child, kind);
|
|
83
|
+
if (childStatements && childStatements.length > 0)
|
|
84
|
+
allStatements.push.apply(allStatements, childStatements);
|
|
85
|
+
});
|
|
86
|
+
return allStatements;
|
|
87
|
+
}
|
|
88
|
+
function findEdgeErrors(expectedEdgeOp, node) {
|
|
89
|
+
const edges = findAllEdges(node);
|
|
90
|
+
const wrongEdges = edges && edges.length > 0
|
|
91
|
+
? edges.filter(e => e.operation.kind !== expectedEdgeOp)
|
|
92
|
+
: undefined;
|
|
93
|
+
if (wrongEdges && wrongEdges.length > 0) {
|
|
94
|
+
wrongEdges.forEach(e => e.operation.flags |= 2);
|
|
95
|
+
return wrongEdges;
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
function createEdgeViolationDiagnostics(file, expectedEdgeOp, violators) {
|
|
100
|
+
const op = expectedEdgeOp === SyntaxKind.UndirectedEdgeOp ? "--" : "->";
|
|
101
|
+
const graphType = expectedEdgeOp === SyntaxKind.UndirectedEdgeOp ? "undirected" : "directed";
|
|
102
|
+
const message = `Invalid edge operation, use "${op}" in ${graphType} graph`;
|
|
103
|
+
const code = createCheckerError(0);
|
|
104
|
+
const category = DiagnosticCategory.Error;
|
|
105
|
+
violators.forEach(edge => edge.operation.flags |= 2);
|
|
106
|
+
return violators.map(edge => {
|
|
107
|
+
const start = getStart(file, edge.operation);
|
|
108
|
+
const end = edge.operation.end;
|
|
109
|
+
return {
|
|
110
|
+
message,
|
|
111
|
+
code,
|
|
112
|
+
category,
|
|
113
|
+
start,
|
|
114
|
+
end,
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function getInvalidEdgeRhs(allowedOp, edges) {
|
|
119
|
+
const res = [];
|
|
120
|
+
for (const e of edges) {
|
|
121
|
+
if (e.operation.kind !== allowedOp)
|
|
122
|
+
res.push(e);
|
|
123
|
+
}
|
|
124
|
+
return res;
|
|
125
|
+
}
|
|
126
|
+
export function isAttrStatement(node) {
|
|
127
|
+
return node.kind === SyntaxKind.AttributeStatement;
|
|
128
|
+
}
|
|
129
|
+
export function isEdgeStatement(node) {
|
|
130
|
+
return node.kind === SyntaxKind.EdgeStatement;
|
|
131
|
+
}
|
|
132
|
+
export function isSubGraphStatement(node) {
|
|
133
|
+
return node.kind === SyntaxKind.SubGraphStatement;
|
|
134
|
+
}
|
|
135
|
+
function isGraph(node) {
|
|
136
|
+
return node.kind === SyntaxKind.DirectedGraph || node.kind === SyntaxKind.UndirectedGraph;
|
|
137
|
+
}
|
|
138
|
+
export function isNodeId(node) {
|
|
139
|
+
return node.kind === SyntaxKind.NodeId;
|
|
140
|
+
}
|
|
141
|
+
export function edgeStatementHasAttributes(es) {
|
|
142
|
+
return es.attributes
|
|
143
|
+
&& es.attributes.length > 0
|
|
144
|
+
&& es.attributes.some(a => a.assignments && a.assignments.length > 0);
|
|
145
|
+
}
|
|
146
|
+
export function getIdentifierText(n) {
|
|
147
|
+
switch (n.kind) {
|
|
148
|
+
case SyntaxKind.HtmlIdentifier:
|
|
149
|
+
return n.htmlContent;
|
|
150
|
+
case SyntaxKind.TextIdentifier:
|
|
151
|
+
return n.text;
|
|
152
|
+
case SyntaxKind.NumericIdentifier:
|
|
153
|
+
return n.text;
|
|
154
|
+
case SyntaxKind.QuotedTextIdentifier:
|
|
155
|
+
return n.concatenation;
|
|
156
|
+
default:
|
|
157
|
+
return assertNever(n);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function createCheckerError(sub) {
|
|
161
|
+
return {
|
|
162
|
+
source: 4,
|
|
163
|
+
sub,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
export function nodeContainsErrors(node) {
|
|
167
|
+
return (node.flags & 2) === 2;
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=checker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createMapFromTemplate<T>(template: Record<string, T>): Map<string, T>;
|
package/lib/esm/core.js
ADDED
package/lib/esm/error.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const diagnosicSource = "DOT";
|
|
2
|
+
const errorCodeLength = 4;
|
|
3
|
+
const subErrorCodeLength = errorCodeLength - 1;
|
|
4
|
+
export function formatError(error) {
|
|
5
|
+
const subCode = (error.sub | 0)
|
|
6
|
+
.toString()
|
|
7
|
+
.padStart(subErrorCodeLength, "0");
|
|
8
|
+
return diagnosicSource + error.source + subCode;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=error.js.map
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Scanner } from "./scanner.js";
|
|
2
|
+
import { SyntaxKind, SourceFile, Identifier, SyntaxNode, DiagnosticMessage } from "./types";
|
|
3
|
+
export declare enum ParsingContext {
|
|
4
|
+
None = 0,
|
|
5
|
+
StatementList = 1,
|
|
6
|
+
AttributeContainerList = 2,
|
|
7
|
+
AssignmentList = 3,
|
|
8
|
+
EdgeRhsList = 4,
|
|
9
|
+
QuotedTextIdentifierConcatenation = 5,
|
|
10
|
+
Count = 6
|
|
11
|
+
}
|
|
12
|
+
export declare class Parser {
|
|
13
|
+
currentToken: SyntaxKind;
|
|
14
|
+
nodeCount: number;
|
|
15
|
+
identifiers: Set<string>;
|
|
16
|
+
identifierCount: number;
|
|
17
|
+
sourceText: string;
|
|
18
|
+
scanner: Scanner;
|
|
19
|
+
currentNodeHasError: boolean;
|
|
20
|
+
currentContext: ParsingContext;
|
|
21
|
+
diagnostics: DiagnosticMessage[];
|
|
22
|
+
constructor();
|
|
23
|
+
private resetState;
|
|
24
|
+
private nextToken;
|
|
25
|
+
private token;
|
|
26
|
+
private getLinesFromFile;
|
|
27
|
+
parse(sourceText: string): SourceFile;
|
|
28
|
+
private parseGraph;
|
|
29
|
+
private parseIdentifier;
|
|
30
|
+
private registerIdentifier;
|
|
31
|
+
private parseTextIdentifier;
|
|
32
|
+
private parseQuotedTextIdentifierConcatenation;
|
|
33
|
+
private parseQuotedTextIdentifier;
|
|
34
|
+
private isQuotedStringFollowing;
|
|
35
|
+
private parseHtmlIdentifier;
|
|
36
|
+
private parseNumericIdentifier;
|
|
37
|
+
private parseStatement;
|
|
38
|
+
private parseAttributeStatement;
|
|
39
|
+
private parseAttributeContainer;
|
|
40
|
+
private isAssignmentStart;
|
|
41
|
+
private parseIdEqualsIdStatement;
|
|
42
|
+
private isIdEqualsIdStatement;
|
|
43
|
+
private parseNodeStatement;
|
|
44
|
+
private parseEdgeStatement;
|
|
45
|
+
private parseEdgeRhs;
|
|
46
|
+
private createMissingNode;
|
|
47
|
+
private parseAssignment;
|
|
48
|
+
private parseSubGraph;
|
|
49
|
+
private parseNodeId;
|
|
50
|
+
private parseCompassPortDeclaration;
|
|
51
|
+
private parseNormalPortDeclaration;
|
|
52
|
+
private parsePortDeclaration;
|
|
53
|
+
private isCompassPort;
|
|
54
|
+
private parseList;
|
|
55
|
+
private getContextParseError;
|
|
56
|
+
private isInSomeParsingContext;
|
|
57
|
+
private abortListParsing;
|
|
58
|
+
private isListElement;
|
|
59
|
+
private isListTerminator;
|
|
60
|
+
private createEmptyArray;
|
|
61
|
+
private finishNode;
|
|
62
|
+
private createNode;
|
|
63
|
+
private createNodeArray;
|
|
64
|
+
private parseTokenNode;
|
|
65
|
+
private getLastError;
|
|
66
|
+
private parseErrorAtPosition;
|
|
67
|
+
private parseErrorAtCurrentToken;
|
|
68
|
+
private scanError;
|
|
69
|
+
private reportExpectedError;
|
|
70
|
+
private parseExpectedOneOf;
|
|
71
|
+
private parseExpectedTokenOneOf;
|
|
72
|
+
private parseExpectedToken;
|
|
73
|
+
private parseExpected;
|
|
74
|
+
private parseOptionalToken;
|
|
75
|
+
private parseOptional;
|
|
76
|
+
private isEdgeOp;
|
|
77
|
+
private isIdentifier;
|
|
78
|
+
private isCompassPortKind;
|
|
79
|
+
private speculationHelper;
|
|
80
|
+
private lookAhead;
|
|
81
|
+
private tryParse;
|
|
82
|
+
}
|
|
83
|
+
export declare function isIdentifier(kind: SyntaxKind): boolean;
|
|
84
|
+
export declare function isIdentifierNode(node: SyntaxNode): node is Identifier;
|