Skip to content

Commit

Permalink
Bug #413: Allows the Diagnostic code to be a string or a number (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahgraham authored Feb 29, 2020
1 parent 90eea1d commit d9331c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Breaking API changes:
* `textDocument/documentHighlight` changed to `DocumentHighlightParams`
* `textDocument/prepareRename` changed to `PrepareRenameParams`

* The LSP's Protocol `Diagnostic` field `code` was previouslyt incorrectly declared as `String`,
it is now correctly declared as `Either<String, Number>`

### v0.8.1 (Sep. 2019)

Fixed issues: https://github.com/eclipse/lsp4j/milestone/16?closed=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,7 @@ class Diagnostic {
/**
* The diagnostic's code. Can be omitted.
*/
String code
Either<String, Number> code

/**
* A human-readable string describing the source of this diagnostic, e.g. 'typescript' or 'super lint'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.DiagnosticTag;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
import org.eclipse.lsp4j.util.Preconditions;
import org.eclipse.xtext.xbase.lib.Pure;
Expand All @@ -41,7 +42,7 @@ public class Diagnostic {
/**
* The diagnostic's code. Can be omitted.
*/
private String code;
private Either<String, Number> code;

/**
* A human-readable string describing the source of this diagnostic, e.g. 'typescript' or 'super lint'.
Expand Down Expand Up @@ -85,7 +86,7 @@ public Diagnostic(@NonNull final Range range, @NonNull final String message, fin

public Diagnostic(@NonNull final Range range, @NonNull final String message, final DiagnosticSeverity severity, final String source, final String code) {
this(range, message, severity, source);
this.code = code;
this.setCode(code);
}

/**
Expand Down Expand Up @@ -125,17 +126,33 @@ public void setSeverity(final DiagnosticSeverity severity) {
* The diagnostic's code. Can be omitted.
*/
@Pure
public String getCode() {
public Either<String, Number> getCode() {
return this.code;
}

/**
* The diagnostic's code. Can be omitted.
*/
public void setCode(final String code) {
public void setCode(final Either<String, Number> code) {
this.code = code;
}

public void setCode(final String code) {
if (code == null) {
this.code = null;
return;
}
this.code = Either.forLeft(code);
}

public void setCode(final Number code) {
if (code == null) {
this.code = null;
return;
}
this.code = Either.forRight(code);
}

/**
* A human-readable string describing the source of this diagnostic, e.g. 'typescript' or 'super lint'.
*/
Expand Down

0 comments on commit d9331c8

Please sign in to comment.