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,11 +1,11 @@
|
|
|
1
|
+
import { edgeStatementHasAttributes, findAllEdges, findNodeAtOffset, getAllowedEdgeOperation, getIdentifierText, isAttrStatement, isEdgeStatement, isNodeId, nodeContainsErrors, } from "../checker.js";
|
|
1
2
|
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
3
|
import * as ChangeAllOtherEdgeOpsAndFixGraphCommand from "./command/ChangeAllOtherEdgeOpsAndFixGraphCommand.js";
|
|
4
|
+
import * as ChangeEdgeOpCommand from "./command/ChangeEdgeOpCommand.js";
|
|
6
5
|
import * as ConsolidateDescendantsCommand from "./command/ConsolidateDescendantsCommand.js";
|
|
7
6
|
import * as RemoveSemicolonsCommand from "./command/RemoveSemicolons.js";
|
|
8
|
-
import {
|
|
7
|
+
import { getAllowedOp, getOppositeEdgeOp, getOppositeKind, } from "./command/common.js";
|
|
8
|
+
import { assertNever, getStart } from "./util.js";
|
|
9
9
|
export function getCodeActions(doc, sourceFile, range, _context) {
|
|
10
10
|
let actions = getActionsFromDiagnostics(doc, sourceFile, range);
|
|
11
11
|
const general = getGeneralRefactorings(doc, sourceFile, range);
|
|
@@ -61,10 +61,10 @@ function getGeneralRefactorings(doc, file, range) {
|
|
|
61
61
|
}
|
|
62
62
|
const clickedEdgeStatement = clickedNode.parent;
|
|
63
63
|
if (clickedEdgeStatement && !subtreeContainsErrors(clickedEdgeStatement)) {
|
|
64
|
-
if (isEdgeStatement(clickedEdgeStatement)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
if (isEdgeStatement(clickedEdgeStatement) &&
|
|
65
|
+
clickedEdgeStatement.rhs.length === 1 &&
|
|
66
|
+
isNodeId(clickedEdgeStatement.source) &&
|
|
67
|
+
!edgeStatementHasAttributes(clickedEdgeStatement)) {
|
|
68
68
|
candidates.push(clickedEdgeStatement);
|
|
69
69
|
const source = clickedEdgeStatement.source;
|
|
70
70
|
const sourceText = getIdentifierText(source.id);
|
|
@@ -80,17 +80,17 @@ function getGeneralRefactorings(doc, file, range) {
|
|
|
80
80
|
if (hasVisitedNodeModifier) {
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
if (isAttrStatement(statement)
|
|
85
|
-
|
|
83
|
+
if (hasVisitedStatement) {
|
|
84
|
+
if (isAttrStatement(statement) ||
|
|
85
|
+
subtreeContainsErrors(statement)) {
|
|
86
86
|
hasVisitedNodeModifier = true;
|
|
87
87
|
return true;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
if (hasVisitedStatement) {
|
|
91
|
-
if (isEdgeStatement(statement)
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
if (isEdgeStatement(statement) &&
|
|
92
|
+
statement.rhs.length === 1 &&
|
|
93
|
+
!edgeStatementHasAttributes(statement)) {
|
|
94
94
|
const statementSource = statement.source;
|
|
95
95
|
if (isNodeId(statementSource)) {
|
|
96
96
|
const lowerSourceText = getIdentifierText(statementSource.id);
|
|
@@ -112,14 +112,17 @@ function getGeneralRefactorings(doc, file, range) {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
return res.length === 0 ? undefined : res;
|
|
115
|
-
;
|
|
116
115
|
}
|
|
117
116
|
function getCommandsForDiagnostic(doc, file, d) {
|
|
118
117
|
switch (d.code.source) {
|
|
119
|
-
case 1:
|
|
120
|
-
|
|
121
|
-
case
|
|
122
|
-
|
|
118
|
+
case 1:
|
|
119
|
+
return getScannerErrorCommand(doc, file, d, d.code);
|
|
120
|
+
case 2:
|
|
121
|
+
return getParserErrorCommand(doc, file, d, d.code);
|
|
122
|
+
case 4:
|
|
123
|
+
return getCheckerErrorCommand(doc, file, d, d.code);
|
|
124
|
+
default:
|
|
125
|
+
return assertNever(d.code);
|
|
123
126
|
}
|
|
124
127
|
}
|
|
125
128
|
function getScannerErrorCommand(_doc, _file, d, code) {
|
|
@@ -146,11 +149,7 @@ function getCheckerErrorCommand(_doc, file, d, code) {
|
|
|
146
149
|
const fixSingleEdge = ChangeEdgeOpCommand.create(d.start, d.end, allowedOp, wrongOp);
|
|
147
150
|
const fixAll = convertGraphTypeCommand(file, graph, kwk);
|
|
148
151
|
const convertToThisWrongType = convertGraphTypeCommand(file, graph, getOppositeKind(kwk));
|
|
149
|
-
return [
|
|
150
|
-
fixSingleEdge,
|
|
151
|
-
fixAll,
|
|
152
|
-
convertToThisWrongType,
|
|
153
|
-
];
|
|
152
|
+
return [fixSingleEdge, fixAll, convertToThisWrongType];
|
|
154
153
|
}
|
|
155
154
|
case 1:
|
|
156
155
|
return undefined;
|
|
@@ -163,11 +162,11 @@ function convertGraphTypeCommand(file, graph, changeToGraphType) {
|
|
|
163
162
|
.filter(e => e.operation.kind !== changeToEdgeOp)
|
|
164
163
|
.map(e => ({
|
|
165
164
|
start: getStart(file, e.operation),
|
|
166
|
-
end: e.operation.end
|
|
165
|
+
end: e.operation.end,
|
|
167
166
|
}));
|
|
168
167
|
const graphTypeOffset = {
|
|
169
168
|
start: getStart(file, graph.keyword),
|
|
170
|
-
end: graph.keyword.end
|
|
169
|
+
end: graph.keyword.end,
|
|
171
170
|
};
|
|
172
171
|
return ChangeAllOtherEdgeOpsAndFixGraphCommand.create(edgeOffsets, changeToEdgeOp, graphTypeOffset, graph.keyword.kind, changeToGraphType);
|
|
173
172
|
}
|
|
@@ -189,9 +188,7 @@ export function getAvailableCommands() {
|
|
|
189
188
|
}
|
|
190
189
|
export function executeCommand(doc, sourceFile, cmd) {
|
|
191
190
|
const handler = commandHandlers[cmd.command];
|
|
192
|
-
return handler === undefined
|
|
193
|
-
? undefined
|
|
194
|
-
: handler(doc, sourceFile, cmd);
|
|
191
|
+
return handler === undefined ? undefined : handler(doc, sourceFile, cmd);
|
|
195
192
|
}
|
|
196
193
|
function subtreeContainsErrors(node) {
|
|
197
194
|
if (nodeContainsErrors(node))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ColorInformation, ColorPresentation, Range
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { Color, ColorInformation, ColorPresentation, Range } from "vscode-languageserver-types";
|
|
2
|
+
import type { DocumentLike } from "../index.js";
|
|
3
|
+
import type { SourceFile } from "../types.js";
|
|
4
4
|
export declare function getDocumentColors(doc: DocumentLike, sourceFile: SourceFile): ColorInformation[] | undefined;
|
|
5
5
|
export declare function getColorRepresentations(_doc: DocumentLike, _sourceFile: SourceFile, color: Color, range: Range): ColorPresentation[] | undefined;
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import { syntaxNodeToRange } from "./util.js";
|
|
2
1
|
import * as languageFacts from "./languageFacts.js";
|
|
2
|
+
import { syntaxNodeToRange } from "./util.js";
|
|
3
3
|
const colorMap = languageFacts.colors;
|
|
4
4
|
export function getDocumentColors(doc, sourceFile) {
|
|
5
5
|
const cs = sourceFile.colors;
|
|
6
|
-
return cs
|
|
7
|
-
? colorTableToColorInformation(doc, sourceFile, cs)
|
|
8
|
-
: undefined;
|
|
6
|
+
return cs ? colorTableToColorInformation(doc, sourceFile, cs) : undefined;
|
|
9
7
|
}
|
|
10
8
|
export function getColorRepresentations(_doc, _sourceFile, color, range) {
|
|
11
|
-
return !color || !range
|
|
12
|
-
? undefined
|
|
13
|
-
: [{ label: '"' + getColorStringFromColor(color) + '"', }];
|
|
9
|
+
return !color || !range ? undefined : [{ label: `"${getColorStringFromColor(color)}"` }];
|
|
14
10
|
}
|
|
15
11
|
function colorTableToColorInformation(doc, sf, colors) {
|
|
16
12
|
if (!colors || colors.size === 0)
|
|
@@ -33,32 +29,26 @@ function getColorFromName(name) {
|
|
|
33
29
|
if (name.charAt(0) === "#")
|
|
34
30
|
return getHexCodeColor(name);
|
|
35
31
|
const colorAlias = colorMap[name.toLowerCase()];
|
|
36
|
-
return colorAlias
|
|
37
|
-
? getHexCodeColor(colorAlias)
|
|
38
|
-
: undefined;
|
|
32
|
+
return colorAlias ? getHexCodeColor(colorAlias) : undefined;
|
|
39
33
|
}
|
|
40
34
|
function getHexCodeColor(colorCode) {
|
|
41
|
-
const hexCode = colorCode.charAt(0) === "#"
|
|
42
|
-
|
|
43
|
-
: colorCode;
|
|
44
|
-
const colorInt = parseInt(hexCode, 16);
|
|
35
|
+
const hexCode = colorCode.charAt(0) === "#" ? colorCode.substring(1) : colorCode;
|
|
36
|
+
const colorInt = Number.parseInt(hexCode, 16);
|
|
45
37
|
return {
|
|
46
|
-
red: (colorInt >> 16 & 0xff) / 255.0,
|
|
47
|
-
green: (colorInt >> 8 & 0xff) / 255.0,
|
|
38
|
+
red: ((colorInt >> 16) & 0xff) / 255.0,
|
|
39
|
+
green: ((colorInt >> 8) & 0xff) / 255.0,
|
|
48
40
|
blue: (colorInt & 0xff) / 255.0,
|
|
49
|
-
alpha: hexCode.length === 8 ? (colorInt >> 24 & 0xff) / 255.0 : 1.0,
|
|
41
|
+
alpha: hexCode.length === 8 ? ((colorInt >> 24) & 0xff) / 255.0 : 1.0,
|
|
50
42
|
};
|
|
51
43
|
}
|
|
52
44
|
function getColorStringFromColor(c) {
|
|
53
45
|
const red = (c.red * 255) | 0;
|
|
54
46
|
const green = (c.green * 255) | 0;
|
|
55
47
|
const blue = (c.blue * 255) | 0;
|
|
56
|
-
return
|
|
48
|
+
return `#${numberToPaddedString(red)}${numberToPaddedString(green)}${numberToPaddedString(blue)}`;
|
|
57
49
|
}
|
|
58
50
|
function numberToPaddedString(n) {
|
|
59
51
|
const s = n.toString(16);
|
|
60
|
-
return (s.length === 1
|
|
61
|
-
? "0" + s
|
|
62
|
-
: s).toLowerCase();
|
|
52
|
+
return (s.length === 1 ? `0${s}` : s).toLowerCase();
|
|
63
53
|
}
|
|
64
54
|
//# sourceMappingURL=colorProvider.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as lst from "vscode-languageserver-types";
|
|
1
|
+
import type * as lst from "vscode-languageserver-types";
|
|
2
|
+
import type { CommandApplication, DocumentLike, SourceFile } from "../../index.js";
|
|
2
3
|
import { CommandIds } from "../codeAction.js";
|
|
3
|
-
import {
|
|
4
|
-
import { DocumentLike, SourceFile, CommandApplication } from "../../index.js";
|
|
4
|
+
import { type EdgeOpStr, type EdgeType, type ExecutableCommand, type GraphType, type GraphTypeStr, type Offset } from "./common.js";
|
|
5
5
|
export interface ChangeAllOtherEdgeOpsAndFixGraphCommand extends lst.Command {
|
|
6
6
|
command: CommandIds.ConvertGraphType;
|
|
7
7
|
arguments: [Offset[], EdgeOpStr, Offset, GraphTypeStr];
|
|
8
8
|
}
|
|
9
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;
|
|
10
|
+
export declare function execute(doc: DocumentLike, _sourceFile: SourceFile, cmd: ExecutableCommand<unknown[]>): CommandApplication | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createChangeToEdit, getEdgeStr, getGraphKeywordStr } from "./common.js";
|
|
1
|
+
import { createChangeToEdit, getEdgeStr, getGraphKeywordStr, } from "./common.js";
|
|
2
2
|
export function create(edgeOffsets, changeEdgesTo, graphOffset, changeFromGraph, changeGraphTo) {
|
|
3
3
|
const toGraph = getGraphKeywordStr(changeGraphTo);
|
|
4
4
|
const title = changeGraphTo === changeFromGraph
|
|
@@ -28,11 +28,11 @@ export function execute(doc, _sourceFile, cmd) {
|
|
|
28
28
|
edit: {
|
|
29
29
|
changes: {
|
|
30
30
|
[doc.uri]: edits,
|
|
31
|
-
}
|
|
32
|
-
}
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
function isChangeAllOtherEdgeOpsAndFixGraphCommand(cmd) {
|
|
36
|
-
return cmd.command === "DOT.convertGraphType" && !!cmd.arguments && cmd.arguments.length === 4;
|
|
36
|
+
return (cmd.command === "DOT.convertGraphType" && !!cmd.arguments && cmd.arguments.length === 4);
|
|
37
37
|
}
|
|
38
38
|
//# sourceMappingURL=ChangeAllOtherEdgeOpsAndFixGraphCommand.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as lst from "vscode-languageserver-types";
|
|
2
|
+
import type { CommandApplication, DocumentLike, SourceFile } from "../../index.js";
|
|
2
3
|
import { CommandIds } from "../codeAction.js";
|
|
3
|
-
import { EdgeOpStr,
|
|
4
|
-
import { DocumentLike, SourceFile, CommandApplication } from "../../index.js";
|
|
4
|
+
import { type EdgeOpStr, type EdgeType, type ExecutableCommand } from "./common.js";
|
|
5
5
|
export interface ChangeEdgeOpCommand extends lst.Command {
|
|
6
6
|
command: CommandIds.ChangeEdgeOp;
|
|
7
7
|
arguments: [number, number, EdgeOpStr];
|
|
8
8
|
}
|
|
9
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;
|
|
10
|
+
export declare function execute(doc: DocumentLike, _sourceFile: SourceFile, cmd: ExecutableCommand<unknown[]>): CommandApplication | undefined;
|
|
@@ -19,11 +19,9 @@ export function execute(doc, _sourceFile, cmd) {
|
|
|
19
19
|
label: `Change of invalid edge to "${changeTo}"'"`,
|
|
20
20
|
edit: {
|
|
21
21
|
changes: {
|
|
22
|
-
[doc.uri]: [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
}
|
|
22
|
+
[doc.uri]: [lst.TextEdit.replace(lst.Range.create(startPos, endPos), changeTo)],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
27
25
|
};
|
|
28
26
|
}
|
|
29
27
|
function isChangeEdgeOpCommand(cmd) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as lst from "vscode-languageserver-types";
|
|
1
|
+
import type * as lst from "vscode-languageserver-types";
|
|
2
|
+
import type { CommandApplication, DocumentLike, EdgeStatement, SourceFile } from "../../index.js";
|
|
2
3
|
import { CommandIds } from "../codeAction.js";
|
|
3
|
-
import { ExecutableCommand } from "./common.js";
|
|
4
|
-
import { DocumentLike, SourceFile, CommandApplication, EdgeStatement } from "../../index.js";
|
|
4
|
+
import type { ExecutableCommand } from "./common.js";
|
|
5
5
|
export interface ConsolidateDescendantsCommand extends lst.Command {
|
|
6
6
|
command: CommandIds.ConsolidateDescendants;
|
|
7
7
|
arguments: number[];
|
|
8
8
|
}
|
|
9
9
|
export declare function create(statements: EdgeStatement[], below: boolean): ConsolidateDescendantsCommand;
|
|
10
|
-
export declare function execute(doc: DocumentLike, sourceFile: SourceFile, cmd: ExecutableCommand): CommandApplication | undefined;
|
|
10
|
+
export declare function execute(doc: DocumentLike, sourceFile: SourceFile, cmd: ExecutableCommand<unknown[]>): CommandApplication | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { findNodeAtOffset, getIdentifierText } from "../../checker.js";
|
|
2
2
|
import { getStart } from "../util.js";
|
|
3
3
|
export function create(statements, below) {
|
|
4
4
|
const first = statements[0];
|
|
@@ -26,9 +26,7 @@ export function execute(doc, sourceFile, cmd) {
|
|
|
26
26
|
const firstRight = first.rhs[0];
|
|
27
27
|
const firstRightTargetStart = getStart(sourceFile, firstRight.target);
|
|
28
28
|
const firstRightTargetEnd = firstRight.target.end;
|
|
29
|
-
const contents = [
|
|
30
|
-
sourceFile.content.substring(firstRightTargetStart, firstRightTargetEnd)
|
|
31
|
-
];
|
|
29
|
+
const contents = [sourceFile.content.substring(firstRightTargetStart, firstRightTargetEnd)];
|
|
32
30
|
for (const descendant of candidates) {
|
|
33
31
|
const rightItem = descendant.rhs[0];
|
|
34
32
|
const rightItemTarget = rightItem.target;
|
|
@@ -40,14 +38,14 @@ export function execute(doc, sourceFile, cmd) {
|
|
|
40
38
|
range: {
|
|
41
39
|
start: doc.positionAt(descendant.pos),
|
|
42
40
|
end: doc.positionAt(rightItemTargetStart),
|
|
43
|
-
}
|
|
41
|
+
},
|
|
44
42
|
});
|
|
45
43
|
edits.push({
|
|
46
44
|
newText: "",
|
|
47
45
|
range: {
|
|
48
46
|
start: doc.positionAt(rightItemTargetStart),
|
|
49
47
|
end: doc.positionAt(rightItemTargetEnd),
|
|
50
|
-
}
|
|
48
|
+
},
|
|
51
49
|
});
|
|
52
50
|
if (descendant.terminator !== undefined) {
|
|
53
51
|
edits.push({
|
|
@@ -55,7 +53,7 @@ export function execute(doc, sourceFile, cmd) {
|
|
|
55
53
|
range: {
|
|
56
54
|
start: doc.positionAt(getStart(sourceFile, descendant.terminator)),
|
|
57
55
|
end: doc.positionAt(descendant.terminator.end),
|
|
58
|
-
}
|
|
56
|
+
},
|
|
59
57
|
});
|
|
60
58
|
}
|
|
61
59
|
contents.push(rightItemContent);
|
|
@@ -66,18 +64,20 @@ export function execute(doc, sourceFile, cmd) {
|
|
|
66
64
|
range: {
|
|
67
65
|
start: doc.positionAt(firstRightTargetStart),
|
|
68
66
|
end: doc.positionAt(firstRightTargetEnd),
|
|
69
|
-
}
|
|
67
|
+
},
|
|
70
68
|
});
|
|
71
69
|
return {
|
|
72
70
|
label: `Convert edges from "${from}" to subgraph.`,
|
|
73
71
|
edit: {
|
|
74
72
|
changes: {
|
|
75
73
|
[doc.uri]: edits,
|
|
76
|
-
}
|
|
77
|
-
}
|
|
74
|
+
},
|
|
75
|
+
},
|
|
78
76
|
};
|
|
79
77
|
}
|
|
80
78
|
function isConsolidateDescendantsCommand(cmd) {
|
|
81
|
-
return cmd.command === "DOT.consolidateDescendants" &&
|
|
79
|
+
return (cmd.command === "DOT.consolidateDescendants" &&
|
|
80
|
+
!!cmd.arguments &&
|
|
81
|
+
cmd.arguments.length > 1);
|
|
82
82
|
}
|
|
83
83
|
//# sourceMappingURL=ConsolidateDescendantsCommand.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as lst from "vscode-languageserver-types";
|
|
1
|
+
import type * as lst from "vscode-languageserver-types";
|
|
2
|
+
import type { CommandApplication, DocumentLike, SourceFile } from "../../index.js";
|
|
2
3
|
import { CommandIds } from "../codeAction.js";
|
|
3
|
-
import { ExecutableCommand } from "./common.js";
|
|
4
|
-
import { DocumentLike, SourceFile, CommandApplication } from "../../index.js";
|
|
4
|
+
import { type ExecutableCommand } from "./common.js";
|
|
5
5
|
export interface RemoveSemicolonsCommand extends lst.Command {
|
|
6
6
|
command: CommandIds.RemoveSemicolons;
|
|
7
7
|
arguments: undefined;
|
|
8
8
|
}
|
|
9
9
|
export declare function create(): RemoveSemicolonsCommand;
|
|
10
|
-
export declare function execute(doc: DocumentLike, sourceFile: SourceFile, cmd: ExecutableCommand): CommandApplication | undefined;
|
|
10
|
+
export declare function execute(doc: DocumentLike, sourceFile: SourceFile, cmd: ExecutableCommand<unknown[]>): CommandApplication | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createChangeToEdit } from "./common.js";
|
|
2
1
|
import { findOptionalSemicolons } from "../../checker.js";
|
|
2
|
+
import { createChangeToEdit } from "./common.js";
|
|
3
3
|
export function create() {
|
|
4
4
|
return {
|
|
5
5
|
title: "Remove optional semicolons",
|
|
@@ -20,18 +20,16 @@ export function execute(doc, sourceFile, cmd) {
|
|
|
20
20
|
return createChangeToEdit(doc.positionAt(start), doc.positionAt(end), "");
|
|
21
21
|
});
|
|
22
22
|
return {
|
|
23
|
-
label:
|
|
23
|
+
label: "Remove optional semicolons",
|
|
24
24
|
edit: {
|
|
25
25
|
changes: {
|
|
26
26
|
[doc.uri]: edits,
|
|
27
|
-
}
|
|
28
|
-
}
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
function isRemoveSemicolonsCommand(cmd) {
|
|
32
|
-
return cmd.command === "DOT.removeSemicolons"
|
|
33
|
-
|
|
34
|
-
|| cmd.arguments.length === 0
|
|
35
|
-
|| cmd.arguments.every(e => e === undefined));
|
|
32
|
+
return (cmd.command === "DOT.removeSemicolons" &&
|
|
33
|
+
(!cmd.arguments || cmd.arguments.length === 0 || cmd.arguments.every(e => e === undefined)));
|
|
36
34
|
}
|
|
37
35
|
//# sourceMappingURL=RemoveSemicolons.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Position, TextEdit } from "vscode-languageserver-types";
|
|
2
2
|
import { SyntaxKind } from "../../index.js";
|
|
3
|
-
import { CommandIds } from "../codeAction.js";
|
|
3
|
+
import type { CommandIds } from "../codeAction.js";
|
|
4
4
|
export declare function createChangeToEdit(start: Position, end: Position, changeTo: string): TextEdit;
|
|
5
5
|
export interface Offset {
|
|
6
6
|
start: number;
|
|
7
7
|
end: number;
|
|
8
8
|
}
|
|
9
|
-
export type ExecutableCommand = {
|
|
9
|
+
export type ExecutableCommand<TArgs> = {
|
|
10
10
|
command: CommandIds;
|
|
11
|
-
arguments?:
|
|
11
|
+
arguments?: TArgs;
|
|
12
12
|
};
|
|
13
13
|
export type EdgeOpStr = "--" | "->";
|
|
14
14
|
export declare function getEdgeStr(op: SyntaxKind.UndirectedEdgeOp): "--";
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Range, TextEdit } from "vscode-languageserver-types";
|
|
2
2
|
import { SyntaxKind } from "../../index.js";
|
|
3
3
|
export function createChangeToEdit(start, end, changeTo) {
|
|
4
4
|
return TextEdit.replace(Range.create(start, end), changeTo);
|
|
5
5
|
}
|
|
6
|
-
;
|
|
7
6
|
export function getEdgeStr(op) {
|
|
8
7
|
return op === SyntaxKind.DirectedEdgeOp ? "->" : "--";
|
|
9
8
|
}
|
|
@@ -14,9 +13,13 @@ export function getOppositeKind(g) {
|
|
|
14
13
|
return g === SyntaxKind.DigraphKeyword ? SyntaxKind.GraphKeyword : SyntaxKind.DigraphKeyword;
|
|
15
14
|
}
|
|
16
15
|
export function getOppositeEdgeOp(g) {
|
|
17
|
-
return g === SyntaxKind.DirectedEdgeOp
|
|
16
|
+
return g === SyntaxKind.DirectedEdgeOp
|
|
17
|
+
? SyntaxKind.UndirectedEdgeOp
|
|
18
|
+
: SyntaxKind.DirectedEdgeOp;
|
|
18
19
|
}
|
|
19
20
|
export function getAllowedOp(g) {
|
|
20
|
-
return g === SyntaxKind.DigraphKeyword
|
|
21
|
+
return g === SyntaxKind.DigraphKeyword
|
|
22
|
+
? SyntaxKind.DirectedEdgeOp
|
|
23
|
+
: SyntaxKind.UndirectedEdgeOp;
|
|
21
24
|
}
|
|
22
25
|
//# sourceMappingURL=common.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * 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 getCompletions(doc: DocumentLike, sourceFile: SourceFile, position: lst.Position): lst.CompletionItem[];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as lst from "vscode-languageserver-types";
|
|
2
|
-
import { SyntaxKind } from "../types.js";
|
|
3
2
|
import { findNodeAtOffset, getIdentifierText, isEdgeStatement } from "../checker.js";
|
|
4
|
-
import { escapeIdentifierText } from "./util.js";
|
|
5
3
|
import { isIdentifierNode } from "../index.js";
|
|
4
|
+
import { SyntaxKind, } from "../types.js";
|
|
6
5
|
import * as languageFacts from "./languageFacts.js";
|
|
6
|
+
import { escapeIdentifierText } from "./util.js";
|
|
7
7
|
export function getCompletions(doc, sourceFile, position) {
|
|
8
8
|
const symbols = sourceFile.symbols;
|
|
9
9
|
if (!symbols)
|
|
@@ -18,8 +18,8 @@ export function getCompletions(doc, sourceFile, position) {
|
|
|
18
18
|
const prevOffsetNode = findNodeAtOffset(g, offset - 1, true);
|
|
19
19
|
const parent = node.parent;
|
|
20
20
|
const prevOffsetNodeParent = prevOffsetNode?.parent;
|
|
21
|
-
if ((parent?.parent && isEdgeStatement(parent.parent))
|
|
22
|
-
|
|
21
|
+
if ((parent?.parent && isEdgeStatement(parent.parent)) ||
|
|
22
|
+
(prevOffsetNodeParent?.parent && isEdgeStatement(prevOffsetNodeParent.parent))) {
|
|
23
23
|
return getNodeCompletions(symbols);
|
|
24
24
|
}
|
|
25
25
|
if (node.kind === SyntaxKind.AttributeContainer) {
|
|
@@ -32,13 +32,11 @@ export function getCompletions(doc, sourceFile, position) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
if (node.kind === SyntaxKind.TextIdentifier && parent?.kind === SyntaxKind.NodeId) {
|
|
35
|
-
const exclusions = node.symbol
|
|
36
|
-
? [node.symbol.name]
|
|
37
|
-
: undefined;
|
|
35
|
+
const exclusions = node.symbol ? [node.symbol.name] : undefined;
|
|
38
36
|
return getNodeCompletions(symbols, exclusions);
|
|
39
37
|
}
|
|
40
|
-
if (node.kind === SyntaxKind.AttributeContainer
|
|
41
|
-
|
|
38
|
+
if (node.kind === SyntaxKind.AttributeContainer ||
|
|
39
|
+
(node.kind === SyntaxKind.CommaToken && parent?.kind === SyntaxKind.Assignment)) {
|
|
42
40
|
return getAttributeCompletions(position);
|
|
43
41
|
}
|
|
44
42
|
const prevNode = findNodeAtOffset(g, node.pos - 1, true);
|
|
@@ -57,7 +55,7 @@ export function getCompletions(doc, sourceFile, position) {
|
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
|
-
if (
|
|
58
|
+
if (node.flags & 2 || node.end === node.pos) {
|
|
61
59
|
const attribute = prevNode;
|
|
62
60
|
if (!attribute)
|
|
63
61
|
return [];
|
|
@@ -75,9 +73,12 @@ function getAssignmentCompletion(assignment) {
|
|
|
75
73
|
if (!property)
|
|
76
74
|
return [];
|
|
77
75
|
switch (property.toLowerCase()) {
|
|
78
|
-
case "shape":
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
case "shape":
|
|
77
|
+
return getShapeCompletions();
|
|
78
|
+
case "color":
|
|
79
|
+
return getColorCompletions();
|
|
80
|
+
default:
|
|
81
|
+
return [];
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
function getShapeCompletions() {
|
|
@@ -90,8 +91,7 @@ function getShapeCompletions() {
|
|
|
90
91
|
function getColorCompletions() {
|
|
91
92
|
const kind = lst.CompletionItemKind.Color;
|
|
92
93
|
const colors = languageFacts.colors;
|
|
93
|
-
return Object.keys(colors)
|
|
94
|
-
.map(label => ({
|
|
94
|
+
return Object.keys(colors).map(label => ({
|
|
95
95
|
kind,
|
|
96
96
|
label,
|
|
97
97
|
documentation: colors[label],
|
|
@@ -108,7 +108,7 @@ function getAttributeCompletions(posistion) {
|
|
|
108
108
|
label,
|
|
109
109
|
textEdit: {
|
|
110
110
|
range,
|
|
111
|
-
newText: escapeIdentifierText(label)
|
|
111
|
+
newText: `${escapeIdentifierText(label)}=`,
|
|
112
112
|
},
|
|
113
113
|
}));
|
|
114
114
|
}
|
|
@@ -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/esm/service/hover.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getIdentifierText, findNodeAtOffset } from "../checker.js";
|
|
1
|
+
import { findNodeAtOffset, getIdentifierText } from "../checker.js";
|
|
3
2
|
import { isIdentifierNode } from "../parser.js";
|
|
4
|
-
import {
|
|
3
|
+
import { SyntaxKind, } from "../types.js";
|
|
5
4
|
import { getEdgeStr } from "./command/common.js";
|
|
5
|
+
import { syntaxNodeToRange } from "./util.js";
|
|
6
6
|
export function hover(doc, sourceFile, position) {
|
|
7
7
|
const offset = doc.offsetAt(position);
|
|
8
8
|
const g = sourceFile.graph;
|
|
@@ -65,15 +65,11 @@ function getHoverContents(n) {
|
|
|
65
65
|
case SyntaxKind.SubGraphStatement: {
|
|
66
66
|
const sgs = parent;
|
|
67
67
|
const sg = sgs.subgraph;
|
|
68
|
-
return
|
|
69
|
-
? `(sub graph) ${getIdentifierText(sg.id)}`
|
|
70
|
-
: `(sub graph)`;
|
|
68
|
+
return sg.id ? `(sub graph) ${getIdentifierText(sg.id)}` : "(sub graph)";
|
|
71
69
|
}
|
|
72
70
|
case SyntaxKind.SubGraph: {
|
|
73
71
|
const sg = parent;
|
|
74
|
-
return
|
|
75
|
-
? `(sub graph) ${getIdentifierText(sg.id)}`
|
|
76
|
-
: `(sub graph)`;
|
|
72
|
+
return sg.id ? `(sub graph) ${getIdentifierText(sg.id)}` : "(sub graph)";
|
|
77
73
|
}
|
|
78
74
|
case SyntaxKind.IdEqualsIdStatement: {
|
|
79
75
|
const idEqId = parent;
|
|
@@ -87,9 +83,7 @@ function getHoverContents(n) {
|
|
|
87
83
|
return SyntaxKind[parent.kind];
|
|
88
84
|
}
|
|
89
85
|
const fallback = SyntaxKind[n.kind];
|
|
90
|
-
return fallback
|
|
91
|
-
? "(" + fallback.toLowerCase() + ")"
|
|
92
|
-
: undefined;
|
|
86
|
+
return fallback ? `(${fallback.toLowerCase()})` : undefined;
|
|
93
87
|
}
|
|
94
88
|
switch (n.kind) {
|
|
95
89
|
case SyntaxKind.GraphKeyword:
|
|
@@ -110,8 +104,8 @@ function getGraphHover(g) {
|
|
|
110
104
|
const direction = g.kind === SyntaxKind.DirectedGraph ? "directed" : "undirected";
|
|
111
105
|
const graphId = g.id;
|
|
112
106
|
const strict = g.strict ? "strict " : "";
|
|
113
|
-
return
|
|
114
|
-
? `(${strict}${direction} graph) ${
|
|
107
|
+
return graphId
|
|
108
|
+
? `(${strict}${direction} graph) ${getIdentifierText(graphId)}`
|
|
115
109
|
: `(${strict}${direction} graph)`;
|
|
116
110
|
}
|
|
117
111
|
function getEdgeHover(n) {
|
|
@@ -307,12 +307,7 @@ const clusterAttributes = Object.freeze([
|
|
|
307
307
|
"target",
|
|
308
308
|
"tooltip",
|
|
309
309
|
]);
|
|
310
|
-
export const attributes = Array.from(new Set([
|
|
311
|
-
...nodeAttributes,
|
|
312
|
-
...edgeAttributes,
|
|
313
|
-
...graphAttributes,
|
|
314
|
-
...clusterAttributes,
|
|
315
|
-
])).sort();
|
|
310
|
+
export const attributes = Array.from(new Set([...nodeAttributes, ...edgeAttributes, ...graphAttributes, ...clusterAttributes])).sort();
|
|
316
311
|
export const colors = Object.freeze({
|
|
317
312
|
aliceblue: "#f0f8ff",
|
|
318
313
|
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,6 +1,6 @@
|
|
|
1
|
-
import { isIdentifierNode } from "../index.js";
|
|
2
1
|
import { findNodeAtOffset } from "../checker.js";
|
|
3
|
-
import {
|
|
2
|
+
import { isIdentifierNode } from "../index.js";
|
|
3
|
+
import { syntaxNodeToRange, syntaxNodesToRanges } from "./util.js";
|
|
4
4
|
export function findReferences(doc, sourceFile, position, context) {
|
|
5
5
|
if (!sourceFile.symbols)
|
|
6
6
|
throw "sourceFile is not bound";
|
|
@@ -25,10 +25,7 @@ export function findReferences(doc, sourceFile, position, context) {
|
|
|
25
25
|
symbolRefs = refs;
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
symbolRefs = [
|
|
29
|
-
nodeSymbol.firstMention,
|
|
30
|
-
...refs.filter(r => r !== node),
|
|
31
|
-
];
|
|
28
|
+
symbolRefs = [nodeSymbol.firstMention, ...refs.filter(r => r !== node)];
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
31
|
const ranges = syntaxNodesToRanges(doc, sourceFile, symbolRefs);
|
|
@@ -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;
|