@herb-tools/core 0.3.1 → 0.4.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.
@@ -1,13 +1,6 @@
1
1
  import { Location, SerializedLocation } from "./location.js";
2
2
  import { Token, SerializedToken } from "./token.js";
3
- type HerbDiagnostic = {
4
- line: number;
5
- column: number;
6
- endLine: number;
7
- endColumn: number;
8
- message: string;
9
- severity: "error" | "warning" | "info";
10
- };
3
+ import { Diagnostic, MonacoDiagnostic } from "./diagnostic.js";
11
4
  export type HerbErrorType = "UNEXPECTED_ERROR" | "UNEXPECTED_TOKEN_ERROR" | "MISSING_OPENING_TAG_ERROR" | "MISSING_CLOSING_TAG_ERROR" | "TAG_NAMES_MISMATCH_ERROR" | "QUOTES_MISMATCH_ERROR" | "VOID_ELEMENT_CLOSING_TAG_ERROR" | "UNCLOSED_ELEMENT_ERROR" | "RUBY_PARSE_ERROR";
12
5
  export type SerializedErrorType = string;
13
6
  export interface SerializedHerbError {
@@ -15,10 +8,13 @@ export interface SerializedHerbError {
15
8
  message: string;
16
9
  location: SerializedLocation;
17
10
  }
18
- export declare abstract class HerbError {
11
+ export declare abstract class HerbError implements Diagnostic {
19
12
  readonly type: string;
20
13
  readonly message: string;
21
14
  readonly location: Location;
15
+ readonly severity: "error" | "warning" | "info" | "hint";
16
+ readonly source: string;
17
+ get code(): string;
22
18
  static from(error: SerializedHerbError): HerbError;
23
19
  constructor(type: string, message: string, location: Location);
24
20
  toJSON(): SerializedHerbError;
@@ -48,7 +44,7 @@ export declare class UnexpectedError extends HerbError {
48
44
  static from(data: SerializedUnexpectedError): UnexpectedError;
49
45
  constructor(props: UnexpectedErrorProps);
50
46
  toJSON(): SerializedUnexpectedError;
51
- toDiagnostics(): HerbDiagnostic[];
47
+ toMonacoDiagnostic(): MonacoDiagnostic;
52
48
  treeInspect(): string;
53
49
  }
54
50
  export interface SerializedUnexpectedTokenError {
@@ -71,7 +67,7 @@ export declare class UnexpectedTokenError extends HerbError {
71
67
  static from(data: SerializedUnexpectedTokenError): UnexpectedTokenError;
72
68
  constructor(props: UnexpectedTokenErrorProps);
73
69
  toJSON(): SerializedUnexpectedTokenError;
74
- toDiagnostics(): HerbDiagnostic[];
70
+ toMonacoDiagnostic(): MonacoDiagnostic;
75
71
  treeInspect(): string;
76
72
  }
77
73
  export interface SerializedMissingOpeningTagError {
@@ -91,7 +87,7 @@ export declare class MissingOpeningTagError extends HerbError {
91
87
  static from(data: SerializedMissingOpeningTagError): MissingOpeningTagError;
92
88
  constructor(props: MissingOpeningTagErrorProps);
93
89
  toJSON(): SerializedMissingOpeningTagError;
94
- toDiagnostics(): HerbDiagnostic[];
90
+ toMonacoDiagnostic(): MonacoDiagnostic;
95
91
  treeInspect(): string;
96
92
  }
97
93
  export interface SerializedMissingClosingTagError {
@@ -111,7 +107,7 @@ export declare class MissingClosingTagError extends HerbError {
111
107
  static from(data: SerializedMissingClosingTagError): MissingClosingTagError;
112
108
  constructor(props: MissingClosingTagErrorProps);
113
109
  toJSON(): SerializedMissingClosingTagError;
114
- toDiagnostics(): HerbDiagnostic[];
110
+ toMonacoDiagnostic(): MonacoDiagnostic;
115
111
  treeInspect(): string;
116
112
  }
117
113
  export interface SerializedTagNamesMismatchError {
@@ -134,7 +130,7 @@ export declare class TagNamesMismatchError extends HerbError {
134
130
  static from(data: SerializedTagNamesMismatchError): TagNamesMismatchError;
135
131
  constructor(props: TagNamesMismatchErrorProps);
136
132
  toJSON(): SerializedTagNamesMismatchError;
137
- toDiagnostics(): HerbDiagnostic[];
133
+ toMonacoDiagnostic(): MonacoDiagnostic;
138
134
  treeInspect(): string;
139
135
  }
140
136
  export interface SerializedQuotesMismatchError {
@@ -157,7 +153,7 @@ export declare class QuotesMismatchError extends HerbError {
157
153
  static from(data: SerializedQuotesMismatchError): QuotesMismatchError;
158
154
  constructor(props: QuotesMismatchErrorProps);
159
155
  toJSON(): SerializedQuotesMismatchError;
160
- toDiagnostics(): HerbDiagnostic[];
156
+ toMonacoDiagnostic(): MonacoDiagnostic;
161
157
  treeInspect(): string;
162
158
  }
163
159
  export interface SerializedVoidElementClosingTagError {
@@ -183,7 +179,7 @@ export declare class VoidElementClosingTagError extends HerbError {
183
179
  static from(data: SerializedVoidElementClosingTagError): VoidElementClosingTagError;
184
180
  constructor(props: VoidElementClosingTagErrorProps);
185
181
  toJSON(): SerializedVoidElementClosingTagError;
186
- toDiagnostics(): HerbDiagnostic[];
182
+ toMonacoDiagnostic(): MonacoDiagnostic;
187
183
  treeInspect(): string;
188
184
  }
189
185
  export interface SerializedUnclosedElementError {
@@ -203,7 +199,7 @@ export declare class UnclosedElementError extends HerbError {
203
199
  static from(data: SerializedUnclosedElementError): UnclosedElementError;
204
200
  constructor(props: UnclosedElementErrorProps);
205
201
  toJSON(): SerializedUnclosedElementError;
206
- toDiagnostics(): HerbDiagnostic[];
202
+ toMonacoDiagnostic(): MonacoDiagnostic;
207
203
  treeInspect(): string;
208
204
  }
209
205
  export interface SerializedRubyParseError {
@@ -229,8 +225,7 @@ export declare class RubyParseError extends HerbError {
229
225
  static from(data: SerializedRubyParseError): RubyParseError;
230
226
  constructor(props: RubyParseErrorProps);
231
227
  toJSON(): SerializedRubyParseError;
232
- toDiagnostics(): HerbDiagnostic[];
228
+ toMonacoDiagnostic(): MonacoDiagnostic;
233
229
  treeInspect(): string;
234
230
  }
235
231
  export declare function fromSerializedError(error: SerializedHerbError): HerbError;
236
- export {};
@@ -1,4 +1,5 @@
1
1
  export * from "./backend.js";
2
+ export * from "./diagnostic.js";
2
3
  export * from "./errors.js";
3
4
  export * from "./herb-backend.js";
4
5
  export * from "./lex-result.js";
@@ -15,7 +15,6 @@ export interface BaseNodeProps {
15
15
  location: Location;
16
16
  errors: HerbError[];
17
17
  }
18
- export type NodeType = "AST_DOCUMENT_NODE" | "AST_LITERAL_NODE" | "AST_HTML_OPEN_TAG_NODE" | "AST_HTML_CLOSE_TAG_NODE" | "AST_HTML_SELF_CLOSE_TAG_NODE" | "AST_HTML_ELEMENT_NODE" | "AST_HTML_ATTRIBUTE_VALUE_NODE" | "AST_HTML_ATTRIBUTE_NAME_NODE" | "AST_HTML_ATTRIBUTE_NODE" | "AST_HTML_TEXT_NODE" | "AST_HTML_COMMENT_NODE" | "AST_HTML_DOCTYPE_NODE" | "AST_WHITESPACE_NODE" | "AST_ERB_CONTENT_NODE" | "AST_ERB_END_NODE" | "AST_ERB_ELSE_NODE" | "AST_ERB_IF_NODE" | "AST_ERB_BLOCK_NODE" | "AST_ERB_WHEN_NODE" | "AST_ERB_CASE_NODE" | "AST_ERB_CASE_MATCH_NODE" | "AST_ERB_WHILE_NODE" | "AST_ERB_UNTIL_NODE" | "AST_ERB_FOR_NODE" | "AST_ERB_RESCUE_NODE" | "AST_ERB_ENSURE_NODE" | "AST_ERB_BEGIN_NODE" | "AST_ERB_UNLESS_NODE" | "AST_ERB_YIELD_NODE" | "AST_ERB_IN_NODE";
19
18
  export declare abstract class Node implements BaseNodeProps {
20
19
  readonly type: NodeType;
21
20
  readonly location: Location;
@@ -850,3 +849,8 @@ export declare class ERBInNode extends Node {
850
849
  treeInspect(): string;
851
850
  }
852
851
  export declare function fromSerializedNode(node: SerializedNode): Node;
852
+ export type NodeType = "AST_DOCUMENT_NODE" | "AST_LITERAL_NODE" | "AST_HTML_OPEN_TAG_NODE" | "AST_HTML_CLOSE_TAG_NODE" | "AST_HTML_SELF_CLOSE_TAG_NODE" | "AST_HTML_ELEMENT_NODE" | "AST_HTML_ATTRIBUTE_VALUE_NODE" | "AST_HTML_ATTRIBUTE_NAME_NODE" | "AST_HTML_ATTRIBUTE_NODE" | "AST_HTML_TEXT_NODE" | "AST_HTML_COMMENT_NODE" | "AST_HTML_DOCTYPE_NODE" | "AST_WHITESPACE_NODE" | "AST_ERB_CONTENT_NODE" | "AST_ERB_END_NODE" | "AST_ERB_ELSE_NODE" | "AST_ERB_IF_NODE" | "AST_ERB_BLOCK_NODE" | "AST_ERB_WHEN_NODE" | "AST_ERB_CASE_NODE" | "AST_ERB_CASE_MATCH_NODE" | "AST_ERB_WHILE_NODE" | "AST_ERB_UNTIL_NODE" | "AST_ERB_FOR_NODE" | "AST_ERB_RESCUE_NODE" | "AST_ERB_ENSURE_NODE" | "AST_ERB_BEGIN_NODE" | "AST_ERB_UNLESS_NODE" | "AST_ERB_YIELD_NODE" | "AST_ERB_IN_NODE";
853
+ export type ERBNodeType = Extract<NodeType, `AST_ERB_${string}`>;
854
+ export type ERBNode = ERBContentNode | ERBEndNode | ERBElseNode | ERBIfNode | ERBBlockNode | ERBWhenNode | ERBCaseNode | ERBCaseMatchNode | ERBWhileNode | ERBUntilNode | ERBForNode | ERBRescueNode | ERBEnsureNode | ERBBeginNode | ERBUnlessNode | ERBYieldNode | ERBInNode;
855
+ export declare const ERBNodeClasses: (typeof ERBContentNode | typeof ERBEndNode | typeof ERBElseNode | typeof ERBIfNode | typeof ERBBlockNode | typeof ERBWhenNode | typeof ERBCaseNode | typeof ERBCaseMatchNode | typeof ERBWhileNode | typeof ERBUntilNode | typeof ERBForNode | typeof ERBRescueNode | typeof ERBEnsureNode | typeof ERBBeginNode | typeof ERBUnlessNode | typeof ERBYieldNode | typeof ERBInNode)[];
856
+ export declare function isERBNode(node: Node): node is ERBNode;
@@ -5,6 +5,7 @@ export declare class TokenList implements Iterable<Token> {
5
5
  static from(list: SerializedTokenList): TokenList;
6
6
  constructor(list: Token[]);
7
7
  get length(): number;
8
+ get tokens(): Token[];
8
9
  [Symbol.iterator](): Iterator<Token>;
9
10
  at(index: number): Token | undefined;
10
11
  forEach(callback: (token: Token, index: number, array: Token[]) => void): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herb-tools/core",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Core module exporting shared interfaces, AST node definitions, and common utilities for Herb",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -31,7 +31,6 @@
31
31
  }
32
32
  },
33
33
  "dependencies": {},
34
- "devDependencies": {},
35
34
  "files": [
36
35
  "package.json",
37
36
  "README.md",
@@ -0,0 +1,78 @@
1
+ import { Location, SerializedLocation } from "./location.js"
2
+
3
+ export type DiagnosticSeverity = "error" | "warning" | "info" | "hint"
4
+
5
+ /**
6
+ * Base interface for all diagnostic information in Herb tooling.
7
+ * This includes parser errors, lexer errors, lint offenses, and any other
8
+ * issues that need to be reported to users.
9
+ */
10
+ export interface Diagnostic {
11
+ /**
12
+ * The diagnostic message describing the issue
13
+ */
14
+ message: string
15
+
16
+ /**
17
+ * The location in the source where this diagnostic applies
18
+ */
19
+ location: Location
20
+
21
+ /**
22
+ * The severity level of the diagnostic
23
+ */
24
+ severity: DiagnosticSeverity
25
+
26
+ /**
27
+ * Optional diagnostic code for categorization (e.g., "E0001", "W0042")
28
+ */
29
+ code?: string
30
+
31
+ /**
32
+ * Optional source that generated this diagnostic (e.g., "parser", "linter", "lexer")
33
+ */
34
+ source?: string
35
+ }
36
+
37
+ /**
38
+ * Serialized form of a Diagnostic for JSON representation
39
+ */
40
+ export interface SerializedDiagnostic {
41
+ message: string
42
+ location: SerializedLocation
43
+ severity: DiagnosticSeverity
44
+ code?: string
45
+ source?: string
46
+ }
47
+
48
+ export type MonacoSeverity = "error" | "warning" | "info"
49
+
50
+ /**
51
+ * Monaco/VSCode-compatible diagnostic format for editor integration
52
+ */
53
+ export type MonacoDiagnostic = {
54
+ line: number
55
+ column: number
56
+ endLine: number
57
+ endColumn: number
58
+ message: string
59
+ severity: MonacoSeverity
60
+ }
61
+
62
+ /**
63
+ * Converts a Diagnostic to Monaco/VSCode-compatible MonacoDiagnostic format
64
+ */
65
+ export function toMonacoDiagnostic(diagnostic: Diagnostic): MonacoDiagnostic {
66
+ const { message, location } = diagnostic
67
+
68
+ const severity: MonacoSeverity = diagnostic.severity === "hint" ? "info" : diagnostic.severity
69
+
70
+ return {
71
+ line: location.start.line,
72
+ column: location.start.column,
73
+ endLine: location.end.line,
74
+ endColumn: location.end.column,
75
+ message,
76
+ severity
77
+ }
78
+ }
package/src/errors.ts CHANGED
@@ -3,15 +3,7 @@
3
3
 
4
4
  import { Location, SerializedLocation } from "./location.js"
5
5
  import { Token, SerializedToken } from "./token.js"
6
-
7
- type HerbDiagnostic = {
8
- line: number
9
- column: number
10
- endLine: number
11
- endColumn: number
12
- message: string
13
- severity: "error" | "warning" | "info"
14
- }
6
+ import { Diagnostic, MonacoDiagnostic } from "./diagnostic.js"
15
7
 
16
8
  export type HerbErrorType =
17
9
  | "UNEXPECTED_ERROR"
@@ -32,10 +24,16 @@ export interface SerializedHerbError {
32
24
  location: SerializedLocation
33
25
  }
34
26
 
35
- export abstract class HerbError {
27
+ export abstract class HerbError implements Diagnostic {
36
28
  readonly type: string
37
29
  readonly message: string
38
30
  readonly location: Location
31
+ readonly severity: "error" | "warning" | "info" | "hint" = "error"
32
+ readonly source: string = "parser"
33
+
34
+ get code(): string {
35
+ return this.type
36
+ }
39
37
 
40
38
  static from(error: SerializedHerbError): HerbError {
41
39
  return fromSerializedError(error)
@@ -114,23 +112,15 @@ export class UnexpectedError extends HerbError {
114
112
  };
115
113
  }
116
114
 
117
- toDiagnostics(): HerbDiagnostic[] {
118
- const diagnostics: HerbDiagnostic[] = [
119
- {
120
- line: this.location.start.line,
121
- column: this.location.start.column,
122
- endLine: this.location.end.line,
123
- endColumn: this.location.end.column,
124
- message: this.message,
125
- severity: 'error'
126
- }
127
- ]
128
-
129
- // no-op for description
130
- // no-op for expected
131
- // no-op for found
132
-
133
- return diagnostics
115
+ toMonacoDiagnostic(): MonacoDiagnostic {
116
+ return {
117
+ line: this.location.start.line,
118
+ column: this.location.start.column,
119
+ endLine: this.location.end.line,
120
+ endColumn: this.location.end.column,
121
+ message: this.message,
122
+ severity: 'error'
123
+ }
134
124
  }
135
125
 
136
126
  treeInspect(): string {
@@ -192,32 +182,15 @@ export class UnexpectedTokenError extends HerbError {
192
182
  };
193
183
  }
194
184
 
195
- toDiagnostics(): HerbDiagnostic[] {
196
- const diagnostics: HerbDiagnostic[] = [
197
- {
198
- line: this.location.start.line,
199
- column: this.location.start.column,
200
- endLine: this.location.end.line,
201
- endColumn: this.location.end.column,
202
- message: this.message,
203
- severity: 'error'
204
- }
205
- ]
206
-
207
- // no-op for expected_type
208
- if (this.found) {
209
- diagnostics.push({
210
- line: this.found.location.start.line,
211
- column: this.found.location.start.column,
212
- endLine: this.found.location.end.line,
213
- endColumn: this.found.location.end.column,
214
- message: `found "${(this.found.value)}" is here`,
215
- severity: 'info'
216
- })
185
+ toMonacoDiagnostic(): MonacoDiagnostic {
186
+ return {
187
+ line: this.location.start.line,
188
+ column: this.location.start.column,
189
+ endLine: this.location.end.line,
190
+ endColumn: this.location.end.column,
191
+ message: this.message,
192
+ severity: 'error'
217
193
  }
218
-
219
-
220
- return diagnostics
221
194
  }
222
195
 
223
196
  treeInspect(): string {
@@ -272,31 +245,15 @@ export class MissingOpeningTagError extends HerbError {
272
245
  };
273
246
  }
274
247
 
275
- toDiagnostics(): HerbDiagnostic[] {
276
- const diagnostics: HerbDiagnostic[] = [
277
- {
278
- line: this.location.start.line,
279
- column: this.location.start.column,
280
- endLine: this.location.end.line,
281
- endColumn: this.location.end.column,
282
- message: this.message,
283
- severity: 'error'
284
- }
285
- ]
286
-
287
- if (this.closing_tag) {
288
- diagnostics.push({
289
- line: this.closing_tag.location.start.line,
290
- column: this.closing_tag.location.start.column,
291
- endLine: this.closing_tag.location.end.line,
292
- endColumn: this.closing_tag.location.end.column,
293
- message: `closing_tag "${(this.closing_tag.value)}" is here`,
294
- severity: 'info'
295
- })
248
+ toMonacoDiagnostic(): MonacoDiagnostic {
249
+ return {
250
+ line: this.location.start.line,
251
+ column: this.location.start.column,
252
+ endLine: this.location.end.line,
253
+ endColumn: this.location.end.column,
254
+ message: this.message,
255
+ severity: 'error'
296
256
  }
297
-
298
-
299
- return diagnostics
300
257
  }
301
258
 
302
259
  treeInspect(): string {
@@ -350,31 +307,15 @@ export class MissingClosingTagError extends HerbError {
350
307
  };
351
308
  }
352
309
 
353
- toDiagnostics(): HerbDiagnostic[] {
354
- const diagnostics: HerbDiagnostic[] = [
355
- {
356
- line: this.location.start.line,
357
- column: this.location.start.column,
358
- endLine: this.location.end.line,
359
- endColumn: this.location.end.column,
360
- message: this.message,
361
- severity: 'error'
362
- }
363
- ]
364
-
365
- if (this.opening_tag) {
366
- diagnostics.push({
367
- line: this.opening_tag.location.start.line,
368
- column: this.opening_tag.location.start.column,
369
- endLine: this.opening_tag.location.end.line,
370
- endColumn: this.opening_tag.location.end.column,
371
- message: `opening_tag "${(this.opening_tag.value)}" is here`,
372
- severity: 'info'
373
- })
310
+ toMonacoDiagnostic(): MonacoDiagnostic {
311
+ return {
312
+ line: this.location.start.line,
313
+ column: this.location.start.column,
314
+ endLine: this.location.end.line,
315
+ endColumn: this.location.end.column,
316
+ message: this.message,
317
+ severity: 'error'
374
318
  }
375
-
376
-
377
- return diagnostics
378
319
  }
379
320
 
380
321
  treeInspect(): string {
@@ -434,42 +375,15 @@ export class TagNamesMismatchError extends HerbError {
434
375
  };
435
376
  }
436
377
 
437
- toDiagnostics(): HerbDiagnostic[] {
438
- const diagnostics: HerbDiagnostic[] = [
439
- {
440
- line: this.location.start.line,
441
- column: this.location.start.column,
442
- endLine: this.location.end.line,
443
- endColumn: this.location.end.column,
444
- message: this.message,
445
- severity: 'error'
446
- }
447
- ]
448
-
449
- if (this.opening_tag) {
450
- diagnostics.push({
451
- line: this.opening_tag.location.start.line,
452
- column: this.opening_tag.location.start.column,
453
- endLine: this.opening_tag.location.end.line,
454
- endColumn: this.opening_tag.location.end.column,
455
- message: `opening_tag "${(this.opening_tag.value)}" is here`,
456
- severity: 'info'
457
- })
458
- }
459
-
460
- if (this.closing_tag) {
461
- diagnostics.push({
462
- line: this.closing_tag.location.start.line,
463
- column: this.closing_tag.location.start.column,
464
- endLine: this.closing_tag.location.end.line,
465
- endColumn: this.closing_tag.location.end.column,
466
- message: `closing_tag "${(this.closing_tag.value)}" is here`,
467
- severity: 'info'
468
- })
378
+ toMonacoDiagnostic(): MonacoDiagnostic {
379
+ return {
380
+ line: this.location.start.line,
381
+ column: this.location.start.column,
382
+ endLine: this.location.end.line,
383
+ endColumn: this.location.end.column,
384
+ message: this.message,
385
+ severity: 'error'
469
386
  }
470
-
471
-
472
- return diagnostics
473
387
  }
474
388
 
475
389
  treeInspect(): string {
@@ -530,42 +444,15 @@ export class QuotesMismatchError extends HerbError {
530
444
  };
531
445
  }
532
446
 
533
- toDiagnostics(): HerbDiagnostic[] {
534
- const diagnostics: HerbDiagnostic[] = [
535
- {
536
- line: this.location.start.line,
537
- column: this.location.start.column,
538
- endLine: this.location.end.line,
539
- endColumn: this.location.end.column,
540
- message: this.message,
541
- severity: 'error'
542
- }
543
- ]
544
-
545
- if (this.opening_quote) {
546
- diagnostics.push({
547
- line: this.opening_quote.location.start.line,
548
- column: this.opening_quote.location.start.column,
549
- endLine: this.opening_quote.location.end.line,
550
- endColumn: this.opening_quote.location.end.column,
551
- message: `opening_quote "${(this.opening_quote.value)}" is here`,
552
- severity: 'info'
553
- })
554
- }
555
-
556
- if (this.closing_quote) {
557
- diagnostics.push({
558
- line: this.closing_quote.location.start.line,
559
- column: this.closing_quote.location.start.column,
560
- endLine: this.closing_quote.location.end.line,
561
- endColumn: this.closing_quote.location.end.column,
562
- message: `closing_quote "${(this.closing_quote.value)}" is here`,
563
- severity: 'info'
564
- })
447
+ toMonacoDiagnostic(): MonacoDiagnostic {
448
+ return {
449
+ line: this.location.start.line,
450
+ column: this.location.start.column,
451
+ endLine: this.location.end.line,
452
+ endColumn: this.location.end.column,
453
+ message: this.message,
454
+ severity: 'error'
565
455
  }
566
-
567
-
568
- return diagnostics
569
456
  }
570
457
 
571
458
  treeInspect(): string {
@@ -632,33 +519,15 @@ export class VoidElementClosingTagError extends HerbError {
632
519
  };
633
520
  }
634
521
 
635
- toDiagnostics(): HerbDiagnostic[] {
636
- const diagnostics: HerbDiagnostic[] = [
637
- {
638
- line: this.location.start.line,
639
- column: this.location.start.column,
640
- endLine: this.location.end.line,
641
- endColumn: this.location.end.column,
642
- message: this.message,
643
- severity: 'error'
644
- }
645
- ]
646
-
647
- if (this.tag_name) {
648
- diagnostics.push({
649
- line: this.tag_name.location.start.line,
650
- column: this.tag_name.location.start.column,
651
- endLine: this.tag_name.location.end.line,
652
- endColumn: this.tag_name.location.end.column,
653
- message: `tag_name "${(this.tag_name.value)}" is here`,
654
- severity: 'info'
655
- })
522
+ toMonacoDiagnostic(): MonacoDiagnostic {
523
+ return {
524
+ line: this.location.start.line,
525
+ column: this.location.start.column,
526
+ endLine: this.location.end.line,
527
+ endColumn: this.location.end.column,
528
+ message: this.message,
529
+ severity: 'error'
656
530
  }
657
-
658
- // no-op for expected
659
- // no-op for found
660
-
661
- return diagnostics
662
531
  }
663
532
 
664
533
  treeInspect(): string {
@@ -714,31 +583,15 @@ export class UnclosedElementError extends HerbError {
714
583
  };
715
584
  }
716
585
 
717
- toDiagnostics(): HerbDiagnostic[] {
718
- const diagnostics: HerbDiagnostic[] = [
719
- {
720
- line: this.location.start.line,
721
- column: this.location.start.column,
722
- endLine: this.location.end.line,
723
- endColumn: this.location.end.column,
724
- message: this.message,
725
- severity: 'error'
726
- }
727
- ]
728
-
729
- if (this.opening_tag) {
730
- diagnostics.push({
731
- line: this.opening_tag.location.start.line,
732
- column: this.opening_tag.location.start.column,
733
- endLine: this.opening_tag.location.end.line,
734
- endColumn: this.opening_tag.location.end.column,
735
- message: `opening_tag "${(this.opening_tag.value)}" is here`,
736
- severity: 'info'
737
- })
586
+ toMonacoDiagnostic(): MonacoDiagnostic {
587
+ return {
588
+ line: this.location.start.line,
589
+ column: this.location.start.column,
590
+ endLine: this.location.end.line,
591
+ endColumn: this.location.end.column,
592
+ message: this.message,
593
+ severity: 'error'
738
594
  }
739
-
740
-
741
- return diagnostics
742
595
  }
743
596
 
744
597
  treeInspect(): string {
@@ -804,23 +657,15 @@ export class RubyParseError extends HerbError {
804
657
  };
805
658
  }
806
659
 
807
- toDiagnostics(): HerbDiagnostic[] {
808
- const diagnostics: HerbDiagnostic[] = [
809
- {
810
- line: this.location.start.line,
811
- column: this.location.start.column,
812
- endLine: this.location.end.line,
813
- endColumn: this.location.end.column,
814
- message: this.message,
815
- severity: 'error'
816
- }
817
- ]
818
-
819
- // no-op for error_message
820
- // no-op for diagnostic_id
821
- // no-op for level
822
-
823
- return diagnostics
660
+ toMonacoDiagnostic(): MonacoDiagnostic {
661
+ return {
662
+ line: this.location.start.line,
663
+ column: this.location.start.column,
664
+ endLine: this.location.end.line,
665
+ endColumn: this.location.end.column,
666
+ message: this.message,
667
+ severity: 'error'
668
+ }
824
669
  }
825
670
 
826
671
  treeInspect(): string {
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./backend.js"
2
+ export * from "./diagnostic.js"
2
3
  export * from "./errors.js"
3
4
  export * from "./herb-backend.js"
4
5
  export * from "./lex-result.js"