Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DiagnosticTag support #362

Merged
merged 3 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/******************************************************************************
* Copyright (c) 2019 Mcirosoft.
akaroml marked this conversation as resolved.
Show resolved Hide resolved
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
******************************************************************************/

package org.eclipse.lsp4j;

public enum DiagnosticTag {

/**
* Unused or unnecessary code.
*
akaroml marked this conversation as resolved.
Show resolved Hide resolved
* Clients are allowed to render diagnostics with this tag faded out instead of having
* an error squiggle.
*/
Unnecessary(1),

/**
* Deprecated or obsolete code.
*
akaroml marked this conversation as resolved.
Show resolved Hide resolved
* Clients are allowed to rendered diagnostics with this tag strike through.
*/
Deprecated(2);

private final int value;

DiagnosticTag(int value) {
akaroml marked this conversation as resolved.
Show resolved Hide resolved
this.value = value;
}

public int getValue() {
return value;
}

public static DiagnosticTag forValue(int value) {
DiagnosticTag[] allValues = DiagnosticTag.values();
if (value < 1 || value > allValues.length)
throw new IllegalArgumentException("Illegal enum value: " + value);
return allValues[value - 1];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,11 @@ class Diagnostic {
@NonNull
String message

/**
* Additional metadata about the diagnostic.
*/
List<DiagnosticTag> tags;

/**
* An array of related diagnostic information, e.g. when symbol-names within a scope collide
* all definitions can be marked via this property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import org.eclipse.lsp4j.DiagnosticRelatedInformation;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.DiagnosticTag;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
import org.eclipse.lsp4j.util.Preconditions;
Expand Down Expand Up @@ -53,6 +54,11 @@ public class Diagnostic {
@NonNull
private String message;

/**
* Additional metadata about the diagnostic.
*/
private List<DiagnosticTag> tags;

/**
* An array of related diagnostic information, e.g. when symbol-names within a scope collide
* all definitions can be marked via this property.
Expand Down Expand Up @@ -159,6 +165,21 @@ public void setMessage(@NonNull final String message) {
this.message = Preconditions.checkNotNull(message, "message");
}

/**
* Additional metadata about the diagnostic.
*/
@Pure
public List<DiagnosticTag> getTags() {
return this.tags;
}

/**
* Additional metadata about the diagnostic.
*/
public void setTags(final List<DiagnosticTag> tags) {
this.tags = tags;
}

/**
* An array of related diagnostic information, e.g. when symbol-names within a scope collide
* all definitions can be marked via this property.
Expand Down Expand Up @@ -189,6 +210,7 @@ public String toString() {
b.add("code", this.code);
b.add("source", this.source);
b.add("message", this.message);
b.add("tags", this.tags);
b.add("relatedInformation", this.relatedInformation);
return b.toString();
}
Expand Down Expand Up @@ -228,6 +250,11 @@ public boolean equals(final Object obj) {
return false;
} else if (!this.message.equals(other.message))
return false;
if (this.tags == null) {
if (other.tags != null)
return false;
} else if (!this.tags.equals(other.tags))
return false;
if (this.relatedInformation == null) {
if (other.relatedInformation != null)
return false;
Expand All @@ -246,6 +273,7 @@ public int hashCode() {
result = prime * result + ((this.code== null) ? 0 : this.code.hashCode());
result = prime * result + ((this.source== null) ? 0 : this.source.hashCode());
result = prime * result + ((this.message== null) ? 0 : this.message.hashCode());
result = prime * result + ((this.tags== null) ? 0 : this.tags.hashCode());
return prime * result + ((this.relatedInformation== null) ? 0 : this.relatedInformation.hashCode());
}
}