-
Notifications
You must be signed in to change notification settings - Fork 201
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
bugfix: Compile only existing classes #2490
Merged
Merged
Changes from all commits
Commits
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 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
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
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 |
---|---|---|
|
@@ -349,6 +349,81 @@ class BspCompileSpec( | |
} | ||
} | ||
|
||
test("compile incrementally renamed file") { | ||
TestUtil.withinWorkspace { workspace => | ||
def path(suffix: String) = s"/main/scala/scala/meta/internal/metals/Foo$suffix.scala" | ||
object Sources { | ||
val `Foo0.scala` = | ||
s"""${path("0")} | ||
|package scala.meta.internal.metals | ||
| | ||
|final class Foo0(conn: () => String) { | ||
| def foo(s: String): String = s | ||
|} | ||
""".stripMargin | ||
} | ||
|
||
val logger = new RecordingLogger(ansiCodesSupported = false) | ||
val `A` = TestProject(workspace, "a", List(Sources.`Foo0.scala`)) | ||
val projects = List(`A`) | ||
val fooFilePath = `A`.srcFor(path("0")) | ||
writeFile(fooFilePath, Sources.`Foo0.scala`) | ||
|
||
def assertCorrectArtifacts(compiledState: ManagedBspTestState, suffix: String): Unit = { | ||
|
||
val buildProject = compiledState.toTestState.getProjectFor(`A`) | ||
val externalClassesDirA = | ||
compiledState.client.getUniqueClassesDirFor(buildProject, forceGeneration = true) | ||
|
||
val classFilesAfterSuccess = takeDirectorySnapshot(externalClassesDirA) | ||
assertEquals( | ||
classFilesAfterSuccess.map { classfile => | ||
val pathString = classfile.path.toString() | ||
// drop drive letter and replace backslashes with forward slashes | ||
if (isWindows) pathString.drop(2).replace("\\", "/") else pathString | ||
}, | ||
List(s"/scala/meta/internal/metals/Foo$suffix.class") | ||
) | ||
} | ||
|
||
loadBspState(workspace, projects, logger) { state => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't been able to reproduce the issue in the test unfortunately, this seems somehow connected to multiple thing being done at the same time via metals and VS Code, but the change in BloopNameHashing is sound anyway. And having this test won't hurt |
||
val firstCompiledState = state.compile(`A`) | ||
assertExitStatus(firstCompiledState, ExitStatus.Ok) | ||
assertValidCompilationState(firstCompiledState, projects) | ||
assertCorrectArtifacts(firstCompiledState, "0") | ||
|
||
// try to rename 10 times the same file | ||
// VS Code will first change the file, then rename it | ||
val last = (1 to 10).foldLeft(firstCompiledState) { (state, num) => | ||
val previousFile = `A`.srcFor(path(s"${num - 1}")) | ||
val newContents = Sources.`Foo0.scala`.replace(s"Foo0", s"Foo$num") | ||
// rename class | ||
writeFile( | ||
previousFile, | ||
newContents | ||
) | ||
val compiledStateChangedFile = state.compile(`A`) | ||
assertExitStatus(compiledStateChangedFile, ExitStatus.Ok) | ||
assertValidCompilationState(compiledStateChangedFile, projects) | ||
assertCorrectArtifacts(compiledStateChangedFile, s"$num") | ||
|
||
// rename file | ||
val newFile = fooFilePath.getParent.resolve(s"Foo$num.scala") | ||
Files.move(previousFile.underlying, newFile.underlying) | ||
|
||
val compiledStateRenameFile = compiledStateChangedFile.compile(`A`) | ||
assertExitStatus(compiledStateRenameFile, ExitStatus.Ok) | ||
assertValidCompilationState(compiledStateRenameFile, projects) | ||
|
||
assertCorrectArtifacts(compiledStateRenameFile, s"$num") | ||
compiledStateRenameFile | ||
} | ||
|
||
assertValidCompilationState(last, projects) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Checks several variants regarding the previous execution of post | ||
* compilation tasks when the compile result is a success and when it is a | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main change, we would previously send all invalidated files even if they were no longer contained in the sources. This make sense for class files to remove them, but no some much to compile new files.
With this change I was no longer able to reproduce the issue in Metals where we would get old compilation artifacts somehow.