Skip to content

Commit 01699ca

Browse files
authored
Add Custom Warning (#24)
1 parent 19924ab commit 01699ca

File tree

7 files changed

+28
-5
lines changed

7 files changed

+28
-5
lines changed
377 Bytes
Binary file not shown.

client/src/types/diagnostics.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export type LJError = CustomError | IllegalConstructorTransitionError |
2828
InvalidRefinementError | NotFoundError | RefinementError | StateConflictError |
2929
StateRefinementError | SyntaxError;
3030

31-
export type LJWarning = ExternalClassNotFoundWarning | ExternalMethodNotFoundWarning;
31+
export type LJWarning = CustomWarning | ExternalClassNotFoundWarning | ExternalMethodNotFoundWarning;
3232

3333
type BaseDiagnostic = {
3434
title: string;
@@ -90,6 +90,11 @@ export type SyntaxError = BaseDiagnostic & {
9090
refinement: string;
9191
}
9292

93+
export type CustomWarning = BaseDiagnostic & {
94+
category: 'warning';
95+
type: 'custom-warning';
96+
}
97+
9398
export type ExternalClassNotFoundWarning = BaseDiagnostic & {
9499
category: 'warning';
95100
type: 'external-class-not-found-warning';

client/src/webview/renderers/diagnostics/errors.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,5 @@ export function renderError(error: LJError): string {
5959
const e = error as StateRefinementError;
6060
return `${header}${renderSection('Expected', `<pre>${e.expected}</pre>`)}${renderSection('Found', `<pre>${e.found}</pre>`)}${location}`;
6161
}
62-
default:
63-
return `${header}${location}`;
6462
}
6563
}

client/src/webview/renderers/diagnostics/warnings.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export function renderWarning(warning: LJWarning): string {
2929
const e = warning as ExternalMethodNotFoundWarning;
3030
return `${header}${renderSection('Method', `<pre>${e.methodName}</pre>`)}${e.overloads.length > 0 ? renderSection("Overloads", `<pre>${e.overloads.join("\n")}</pre>`) : ""}${location}`;
3131
}
32-
default:
32+
case 'custom-warning': {
3333
return `${header}${location}`;
34+
}
3435
}
3536
}

server/src/main/java/dtos/DiagnosticConverter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import dtos.errors.StateConflictErrorDTO;
1313
import dtos.errors.StateRefinementErrorDTO;
1414
import dtos.errors.SyntaxErrorDTO;
15+
import dtos.warnings.CustomWarningDTO;
1516
import dtos.warnings.ExternalClassNotFoundWarningDTO;
1617
import dtos.warnings.ExternalMethodNotFoundWarningDTO;
1718
import dtos.warnings.LJWarningDTO;
@@ -25,6 +26,7 @@
2526
import liquidjava.diagnostics.errors.StateConflictError;
2627
import liquidjava.diagnostics.errors.StateRefinementError;
2728
import liquidjava.diagnostics.errors.SyntaxError;
29+
import liquidjava.diagnostics.warnings.CustomWarning;
2830
import liquidjava.diagnostics.warnings.ExternalClassNotFoundWarning;
2931
import liquidjava.diagnostics.warnings.ExternalMethodNotFoundWarning;
3032
import liquidjava.diagnostics.warnings.LJWarning;
@@ -60,6 +62,8 @@ public static Object convertToDTO(LJDiagnostic diagnostic) {
6062
return ExternalClassNotFoundWarningDTO.from(d);
6163
} else if (diagnostic instanceof ExternalMethodNotFoundWarning d) {
6264
return ExternalMethodNotFoundWarningDTO.from(d);
65+
} else if (diagnostic instanceof CustomWarning d) {
66+
return CustomWarningDTO.from(d);
6367
} else if (diagnostic instanceof LJError d) {
6468
return LJErrorDTO.from(d);
6569
} else if (diagnostic instanceof LJWarning d) {

server/src/main/java/dtos/errors/RefinementErrorDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public record RefinementErrorDTO(String category, String type, String title, Str
1313

1414
public static RefinementErrorDTO from(RefinementError error) {
1515
return new RefinementErrorDTO("error", "refinement-error", error.getTitle(), error.getMessage(), error.getFile(),
16-
error.getPosition(), TranslationTableDTO.from(error.getTranslationTable()), error.getExpected(), error.getFound());
16+
error.getPosition(), TranslationTableDTO.from(error.getTranslationTable()), new ValDerivationNode(null, null), error.getFound());
1717
}
1818
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package dtos.warnings;
2+
3+
import liquidjava.diagnostics.ErrorPosition;
4+
import liquidjava.diagnostics.warnings.CustomWarning;
5+
6+
/**
7+
* DTO for serializing CustomError instances to JSON
8+
*/
9+
public record CustomWarningDTO(String category, String type, String title, String message, String file, ErrorPosition position) {
10+
11+
public static CustomWarningDTO from(CustomWarning warning) {
12+
return new CustomWarningDTO("warning", "custom-warning", warning.getTitle(), warning.getMessage(), warning.getFile(),
13+
warning.getPosition());
14+
}
15+
}

0 commit comments

Comments
 (0)