dot-language-support 1.5.4
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 +36 -0
- package/.github/workflows/CI.yml +33 -0
- package/LICENSE +21 -0
- package/README.md +17 -0
- package/lib/binder.d.ts +2 -0
- package/lib/binder.js +300 -0
- package/lib/checker.d.ts +14 -0
- package/lib/checker.js +185 -0
- package/lib/core.d.ts +1 -0
- package/lib/core.js +14 -0
- package/lib/error.d.ts +3 -0
- package/lib/error.js +14 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +19 -0
- package/lib/parser.d.ts +84 -0
- package/lib/parser.js +698 -0
- package/lib/scanner.d.ts +52 -0
- package/lib/scanner.js +580 -0
- package/lib/service/codeAction.d.ts +12 -0
- package/lib/service/codeAction.js +214 -0
- package/lib/service/colorProvider.d.ts +6 -0
- package/lib/service/colorProvider.js +74 -0
- package/lib/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.d.ts +10 -0
- package/lib/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.js +43 -0
- package/lib/service/command/ChangeEdgeOpCommand.d.ts +10 -0
- package/lib/service/command/ChangeEdgeOpCommand.js +37 -0
- package/lib/service/command/ConsolidateDescendantsCommand.d.ts +10 -0
- package/lib/service/command/ConsolidateDescendantsCommand.js +106 -0
- package/lib/service/command/RemoveSemicolons.d.ts +10 -0
- package/lib/service/command/RemoveSemicolons.js +42 -0
- package/lib/service/command/common.d.ts +31 -0
- package/lib/service/command/common.js +31 -0
- package/lib/service/completion.d.ts +4 -0
- package/lib/service/completion.js +141 -0
- package/lib/service/hover.d.ts +4 -0
- package/lib/service/hover.js +123 -0
- package/lib/service/interop.d.ts +15 -0
- package/lib/service/interop.js +56 -0
- package/lib/service/languageFacts.d.ts +659 -0
- package/lib/service/languageFacts.js +976 -0
- package/lib/service/polyfill.d.ts +16 -0
- package/lib/service/polyfill.js +3 -0
- package/lib/service/reference.d.ts +5 -0
- package/lib/service/reference.js +73 -0
- package/lib/service/rename.d.ts +4 -0
- package/lib/service/rename.js +49 -0
- package/lib/service/service.d.ts +27 -0
- package/lib/service/service.js +39 -0
- package/lib/service/util.d.ts +11 -0
- package/lib/service/util.js +52 -0
- package/lib/service/validation.d.ts +4 -0
- package/lib/service/validation.js +24 -0
- package/lib/types.d.ts +396 -0
- package/lib/types.js +74 -0
- package/lib/visitor.d.ts +2 -0
- package/lib/visitor.js +78 -0
- package/package.json +42 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeCommand = exports.getAvailableCommands = exports.getCodeActions = void 0;
|
|
4
|
+
const __1 = require("../");
|
|
5
|
+
const util_1 = require("./util");
|
|
6
|
+
const checker_1 = require("../checker");
|
|
7
|
+
const ChangeEdgeOpCommand = require("./command/ChangeEdgeOpCommand");
|
|
8
|
+
const ChangeAllOtherEdgeOpsAndFixGraphCommand = require("./command/ChangeAllOtherEdgeOpsAndFixGraphCommand");
|
|
9
|
+
const ConsolidateDescendantsCommand = require("./command/ConsolidateDescendantsCommand");
|
|
10
|
+
const RemoveSemicolonsCommand = require("./command/RemoveSemicolons");
|
|
11
|
+
const common_1 = require("./command/common");
|
|
12
|
+
function getCodeActions(doc, sourceFile, range, context) {
|
|
13
|
+
let actions = getActionsFromDiagnostics(doc, sourceFile, range);
|
|
14
|
+
const general = getGeneralRefactorings(doc, sourceFile, range);
|
|
15
|
+
if (general) {
|
|
16
|
+
if (!actions)
|
|
17
|
+
actions = general;
|
|
18
|
+
else
|
|
19
|
+
actions.push.apply(actions, general);
|
|
20
|
+
}
|
|
21
|
+
return actions;
|
|
22
|
+
}
|
|
23
|
+
exports.getCodeActions = getCodeActions;
|
|
24
|
+
function getActionsFromDiagnostics(doc, file, range) {
|
|
25
|
+
const ds = file.diagnostics;
|
|
26
|
+
if (!ds || ds.length === 0)
|
|
27
|
+
return undefined;
|
|
28
|
+
const rangeStartOffset = doc.offsetAt(range.start);
|
|
29
|
+
const rangeEndOffset = doc.offsetAt(range.end);
|
|
30
|
+
const res = [];
|
|
31
|
+
for (const d of ds) {
|
|
32
|
+
if (isInRange(rangeStartOffset, rangeEndOffset, d.start, d.end)) {
|
|
33
|
+
const commands = getCommandsForDiagnostic(doc, file, d);
|
|
34
|
+
if (commands && commands.length > 0)
|
|
35
|
+
res.push.apply(res, commands);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return res.length === 0 ? undefined : res;
|
|
39
|
+
}
|
|
40
|
+
function getGeneralRefactorings(doc, file, range) {
|
|
41
|
+
if (!file.graph)
|
|
42
|
+
return undefined;
|
|
43
|
+
const g = file.graph;
|
|
44
|
+
const kw = g.keyword;
|
|
45
|
+
const rangeStartOffset = doc.offsetAt(range.start);
|
|
46
|
+
const rangeEndOffset = doc.offsetAt(range.end);
|
|
47
|
+
const keywordStart = (0, util_1.getStart)(file, kw);
|
|
48
|
+
const res = [];
|
|
49
|
+
if (isInRange(rangeStartOffset, rangeEndOffset, keywordStart, kw.end)) {
|
|
50
|
+
if (!subtreeContainsErrors(g)) {
|
|
51
|
+
const oppositeGraphType = (0, common_1.getOppositeKind)(kw.kind);
|
|
52
|
+
const convertGraph = convertGraphTypeCommand(file, g, oppositeGraphType);
|
|
53
|
+
res.push(convertGraph);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (rangeStartOffset === rangeEndOffset) {
|
|
57
|
+
const candidates = [];
|
|
58
|
+
let clickedNode = (0, checker_1.findNodeAtOffset)(g, rangeStartOffset);
|
|
59
|
+
if (clickedNode && !!clickedNode.parent) {
|
|
60
|
+
if (clickedNode.kind === __1.SyntaxKind.SemicolonToken) {
|
|
61
|
+
res.push(RemoveSemicolonsCommand.create());
|
|
62
|
+
}
|
|
63
|
+
if ((0, __1.isIdentifierNode)(clickedNode)) {
|
|
64
|
+
clickedNode = clickedNode.parent;
|
|
65
|
+
}
|
|
66
|
+
const clickedEdgeStatement = clickedNode.parent;
|
|
67
|
+
if (clickedEdgeStatement && !subtreeContainsErrors(clickedEdgeStatement)) {
|
|
68
|
+
if ((0, checker_1.isEdgeStatement)(clickedEdgeStatement)
|
|
69
|
+
&& clickedEdgeStatement.rhs.length === 1
|
|
70
|
+
&& (0, checker_1.isNodeId)(clickedEdgeStatement.source)
|
|
71
|
+
&& !(0, checker_1.edgeStatementHasAttributes)(clickedEdgeStatement)) {
|
|
72
|
+
candidates.push(clickedEdgeStatement);
|
|
73
|
+
const source = clickedEdgeStatement.source;
|
|
74
|
+
const sourceText = (0, checker_1.getIdentifierText)(source.id);
|
|
75
|
+
const graphParent = clickedEdgeStatement.parent;
|
|
76
|
+
if (graphParent) {
|
|
77
|
+
let hasVisitedStatement = false;
|
|
78
|
+
let hasVisitedNodeModifier = false;
|
|
79
|
+
(0, __1.forEachChild)(graphParent, statement => {
|
|
80
|
+
if (statement === clickedEdgeStatement) {
|
|
81
|
+
hasVisitedStatement = true;
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
if (hasVisitedNodeModifier) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
else if (hasVisitedStatement) {
|
|
88
|
+
if ((0, checker_1.isAttrStatement)(statement)
|
|
89
|
+
|| subtreeContainsErrors(statement)) {
|
|
90
|
+
hasVisitedNodeModifier = true;
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (hasVisitedStatement) {
|
|
95
|
+
if ((0, checker_1.isEdgeStatement)(statement)
|
|
96
|
+
&& statement.rhs.length === 1
|
|
97
|
+
&& !(0, checker_1.edgeStatementHasAttributes)(statement)) {
|
|
98
|
+
const statementSource = statement.source;
|
|
99
|
+
if ((0, checker_1.isNodeId)(statementSource)) {
|
|
100
|
+
const lowerSourceText = (0, checker_1.getIdentifierText)(statementSource.id);
|
|
101
|
+
if (sourceText === lowerSourceText) {
|
|
102
|
+
candidates.push(statement);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (candidates.length > 1) {
|
|
112
|
+
const action = ConsolidateDescendantsCommand.create(candidates, true);
|
|
113
|
+
res.push(action);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return res.length === 0 ? undefined : res;
|
|
119
|
+
;
|
|
120
|
+
}
|
|
121
|
+
function getCommandsForDiagnostic(doc, file, d) {
|
|
122
|
+
switch (d.code.source) {
|
|
123
|
+
case 1: return getScannerErrorCommand(doc, file, d, d.code);
|
|
124
|
+
case 2: return getParserErrorCommand(doc, file, d, d.code);
|
|
125
|
+
case 4: return getCheckerErrorCommand(doc, file, d, d.code);
|
|
126
|
+
default: return (0, util_1.assertNever)(d.code);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function getScannerErrorCommand(doc, file, d, code) {
|
|
130
|
+
console.assert(d.code.source === 1);
|
|
131
|
+
console.assert(code.source === 1);
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
function getParserErrorCommand(doc, file, d, code) {
|
|
135
|
+
console.assert(d.code.source === 2);
|
|
136
|
+
console.assert(code.source === 2);
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
function getCheckerErrorCommand(doc, file, d, code) {
|
|
140
|
+
console.assert(d.code.source === 4);
|
|
141
|
+
console.assert(code.source === 4);
|
|
142
|
+
switch (code.sub) {
|
|
143
|
+
case 0: {
|
|
144
|
+
const graph = file.graph;
|
|
145
|
+
if (!graph)
|
|
146
|
+
return undefined;
|
|
147
|
+
const allowedOp = (0, checker_1.getAllowedEdgeOperation)(graph);
|
|
148
|
+
const wrongOp = (0, common_1.getOppositeEdgeOp)(allowedOp);
|
|
149
|
+
const kwk = graph.keyword.kind;
|
|
150
|
+
const fixSingleEdge = ChangeEdgeOpCommand.create(d.start, d.end, allowedOp, wrongOp);
|
|
151
|
+
const fixAll = convertGraphTypeCommand(file, graph, kwk);
|
|
152
|
+
const convertToThisWrongType = convertGraphTypeCommand(file, graph, (0, common_1.getOppositeKind)(kwk));
|
|
153
|
+
return [
|
|
154
|
+
fixSingleEdge,
|
|
155
|
+
fixAll,
|
|
156
|
+
convertToThisWrongType,
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function convertGraphTypeCommand(file, graph, changeToGraphType) {
|
|
162
|
+
const changeToEdgeOp = (0, common_1.getAllowedOp)(changeToGraphType);
|
|
163
|
+
const allEdges = (0, checker_1.findAllEdges)(graph);
|
|
164
|
+
const edgeOffsets = allEdges
|
|
165
|
+
.filter(e => e.operation.kind !== changeToEdgeOp)
|
|
166
|
+
.map(e => ({
|
|
167
|
+
start: (0, util_1.getStart)(file, e.operation),
|
|
168
|
+
end: e.operation.end
|
|
169
|
+
}));
|
|
170
|
+
const graphTypeOffset = {
|
|
171
|
+
start: (0, util_1.getStart)(file, graph.keyword),
|
|
172
|
+
end: graph.keyword.end
|
|
173
|
+
};
|
|
174
|
+
return ChangeAllOtherEdgeOpsAndFixGraphCommand.create(edgeOffsets, changeToEdgeOp, graphTypeOffset, graph.keyword.kind, changeToGraphType);
|
|
175
|
+
}
|
|
176
|
+
function isInRange(rangeStartOffset, rangeEndOffset, startOffset, endOffset) {
|
|
177
|
+
if (rangeStartOffset === rangeEndOffset)
|
|
178
|
+
return startOffset <= rangeStartOffset && rangeEndOffset <= endOffset;
|
|
179
|
+
if (rangeStartOffset === startOffset && rangeEndOffset === endOffset)
|
|
180
|
+
return true;
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
const commandHandlers = {
|
|
184
|
+
["DOT.changeEdgeOp"]: ChangeEdgeOpCommand.execute,
|
|
185
|
+
["DOT.convertGraphType"]: ChangeAllOtherEdgeOpsAndFixGraphCommand.execute,
|
|
186
|
+
["DOT.consolidateDescendants"]: ConsolidateDescendantsCommand.execute,
|
|
187
|
+
["DOT.removeSemicolons"]: RemoveSemicolonsCommand.execute,
|
|
188
|
+
};
|
|
189
|
+
function getAvailableCommands() {
|
|
190
|
+
return Object.keys(commandHandlers);
|
|
191
|
+
}
|
|
192
|
+
exports.getAvailableCommands = getAvailableCommands;
|
|
193
|
+
function executeCommand(doc, sourceFile, cmd) {
|
|
194
|
+
const handler = commandHandlers[cmd.command];
|
|
195
|
+
return handler === undefined
|
|
196
|
+
? undefined
|
|
197
|
+
: handler(doc, sourceFile, cmd);
|
|
198
|
+
}
|
|
199
|
+
exports.executeCommand = executeCommand;
|
|
200
|
+
function subtreeContainsErrors(node) {
|
|
201
|
+
if ((0, checker_1.nodeContainsErrors)(node))
|
|
202
|
+
return true;
|
|
203
|
+
let hasError = false;
|
|
204
|
+
(0, __1.forEachChild)(node, child => {
|
|
205
|
+
if ((0, checker_1.nodeContainsErrors)(child)) {
|
|
206
|
+
hasError = true;
|
|
207
|
+
}
|
|
208
|
+
if (!hasError) {
|
|
209
|
+
hasError = subtreeContainsErrors(child);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
return hasError;
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=codeAction.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as lst from "vscode-languageserver-types";
|
|
2
|
+
import { ColorInformation, Color, ColorPresentation } from "./polyfill";
|
|
3
|
+
import { SourceFile } from "../types";
|
|
4
|
+
import { DocumentLike } from "../";
|
|
5
|
+
export declare function getDocumentColors(doc: DocumentLike, sourceFile: SourceFile): ColorInformation[] | undefined;
|
|
6
|
+
export declare function getColorRepresentations(doc: DocumentLike, sourceFile: SourceFile, color: Color, range: lst.Range): ColorPresentation[] | undefined;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getColorRepresentations = exports.getDocumentColors = void 0;
|
|
4
|
+
const util_1 = require("./util");
|
|
5
|
+
const languageFacts = require("./languageFacts");
|
|
6
|
+
const colorMap = languageFacts.colors;
|
|
7
|
+
function getDocumentColors(doc, sourceFile) {
|
|
8
|
+
const cs = sourceFile.colors;
|
|
9
|
+
return cs
|
|
10
|
+
? colorTableToColorInformation(doc, sourceFile, cs)
|
|
11
|
+
: undefined;
|
|
12
|
+
}
|
|
13
|
+
exports.getDocumentColors = getDocumentColors;
|
|
14
|
+
function getColorRepresentations(doc, sourceFile, color, range) {
|
|
15
|
+
if (!color || !range)
|
|
16
|
+
return undefined;
|
|
17
|
+
const hexColor = getColorStringFromColor(color);
|
|
18
|
+
return [
|
|
19
|
+
{
|
|
20
|
+
label: '"' + hexColor + '"',
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
exports.getColorRepresentations = getColorRepresentations;
|
|
25
|
+
function colorTableToColorInformation(doc, sf, colors) {
|
|
26
|
+
if (!colors || colors.size === 0)
|
|
27
|
+
return [];
|
|
28
|
+
const res = [];
|
|
29
|
+
for (const [name, value] of colors) {
|
|
30
|
+
if (!name || !value)
|
|
31
|
+
continue;
|
|
32
|
+
const color = getColorFromName(name);
|
|
33
|
+
if (color) {
|
|
34
|
+
res.push({
|
|
35
|
+
range: (0, util_1.syntaxNodeToRange)(doc, sf, value.node),
|
|
36
|
+
color,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return res;
|
|
41
|
+
}
|
|
42
|
+
function getColorFromName(name) {
|
|
43
|
+
if (name.charAt(0) === "#")
|
|
44
|
+
return getHexCodeColor(name);
|
|
45
|
+
const colorAlias = colorMap[name];
|
|
46
|
+
return colorAlias
|
|
47
|
+
? getHexCodeColor(colorAlias)
|
|
48
|
+
: undefined;
|
|
49
|
+
}
|
|
50
|
+
function getHexCodeColor(colorCode) {
|
|
51
|
+
const hexCode = colorCode.charAt(0) === "#"
|
|
52
|
+
? colorCode.substring(1)
|
|
53
|
+
: colorCode;
|
|
54
|
+
const colorInt = parseInt(hexCode, 16);
|
|
55
|
+
return {
|
|
56
|
+
red: (colorInt >> 16 & 0xff) / 255.0,
|
|
57
|
+
green: (colorInt >> 8 & 0xff) / 255.0,
|
|
58
|
+
blue: (colorInt & 0xff) / 255.0,
|
|
59
|
+
alpha: hexCode.length === 8 ? (colorInt >> 24 & 0xff) / 255.0 : 1.0,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function getColorStringFromColor(c) {
|
|
63
|
+
const red = (c.red * 255) | 0;
|
|
64
|
+
const green = (c.green * 255) | 0;
|
|
65
|
+
const blue = (c.blue * 255) | 0;
|
|
66
|
+
return "#" + numberToPaddedString(red) + numberToPaddedString(green) + numberToPaddedString(blue);
|
|
67
|
+
}
|
|
68
|
+
function numberToPaddedString(n) {
|
|
69
|
+
const s = n.toString(16);
|
|
70
|
+
return (s.length === 1
|
|
71
|
+
? "0" + s
|
|
72
|
+
: s).toLowerCase();
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=colorProvider.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as lst from "vscode-languageserver-types";
|
|
2
|
+
import { CommandIds } from "../codeAction";
|
|
3
|
+
import { GraphTypeStr, Offset, EdgeOpStr, ExecutableCommand, EdgeType, GraphType } from "./common";
|
|
4
|
+
import { DocumentLike, SourceFile, CommandApplication } from "../../";
|
|
5
|
+
export interface ChangeAllOtherEdgeOpsAndFixGraphCommand extends lst.Command {
|
|
6
|
+
command: CommandIds.ConvertGraphType;
|
|
7
|
+
arguments: [Offset[], EdgeOpStr, Offset, GraphTypeStr];
|
|
8
|
+
}
|
|
9
|
+
export declare function create(edgeOffsets: Offset[], changeEdgesTo: EdgeType, graphOffset: Offset, changeFromGraph: GraphType, changeGraphTo: GraphType): ChangeAllOtherEdgeOpsAndFixGraphCommand;
|
|
10
|
+
export declare function execute(doc: DocumentLike, sourceFile: SourceFile, cmd: ExecutableCommand): CommandApplication | undefined;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execute = exports.create = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
function create(edgeOffsets, changeEdgesTo, graphOffset, changeFromGraph, changeGraphTo) {
|
|
6
|
+
const toGraph = (0, common_1.getGraphKeywordStr)(changeGraphTo);
|
|
7
|
+
const title = changeGraphTo === changeFromGraph
|
|
8
|
+
? `Fix all edges to match ${toGraph}`
|
|
9
|
+
: `Convert ${(0, common_1.getGraphKeywordStr)(changeFromGraph)} to ${toGraph}`;
|
|
10
|
+
const edgeStr = (0, common_1.getEdgeStr)(changeEdgesTo);
|
|
11
|
+
return {
|
|
12
|
+
title,
|
|
13
|
+
command: "DOT.convertGraphType",
|
|
14
|
+
arguments: [edgeOffsets, edgeStr, graphOffset, toGraph],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
exports.create = create;
|
|
18
|
+
function execute(doc, sourceFile, cmd) {
|
|
19
|
+
if (!isChangeAllOtherEdgeOpsAndFixGraphCommand(cmd))
|
|
20
|
+
return undefined;
|
|
21
|
+
const [edgeOffsets, changeEdgeTo, graphOffset, changeGraphTo] = cmd.arguments;
|
|
22
|
+
const edits = edgeOffsets.map(o => {
|
|
23
|
+
const startPos = doc.positionAt(o.start);
|
|
24
|
+
const endPos = doc.positionAt(o.end);
|
|
25
|
+
return (0, common_1.createChangeToEdit)(startPos, endPos, changeEdgeTo);
|
|
26
|
+
});
|
|
27
|
+
const graphStart = doc.positionAt(graphOffset.start);
|
|
28
|
+
const graphEnd = doc.positionAt(graphOffset.end);
|
|
29
|
+
edits.push((0, common_1.createChangeToEdit)(graphStart, graphEnd, changeGraphTo));
|
|
30
|
+
return {
|
|
31
|
+
label: `Convert graph to "${changeGraphTo}"`,
|
|
32
|
+
edit: {
|
|
33
|
+
changes: {
|
|
34
|
+
[doc.uri]: edits,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
exports.execute = execute;
|
|
40
|
+
function isChangeAllOtherEdgeOpsAndFixGraphCommand(cmd) {
|
|
41
|
+
return cmd.command === "DOT.convertGraphType" && !!cmd.arguments && cmd.arguments.length === 4;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=ChangeAllOtherEdgeOpsAndFixGraphCommand.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as lst from "vscode-languageserver-types";
|
|
2
|
+
import { CommandIds } from "../codeAction";
|
|
3
|
+
import { EdgeOpStr, ExecutableCommand, EdgeType } from "./common";
|
|
4
|
+
import { DocumentLike, SourceFile, CommandApplication } from "../../";
|
|
5
|
+
export interface ChangeEdgeOpCommand extends lst.Command {
|
|
6
|
+
command: CommandIds.ChangeEdgeOp;
|
|
7
|
+
arguments: [number, number, EdgeOpStr];
|
|
8
|
+
}
|
|
9
|
+
export declare function create(startOffset: number, endOffset: number, changeTo: EdgeType, changeFrom: EdgeType): ChangeEdgeOpCommand;
|
|
10
|
+
export declare function execute(doc: DocumentLike, sourceFile: SourceFile, cmd: ExecutableCommand): CommandApplication | undefined;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execute = exports.create = void 0;
|
|
4
|
+
const lst = require("vscode-languageserver-types");
|
|
5
|
+
const common_1 = require("./common");
|
|
6
|
+
function create(startOffset, endOffset, changeTo, changeFrom) {
|
|
7
|
+
const from = (0, common_1.getEdgeStr)(changeFrom);
|
|
8
|
+
const to = (0, common_1.getEdgeStr)(changeTo);
|
|
9
|
+
return {
|
|
10
|
+
title: `Change "${from}" to "${to}".`,
|
|
11
|
+
command: "DOT.changeEdgeOp",
|
|
12
|
+
arguments: [startOffset, endOffset, to],
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.create = create;
|
|
16
|
+
function execute(doc, sourceFile, cmd) {
|
|
17
|
+
if (!isChangeEdgeOpCommand(cmd))
|
|
18
|
+
return undefined;
|
|
19
|
+
const [startOffset, endOffset, changeTo] = cmd.arguments;
|
|
20
|
+
const startPos = doc.positionAt(startOffset);
|
|
21
|
+
const endPos = doc.positionAt(endOffset);
|
|
22
|
+
return {
|
|
23
|
+
label: `Change of invalid edge to "${changeTo}"'"`,
|
|
24
|
+
edit: {
|
|
25
|
+
changes: {
|
|
26
|
+
[doc.uri]: [
|
|
27
|
+
lst.TextEdit.replace(lst.Range.create(startPos, endPos), changeTo),
|
|
28
|
+
],
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.execute = execute;
|
|
34
|
+
function isChangeEdgeOpCommand(cmd) {
|
|
35
|
+
return cmd.command === "DOT.changeEdgeOp" && !!cmd.arguments && cmd.arguments.length === 3;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=ChangeEdgeOpCommand.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as lst from "vscode-languageserver-types";
|
|
2
|
+
import { CommandIds } from "../codeAction";
|
|
3
|
+
import { ExecutableCommand } from "./common";
|
|
4
|
+
import { DocumentLike, SourceFile, CommandApplication, EdgeStatement } from "../../";
|
|
5
|
+
export interface ConsolidateDescendantsCommand extends lst.Command {
|
|
6
|
+
command: CommandIds.ConsolidateDescendants;
|
|
7
|
+
arguments: number[];
|
|
8
|
+
}
|
|
9
|
+
export declare function create(statements: EdgeStatement[], below: boolean): ConsolidateDescendantsCommand;
|
|
10
|
+
export declare function execute(doc: DocumentLike, sourceFile: SourceFile, cmd: ExecutableCommand): CommandApplication | undefined;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.execute = exports.create = void 0;
|
|
15
|
+
const checker_1 = require("../../checker");
|
|
16
|
+
const util_1 = require("../util");
|
|
17
|
+
function create(statements, below) {
|
|
18
|
+
const first = statements[0];
|
|
19
|
+
const from = (0, checker_1.getIdentifierText)(first.source.id);
|
|
20
|
+
const title = below
|
|
21
|
+
? `Convert edges below from "${from}" to subgraph`
|
|
22
|
+
: `Convert edges from "${from}" to subgraph`;
|
|
23
|
+
return {
|
|
24
|
+
title,
|
|
25
|
+
command: "DOT.consolidateDescendants",
|
|
26
|
+
arguments: statements.map(s => s.pos),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.create = create;
|
|
30
|
+
function unbind(statements) {
|
|
31
|
+
const res = [];
|
|
32
|
+
for (const statement of statements) {
|
|
33
|
+
const { parent } = statement, copy = __rest(statement, ["parent"]);
|
|
34
|
+
}
|
|
35
|
+
return res;
|
|
36
|
+
}
|
|
37
|
+
function execute(doc, sourceFile, cmd) {
|
|
38
|
+
if (!isConsolidateDescendantsCommand(cmd))
|
|
39
|
+
return undefined;
|
|
40
|
+
const g = sourceFile.graph;
|
|
41
|
+
if (!g)
|
|
42
|
+
return undefined;
|
|
43
|
+
const candidateIndexes = cmd.arguments;
|
|
44
|
+
const candidates = candidateIndexes.map(i => (0, checker_1.findNodeAtOffset)(g, i).parent.parent);
|
|
45
|
+
const first = candidates.shift();
|
|
46
|
+
const from = (0, checker_1.getIdentifierText)(first.source.id);
|
|
47
|
+
const edits = [];
|
|
48
|
+
const firstRight = first.rhs[0];
|
|
49
|
+
const firstRightTargetStart = (0, util_1.getStart)(sourceFile, firstRight.target);
|
|
50
|
+
const firstRightTargetEnd = firstRight.target.end;
|
|
51
|
+
const contents = [
|
|
52
|
+
sourceFile.content.substring(firstRightTargetStart, firstRightTargetEnd)
|
|
53
|
+
];
|
|
54
|
+
for (const descendant of candidates) {
|
|
55
|
+
const rightItem = descendant.rhs[0];
|
|
56
|
+
const rightItemTarget = rightItem.target;
|
|
57
|
+
const rightItemTargetStart = rightItemTarget.pos;
|
|
58
|
+
const rightItemTargetEnd = rightItem.target.end;
|
|
59
|
+
const rightItemContent = sourceFile.content.substring(rightItemTargetStart, rightItemTargetEnd);
|
|
60
|
+
edits.push({
|
|
61
|
+
newText: "",
|
|
62
|
+
range: {
|
|
63
|
+
start: doc.positionAt(descendant.pos),
|
|
64
|
+
end: doc.positionAt(rightItemTargetStart),
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
edits.push({
|
|
68
|
+
newText: "",
|
|
69
|
+
range: {
|
|
70
|
+
start: doc.positionAt(rightItemTargetStart),
|
|
71
|
+
end: doc.positionAt(rightItemTargetEnd),
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
if (descendant.terminator !== undefined) {
|
|
75
|
+
edits.push({
|
|
76
|
+
newText: "",
|
|
77
|
+
range: {
|
|
78
|
+
start: doc.positionAt((0, util_1.getStart)(sourceFile, descendant.terminator)),
|
|
79
|
+
end: doc.positionAt(descendant.terminator.end),
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
contents.push(rightItemContent);
|
|
84
|
+
}
|
|
85
|
+
const toInsert = `{ ${contents.map(s => s.trim()).join(" ")} }`;
|
|
86
|
+
edits.push({
|
|
87
|
+
newText: toInsert,
|
|
88
|
+
range: {
|
|
89
|
+
start: doc.positionAt(firstRightTargetStart),
|
|
90
|
+
end: doc.positionAt(firstRightTargetEnd),
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
label: `Convert edges from "${from}" to subgraph.`,
|
|
95
|
+
edit: {
|
|
96
|
+
changes: {
|
|
97
|
+
[doc.uri]: edits,
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
exports.execute = execute;
|
|
103
|
+
function isConsolidateDescendantsCommand(cmd) {
|
|
104
|
+
return cmd.command === "DOT.consolidateDescendants" && !!cmd.arguments && cmd.arguments.length > 1;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=ConsolidateDescendantsCommand.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as lst from "vscode-languageserver-types";
|
|
2
|
+
import { CommandIds } from "../codeAction";
|
|
3
|
+
import { ExecutableCommand } from "./common";
|
|
4
|
+
import { DocumentLike, SourceFile, CommandApplication } from "../../";
|
|
5
|
+
export interface RemoveSemicolonsCommand extends lst.Command {
|
|
6
|
+
command: CommandIds.RemoveSemicolons;
|
|
7
|
+
arguments: undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare function create(): RemoveSemicolonsCommand;
|
|
10
|
+
export declare function execute(doc: DocumentLike, sourceFile: SourceFile, cmd: ExecutableCommand): CommandApplication | undefined;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execute = exports.create = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
const checker_1 = require("../../checker");
|
|
6
|
+
function create() {
|
|
7
|
+
return {
|
|
8
|
+
title: "Remove optional semicolons",
|
|
9
|
+
command: "DOT.removeSemicolons",
|
|
10
|
+
arguments: undefined,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
exports.create = create;
|
|
14
|
+
function execute(doc, sourceFile, cmd) {
|
|
15
|
+
if (!isRemoveSemicolonsCommand(cmd))
|
|
16
|
+
return undefined;
|
|
17
|
+
const g = sourceFile.graph;
|
|
18
|
+
if (!g)
|
|
19
|
+
return undefined;
|
|
20
|
+
const semicolons = (0, checker_1.findOptionalSemicolons)(g);
|
|
21
|
+
const edits = semicolons.map(s => {
|
|
22
|
+
const end = s.end;
|
|
23
|
+
const start = end - 1;
|
|
24
|
+
return (0, common_1.createChangeToEdit)(doc.positionAt(start), doc.positionAt(end), "");
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
label: `Remove optional semicolons`,
|
|
28
|
+
edit: {
|
|
29
|
+
changes: {
|
|
30
|
+
[doc.uri]: edits,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.execute = execute;
|
|
36
|
+
function isRemoveSemicolonsCommand(cmd) {
|
|
37
|
+
return cmd.command === "DOT.removeSemicolons"
|
|
38
|
+
&& (!cmd.arguments
|
|
39
|
+
|| cmd.arguments.length === 0
|
|
40
|
+
|| cmd.arguments.every(e => e === undefined));
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=RemoveSemicolons.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as lst from "vscode-languageserver-types";
|
|
2
|
+
import { SyntaxKind } from "../../";
|
|
3
|
+
import { CommandIds } from "../codeAction";
|
|
4
|
+
export declare function createChangeToEdit(start: lst.Position, end: lst.Position, changeTo: string): lst.TextEdit;
|
|
5
|
+
export interface Offset {
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
}
|
|
9
|
+
export declare type ExecutableCommand = {
|
|
10
|
+
command: CommandIds;
|
|
11
|
+
arguments?: any[];
|
|
12
|
+
};
|
|
13
|
+
export declare type EdgeOpStr = "--" | "->";
|
|
14
|
+
export declare function getEdgeStr(op: SyntaxKind.UndirectedEdgeOp): "--";
|
|
15
|
+
export declare function getEdgeStr(op: SyntaxKind.DirectedEdgeOp): "->";
|
|
16
|
+
export declare function getEdgeStr(op: SyntaxKind.DirectedEdgeOp | SyntaxKind.UndirectedEdgeOp): "->" | "--";
|
|
17
|
+
export declare type GraphTypeStr = "graph" | "digraph";
|
|
18
|
+
export declare function getGraphKeywordStr(g: SyntaxKind.GraphKeyword): "graph";
|
|
19
|
+
export declare function getGraphKeywordStr(g: SyntaxKind.DigraphKeyword): "digraph";
|
|
20
|
+
export declare function getGraphKeywordStr(g: GraphType): "digraph" | "graph";
|
|
21
|
+
export declare type GraphType = SyntaxKind.DigraphKeyword | SyntaxKind.GraphKeyword;
|
|
22
|
+
export declare function getOppositeKind(g: SyntaxKind.DigraphKeyword): SyntaxKind.GraphKeyword;
|
|
23
|
+
export declare function getOppositeKind(g: SyntaxKind.GraphKeyword): SyntaxKind.DigraphKeyword;
|
|
24
|
+
export declare function getOppositeKind(g: GraphType): GraphType;
|
|
25
|
+
export declare type EdgeType = SyntaxKind.DirectedEdgeOp | SyntaxKind.UndirectedEdgeOp;
|
|
26
|
+
export declare function getOppositeEdgeOp(g: SyntaxKind.DirectedEdgeOp): SyntaxKind.UndirectedEdgeOp;
|
|
27
|
+
export declare function getOppositeEdgeOp(g: SyntaxKind.UndirectedEdgeOp): SyntaxKind.DirectedEdgeOp;
|
|
28
|
+
export declare function getOppositeEdgeOp(g: EdgeType): EdgeType;
|
|
29
|
+
export declare function getAllowedOp(g: SyntaxKind.GraphKeyword): SyntaxKind.UndirectedEdgeOp;
|
|
30
|
+
export declare function getAllowedOp(g: SyntaxKind.DigraphKeyword): SyntaxKind.DirectedEdgeOp;
|
|
31
|
+
export declare function getAllowedOp(g: GraphType): EdgeType;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllowedOp = exports.getOppositeEdgeOp = exports.getOppositeKind = exports.getGraphKeywordStr = exports.getEdgeStr = exports.createChangeToEdit = void 0;
|
|
4
|
+
const lst = require("vscode-languageserver-types");
|
|
5
|
+
const __1 = require("../../");
|
|
6
|
+
function createChangeToEdit(start, end, changeTo) {
|
|
7
|
+
return lst.TextEdit.replace(lst.Range.create(start, end), changeTo);
|
|
8
|
+
}
|
|
9
|
+
exports.createChangeToEdit = createChangeToEdit;
|
|
10
|
+
;
|
|
11
|
+
function getEdgeStr(op) {
|
|
12
|
+
return op === __1.SyntaxKind.DirectedEdgeOp ? "->" : "--";
|
|
13
|
+
}
|
|
14
|
+
exports.getEdgeStr = getEdgeStr;
|
|
15
|
+
function getGraphKeywordStr(g) {
|
|
16
|
+
return g === __1.SyntaxKind.DigraphKeyword ? "digraph" : "graph";
|
|
17
|
+
}
|
|
18
|
+
exports.getGraphKeywordStr = getGraphKeywordStr;
|
|
19
|
+
function getOppositeKind(g) {
|
|
20
|
+
return g === __1.SyntaxKind.DigraphKeyword ? __1.SyntaxKind.GraphKeyword : __1.SyntaxKind.DigraphKeyword;
|
|
21
|
+
}
|
|
22
|
+
exports.getOppositeKind = getOppositeKind;
|
|
23
|
+
function getOppositeEdgeOp(g) {
|
|
24
|
+
return g === __1.SyntaxKind.DirectedEdgeOp ? __1.SyntaxKind.UndirectedEdgeOp : __1.SyntaxKind.DirectedEdgeOp;
|
|
25
|
+
}
|
|
26
|
+
exports.getOppositeEdgeOp = getOppositeEdgeOp;
|
|
27
|
+
function getAllowedOp(g) {
|
|
28
|
+
return g === __1.SyntaxKind.DigraphKeyword ? __1.SyntaxKind.DirectedEdgeOp : __1.SyntaxKind.UndirectedEdgeOp;
|
|
29
|
+
}
|
|
30
|
+
exports.getAllowedOp = getAllowedOp;
|
|
31
|
+
//# sourceMappingURL=common.js.map
|