Skip to content

Commit

Permalink
Refactor method visibility for cleaner code
Browse files Browse the repository at this point in the history
  • Loading branch information
RadCod3 committed May 7, 2024
1 parent 2ede880 commit 4129911
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public Ansi renderDiagnostic(Diagnostic diagnostic) {
DiagnosticAnnotation diagnosticAnnotation =
getDiagnosticAnnotation(document, diagnosticLocation, diagnosticInfo.severity());
return renderAnsi(diagnosticToString(diagnostic, isColorEnabled) + NEW_LINE + diagnosticAnnotation);

}

private static int getTerminalWidth() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class DiagnosticAnnotation {

public static final String NEW_LINE = System.lineSeparator();
public static final String JANSI_ANNOTATOR = "@|";
public static final String JANSI_RESET = "|@"; // @|red , TEXT |@
public static final String JANSI_RESET = "|@";
private static final String PIPE = "|";
private static final String COLON = ":";
private static final String ELLIPSIS = "...";
Expand Down Expand Up @@ -97,10 +97,8 @@ public String toString() {
.append(getLineNumberString(digitsNum, startLineNumber)).append(PIPE).append(" ")
.append(result.line).append(NEW_LINE)
.append(padding).append(PIPE).append(" ")
.append(getUnderline(result.diagnosticStart, result.diagnosticLength, this.severity, this.type,
isColorEnabled)).append(NEW_LINE);
.append(getUnderline(result.diagnosticStart, result.diagnosticLength)).append(NEW_LINE);
return outputBuilder.toString();

}
String startLine = lines.get(0);
String endLine = lines.get(lines.size() - 1);
Expand All @@ -127,33 +125,30 @@ public String toString() {

if (lines.size() <= MAX_LINES_BEFORE_HIDING) {
outputBuilder.append(padding).append(PIPE).append(" ")
.append(getUnderline(startLineResult.diagnosticStart, startLineResult.diagnosticLength,
this.severity,
this.type, isColorEnabled)).append(NEW_LINE);
.append(getUnderline(startLineResult.diagnosticStart, startLineResult.diagnosticLength))
.append(NEW_LINE);
for (int i = 1; i < lines.size() - 1; i++) {
String line = replaceTabs(lines.get(i), 0);
TruncateResult lineResult = truncate(line, maxLength, 0, line.length());
outputBuilder.append(getLineNumberString(endDigitsNum, startLineNumber + i)).append(PIPE).append(" ")
.append(lineResult.line).append(NEW_LINE)
.append(padding).append(PIPE).append(" ")
.append(getUnderline(lineResult.diagnosticStart, lineResult.diagnosticLength, this.severity,
this.type, isColorEnabled)).append(NEW_LINE);
.append(getUnderline(lineResult.diagnosticStart, lineResult.diagnosticLength)).append(NEW_LINE);
}

} else {
String paddingToMiddleColon = " ".repeat(Math.min(terminalWidth, maxLineLength) / 2);
String hiddenLinesPlaceholder = paddingWithColon + PIPE + " " + paddingToMiddleColon + COLON + NEW_LINE;
outputBuilder.append(paddingWithColon).append(PIPE).append(" ")
.append(getUnderline(startLineResult.diagnosticStart, startLineResult.diagnosticLength,
this.severity,
this.type, isColorEnabled)).append(NEW_LINE)
.append(getUnderline(startLineResult.diagnosticStart, startLineResult.diagnosticLength))
.append(NEW_LINE)
.append(hiddenLinesPlaceholder).append(hiddenLinesPlaceholder);

}
return outputBuilder.append(getLineNumberString(endDigitsNum, startLineNumber + lines.size() - 1))
.append(PIPE).append(" ").append(endLineResult.line).append(NEW_LINE)
.append(padding).append(PIPE).append(" ")
.append(getUnderline(0, endLineResult.diagnosticLength, this.severity, this.type, isColorEnabled))
.append(getUnderline(0, endLineResult.diagnosticLength))
.append(NEW_LINE).toString();
}

Expand All @@ -169,14 +164,13 @@ private static int getStart(List<String> lines, int start) {
return start + 3 * countTabChars(lines.get(0), start);
}

private static String getUnderline(int offset, int length, DiagnosticSeverity severity,
DiagnosticAnnotationType type, boolean isColorEnabled) {
private String getUnderline(int offset, int length) {
String symbol = "^";
if (type == DiagnosticAnnotationType.MISSING) {
if (this.type == DiagnosticAnnotationType.MISSING) {
symbol = "+";
}
return " ".repeat(offset) +
getColoredString(symbol.repeat(length), SEVERITY_COLORS.get(severity), isColorEnabled);
getColoredString(symbol.repeat(length), SEVERITY_COLORS.get(this.severity), this.isColorEnabled);
}

private static int countTabChars(String line, int end) {
Expand Down

0 comments on commit 4129911

Please sign in to comment.