dot-language-support 1.6.1 → 2.0.0

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 (119) hide show
  1. package/.github/workflows/CD.yml +3 -3
  2. package/.github/workflows/CI.yml +2 -2
  3. package/README.md +5 -4
  4. package/jest.config.mjs +19 -0
  5. package/lib/{binder.d.ts → cjs/binder.d.ts} +1 -1
  6. package/lib/{binder.js → cjs/binder.js} +34 -34
  7. package/lib/{checker.d.ts → cjs/checker.d.ts} +1 -1
  8. package/lib/{checker.js → cjs/checker.js} +28 -28
  9. package/lib/{core.d.ts → cjs/core.d.ts} +0 -0
  10. package/lib/{core.js → cjs/core.js} +0 -0
  11. package/lib/{error.d.ts → cjs/error.d.ts} +1 -1
  12. package/lib/{error.js → cjs/error.js} +0 -0
  13. package/lib/cjs/index.d.ts +5 -0
  14. package/lib/{index.js → cjs/index.js} +5 -6
  15. package/lib/{parser.d.ts → cjs/parser.d.ts} +2 -2
  16. package/lib/{parser.js → cjs/parser.js} +14 -12
  17. package/lib/{scanner.d.ts → cjs/scanner.d.ts} +1 -1
  18. package/lib/{scanner.js → cjs/scanner.js} +67 -67
  19. package/lib/{service → cjs/service}/codeAction.d.ts +4 -4
  20. package/lib/cjs/service/codeAction.js +237 -0
  21. package/lib/cjs/service/colorProvider.d.ts +6 -0
  22. package/lib/cjs/service/colorProvider.js +97 -0
  23. package/lib/{service → cjs/service}/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.d.ts +4 -4
  24. package/lib/{service → cjs/service}/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.js +7 -7
  25. package/lib/{service → cjs/service}/command/ChangeEdgeOpCommand.d.ts +4 -4
  26. package/lib/cjs/service/command/ChangeEdgeOpCommand.js +60 -0
  27. package/lib/{service → cjs/service}/command/ConsolidateDescendantsCommand.d.ts +3 -3
  28. package/lib/{service → cjs/service}/command/ConsolidateDescendantsCommand.js +7 -25
  29. package/lib/{service → cjs/service}/command/RemoveSemicolons.d.ts +3 -3
  30. package/lib/{service → cjs/service}/command/RemoveSemicolons.js +4 -4
  31. package/lib/{service → cjs/service}/command/common.d.ts +4 -4
  32. package/lib/cjs/service/command/common.js +31 -0
  33. package/lib/{service → cjs/service}/completion.d.ts +2 -2
  34. package/lib/{service → cjs/service}/completion.js +49 -26
  35. package/lib/cjs/service/hover.d.ts +4 -0
  36. package/lib/{service → cjs/service}/hover.js +38 -38
  37. package/lib/{service → cjs/service}/languageFacts.d.ts +0 -0
  38. package/lib/{service → cjs/service}/languageFacts.js +0 -0
  39. package/lib/{service → cjs/service}/polyfill.d.ts +4 -4
  40. package/lib/{service → cjs/service}/polyfill.js +0 -0
  41. package/lib/cjs/service/reference.d.ts +5 -0
  42. package/lib/{service → cjs/service}/reference.js +9 -11
  43. package/lib/cjs/service/rename.d.ts +4 -0
  44. package/lib/{service → cjs/service}/rename.js +13 -13
  45. package/lib/{service → cjs/service}/service.d.ts +5 -4
  46. package/lib/cjs/service/service.js +39 -0
  47. package/lib/cjs/service/util.d.ts +11 -0
  48. package/lib/{service → cjs/service}/util.js +7 -7
  49. package/lib/{service → cjs/service}/validation.d.ts +2 -2
  50. package/lib/{service → cjs/service}/validation.js +3 -3
  51. package/lib/cjs/tester.d.ts +1 -0
  52. package/lib/cjs/tester.js +23 -0
  53. package/lib/{types.d.ts → cjs/types.d.ts} +0 -0
  54. package/lib/{types.js → cjs/types.js} +0 -0
  55. package/lib/{visitor.d.ts → cjs/visitor.d.ts} +1 -1
  56. package/lib/{visitor.js → cjs/visitor.js} +17 -17
  57. package/lib/esm/binder.d.ts +2 -0
  58. package/lib/esm/binder.js +296 -0
  59. package/lib/esm/checker.d.ts +14 -0
  60. package/lib/esm/checker.js +169 -0
  61. package/lib/esm/core.d.ts +1 -0
  62. package/lib/esm/core.js +10 -0
  63. package/lib/esm/error.d.ts +3 -0
  64. package/lib/esm/error.js +10 -0
  65. package/lib/esm/index.d.ts +5 -0
  66. package/lib/esm/index.js +6 -0
  67. package/lib/esm/parser.d.ts +84 -0
  68. package/lib/esm/parser.js +700 -0
  69. package/lib/esm/scanner.d.ts +52 -0
  70. package/lib/esm/scanner.js +581 -0
  71. package/lib/esm/service/codeAction.d.ts +12 -0
  72. package/lib/{service → esm/service}/codeAction.js +40 -46
  73. package/lib/esm/service/colorProvider.d.ts +6 -0
  74. package/lib/{service → esm/service}/colorProvider.js +5 -10
  75. package/lib/esm/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.d.ts +10 -0
  76. package/lib/esm/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.js +38 -0
  77. package/lib/esm/service/command/ChangeEdgeOpCommand.d.ts +10 -0
  78. package/lib/{service → esm/service}/command/ChangeEdgeOpCommand.js +6 -11
  79. package/lib/esm/service/command/ConsolidateDescendantsCommand.d.ts +10 -0
  80. package/lib/esm/service/command/ConsolidateDescendantsCommand.js +83 -0
  81. package/lib/esm/service/command/RemoveSemicolons.d.ts +10 -0
  82. package/lib/esm/service/command/RemoveSemicolons.js +37 -0
  83. package/lib/esm/service/command/common.d.ts +31 -0
  84. package/lib/esm/service/command/common.js +22 -0
  85. package/lib/esm/service/completion.d.ts +4 -0
  86. package/lib/esm/service/completion.js +137 -0
  87. package/lib/esm/service/hover.d.ts +4 -0
  88. package/lib/esm/service/hover.js +119 -0
  89. package/lib/esm/service/languageFacts.d.ts +683 -0
  90. package/lib/esm/service/languageFacts.js +997 -0
  91. package/lib/esm/service/polyfill.d.ts +16 -0
  92. package/lib/esm/service/polyfill.js +2 -0
  93. package/lib/esm/service/reference.d.ts +5 -0
  94. package/lib/esm/service/reference.js +66 -0
  95. package/lib/esm/service/rename.d.ts +4 -0
  96. package/lib/esm/service/rename.js +45 -0
  97. package/lib/esm/service/service.d.ts +28 -0
  98. package/lib/esm/service/service.js +35 -0
  99. package/lib/esm/service/util.d.ts +11 -0
  100. package/lib/esm/service/util.js +44 -0
  101. package/lib/esm/service/validation.d.ts +4 -0
  102. package/lib/esm/service/validation.js +20 -0
  103. package/lib/esm/tester.d.ts +1 -0
  104. package/lib/esm/tester.js +21 -0
  105. package/lib/esm/types.d.ts +396 -0
  106. package/lib/esm/types.js +71 -0
  107. package/lib/esm/visitor.d.ts +2 -0
  108. package/lib/esm/visitor.js +74 -0
  109. package/package.json +14 -10
  110. package/lib/index.d.ts +0 -6
  111. package/lib/service/colorProvider.d.ts +0 -6
  112. package/lib/service/command/common.js +0 -31
  113. package/lib/service/hover.d.ts +0 -4
  114. package/lib/service/interop.d.ts +0 -15
  115. package/lib/service/interop.js +0 -56
  116. package/lib/service/reference.d.ts +0 -5
  117. package/lib/service/rename.d.ts +0 -4
  118. package/lib/service/service.js +0 -39
  119. package/lib/service/util.d.ts +0 -11
@@ -1,39 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isLineBreak = exports.skipTrivia = exports.isIdentifierStart = exports.DefaultScanner = exports.getTextAsToken = exports.getTokenAsText = void 0;
4
- const core_1 = require("./core");
5
- const types_1 = require("./types");
6
- const util_1 = require("./service/util");
7
- const textToToken = (0, core_1.createMapFromTemplate)({
8
- "digraph": types_1.SyntaxKind.DigraphKeyword,
9
- "graph": types_1.SyntaxKind.GraphKeyword,
10
- "edge": types_1.SyntaxKind.EdgeKeyword,
11
- "node": types_1.SyntaxKind.NodeKeyword,
12
- "strict": types_1.SyntaxKind.StrictKeyword,
13
- "subgraph": types_1.SyntaxKind.SubgraphKeyword,
14
- "n": types_1.SyntaxKind.CompassNorthToken,
15
- "ne": types_1.SyntaxKind.CompassNorthEastToken,
16
- "e": types_1.SyntaxKind.CompassEastToken,
17
- "se": types_1.SyntaxKind.CompassSouthEastToken,
18
- "s": types_1.SyntaxKind.CompassSouthToken,
19
- "sw": types_1.SyntaxKind.CompassSouthWestToken,
20
- "w": types_1.SyntaxKind.CompassWestToken,
21
- "nw": types_1.SyntaxKind.CompassNorthWestToken,
22
- "c": types_1.SyntaxKind.CompassCenterToken,
23
- "+": types_1.SyntaxKind.PlusToken,
24
- "=": types_1.SyntaxKind.EqualsToken,
25
- "->": types_1.SyntaxKind.DirectedEdgeOp,
26
- "--": types_1.SyntaxKind.UndirectedEdgeOp,
27
- "{": types_1.SyntaxKind.OpenBraceToken,
28
- "}": types_1.SyntaxKind.CloseBraceToken,
29
- "[": types_1.SyntaxKind.OpenBracketToken,
30
- "]": types_1.SyntaxKind.CloseBracketToken,
31
- ";": types_1.SyntaxKind.SemicolonToken,
32
- ":": types_1.SyntaxKind.ColonToken,
33
- "_": types_1.SyntaxKind.UnderscoreToken,
34
- ",": types_1.SyntaxKind.CommaToken,
35
- "<": types_1.SyntaxKind.LessThan,
36
- ">": types_1.SyntaxKind.GreaterThan,
4
+ const core_js_1 = require("./core.js");
5
+ const types_js_1 = require("./types.js");
6
+ const util_js_1 = require("./service/util.js");
7
+ const textToToken = (0, core_js_1.createMapFromTemplate)({
8
+ "digraph": types_js_1.SyntaxKind.DigraphKeyword,
9
+ "graph": types_js_1.SyntaxKind.GraphKeyword,
10
+ "edge": types_js_1.SyntaxKind.EdgeKeyword,
11
+ "node": types_js_1.SyntaxKind.NodeKeyword,
12
+ "strict": types_js_1.SyntaxKind.StrictKeyword,
13
+ "subgraph": types_js_1.SyntaxKind.SubgraphKeyword,
14
+ "n": types_js_1.SyntaxKind.CompassNorthToken,
15
+ "ne": types_js_1.SyntaxKind.CompassNorthEastToken,
16
+ "e": types_js_1.SyntaxKind.CompassEastToken,
17
+ "se": types_js_1.SyntaxKind.CompassSouthEastToken,
18
+ "s": types_js_1.SyntaxKind.CompassSouthToken,
19
+ "sw": types_js_1.SyntaxKind.CompassSouthWestToken,
20
+ "w": types_js_1.SyntaxKind.CompassWestToken,
21
+ "nw": types_js_1.SyntaxKind.CompassNorthWestToken,
22
+ "c": types_js_1.SyntaxKind.CompassCenterToken,
23
+ "+": types_js_1.SyntaxKind.PlusToken,
24
+ "=": types_js_1.SyntaxKind.EqualsToken,
25
+ "->": types_js_1.SyntaxKind.DirectedEdgeOp,
26
+ "--": types_js_1.SyntaxKind.UndirectedEdgeOp,
27
+ "{": types_js_1.SyntaxKind.OpenBraceToken,
28
+ "}": types_js_1.SyntaxKind.CloseBraceToken,
29
+ "[": types_js_1.SyntaxKind.OpenBracketToken,
30
+ "]": types_js_1.SyntaxKind.CloseBracketToken,
31
+ ";": types_js_1.SyntaxKind.SemicolonToken,
32
+ ":": types_js_1.SyntaxKind.ColonToken,
33
+ "_": types_js_1.SyntaxKind.UnderscoreToken,
34
+ ",": types_js_1.SyntaxKind.CommaToken,
35
+ "<": types_js_1.SyntaxKind.LessThan,
36
+ ">": types_js_1.SyntaxKind.GreaterThan,
37
37
  });
38
38
  function makeReverseMap(source) {
39
39
  const result = new Map();
@@ -65,7 +65,7 @@ class DefaultScanner {
65
65
  this.pos = textPos;
66
66
  this.startPos = textPos;
67
67
  this.tokenPos = textPos;
68
- this.token = types_1.SyntaxKind.Unknown;
68
+ this.token = types_js_1.SyntaxKind.Unknown;
69
69
  this.tokenValue = undefined;
70
70
  this.tokenFlags = 0;
71
71
  }
@@ -76,7 +76,7 @@ class DefaultScanner {
76
76
  while (true) {
77
77
  this.tokenPos = this.pos;
78
78
  if (this.pos >= this.end) {
79
- return this.token = types_1.SyntaxKind.EndOfFileToken;
79
+ return this.token = types_js_1.SyntaxKind.EndOfFileToken;
80
80
  }
81
81
  let ch = this.text.charCodeAt(this.pos);
82
82
  switch (ch) {
@@ -95,7 +95,7 @@ class DefaultScanner {
95
95
  else {
96
96
  this.pos++;
97
97
  }
98
- return this.token = types_1.SyntaxKind.NewLineTrivia;
98
+ return this.token = types_js_1.SyntaxKind.NewLineTrivia;
99
99
  case 9:
100
100
  case 11:
101
101
  case 12:
@@ -106,13 +106,13 @@ class DefaultScanner {
106
106
  }
107
107
  while (this.pos < this.end && this.isWhiteSpaceSingleLine(this.text.charCodeAt(this.pos)))
108
108
  this.pos++;
109
- return this.token = types_1.SyntaxKind.WhitespaceTrivia;
109
+ return this.token = types_js_1.SyntaxKind.WhitespaceTrivia;
110
110
  case 35: {
111
111
  const content = this.scanHashCommentTrivia(skipTrivia);
112
112
  if (skipTrivia)
113
113
  continue;
114
114
  this.tokenValue = content;
115
- return this.token = types_1.SyntaxKind.HashCommentTrivia;
115
+ return this.token = types_js_1.SyntaxKind.HashCommentTrivia;
116
116
  }
117
117
  case 47: {
118
118
  if (this.pos + 1 < this.end) {
@@ -123,14 +123,14 @@ class DefaultScanner {
123
123
  if (skipTrivia)
124
124
  continue;
125
125
  this.tokenValue = commentContent;
126
- return this.token = types_1.SyntaxKind.SingleLineCommentTrivia;
126
+ return this.token = types_js_1.SyntaxKind.SingleLineCommentTrivia;
127
127
  }
128
128
  case 42: {
129
129
  const commentContent = this.scanMultiLineCommentTrivia(skipTrivia);
130
130
  if (skipTrivia)
131
131
  continue;
132
132
  this.tokenValue = commentContent;
133
- return this.token = types_1.SyntaxKind.MultiLineCommentTrivia;
133
+ return this.token = types_js_1.SyntaxKind.MultiLineCommentTrivia;
134
134
  }
135
135
  }
136
136
  }
@@ -140,22 +140,22 @@ class DefaultScanner {
140
140
  }
141
141
  case 123:
142
142
  this.pos++;
143
- return this.token = types_1.SyntaxKind.OpenBraceToken;
143
+ return this.token = types_js_1.SyntaxKind.OpenBraceToken;
144
144
  case 125:
145
145
  this.pos++;
146
- return this.token = types_1.SyntaxKind.CloseBraceToken;
146
+ return this.token = types_js_1.SyntaxKind.CloseBraceToken;
147
147
  case 91:
148
148
  this.pos++;
149
- return this.token = types_1.SyntaxKind.OpenBracketToken;
149
+ return this.token = types_js_1.SyntaxKind.OpenBracketToken;
150
150
  case 93:
151
151
  this.pos++;
152
- return this.token = types_1.SyntaxKind.CloseBracketToken;
152
+ return this.token = types_js_1.SyntaxKind.CloseBracketToken;
153
153
  case 43:
154
154
  this.pos++;
155
- return this.token = types_1.SyntaxKind.PlusToken;
155
+ return this.token = types_js_1.SyntaxKind.PlusToken;
156
156
  case 61:
157
157
  this.pos++;
158
- return this.token = types_1.SyntaxKind.EqualsToken;
158
+ return this.token = types_js_1.SyntaxKind.EqualsToken;
159
159
  case 48:
160
160
  case 49:
161
161
  case 50:
@@ -168,14 +168,14 @@ class DefaultScanner {
168
168
  case 57:
169
169
  case 46:
170
170
  this.tokenValue = this.scanNumber();
171
- return this.token = types_1.SyntaxKind.NumericIdentifier;
171
+ return this.token = types_js_1.SyntaxKind.NumericIdentifier;
172
172
  case 45: {
173
173
  const nextChar = this.text.charCodeAt(this.pos + 1);
174
174
  switch (nextChar) {
175
175
  case 45:
176
- return this.pos += 2, this.token = types_1.SyntaxKind.UndirectedEdgeOp;
176
+ return this.pos += 2, this.token = types_js_1.SyntaxKind.UndirectedEdgeOp;
177
177
  case 62:
178
- return this.pos += 2, this.token = types_1.SyntaxKind.DirectedEdgeOp;
178
+ return this.pos += 2, this.token = types_js_1.SyntaxKind.DirectedEdgeOp;
179
179
  case 48:
180
180
  case 49:
181
181
  case 50:
@@ -188,7 +188,7 @@ class DefaultScanner {
188
188
  case 57:
189
189
  case 46:
190
190
  this.tokenValue = this.scanNumber();
191
- return this.token = types_1.SyntaxKind.NumericIdentifier;
191
+ return this.token = types_js_1.SyntaxKind.NumericIdentifier;
192
192
  default:
193
193
  const chr = this.text.charAt(this.pos + 1);
194
194
  this.error(`Unexpected "${chr}". Did you mean to define an edge? Depending on the type of graph you are defining, use "->" or "--".`, 0);
@@ -199,22 +199,22 @@ class DefaultScanner {
199
199
  }
200
200
  case 95:
201
201
  this.pos++;
202
- return this.token = types_1.SyntaxKind.UnderscoreToken;
202
+ return this.token = types_js_1.SyntaxKind.UnderscoreToken;
203
203
  case 59:
204
204
  this.pos++;
205
- return this.token = types_1.SyntaxKind.SemicolonToken;
205
+ return this.token = types_js_1.SyntaxKind.SemicolonToken;
206
206
  case 58:
207
207
  this.pos++;
208
- return this.token = types_1.SyntaxKind.ColonToken;
208
+ return this.token = types_js_1.SyntaxKind.ColonToken;
209
209
  case 44:
210
210
  this.pos++;
211
- return this.token = types_1.SyntaxKind.CommaToken;
211
+ return this.token = types_js_1.SyntaxKind.CommaToken;
212
212
  case 60:
213
213
  this.tokenValue = this.scanHtml();
214
- return this.token = types_1.SyntaxKind.HtmlIdentifier;
214
+ return this.token = types_js_1.SyntaxKind.HtmlIdentifier;
215
215
  case 34:
216
216
  this.tokenValue = this.scanString();
217
- return this.token = types_1.SyntaxKind.StringLiteral;
217
+ return this.token = types_js_1.SyntaxKind.StringLiteral;
218
218
  default:
219
219
  {
220
220
  if (isIdentifierStart(ch)) {
@@ -237,7 +237,7 @@ class DefaultScanner {
237
237
  }
238
238
  }
239
239
  }
240
- error(message, sub, category = types_1.DiagnosticCategory.Error, errPos = this.pos, length = 0) {
240
+ error(message, sub, category = types_js_1.DiagnosticCategory.Error, errPos = this.pos, length = 0) {
241
241
  const cb = this.onError;
242
242
  if (cb) {
243
243
  const posSave = this.pos;
@@ -425,7 +425,7 @@ class DefaultScanner {
425
425
  }
426
426
  }
427
427
  }
428
- return this.token = types_1.SyntaxKind.TextIdentifier;
428
+ return this.token = types_js_1.SyntaxKind.TextIdentifier;
429
429
  }
430
430
  lookAhead(callback) {
431
431
  return this.speculationHelper(callback, true);
@@ -455,12 +455,12 @@ class DefaultScanner {
455
455
  exports.DefaultScanner = DefaultScanner;
456
456
  function isIdentifierPartOf(ch, idType) {
457
457
  switch (idType) {
458
- case types_1.SyntaxKind.TextIdentifier:
458
+ case types_js_1.SyntaxKind.TextIdentifier:
459
459
  return ch === 95
460
460
  || 65 <= ch && ch <= 90
461
461
  || 97 <= ch && ch <= 122
462
462
  || 48 <= ch && ch <= 57;
463
- case types_1.SyntaxKind.HtmlIdentifier:
463
+ case types_js_1.SyntaxKind.HtmlIdentifier:
464
464
  return ch === 95
465
465
  || ch === 60
466
466
  || ch === 61
@@ -468,7 +468,7 @@ function isIdentifierPartOf(ch, idType) {
468
468
  || 65 <= ch && ch <= 90
469
469
  || 97 <= ch && ch <= 122
470
470
  || 48 <= ch && ch <= 57;
471
- case types_1.SyntaxKind.StringLiteral:
471
+ case types_js_1.SyntaxKind.StringLiteral:
472
472
  return ch === 95
473
473
  || ch === 92
474
474
  || ch === 60
@@ -477,26 +477,26 @@ function isIdentifierPartOf(ch, idType) {
477
477
  || 65 <= ch && ch <= 90
478
478
  || 97 <= ch && ch <= 122
479
479
  || 48 <= ch && ch <= 57;
480
- case types_1.SyntaxKind.NumericIdentifier:
480
+ case types_js_1.SyntaxKind.NumericIdentifier:
481
481
  return ch === 45
482
482
  || ch === 46
483
483
  || 48 <= ch && ch <= 57;
484
- default: return (0, util_1.assertNever)(idType);
484
+ default: return (0, util_js_1.assertNever)(idType);
485
485
  }
486
486
  }
487
487
  function getIdentifierStart(ch) {
488
488
  if (ch === 60)
489
- return types_1.SyntaxKind.HtmlIdentifier;
489
+ return types_js_1.SyntaxKind.HtmlIdentifier;
490
490
  if (ch === 34)
491
- return types_1.SyntaxKind.StringLiteral;
491
+ return types_js_1.SyntaxKind.StringLiteral;
492
492
  if (ch === 95
493
493
  || 65 <= ch && ch <= 90
494
494
  || 97 <= ch && ch <= 122)
495
- return types_1.SyntaxKind.TextIdentifier;
495
+ return types_js_1.SyntaxKind.TextIdentifier;
496
496
  if (ch === 45
497
497
  || ch === 46
498
498
  || 48 <= ch && ch <= 57)
499
- return types_1.SyntaxKind.NumericIdentifier;
499
+ return types_js_1.SyntaxKind.NumericIdentifier;
500
500
  return undefined;
501
501
  }
502
502
  function isIdentifierStart(ch) {
@@ -1,7 +1,7 @@
1
- import * as lst from "vscode-languageserver-types";
2
- import { DocumentLike, SourceFile, CommandApplication } from "../";
3
- import { ExecutableCommand } from "./command/common";
4
- export declare function getCodeActions(doc: DocumentLike, sourceFile: SourceFile, range: lst.Range, context?: lst.CodeActionContext): lst.Command[] | undefined;
1
+ import type * as lst from "vscode-languageserver-types";
2
+ import { DocumentLike, SourceFile, CommandApplication } from "../index.js";
3
+ import { ExecutableCommand } from "./command/common.js";
4
+ export declare function getCodeActions(doc: DocumentLike, sourceFile: SourceFile, range: lst.Range, _context?: lst.CodeActionContext): lst.Command[] | undefined;
5
5
  export declare const enum CommandIds {
6
6
  ChangeEdgeOp = "DOT.changeEdgeOp",
7
7
  ConvertGraphType = "DOT.convertGraphType",
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.executeCommand = exports.getAvailableCommands = exports.getCodeActions = void 0;
27
+ const index_js_1 = require("../index.js");
28
+ const util_js_1 = require("./util.js");
29
+ const checker_js_1 = require("../checker.js");
30
+ const ChangeEdgeOpCommand = __importStar(require("./command/ChangeEdgeOpCommand.js"));
31
+ const ChangeAllOtherEdgeOpsAndFixGraphCommand = __importStar(require("./command/ChangeAllOtherEdgeOpsAndFixGraphCommand.js"));
32
+ const ConsolidateDescendantsCommand = __importStar(require("./command/ConsolidateDescendantsCommand.js"));
33
+ const RemoveSemicolonsCommand = __importStar(require("./command/RemoveSemicolons.js"));
34
+ const common_js_1 = require("./command/common.js");
35
+ function getCodeActions(doc, sourceFile, range, _context) {
36
+ let actions = getActionsFromDiagnostics(doc, sourceFile, range);
37
+ const general = getGeneralRefactorings(doc, sourceFile, range);
38
+ if (general) {
39
+ if (!actions)
40
+ actions = general;
41
+ else
42
+ actions.push.apply(actions, general);
43
+ }
44
+ return actions;
45
+ }
46
+ exports.getCodeActions = getCodeActions;
47
+ function getActionsFromDiagnostics(doc, file, range) {
48
+ const ds = file.diagnostics;
49
+ if (!ds || ds.length === 0)
50
+ return undefined;
51
+ const rangeStartOffset = doc.offsetAt(range.start);
52
+ const rangeEndOffset = doc.offsetAt(range.end);
53
+ const res = [];
54
+ for (const d of ds) {
55
+ if (isInRange(rangeStartOffset, rangeEndOffset, d.start, d.end)) {
56
+ const commands = getCommandsForDiagnostic(doc, file, d);
57
+ if (commands && commands.length > 0)
58
+ res.push.apply(res, commands);
59
+ }
60
+ }
61
+ return res.length === 0 ? undefined : res;
62
+ }
63
+ function getGeneralRefactorings(doc, file, range) {
64
+ if (!file.graph)
65
+ return undefined;
66
+ const g = file.graph;
67
+ const kw = g.keyword;
68
+ const rangeStartOffset = doc.offsetAt(range.start);
69
+ const rangeEndOffset = doc.offsetAt(range.end);
70
+ const keywordStart = (0, util_js_1.getStart)(file, kw);
71
+ const res = [];
72
+ if (isInRange(rangeStartOffset, rangeEndOffset, keywordStart, kw.end)) {
73
+ if (!subtreeContainsErrors(g)) {
74
+ const oppositeGraphType = (0, common_js_1.getOppositeKind)(kw.kind);
75
+ const convertGraph = convertGraphTypeCommand(file, g, oppositeGraphType);
76
+ res.push(convertGraph);
77
+ }
78
+ }
79
+ if (rangeStartOffset === rangeEndOffset) {
80
+ const candidates = [];
81
+ let clickedNode = (0, checker_js_1.findNodeAtOffset)(g, rangeStartOffset);
82
+ if (clickedNode && !!clickedNode.parent) {
83
+ if (clickedNode.kind === index_js_1.SyntaxKind.SemicolonToken) {
84
+ res.push(RemoveSemicolonsCommand.create());
85
+ }
86
+ if ((0, index_js_1.isIdentifierNode)(clickedNode)) {
87
+ clickedNode = clickedNode.parent;
88
+ }
89
+ const clickedEdgeStatement = clickedNode.parent;
90
+ if (clickedEdgeStatement && !subtreeContainsErrors(clickedEdgeStatement)) {
91
+ if ((0, checker_js_1.isEdgeStatement)(clickedEdgeStatement)
92
+ && clickedEdgeStatement.rhs.length === 1
93
+ && (0, checker_js_1.isNodeId)(clickedEdgeStatement.source)
94
+ && !(0, checker_js_1.edgeStatementHasAttributes)(clickedEdgeStatement)) {
95
+ candidates.push(clickedEdgeStatement);
96
+ const source = clickedEdgeStatement.source;
97
+ const sourceText = (0, checker_js_1.getIdentifierText)(source.id);
98
+ const graphParent = clickedEdgeStatement.parent;
99
+ if (graphParent) {
100
+ let hasVisitedStatement = false;
101
+ let hasVisitedNodeModifier = false;
102
+ (0, index_js_1.forEachChild)(graphParent, statement => {
103
+ if (statement === clickedEdgeStatement) {
104
+ hasVisitedStatement = true;
105
+ return undefined;
106
+ }
107
+ if (hasVisitedNodeModifier) {
108
+ return;
109
+ }
110
+ else if (hasVisitedStatement) {
111
+ if ((0, checker_js_1.isAttrStatement)(statement)
112
+ || subtreeContainsErrors(statement)) {
113
+ hasVisitedNodeModifier = true;
114
+ return true;
115
+ }
116
+ }
117
+ if (hasVisitedStatement) {
118
+ if ((0, checker_js_1.isEdgeStatement)(statement)
119
+ && statement.rhs.length === 1
120
+ && !(0, checker_js_1.edgeStatementHasAttributes)(statement)) {
121
+ const statementSource = statement.source;
122
+ if ((0, checker_js_1.isNodeId)(statementSource)) {
123
+ const lowerSourceText = (0, checker_js_1.getIdentifierText)(statementSource.id);
124
+ if (sourceText === lowerSourceText) {
125
+ candidates.push(statement);
126
+ }
127
+ }
128
+ }
129
+ }
130
+ return undefined;
131
+ });
132
+ }
133
+ }
134
+ if (candidates.length > 1) {
135
+ const action = ConsolidateDescendantsCommand.create(candidates, true);
136
+ res.push(action);
137
+ }
138
+ }
139
+ }
140
+ }
141
+ return res.length === 0 ? undefined : res;
142
+ ;
143
+ }
144
+ function getCommandsForDiagnostic(doc, file, d) {
145
+ switch (d.code.source) {
146
+ case 1: return getScannerErrorCommand(doc, file, d, d.code);
147
+ case 2: return getParserErrorCommand(doc, file, d, d.code);
148
+ case 4: return getCheckerErrorCommand(doc, file, d, d.code);
149
+ default: return (0, util_js_1.assertNever)(d.code);
150
+ }
151
+ }
152
+ function getScannerErrorCommand(_doc, _file, d, code) {
153
+ console.assert(d.code.source === 1);
154
+ console.assert(code.source === 1);
155
+ return undefined;
156
+ }
157
+ function getParserErrorCommand(_doc, _file, d, code) {
158
+ console.assert(d.code.source === 2);
159
+ console.assert(code.source === 2);
160
+ return undefined;
161
+ }
162
+ function getCheckerErrorCommand(_doc, file, d, code) {
163
+ console.assert(d.code.source === 4);
164
+ console.assert(code.source === 4);
165
+ switch (code.sub) {
166
+ case 0: {
167
+ const graph = file.graph;
168
+ if (!graph)
169
+ return undefined;
170
+ const allowedOp = (0, checker_js_1.getAllowedEdgeOperation)(graph);
171
+ const wrongOp = (0, common_js_1.getOppositeEdgeOp)(allowedOp);
172
+ const kwk = graph.keyword.kind;
173
+ const fixSingleEdge = ChangeEdgeOpCommand.create(d.start, d.end, allowedOp, wrongOp);
174
+ const fixAll = convertGraphTypeCommand(file, graph, kwk);
175
+ const convertToThisWrongType = convertGraphTypeCommand(file, graph, (0, common_js_1.getOppositeKind)(kwk));
176
+ return [
177
+ fixSingleEdge,
178
+ fixAll,
179
+ convertToThisWrongType,
180
+ ];
181
+ }
182
+ }
183
+ }
184
+ function convertGraphTypeCommand(file, graph, changeToGraphType) {
185
+ const changeToEdgeOp = (0, common_js_1.getAllowedOp)(changeToGraphType);
186
+ const allEdges = (0, checker_js_1.findAllEdges)(graph);
187
+ const edgeOffsets = allEdges
188
+ .filter(e => e.operation.kind !== changeToEdgeOp)
189
+ .map(e => ({
190
+ start: (0, util_js_1.getStart)(file, e.operation),
191
+ end: e.operation.end
192
+ }));
193
+ const graphTypeOffset = {
194
+ start: (0, util_js_1.getStart)(file, graph.keyword),
195
+ end: graph.keyword.end
196
+ };
197
+ return ChangeAllOtherEdgeOpsAndFixGraphCommand.create(edgeOffsets, changeToEdgeOp, graphTypeOffset, graph.keyword.kind, changeToGraphType);
198
+ }
199
+ function isInRange(rangeStartOffset, rangeEndOffset, startOffset, endOffset) {
200
+ if (rangeStartOffset === rangeEndOffset)
201
+ return startOffset <= rangeStartOffset && rangeEndOffset <= endOffset;
202
+ if (rangeStartOffset === startOffset && rangeEndOffset === endOffset)
203
+ return true;
204
+ return false;
205
+ }
206
+ const commandHandlers = {
207
+ ["DOT.changeEdgeOp"]: ChangeEdgeOpCommand.execute,
208
+ ["DOT.convertGraphType"]: ChangeAllOtherEdgeOpsAndFixGraphCommand.execute,
209
+ ["DOT.consolidateDescendants"]: ConsolidateDescendantsCommand.execute,
210
+ ["DOT.removeSemicolons"]: RemoveSemicolonsCommand.execute,
211
+ };
212
+ function getAvailableCommands() {
213
+ return Object.keys(commandHandlers);
214
+ }
215
+ exports.getAvailableCommands = getAvailableCommands;
216
+ function executeCommand(doc, sourceFile, cmd) {
217
+ const handler = commandHandlers[cmd.command];
218
+ return handler === undefined
219
+ ? undefined
220
+ : handler(doc, sourceFile, cmd);
221
+ }
222
+ exports.executeCommand = executeCommand;
223
+ function subtreeContainsErrors(node) {
224
+ if ((0, checker_js_1.nodeContainsErrors)(node))
225
+ return true;
226
+ let hasError = false;
227
+ (0, index_js_1.forEachChild)(node, child => {
228
+ if ((0, checker_js_1.nodeContainsErrors)(child)) {
229
+ hasError = true;
230
+ }
231
+ if (!hasError) {
232
+ hasError = subtreeContainsErrors(child);
233
+ }
234
+ });
235
+ return hasError;
236
+ }
237
+ //# sourceMappingURL=codeAction.js.map
@@ -0,0 +1,6 @@
1
+ import type * as lst from "vscode-languageserver-types";
2
+ import { ColorInformation, Color, ColorPresentation } from "./polyfill.js";
3
+ import { SourceFile } from "../types.js";
4
+ import { DocumentLike } from "../index.js";
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,97 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getColorRepresentations = exports.getDocumentColors = void 0;
27
+ const util_js_1 = require("./util.js");
28
+ const languageFacts = __importStar(require("./languageFacts.js"));
29
+ const colorMap = languageFacts.colors;
30
+ function getDocumentColors(doc, sourceFile) {
31
+ const cs = sourceFile.colors;
32
+ return cs
33
+ ? colorTableToColorInformation(doc, sourceFile, cs)
34
+ : undefined;
35
+ }
36
+ exports.getDocumentColors = getDocumentColors;
37
+ function getColorRepresentations(_doc, _sourceFile, color, range) {
38
+ if (!color || !range)
39
+ return undefined;
40
+ const hexColor = getColorStringFromColor(color);
41
+ return [
42
+ {
43
+ label: '"' + hexColor + '"',
44
+ }
45
+ ];
46
+ }
47
+ exports.getColorRepresentations = getColorRepresentations;
48
+ function colorTableToColorInformation(doc, sf, colors) {
49
+ if (!colors || colors.size === 0)
50
+ return [];
51
+ const res = [];
52
+ for (const [name, value] of colors) {
53
+ if (!name || !value)
54
+ continue;
55
+ const color = getColorFromName(name);
56
+ if (color) {
57
+ res.push({
58
+ range: (0, util_js_1.syntaxNodeToRange)(doc, sf, value.node),
59
+ color,
60
+ });
61
+ }
62
+ }
63
+ return res;
64
+ }
65
+ function getColorFromName(name) {
66
+ if (name.charAt(0) === "#")
67
+ return getHexCodeColor(name);
68
+ const colorAlias = colorMap[name];
69
+ return colorAlias
70
+ ? getHexCodeColor(colorAlias)
71
+ : undefined;
72
+ }
73
+ function getHexCodeColor(colorCode) {
74
+ const hexCode = colorCode.charAt(0) === "#"
75
+ ? colorCode.substring(1)
76
+ : colorCode;
77
+ const colorInt = parseInt(hexCode, 16);
78
+ return {
79
+ red: (colorInt >> 16 & 0xff) / 255.0,
80
+ green: (colorInt >> 8 & 0xff) / 255.0,
81
+ blue: (colorInt & 0xff) / 255.0,
82
+ alpha: hexCode.length === 8 ? (colorInt >> 24 & 0xff) / 255.0 : 1.0,
83
+ };
84
+ }
85
+ function getColorStringFromColor(c) {
86
+ const red = (c.red * 255) | 0;
87
+ const green = (c.green * 255) | 0;
88
+ const blue = (c.blue * 255) | 0;
89
+ return "#" + numberToPaddedString(red) + numberToPaddedString(green) + numberToPaddedString(blue);
90
+ }
91
+ function numberToPaddedString(n) {
92
+ const s = n.toString(16);
93
+ return (s.length === 1
94
+ ? "0" + s
95
+ : s).toLowerCase();
96
+ }
97
+ //# sourceMappingURL=colorProvider.js.map
@@ -1,10 +1,10 @@
1
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 "../../";
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
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): CommandApplication | undefined;