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.
Files changed (57) hide show
  1. package/.github/workflows/CD.yml +36 -0
  2. package/.github/workflows/CI.yml +33 -0
  3. package/LICENSE +21 -0
  4. package/README.md +17 -0
  5. package/lib/binder.d.ts +2 -0
  6. package/lib/binder.js +300 -0
  7. package/lib/checker.d.ts +14 -0
  8. package/lib/checker.js +185 -0
  9. package/lib/core.d.ts +1 -0
  10. package/lib/core.js +14 -0
  11. package/lib/error.d.ts +3 -0
  12. package/lib/error.js +14 -0
  13. package/lib/index.d.ts +6 -0
  14. package/lib/index.js +19 -0
  15. package/lib/parser.d.ts +84 -0
  16. package/lib/parser.js +698 -0
  17. package/lib/scanner.d.ts +52 -0
  18. package/lib/scanner.js +580 -0
  19. package/lib/service/codeAction.d.ts +12 -0
  20. package/lib/service/codeAction.js +214 -0
  21. package/lib/service/colorProvider.d.ts +6 -0
  22. package/lib/service/colorProvider.js +74 -0
  23. package/lib/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.d.ts +10 -0
  24. package/lib/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.js +43 -0
  25. package/lib/service/command/ChangeEdgeOpCommand.d.ts +10 -0
  26. package/lib/service/command/ChangeEdgeOpCommand.js +37 -0
  27. package/lib/service/command/ConsolidateDescendantsCommand.d.ts +10 -0
  28. package/lib/service/command/ConsolidateDescendantsCommand.js +106 -0
  29. package/lib/service/command/RemoveSemicolons.d.ts +10 -0
  30. package/lib/service/command/RemoveSemicolons.js +42 -0
  31. package/lib/service/command/common.d.ts +31 -0
  32. package/lib/service/command/common.js +31 -0
  33. package/lib/service/completion.d.ts +4 -0
  34. package/lib/service/completion.js +141 -0
  35. package/lib/service/hover.d.ts +4 -0
  36. package/lib/service/hover.js +123 -0
  37. package/lib/service/interop.d.ts +15 -0
  38. package/lib/service/interop.js +56 -0
  39. package/lib/service/languageFacts.d.ts +659 -0
  40. package/lib/service/languageFacts.js +976 -0
  41. package/lib/service/polyfill.d.ts +16 -0
  42. package/lib/service/polyfill.js +3 -0
  43. package/lib/service/reference.d.ts +5 -0
  44. package/lib/service/reference.js +73 -0
  45. package/lib/service/rename.d.ts +4 -0
  46. package/lib/service/rename.js +49 -0
  47. package/lib/service/service.d.ts +27 -0
  48. package/lib/service/service.js +39 -0
  49. package/lib/service/util.d.ts +11 -0
  50. package/lib/service/util.js +52 -0
  51. package/lib/service/validation.d.ts +4 -0
  52. package/lib/service/validation.js +24 -0
  53. package/lib/types.d.ts +396 -0
  54. package/lib/types.js +74 -0
  55. package/lib/visitor.d.ts +2 -0
  56. package/lib/visitor.js +78 -0
  57. package/package.json +42 -0
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCompletions = void 0;
4
+ const lst = require("vscode-languageserver-types");
5
+ const types_1 = require("../types");
6
+ const checker_1 = require("../checker");
7
+ const util_1 = require("./util");
8
+ const __1 = require("../");
9
+ const languageFacts = require("./languageFacts");
10
+ function getCompletions(doc, sourceFile, position) {
11
+ const symbols = sourceFile.symbols;
12
+ if (!symbols)
13
+ throw "sourceFile is not bound";
14
+ const g = sourceFile.graph;
15
+ if (!g)
16
+ return [];
17
+ const offset = doc.offsetAt(position);
18
+ const node = (0, checker_1.findNodeAtOffset)(g, offset, true);
19
+ if (!node)
20
+ return [];
21
+ const prevOffsetNode = (0, checker_1.findNodeAtOffset)(g, offset - 1, true);
22
+ const parent = node.parent;
23
+ const prevOffsetNodeParent = prevOffsetNode === null || prevOffsetNode === void 0 ? void 0 : prevOffsetNode.parent;
24
+ if (((parent === null || parent === void 0 ? void 0 : parent.parent) && (0, checker_1.isEdgeStatement)(parent.parent))
25
+ || ((prevOffsetNodeParent === null || prevOffsetNodeParent === void 0 ? void 0 : prevOffsetNodeParent.parent) && (0, checker_1.isEdgeStatement)(prevOffsetNodeParent.parent))) {
26
+ return getNodeCompletions(symbols);
27
+ }
28
+ if (node.kind === types_1.SyntaxKind.AttributeContainer) {
29
+ const openingBracket = node.openBracket;
30
+ if (openingBracket.end - 1 > offset - 1) {
31
+ const exclusions = (prevOffsetNode === null || prevOffsetNode === void 0 ? void 0 : prevOffsetNode.kind) === types_1.SyntaxKind.TextIdentifier && prevOffsetNode.symbol
32
+ ? [prevOffsetNode.symbol.name]
33
+ : undefined;
34
+ return getNodeCompletions(symbols, exclusions);
35
+ }
36
+ }
37
+ if (node.kind === types_1.SyntaxKind.TextIdentifier && (parent === null || parent === void 0 ? void 0 : parent.kind) === types_1.SyntaxKind.NodeId) {
38
+ const exclusions = node.symbol
39
+ ? [node.symbol.name]
40
+ : undefined;
41
+ return getNodeCompletions(symbols, exclusions);
42
+ }
43
+ if (node.kind === types_1.SyntaxKind.AttributeContainer
44
+ || (node.kind == types_1.SyntaxKind.CommaToken && (parent === null || parent === void 0 ? void 0 : parent.kind) === types_1.SyntaxKind.Assignment)) {
45
+ return getAttributeCompletions(position);
46
+ }
47
+ const prevNode = (0, checker_1.findNodeAtOffset)(g, node.pos - 1, true);
48
+ if (!prevNode)
49
+ return [];
50
+ if ((0, __1.isIdentifierNode)(prevNode)) {
51
+ const p = prevNode.parent;
52
+ if (p) {
53
+ switch (p.kind) {
54
+ case types_1.SyntaxKind.NodeId: {
55
+ return getNodeCompletions(symbols);
56
+ }
57
+ case types_1.SyntaxKind.Assignment: {
58
+ return getAssignmentCompletion(p);
59
+ }
60
+ }
61
+ }
62
+ }
63
+ if ((node.flags & 2) || node.end === node.pos) {
64
+ const attribute = prevNode;
65
+ if (!attribute)
66
+ return [];
67
+ if (!attribute.parent)
68
+ throw "sourceFile is not bound";
69
+ const parent = attribute.parent;
70
+ if (parent.kind === types_1.SyntaxKind.Assignment) {
71
+ return getAssignmentCompletion(parent);
72
+ }
73
+ }
74
+ return [];
75
+ }
76
+ exports.getCompletions = getCompletions;
77
+ function getAssignmentCompletion(assignment) {
78
+ const property = (0, checker_1.getIdentifierText)(assignment.leftId);
79
+ if (!property)
80
+ return [];
81
+ switch (property.toLowerCase()) {
82
+ case "shape": return getShapeCompletions();
83
+ case "color": return getColorCompletions();
84
+ default: return [];
85
+ }
86
+ }
87
+ function getShapeCompletions() {
88
+ const kind = lst.CompletionItemKind.EnumMember;
89
+ return languageFacts.shapes.map(s => ({
90
+ kind,
91
+ label: (0, util_1.escapeIdentifierText)(s),
92
+ }));
93
+ }
94
+ function getColorCompletions() {
95
+ const kind = lst.CompletionItemKind.Color;
96
+ const colors = languageFacts.colors;
97
+ return Object.keys(colors)
98
+ .map(label => ({
99
+ kind,
100
+ label,
101
+ documentation: colors[label],
102
+ }));
103
+ }
104
+ function getAttributeCompletions(posistion) {
105
+ const kind = lst.CompletionItemKind.Property;
106
+ const range = {
107
+ start: posistion,
108
+ end: posistion,
109
+ };
110
+ return languageFacts.attributes.map(label => ({
111
+ kind,
112
+ label,
113
+ textEdit: {
114
+ range,
115
+ newText: (0, util_1.escapeIdentifierText)(label) + "=",
116
+ },
117
+ }));
118
+ }
119
+ function getNodeCompletions(symbols, exlucdedSymbols) {
120
+ const res = new Array();
121
+ for (const [key, value] of symbols) {
122
+ if (exlucdedSymbols === null || exlucdedSymbols === void 0 ? void 0 : exlucdedSymbols.includes(key))
123
+ continue;
124
+ let kind = lst.CompletionItemKind.Variable;
125
+ const a = value.firstMention.parent;
126
+ if (a) {
127
+ switch (a.kind) {
128
+ case types_1.SyntaxKind.DirectedGraph:
129
+ case types_1.SyntaxKind.UndirectedGraph:
130
+ kind = lst.CompletionItemKind.Class;
131
+ break;
132
+ }
133
+ }
134
+ res.push({
135
+ label: (0, util_1.escapeIdentifierText)(key),
136
+ kind: kind,
137
+ });
138
+ }
139
+ return res;
140
+ }
141
+ //# sourceMappingURL=completion.js.map
@@ -0,0 +1,4 @@
1
+ import * as lst from "vscode-languageserver-types";
2
+ import { SourceFile } from "../types";
3
+ import { DocumentLike } from "../";
4
+ export declare function hover(doc: DocumentLike, sourceFile: SourceFile, position: lst.Position): lst.Hover | undefined;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hover = void 0;
4
+ const types_1 = require("../types");
5
+ const checker_1 = require("../checker");
6
+ const parser_1 = require("../parser");
7
+ const util_1 = require("./util");
8
+ const common_1 = require("./command/common");
9
+ function hover(doc, sourceFile, position) {
10
+ const offset = doc.offsetAt(position);
11
+ const g = sourceFile.graph;
12
+ if (!g)
13
+ return undefined;
14
+ const node = (0, checker_1.findNodeAtOffset)(g, offset);
15
+ if (node === undefined)
16
+ return undefined;
17
+ return getNodeHover(doc, sourceFile, node);
18
+ }
19
+ exports.hover = hover;
20
+ function getNodeHover(doc, sf, n) {
21
+ const contents = getHoverContents(n);
22
+ if (contents) {
23
+ return {
24
+ contents,
25
+ range: (0, util_1.syntaxNodeToRange)(doc, sf, n),
26
+ };
27
+ }
28
+ return undefined;
29
+ }
30
+ function getHoverContents(n) {
31
+ if ((0, parser_1.isIdentifierNode)(n)) {
32
+ const parent = n.parent;
33
+ if (parent) {
34
+ switch (parent.kind) {
35
+ case types_1.SyntaxKind.NodeId:
36
+ return `(node) ${(0, checker_1.getIdentifierText)(n)}`;
37
+ case types_1.SyntaxKind.Assignment: {
38
+ const assignment = parent;
39
+ const left = (0, checker_1.getIdentifierText)(assignment.leftId);
40
+ const right = (0, checker_1.getIdentifierText)(assignment.rightId);
41
+ return `(assignment) \`${left}\` = \`${right}\``;
42
+ }
43
+ case types_1.SyntaxKind.DirectedGraph:
44
+ return getGraphHover(parent);
45
+ case types_1.SyntaxKind.UndirectedGraph:
46
+ return getGraphHover(parent);
47
+ case types_1.SyntaxKind.SubGraphStatement: {
48
+ const sgs = parent;
49
+ const sg = sgs.subgraph;
50
+ return !!sg.id
51
+ ? `(sub graph) ${(0, checker_1.getIdentifierText)(sg.id)}`
52
+ : `(sub graph)`;
53
+ }
54
+ case types_1.SyntaxKind.SubGraph: {
55
+ const sg = parent;
56
+ return !!sg.id
57
+ ? `(sub graph) ${(0, checker_1.getIdentifierText)(sg.id)}`
58
+ : `(sub graph)`;
59
+ }
60
+ case types_1.SyntaxKind.IdEqualsIdStatement: {
61
+ const idEqId = parent;
62
+ const left = (0, checker_1.getIdentifierText)(idEqId.leftId);
63
+ const right = (0, checker_1.getIdentifierText)(idEqId.rightId);
64
+ return `(graph property) \`${left}\` = \`${right}\``;
65
+ }
66
+ case types_1.SyntaxKind.EdgeRhs:
67
+ return getEdgeHover(parent);
68
+ }
69
+ return types_1.SyntaxKind[parent.kind];
70
+ }
71
+ const fallback = types_1.SyntaxKind[n.kind];
72
+ return fallback
73
+ ? "(" + fallback.toLowerCase() + ")"
74
+ : undefined;
75
+ }
76
+ switch (n.kind) {
77
+ case types_1.SyntaxKind.GraphKeyword:
78
+ case types_1.SyntaxKind.DigraphKeyword:
79
+ case types_1.SyntaxKind.StrictKeyword:
80
+ return getGraphHover(n.parent);
81
+ case types_1.SyntaxKind.DirectedGraph:
82
+ case types_1.SyntaxKind.UndirectedGraph:
83
+ return getGraphHover(n);
84
+ case types_1.SyntaxKind.DirectedEdgeOp:
85
+ case types_1.SyntaxKind.UndirectedEdgeOp:
86
+ return getEdgeHover(n.parent);
87
+ default:
88
+ return undefined;
89
+ }
90
+ }
91
+ function getGraphHover(g) {
92
+ const direction = g.kind === types_1.SyntaxKind.DirectedGraph ? "directed" : "undirected";
93
+ const graphId = g.id;
94
+ const strict = g.strict ? "strict " : "";
95
+ return !!graphId
96
+ ? `(${strict}${direction} graph) ${((0, checker_1.getIdentifierText)(graphId))}`
97
+ : `(${strict}${direction} graph)`;
98
+ }
99
+ function getEdgeHover(n) {
100
+ const p = n.parent;
101
+ if (!p || p.rhs.length === 0)
102
+ return undefined;
103
+ let source = undefined;
104
+ for (const curr of p.rhs) {
105
+ if (curr === n)
106
+ break;
107
+ source = curr.target;
108
+ }
109
+ if (source === undefined)
110
+ source = p.source;
111
+ const edgeOpStr = (0, common_1.getEdgeStr)(n.operation.kind);
112
+ return source === undefined
113
+ ? undefined
114
+ : `(edge) ${getEdgeSourceOrTargetText(source)} ${edgeOpStr} ${getEdgeSourceOrTargetText(n.target)}`;
115
+ }
116
+ function getEdgeSourceOrTargetText(n) {
117
+ return n.kind === types_1.SyntaxKind.NodeId
118
+ ? (0, checker_1.getIdentifierText)(n.id)
119
+ : n.id !== undefined
120
+ ? `${(0, checker_1.getIdentifierText)(n.id)}`
121
+ : "sub graph";
122
+ }
123
+ //# sourceMappingURL=hover.js.map
@@ -0,0 +1,15 @@
1
+ import * as lst from "vscode-languageserver-types";
2
+ import { DiagnosticMessage } from "../types";
3
+ import { DocumentLike } from "../";
4
+ export interface IMarkerData {
5
+ code?: string;
6
+ severity: number;
7
+ message: string;
8
+ source?: string;
9
+ startLineNumber: number;
10
+ startColumn: number;
11
+ endLineNumber: number;
12
+ endColumn: number;
13
+ }
14
+ export declare function getDiagnosticMarkerData(doc: DocumentLike, source: DiagnosticMessage): IMarkerData;
15
+ export declare function getMarkerDataDiagnostic(m: IMarkerData): lst.Diagnostic;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMarkerDataDiagnostic = exports.getDiagnosticMarkerData = void 0;
4
+ const lst = require("vscode-languageserver-types");
5
+ const types_1 = require("../types");
6
+ function getDiagnosticMarkerData(doc, source) {
7
+ const start = doc.positionAt(source.start);
8
+ const end = doc.positionAt(source.end);
9
+ return {
10
+ message: source.message,
11
+ severity: source.category ? convertToMonacoSeverity(source.category) : 0,
12
+ startLineNumber: start.line,
13
+ startColumn: start.character,
14
+ endLineNumber: end.line,
15
+ endColumn: end.character,
16
+ };
17
+ }
18
+ exports.getDiagnosticMarkerData = getDiagnosticMarkerData;
19
+ function getMarkerDataDiagnostic(m) {
20
+ return {
21
+ message: m.message,
22
+ range: {
23
+ start: {
24
+ line: m.startLineNumber,
25
+ character: m.startColumn,
26
+ },
27
+ end: {
28
+ line: m.endLineNumber,
29
+ character: m.endColumn,
30
+ }
31
+ },
32
+ code: m.code,
33
+ severity: m.severity ? convertToLspSeverity(m.severity) : types_1.DiagnosticCategory.Suggestion,
34
+ source: m.source,
35
+ };
36
+ }
37
+ exports.getMarkerDataDiagnostic = getMarkerDataDiagnostic;
38
+ const lspToMonacoSeverityMap = {
39
+ [lst.DiagnosticSeverity.Error]: 3,
40
+ [lst.DiagnosticSeverity.Warning]: 2,
41
+ [lst.DiagnosticSeverity.Information]: 1,
42
+ [lst.DiagnosticSeverity.Hint]: 0,
43
+ };
44
+ const monacoToLspSeverityMap = {
45
+ [3]: lst.DiagnosticSeverity.Error,
46
+ [2]: lst.DiagnosticSeverity.Warning,
47
+ [1]: lst.DiagnosticSeverity.Information,
48
+ [0]: lst.DiagnosticSeverity.Hint,
49
+ };
50
+ function convertToMonacoSeverity(s) {
51
+ return lspToMonacoSeverityMap[s];
52
+ }
53
+ function convertToLspSeverity(n) {
54
+ return monacoToLspSeverityMap[n];
55
+ }
56
+ //# sourceMappingURL=interop.js.map