-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update Problem to account for related information and code
This PR makes changes to the existing `xsbti.Problem` to account for an optional diagnostic code that the compiler can return for a given diagnostic and also related information. Given a piece of code like: ```scala try {} ``` You'll receive the following: ``` -- [E002] Syntax Warning: /Users/ckipp/Documents/scala-workspace/dotty-error-index/examples/002_EmptyCatchAndFinallyBlockID.scala:3:2 3 | try {} | ^^^^^^ | A try without catch or finally is equivalent to putting | its body in a block; no exceptions are handled. ``` The `E002` here is the actual code. Right now there would be no description. Some diagnostics have multiple positions that they need to represent. You can see an example of this [here](scala/scala3#14002) in Dotty with the use of inlining. Instead of needing to rely on including all of that information in the diagnostic message it can now be extracted out into a `DiagnosticRelatedInformation`. These changes reference the conversation in sbt#6868
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
internal/util-interface/src/main/java/xsbti/DiagnosticCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* sbt | ||
* Copyright 2011 - 2018, Lightbend, Inc. | ||
* Copyright 2008 - 2010, Mark Harrah | ||
* Licensed under Apache License 2.0 (see LICENSE) | ||
*/ | ||
|
||
package xsbti; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* A DiagnosticCode is a unique identifier that the compiler can associate with a diagnostic. This | ||
* is useful for tools to be able to quickly identify what diagnostic is being reported without | ||
* having to rely on parsing the actual diagnostic message, which might not be stable. | ||
*/ | ||
public interface DiagnosticCode { | ||
/** The unique code. This is typically in the format of E000 */ | ||
String code(); | ||
|
||
/** Possible explanation to explain the meaning of the code */ | ||
Optional<String> explanation(); | ||
} |
20 changes: 20 additions & 0 deletions
20
internal/util-interface/src/main/java/xsbti/DiagnosticRelatedInformation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* sbt | ||
* Copyright 2011 - 2018, Lightbend, Inc. | ||
* Copyright 2008 - 2010, Mark Harrah | ||
* Licensed under Apache License 2.0 (see LICENSE) | ||
*/ | ||
|
||
package xsbti; | ||
|
||
/** | ||
* Related information for a given diagnostic. At times this can be another place in your code | ||
* contributing to the diagnostic or just relevant code relating to the diagnostic. | ||
*/ | ||
public interface DiagnosticRelatedInformation { | ||
/** Position of the related inforamtion */ | ||
Position position(); | ||
|
||
/** Message indicating why this related information is attatched to the diagnostic. */ | ||
String message(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters