Skip to content

Commit

Permalink
Add support for varying priorities of warnings
Browse files Browse the repository at this point in the history
Different warnings are classified differently in the LangServ, including
the low category, which prevents the issues from showing up in problem
lists.
  • Loading branch information
LadyCailin committed Sep 5, 2019
1 parent 9991bdb commit 621c79b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
47 changes: 40 additions & 7 deletions src/main/java/com/laytonsmith/core/compiler/FileOptions.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -294,32 +294,60 @@ public Version since() {


} }


/**
* This determines the severity level of the warning. Different severities may be handled differently by
* the view code.
*/
public static enum SeverityLevel {
/**
* High impact warnings are ones that have a performance impact, or can cause issues with upgrading in
* the future. These should usually be shown in the UI and not ignored.
*/
HIGH,
/**
* Medium impact warnings are ones that are likely to point to a bug, but may not. These should usually
* not show up readily in the UI, but should show up in lists of issues.
*/
MEDIUM,
/**
* Low impact warnings are ones that are generally safe to completely ignore, but may point to poor
* coding practices or less readability. These should only show up in the UI if the user is looking
* directly at the code.
*/
LOW;
}

// TODO: Make these extensible, so extensions can add their own easily // TODO: Make these extensible, so extensions can add their own easily
public static enum SuppressWarning implements Documentation { public static enum SuppressWarning implements Documentation {
UnreachableCode("Code that comes after methods such as return() or exit() won't be run, and represents dead" UnreachableCode("Code that comes after methods such as return() or exit() won't be run, and represents dead"
+ " code, which should usually be removed, or can represent an error with your branching logic.", + " code, which should usually be removed, or can represent an error with your branching logic.",
MSVersion.V3_3_4), MSVersion.V3_3_4, SeverityLevel.MEDIUM),
HardcodedDynamicParameter("Code that is hardcoded and sent to eval is going to perform worse than simply" HardcodedDynamicParameter("Code that is hardcoded and sent to eval is going to perform worse than simply"
+ " writing the code normally.", MSVersion.V3_3_4), + " writing the code normally.", MSVersion.V3_3_4, SeverityLevel.HIGH),
OverrideArguments("Defining a variable called @arguments overrides the built in @arguments value," OverrideArguments("Defining a variable called @arguments overrides the built in @arguments value,"
+ " making it impossible to access.", MSVersion.V3_3_4), + " making it impossible to access.", MSVersion.V3_3_4, SeverityLevel.HIGH),
UseBareStrings("Using bare strings can cause code to error or worse silently change behavior when using future" UseBareStrings("Using bare strings can cause code to error or worse silently change behavior when using future"
+ " versions of MethodScript that introduce new keywords. Therefore, it is always recommended to quote" + " versions of MethodScript that introduce new keywords. Therefore, it is always recommended to quote"
+ " all strings. In strict mode, this is always an error that can't be suppressed.", MSVersion.V3_3_4), + " all strings. In strict mode, this is always an error that can't be suppressed.", MSVersion.V3_3_4,
SeverityLevel.HIGH),
IncludedFileNotFound("When an include is encountered by the compiler, it checks to ensure that the file being" IncludedFileNotFound("When an include is encountered by the compiler, it checks to ensure that the file being"
+ " included exists. It doesn't actually need to exist until runtime, but a warning is issued at" + " included exists. It doesn't actually need to exist until runtime, but a warning is issued at"
+ " compile time if it can't be found.", MSVersion.V3_3_4), + " compile time if it can't be found.", MSVersion.V3_3_4, SeverityLevel.MEDIUM),
CodeUpgradeNotices("Code that uses old formats should generally be upgraded to newer versions." CodeUpgradeNotices("Code that uses old formats should generally be upgraded to newer versions."
+ " This is encouraged to make code more readable, and is not a deprecation notice. This type of" + " This is encouraged to make code more readable, and is not a deprecation notice. This type of"
+ " warning is only displayed in strict mode, and is even still suppressable.", MSVersion.V3_3_4); + " warning is only displayed in strict mode, and is even still suppressable.", MSVersion.V3_3_4,
SeverityLevel.LOW);


private SuppressWarning(String docs, Version version) { private SuppressWarning(String docs, Version version, SeverityLevel severityLevel) {
this.docs = docs; this.docs = docs;
this.version = version; this.version = version;
this.severityLevel = severityLevel;
} }


private final String docs; private final String docs;
private final Version version; private final Version version;
private final SeverityLevel severityLevel;

@Override @Override
public URL getSourceJar() { public URL getSourceJar() {
return ClassDiscovery.GetClassContainer(this.getClass()); return ClassDiscovery.GetClassContainer(this.getClass());
Expand All @@ -344,6 +372,11 @@ public String docs() {
public Version since() { public Version since() {
return version; return version;
} }

public SeverityLevel getSeverityLevel() {
return severityLevel;
}

} }


@Target(ElementType.FIELD) @Target(ElementType.FIELD)
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/com/laytonsmith/tools/langserv/LangServ.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -556,6 +556,21 @@ public WorkspaceService getWorkspaceService() {
private final Map<String, Triplet<Long, Executor, CompletableFuture<ParseTree>>> compileDelays = new HashMap<>(); private final Map<String, Triplet<Long, Executor, CompletableFuture<ParseTree>>> compileDelays = new HashMap<>();


private Thread compilerDelayThread = null; private Thread compilerDelayThread = null;

private static DiagnosticSeverity getSeverity(CompilerWarning warning) {
if(warning.getSuppressCategory() == null) {
return DiagnosticSeverity.Warning;
}
switch(warning.getSuppressCategory().getSeverityLevel()) {
case HIGH:
return DiagnosticSeverity.Warning;
case MEDIUM:
return DiagnosticSeverity.Information;
case LOW:
return DiagnosticSeverity.Hint;
}
throw new Error("Unaccounted for case: " + warning.getSuppressCategory());
}
/** /**
* Compiles the file, on the given thread pool. * Compiles the file, on the given thread pool.
* @param future After compilation is done, the parse tree is returned. May be null if you don't need it. * @param future After compilation is done, the parse tree is returned. May be null if you don't need it.
Expand Down Expand Up @@ -687,7 +702,7 @@ public void doCompilation(CompletableFuture<ParseTree> future, Executor threadPo
for(CompilerWarning c : warnings) { for(CompilerWarning c : warnings) {
Diagnostic d = new Diagnostic(); Diagnostic d = new Diagnostic();
d.setRange(convertTargetToRange(tokens, c.getTarget())); d.setRange(convertTargetToRange(tokens, c.getTarget()));
d.setSeverity(DiagnosticSeverity.Warning); d.setSeverity(getSeverity(c));
d.setMessage(c.getMessage()); d.setMessage(c.getMessage());
diagnosticsList.add(d); diagnosticsList.add(d);
} }
Expand Down

0 comments on commit 621c79b

Please sign in to comment.