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
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const RemoveSemicolonsCommand = require("./command/RemoveSemicolons");
|
|
11
|
-
const common_1 = require("./command/common");
|
|
12
|
-
function getCodeActions(doc, sourceFile, range, context) {
|
|
1
|
+
import { SyntaxKind, forEachChild, isIdentifierNode, } from "../index.js";
|
|
2
|
+
import { assertNever, getStart } from "./util.js";
|
|
3
|
+
import { getAllowedEdgeOperation, findAllEdges, findNodeAtOffset, isEdgeStatement, isNodeId, getIdentifierText, isAttrStatement, edgeStatementHasAttributes, nodeContainsErrors, } from "../checker.js";
|
|
4
|
+
import * as ChangeEdgeOpCommand from "./command/ChangeEdgeOpCommand.js";
|
|
5
|
+
import * as ChangeAllOtherEdgeOpsAndFixGraphCommand from "./command/ChangeAllOtherEdgeOpsAndFixGraphCommand.js";
|
|
6
|
+
import * as ConsolidateDescendantsCommand from "./command/ConsolidateDescendantsCommand.js";
|
|
7
|
+
import * as RemoveSemicolonsCommand from "./command/RemoveSemicolons.js";
|
|
8
|
+
import { getOppositeKind, getOppositeEdgeOp, getAllowedOp } from "./command/common.js";
|
|
9
|
+
export function getCodeActions(doc, sourceFile, range, _context) {
|
|
13
10
|
let actions = getActionsFromDiagnostics(doc, sourceFile, range);
|
|
14
11
|
const general = getGeneralRefactorings(doc, sourceFile, range);
|
|
15
12
|
if (general) {
|
|
@@ -20,7 +17,6 @@ function getCodeActions(doc, sourceFile, range, context) {
|
|
|
20
17
|
}
|
|
21
18
|
return actions;
|
|
22
19
|
}
|
|
23
|
-
exports.getCodeActions = getCodeActions;
|
|
24
20
|
function getActionsFromDiagnostics(doc, file, range) {
|
|
25
21
|
const ds = file.diagnostics;
|
|
26
22
|
if (!ds || ds.length === 0)
|
|
@@ -44,39 +40,39 @@ function getGeneralRefactorings(doc, file, range) {
|
|
|
44
40
|
const kw = g.keyword;
|
|
45
41
|
const rangeStartOffset = doc.offsetAt(range.start);
|
|
46
42
|
const rangeEndOffset = doc.offsetAt(range.end);
|
|
47
|
-
const keywordStart =
|
|
43
|
+
const keywordStart = getStart(file, kw);
|
|
48
44
|
const res = [];
|
|
49
45
|
if (isInRange(rangeStartOffset, rangeEndOffset, keywordStart, kw.end)) {
|
|
50
46
|
if (!subtreeContainsErrors(g)) {
|
|
51
|
-
const oppositeGraphType =
|
|
47
|
+
const oppositeGraphType = getOppositeKind(kw.kind);
|
|
52
48
|
const convertGraph = convertGraphTypeCommand(file, g, oppositeGraphType);
|
|
53
49
|
res.push(convertGraph);
|
|
54
50
|
}
|
|
55
51
|
}
|
|
56
52
|
if (rangeStartOffset === rangeEndOffset) {
|
|
57
53
|
const candidates = [];
|
|
58
|
-
let clickedNode =
|
|
54
|
+
let clickedNode = findNodeAtOffset(g, rangeStartOffset);
|
|
59
55
|
if (clickedNode && !!clickedNode.parent) {
|
|
60
|
-
if (clickedNode.kind ===
|
|
56
|
+
if (clickedNode.kind === SyntaxKind.SemicolonToken) {
|
|
61
57
|
res.push(RemoveSemicolonsCommand.create());
|
|
62
58
|
}
|
|
63
|
-
if (
|
|
59
|
+
if (isIdentifierNode(clickedNode)) {
|
|
64
60
|
clickedNode = clickedNode.parent;
|
|
65
61
|
}
|
|
66
62
|
const clickedEdgeStatement = clickedNode.parent;
|
|
67
63
|
if (clickedEdgeStatement && !subtreeContainsErrors(clickedEdgeStatement)) {
|
|
68
|
-
if (
|
|
64
|
+
if (isEdgeStatement(clickedEdgeStatement)
|
|
69
65
|
&& clickedEdgeStatement.rhs.length === 1
|
|
70
|
-
&&
|
|
71
|
-
&& !
|
|
66
|
+
&& isNodeId(clickedEdgeStatement.source)
|
|
67
|
+
&& !edgeStatementHasAttributes(clickedEdgeStatement)) {
|
|
72
68
|
candidates.push(clickedEdgeStatement);
|
|
73
69
|
const source = clickedEdgeStatement.source;
|
|
74
|
-
const sourceText =
|
|
70
|
+
const sourceText = getIdentifierText(source.id);
|
|
75
71
|
const graphParent = clickedEdgeStatement.parent;
|
|
76
72
|
if (graphParent) {
|
|
77
73
|
let hasVisitedStatement = false;
|
|
78
74
|
let hasVisitedNodeModifier = false;
|
|
79
|
-
|
|
75
|
+
forEachChild(graphParent, statement => {
|
|
80
76
|
if (statement === clickedEdgeStatement) {
|
|
81
77
|
hasVisitedStatement = true;
|
|
82
78
|
return undefined;
|
|
@@ -85,19 +81,19 @@ function getGeneralRefactorings(doc, file, range) {
|
|
|
85
81
|
return;
|
|
86
82
|
}
|
|
87
83
|
else if (hasVisitedStatement) {
|
|
88
|
-
if (
|
|
84
|
+
if (isAttrStatement(statement)
|
|
89
85
|
|| subtreeContainsErrors(statement)) {
|
|
90
86
|
hasVisitedNodeModifier = true;
|
|
91
87
|
return true;
|
|
92
88
|
}
|
|
93
89
|
}
|
|
94
90
|
if (hasVisitedStatement) {
|
|
95
|
-
if (
|
|
91
|
+
if (isEdgeStatement(statement)
|
|
96
92
|
&& statement.rhs.length === 1
|
|
97
|
-
&& !
|
|
93
|
+
&& !edgeStatementHasAttributes(statement)) {
|
|
98
94
|
const statementSource = statement.source;
|
|
99
|
-
if (
|
|
100
|
-
const lowerSourceText =
|
|
95
|
+
if (isNodeId(statementSource)) {
|
|
96
|
+
const lowerSourceText = getIdentifierText(statementSource.id);
|
|
101
97
|
if (sourceText === lowerSourceText) {
|
|
102
98
|
candidates.push(statement);
|
|
103
99
|
}
|
|
@@ -123,20 +119,20 @@ function getCommandsForDiagnostic(doc, file, d) {
|
|
|
123
119
|
case 1: return getScannerErrorCommand(doc, file, d, d.code);
|
|
124
120
|
case 2: return getParserErrorCommand(doc, file, d, d.code);
|
|
125
121
|
case 4: return getCheckerErrorCommand(doc, file, d, d.code);
|
|
126
|
-
default: return
|
|
122
|
+
default: return assertNever(d.code);
|
|
127
123
|
}
|
|
128
124
|
}
|
|
129
|
-
function getScannerErrorCommand(
|
|
125
|
+
function getScannerErrorCommand(_doc, _file, d, code) {
|
|
130
126
|
console.assert(d.code.source === 1);
|
|
131
127
|
console.assert(code.source === 1);
|
|
132
128
|
return undefined;
|
|
133
129
|
}
|
|
134
|
-
function getParserErrorCommand(
|
|
130
|
+
function getParserErrorCommand(_doc, _file, d, code) {
|
|
135
131
|
console.assert(d.code.source === 2);
|
|
136
132
|
console.assert(code.source === 2);
|
|
137
133
|
return undefined;
|
|
138
134
|
}
|
|
139
|
-
function getCheckerErrorCommand(
|
|
135
|
+
function getCheckerErrorCommand(_doc, file, d, code) {
|
|
140
136
|
console.assert(d.code.source === 4);
|
|
141
137
|
console.assert(code.source === 4);
|
|
142
138
|
switch (code.sub) {
|
|
@@ -144,12 +140,12 @@ function getCheckerErrorCommand(doc, file, d, code) {
|
|
|
144
140
|
const graph = file.graph;
|
|
145
141
|
if (!graph)
|
|
146
142
|
return undefined;
|
|
147
|
-
const allowedOp =
|
|
148
|
-
const wrongOp =
|
|
143
|
+
const allowedOp = getAllowedEdgeOperation(graph);
|
|
144
|
+
const wrongOp = getOppositeEdgeOp(allowedOp);
|
|
149
145
|
const kwk = graph.keyword.kind;
|
|
150
146
|
const fixSingleEdge = ChangeEdgeOpCommand.create(d.start, d.end, allowedOp, wrongOp);
|
|
151
147
|
const fixAll = convertGraphTypeCommand(file, graph, kwk);
|
|
152
|
-
const convertToThisWrongType = convertGraphTypeCommand(file, graph,
|
|
148
|
+
const convertToThisWrongType = convertGraphTypeCommand(file, graph, getOppositeKind(kwk));
|
|
153
149
|
return [
|
|
154
150
|
fixSingleEdge,
|
|
155
151
|
fixAll,
|
|
@@ -159,16 +155,16 @@ function getCheckerErrorCommand(doc, file, d, code) {
|
|
|
159
155
|
}
|
|
160
156
|
}
|
|
161
157
|
function convertGraphTypeCommand(file, graph, changeToGraphType) {
|
|
162
|
-
const changeToEdgeOp =
|
|
163
|
-
const allEdges =
|
|
158
|
+
const changeToEdgeOp = getAllowedOp(changeToGraphType);
|
|
159
|
+
const allEdges = findAllEdges(graph);
|
|
164
160
|
const edgeOffsets = allEdges
|
|
165
161
|
.filter(e => e.operation.kind !== changeToEdgeOp)
|
|
166
162
|
.map(e => ({
|
|
167
|
-
start:
|
|
163
|
+
start: getStart(file, e.operation),
|
|
168
164
|
end: e.operation.end
|
|
169
165
|
}));
|
|
170
166
|
const graphTypeOffset = {
|
|
171
|
-
start:
|
|
167
|
+
start: getStart(file, graph.keyword),
|
|
172
168
|
end: graph.keyword.end
|
|
173
169
|
};
|
|
174
170
|
return ChangeAllOtherEdgeOpsAndFixGraphCommand.create(edgeOffsets, changeToEdgeOp, graphTypeOffset, graph.keyword.kind, changeToGraphType);
|
|
@@ -186,23 +182,21 @@ const commandHandlers = {
|
|
|
186
182
|
["DOT.consolidateDescendants"]: ConsolidateDescendantsCommand.execute,
|
|
187
183
|
["DOT.removeSemicolons"]: RemoveSemicolonsCommand.execute,
|
|
188
184
|
};
|
|
189
|
-
function getAvailableCommands() {
|
|
185
|
+
export function getAvailableCommands() {
|
|
190
186
|
return Object.keys(commandHandlers);
|
|
191
187
|
}
|
|
192
|
-
|
|
193
|
-
function executeCommand(doc, sourceFile, cmd) {
|
|
188
|
+
export function executeCommand(doc, sourceFile, cmd) {
|
|
194
189
|
const handler = commandHandlers[cmd.command];
|
|
195
190
|
return handler === undefined
|
|
196
191
|
? undefined
|
|
197
192
|
: handler(doc, sourceFile, cmd);
|
|
198
193
|
}
|
|
199
|
-
exports.executeCommand = executeCommand;
|
|
200
194
|
function subtreeContainsErrors(node) {
|
|
201
|
-
if (
|
|
195
|
+
if (nodeContainsErrors(node))
|
|
202
196
|
return true;
|
|
203
197
|
let hasError = false;
|
|
204
|
-
|
|
205
|
-
if (
|
|
198
|
+
forEachChild(node, child => {
|
|
199
|
+
if (nodeContainsErrors(child)) {
|
|
206
200
|
hasError = true;
|
|
207
201
|
}
|
|
208
202
|
if (!hasError) {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ColorInformation, ColorPresentation, Range, Color } from "vscode-languageserver-types";
|
|
2
|
+
import { SourceFile } from "../types.js";
|
|
3
|
+
import { DocumentLike } from "../index.js";
|
|
4
|
+
export declare function getDocumentColors(doc: DocumentLike, sourceFile: SourceFile): ColorInformation[] | undefined;
|
|
5
|
+
export declare function getColorRepresentations(_doc: DocumentLike, _sourceFile: SourceFile, color: Color, range: Range): ColorPresentation[] | undefined;
|
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getColorRepresentations = exports.getDocumentColors = void 0;
|
|
4
|
-
const util_1 = require("./util");
|
|
5
|
-
const languageFacts = require("./languageFacts");
|
|
1
|
+
import { syntaxNodeToRange } from "./util.js";
|
|
2
|
+
import * as languageFacts from "./languageFacts.js";
|
|
6
3
|
const colorMap = languageFacts.colors;
|
|
7
|
-
function getDocumentColors(doc, sourceFile) {
|
|
4
|
+
export function getDocumentColors(doc, sourceFile) {
|
|
8
5
|
const cs = sourceFile.colors;
|
|
9
6
|
return cs
|
|
10
7
|
? colorTableToColorInformation(doc, sourceFile, cs)
|
|
11
8
|
: undefined;
|
|
12
9
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const hexColor = getColorStringFromColor(color);
|
|
18
|
-
return [
|
|
19
|
-
{
|
|
20
|
-
label: '"' + hexColor + '"',
|
|
21
|
-
}
|
|
22
|
-
];
|
|
10
|
+
export function getColorRepresentations(_doc, _sourceFile, color, range) {
|
|
11
|
+
return !color || !range
|
|
12
|
+
? undefined
|
|
13
|
+
: [{ label: '"' + getColorStringFromColor(color) + '"', }];
|
|
23
14
|
}
|
|
24
|
-
exports.getColorRepresentations = getColorRepresentations;
|
|
25
15
|
function colorTableToColorInformation(doc, sf, colors) {
|
|
26
16
|
if (!colors || colors.size === 0)
|
|
27
17
|
return [];
|
|
@@ -32,7 +22,7 @@ function colorTableToColorInformation(doc, sf, colors) {
|
|
|
32
22
|
const color = getColorFromName(name);
|
|
33
23
|
if (color) {
|
|
34
24
|
res.push({
|
|
35
|
-
range:
|
|
25
|
+
range: syntaxNodeToRange(doc, sf, value.node),
|
|
36
26
|
color,
|
|
37
27
|
});
|
|
38
28
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as lst from "vscode-languageserver-types";
|
|
2
|
+
import { CommandIds } from "../codeAction.js";
|
|
3
|
+
import { GraphTypeStr, Offset, EdgeOpStr, ExecutableCommand, EdgeType, GraphType } from "./common.js";
|
|
4
|
+
import { DocumentLike, SourceFile, CommandApplication } from "../../index.js";
|
|
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,38 @@
|
|
|
1
|
+
import { createChangeToEdit, getEdgeStr, getGraphKeywordStr } from "./common.js";
|
|
2
|
+
export function create(edgeOffsets, changeEdgesTo, graphOffset, changeFromGraph, changeGraphTo) {
|
|
3
|
+
const toGraph = getGraphKeywordStr(changeGraphTo);
|
|
4
|
+
const title = changeGraphTo === changeFromGraph
|
|
5
|
+
? `Fix all edges to match ${toGraph}`
|
|
6
|
+
: `Convert ${getGraphKeywordStr(changeFromGraph)} to ${toGraph}`;
|
|
7
|
+
const edgeStr = getEdgeStr(changeEdgesTo);
|
|
8
|
+
return {
|
|
9
|
+
title,
|
|
10
|
+
command: "DOT.convertGraphType",
|
|
11
|
+
arguments: [edgeOffsets, edgeStr, graphOffset, toGraph],
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function execute(doc, _sourceFile, cmd) {
|
|
15
|
+
if (!isChangeAllOtherEdgeOpsAndFixGraphCommand(cmd))
|
|
16
|
+
return undefined;
|
|
17
|
+
const [edgeOffsets, changeEdgeTo, graphOffset, changeGraphTo] = cmd.arguments;
|
|
18
|
+
const edits = edgeOffsets.map(o => {
|
|
19
|
+
const startPos = doc.positionAt(o.start);
|
|
20
|
+
const endPos = doc.positionAt(o.end);
|
|
21
|
+
return createChangeToEdit(startPos, endPos, changeEdgeTo);
|
|
22
|
+
});
|
|
23
|
+
const graphStart = doc.positionAt(graphOffset.start);
|
|
24
|
+
const graphEnd = doc.positionAt(graphOffset.end);
|
|
25
|
+
edits.push(createChangeToEdit(graphStart, graphEnd, changeGraphTo));
|
|
26
|
+
return {
|
|
27
|
+
label: `Convert graph to "${changeGraphTo}"`,
|
|
28
|
+
edit: {
|
|
29
|
+
changes: {
|
|
30
|
+
[doc.uri]: edits,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function isChangeAllOtherEdgeOpsAndFixGraphCommand(cmd) {
|
|
36
|
+
return cmd.command === "DOT.convertGraphType" && !!cmd.arguments && cmd.arguments.length === 4;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=ChangeAllOtherEdgeOpsAndFixGraphCommand.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as lst from "vscode-languageserver-types";
|
|
2
|
+
import { CommandIds } from "../codeAction.js";
|
|
3
|
+
import { EdgeOpStr, ExecutableCommand, EdgeType } from "./common.js";
|
|
4
|
+
import { DocumentLike, SourceFile, CommandApplication } from "../../index.js";
|
|
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;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
function create(startOffset, endOffset, changeTo, changeFrom) {
|
|
7
|
-
const from = (0, common_1.getEdgeStr)(changeFrom);
|
|
8
|
-
const to = (0, common_1.getEdgeStr)(changeTo);
|
|
1
|
+
import * as lst from "vscode-languageserver-types";
|
|
2
|
+
import { getEdgeStr } from "./common.js";
|
|
3
|
+
export function create(startOffset, endOffset, changeTo, changeFrom) {
|
|
4
|
+
const from = getEdgeStr(changeFrom);
|
|
5
|
+
const to = getEdgeStr(changeTo);
|
|
9
6
|
return {
|
|
10
7
|
title: `Change "${from}" to "${to}".`,
|
|
11
8
|
command: "DOT.changeEdgeOp",
|
|
12
9
|
arguments: [startOffset, endOffset, to],
|
|
13
10
|
};
|
|
14
11
|
}
|
|
15
|
-
|
|
16
|
-
function execute(doc, sourceFile, cmd) {
|
|
12
|
+
export function execute(doc, _sourceFile, cmd) {
|
|
17
13
|
if (!isChangeEdgeOpCommand(cmd))
|
|
18
14
|
return undefined;
|
|
19
15
|
const [startOffset, endOffset, changeTo] = cmd.arguments;
|
|
@@ -30,7 +26,6 @@ function execute(doc, sourceFile, cmd) {
|
|
|
30
26
|
}
|
|
31
27
|
};
|
|
32
28
|
}
|
|
33
|
-
exports.execute = execute;
|
|
34
29
|
function isChangeEdgeOpCommand(cmd) {
|
|
35
30
|
return cmd.command === "DOT.changeEdgeOp" && !!cmd.arguments && cmd.arguments.length === 3;
|
|
36
31
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as lst from "vscode-languageserver-types";
|
|
2
|
+
import { CommandIds } from "../codeAction.js";
|
|
3
|
+
import { ExecutableCommand } from "./common.js";
|
|
4
|
+
import { DocumentLike, SourceFile, CommandApplication, EdgeStatement } from "../../index.js";
|
|
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,83 @@
|
|
|
1
|
+
import { getIdentifierText, findNodeAtOffset } from "../../checker.js";
|
|
2
|
+
import { getStart } from "../util.js";
|
|
3
|
+
export function create(statements, below) {
|
|
4
|
+
const first = statements[0];
|
|
5
|
+
const from = getIdentifierText(first.source.id);
|
|
6
|
+
const title = below
|
|
7
|
+
? `Convert edges below from "${from}" to subgraph`
|
|
8
|
+
: `Convert edges from "${from}" to subgraph`;
|
|
9
|
+
return {
|
|
10
|
+
title,
|
|
11
|
+
command: "DOT.consolidateDescendants",
|
|
12
|
+
arguments: statements.map(s => s.pos),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function execute(doc, sourceFile, cmd) {
|
|
16
|
+
if (!isConsolidateDescendantsCommand(cmd))
|
|
17
|
+
return undefined;
|
|
18
|
+
const g = sourceFile.graph;
|
|
19
|
+
if (!g)
|
|
20
|
+
return undefined;
|
|
21
|
+
const candidateIndexes = cmd.arguments;
|
|
22
|
+
const candidates = candidateIndexes.map(i => findNodeAtOffset(g, i).parent.parent);
|
|
23
|
+
const first = candidates.shift();
|
|
24
|
+
const from = getIdentifierText(first.source.id);
|
|
25
|
+
const edits = [];
|
|
26
|
+
const firstRight = first.rhs[0];
|
|
27
|
+
const firstRightTargetStart = getStart(sourceFile, firstRight.target);
|
|
28
|
+
const firstRightTargetEnd = firstRight.target.end;
|
|
29
|
+
const contents = [
|
|
30
|
+
sourceFile.content.substring(firstRightTargetStart, firstRightTargetEnd)
|
|
31
|
+
];
|
|
32
|
+
for (const descendant of candidates) {
|
|
33
|
+
const rightItem = descendant.rhs[0];
|
|
34
|
+
const rightItemTarget = rightItem.target;
|
|
35
|
+
const rightItemTargetStart = rightItemTarget.pos;
|
|
36
|
+
const rightItemTargetEnd = rightItem.target.end;
|
|
37
|
+
const rightItemContent = sourceFile.content.substring(rightItemTargetStart, rightItemTargetEnd);
|
|
38
|
+
edits.push({
|
|
39
|
+
newText: "",
|
|
40
|
+
range: {
|
|
41
|
+
start: doc.positionAt(descendant.pos),
|
|
42
|
+
end: doc.positionAt(rightItemTargetStart),
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
edits.push({
|
|
46
|
+
newText: "",
|
|
47
|
+
range: {
|
|
48
|
+
start: doc.positionAt(rightItemTargetStart),
|
|
49
|
+
end: doc.positionAt(rightItemTargetEnd),
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
if (descendant.terminator !== undefined) {
|
|
53
|
+
edits.push({
|
|
54
|
+
newText: "",
|
|
55
|
+
range: {
|
|
56
|
+
start: doc.positionAt(getStart(sourceFile, descendant.terminator)),
|
|
57
|
+
end: doc.positionAt(descendant.terminator.end),
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
contents.push(rightItemContent);
|
|
62
|
+
}
|
|
63
|
+
const toInsert = `{ ${contents.map(s => s.trim()).join(" ")} }`;
|
|
64
|
+
edits.push({
|
|
65
|
+
newText: toInsert,
|
|
66
|
+
range: {
|
|
67
|
+
start: doc.positionAt(firstRightTargetStart),
|
|
68
|
+
end: doc.positionAt(firstRightTargetEnd),
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
label: `Convert edges from "${from}" to subgraph.`,
|
|
73
|
+
edit: {
|
|
74
|
+
changes: {
|
|
75
|
+
[doc.uri]: edits,
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function isConsolidateDescendantsCommand(cmd) {
|
|
81
|
+
return cmd.command === "DOT.consolidateDescendants" && !!cmd.arguments && cmd.arguments.length > 1;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=ConsolidateDescendantsCommand.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as lst from "vscode-languageserver-types";
|
|
2
|
+
import { CommandIds } from "../codeAction.js";
|
|
3
|
+
import { ExecutableCommand } from "./common.js";
|
|
4
|
+
import { DocumentLike, SourceFile, CommandApplication } from "../../index.js";
|
|
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,37 @@
|
|
|
1
|
+
import { createChangeToEdit } from "./common.js";
|
|
2
|
+
import { findOptionalSemicolons } from "../../checker.js";
|
|
3
|
+
export function create() {
|
|
4
|
+
return {
|
|
5
|
+
title: "Remove optional semicolons",
|
|
6
|
+
command: "DOT.removeSemicolons",
|
|
7
|
+
arguments: undefined,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export function execute(doc, sourceFile, cmd) {
|
|
11
|
+
if (!isRemoveSemicolonsCommand(cmd))
|
|
12
|
+
return undefined;
|
|
13
|
+
const g = sourceFile.graph;
|
|
14
|
+
if (!g)
|
|
15
|
+
return undefined;
|
|
16
|
+
const semicolons = findOptionalSemicolons(g);
|
|
17
|
+
const edits = semicolons.map(s => {
|
|
18
|
+
const end = s.end;
|
|
19
|
+
const start = end - 1;
|
|
20
|
+
return createChangeToEdit(doc.positionAt(start), doc.positionAt(end), "");
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
label: `Remove optional semicolons`,
|
|
24
|
+
edit: {
|
|
25
|
+
changes: {
|
|
26
|
+
[doc.uri]: edits,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function isRemoveSemicolonsCommand(cmd) {
|
|
32
|
+
return cmd.command === "DOT.removeSemicolons"
|
|
33
|
+
&& (!cmd.arguments
|
|
34
|
+
|| cmd.arguments.length === 0
|
|
35
|
+
|| cmd.arguments.every(e => e === undefined));
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=RemoveSemicolons.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TextEdit, type Position } from "vscode-languageserver-types";
|
|
2
|
+
import { SyntaxKind } from "../../index.js";
|
|
3
|
+
import { CommandIds } from "../codeAction.js";
|
|
4
|
+
export declare function createChangeToEdit(start: Position, end: Position, changeTo: string): 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,22 @@
|
|
|
1
|
+
import { TextEdit, Range } from "vscode-languageserver-types";
|
|
2
|
+
import { SyntaxKind } from "../../index.js";
|
|
3
|
+
export function createChangeToEdit(start, end, changeTo) {
|
|
4
|
+
return TextEdit.replace(Range.create(start, end), changeTo);
|
|
5
|
+
}
|
|
6
|
+
;
|
|
7
|
+
export function getEdgeStr(op) {
|
|
8
|
+
return op === SyntaxKind.DirectedEdgeOp ? "->" : "--";
|
|
9
|
+
}
|
|
10
|
+
export function getGraphKeywordStr(g) {
|
|
11
|
+
return g === SyntaxKind.DigraphKeyword ? "digraph" : "graph";
|
|
12
|
+
}
|
|
13
|
+
export function getOppositeKind(g) {
|
|
14
|
+
return g === SyntaxKind.DigraphKeyword ? SyntaxKind.GraphKeyword : SyntaxKind.DigraphKeyword;
|
|
15
|
+
}
|
|
16
|
+
export function getOppositeEdgeOp(g) {
|
|
17
|
+
return g === SyntaxKind.DirectedEdgeOp ? SyntaxKind.UndirectedEdgeOp : SyntaxKind.DirectedEdgeOp;
|
|
18
|
+
}
|
|
19
|
+
export function getAllowedOp(g) {
|
|
20
|
+
return g === SyntaxKind.DigraphKeyword ? SyntaxKind.DirectedEdgeOp : SyntaxKind.UndirectedEdgeOp;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=common.js.map
|