-
Notifications
You must be signed in to change notification settings - Fork 1.1k
improvement: Allow passing -explain to the presentation compiler #24740
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
Merged
+190
−49
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
39 changes: 39 additions & 0 deletions
39
presentation-compiler/test/dotty/tools/pc/base/BaseDiagnosticsSuite.scala
This file contains hidden or 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,39 @@ | ||
| package dotty.tools.pc.base | ||
|
|
||
| import dotty.tools.pc.RawScalaPresentationCompiler | ||
| import dotty.tools.pc.base.TestResources | ||
| import dotty.tools.pc.utils.PcAssertions | ||
| import dotty.tools.pc.utils.TestExtensions.getOffset | ||
| import org.eclipse.lsp4j.Diagnostic | ||
| import org.eclipse.lsp4j.DiagnosticSeverity | ||
|
|
||
| import java.net.URI | ||
| import scala.meta.internal.jdk.CollectionConverters.* | ||
| import scala.meta.internal.metals.EmptyCancelToken | ||
| import scala.meta.pc.CancelToken | ||
| import scala.meta.pc.VirtualFileParams | ||
|
|
||
| class BaseDiagnosticsSuite extends PcAssertions: | ||
| case class TestDiagnostic(startIndex: Int, endIndex: Int, msg: String, severity: DiagnosticSeverity) | ||
|
|
||
| def options : List[String] = Nil | ||
|
|
||
| val pc = RawScalaPresentationCompiler().newInstance("", TestResources.classpath.asJava, options.asJava) | ||
|
|
||
| case class TestVirtualFileParams(uri: URI, text: String) extends VirtualFileParams { | ||
| override def shouldReturnDiagnostics: Boolean = true | ||
| override def token: CancelToken = EmptyCancelToken | ||
| } | ||
|
|
||
| def check( | ||
| text: String, | ||
| expected: List[TestDiagnostic], | ||
| additionalChecks: List[Diagnostic] => Unit = identity | ||
| ): Unit = | ||
| val diagnostics = pc | ||
| .didChange(TestVirtualFileParams(URI.create("file:/Diagnostic.scala"), text)) | ||
| .asScala | ||
|
|
||
| val actual = diagnostics.map(d => TestDiagnostic(d.getRange().getStart().getOffset(text), d.getRange().getEnd().getOffset(text), d.getMessage(), d.getSeverity())) | ||
tgodzik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assertEquals(expected, actual, s"Expected [${expected.mkString(", ")}] but got [${actual.mkString(", ")}]") | ||
| additionalChecks(diagnostics.toList) | ||
44 changes: 8 additions & 36 deletions
44
presentation-compiler/test/dotty/tools/pc/tests/DiagnosticProviderSuite.scala
This file contains hidden or 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
57 changes: 57 additions & 0 deletions
57
presentation-compiler/test/dotty/tools/pc/tests/ExplainDiagnosticProviderSuite.scala
This file contains hidden or 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,57 @@ | ||
| package dotty.tools.pc.tests | ||
|
|
||
| import dotty.tools.pc.base.BaseDiagnosticsSuite | ||
| import org.eclipse.lsp4j.CodeAction | ||
| import org.eclipse.lsp4j.Diagnostic | ||
| import org.eclipse.lsp4j.DiagnosticSeverity | ||
| import org.junit.Test | ||
|
|
||
| import java.net.URI | ||
| import scala.meta.internal.jdk.CollectionConverters.* | ||
|
|
||
| class ExplainDiagnosticProviderSuite extends BaseDiagnosticsSuite { | ||
|
|
||
| override def options : List[String] = List("-explain") | ||
|
|
||
| @Test def error1 = | ||
| check( | ||
| """|object C: | ||
| | def m(x: Int) = 1 | ||
| | object T extends K: | ||
| | val x = m(1) // error | ||
| |class K: | ||
| | def m(i: Int) = 2 | ||
| |""".stripMargin, | ||
| List( | ||
| TestDiagnostic( | ||
| 64,65, | ||
| """|Reference to m is ambiguous. | ||
| |It is both defined in object C | ||
| |and inherited subsequently in object T | ||
| | | ||
| |# Explanation (enabled by `-explain`) | ||
| | | ||
| |The identifier m is ambiguous because a name binding of lower precedence | ||
| |in an inner scope cannot shadow a binding with higher precedence in | ||
| |an outer scope. | ||
| | | ||
| |The precedence of the different kinds of name bindings, from highest to lowest, is: | ||
| | - Definitions in an enclosing scope | ||
| | - Inherited definitions and top-level definitions in packages | ||
| | - Names introduced by import of a specific name | ||
| | - Names introduced by wildcard import | ||
| | - Definitions from packages in other files | ||
| |Note: | ||
| | - As a rule, definitions take precedence over imports. | ||
| | - Definitions in an enclosing scope take precedence over inherited definitions, | ||
| | which can result in ambiguities in nested classes. | ||
| | - When importing, you can avoid naming conflicts by renaming: | ||
| | import scala.{m => mTick} | ||
| |""".stripMargin, | ||
| DiagnosticSeverity.Error | ||
|
|
||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.