Skip to content

Commit

Permalink
0.2.1 show diff
Browse files Browse the repository at this point in the history
  • Loading branch information
JakkuSakura committed Jul 30, 2021
1 parent 4865448 commit fa55779
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@
# IntelliJ Idea Astor Plugin ChangeLog

## [Unreleased]
## [0.2.1]
### Added
- Show diff

### Problems
- Comments missing from repaired code
- Unnecessary full class name
- Unreserved code format


## [0.2.0]
### Changes
- Icon for tool window
- Reformatting patches
- Various bugfixes

## [0.1.8]
### Added
- Logging forawrding
- Logging forwarding
- Multithreading
- Separate gRPC without direct dependency on astor
- Load result config
Expand All @@ -32,6 +43,7 @@
- java_home error from astor
### Added
- full arguments

## [0.1.4]
### Added
- Extract jreVersion
Expand Down
4 changes: 1 addition & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pluginGroup = org.bytecamp.program_repair.astor_plugin
pluginName = IntelliJ Idea Astor Plugin
pluginVersion = 0.2.0
pluginVersion = 0.2.1

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand All @@ -21,8 +21,6 @@ platformVersion = 2021.2
platformDownloadSources = true
#jreVersion =



# Opt-out flag for bundling Kotlin standard library.
# See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details.
kotlin.stdlib.default.dependency = false
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import com.intellij.lang.java.JavaLanguage
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.service
import com.intellij.openapi.vcs.FilePath
import com.intellij.openapi.vcs.changes.Change
import com.intellij.openapi.vcs.changes.CurrentContentRevision
import com.intellij.openapi.vcs.changes.actions.diff.ShowDiffAction
import com.intellij.openapi.vcs.impl.VcsVirtualFileContentRevision
import com.intellij.openapi.vcs.vfs.VcsVirtualFile
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.psi.PsiFileFactory
import com.intellij.vcsUtil.VcsUtil
import org.bytecamp.program_repair.astor_plugin.code.ReformatCode
import org.bytecamp.program_repair.astor_plugin.services.AstorProjectService
import java.io.File
Expand All @@ -14,14 +22,25 @@ class AstorDiffAction : AnAction() {

val service = e.project?.service<AstorProjectService>()!!
val outputConfig = service.getConfig().getOutConfig()
val changes = ArrayList<Change>()
for (patch in outputConfig.patches) {
for (chunk in patch.patchhunks) {
val srcCode = File(chunk.getModifiedFilePath()).readText(Charsets.UTF_8)
val file = PsiFileFactory.getInstance(e.project!!)
.createFileFromText(chunk.getModifiedFilePath(), JavaLanguage.INSTANCE, srcCode)
ReformatCode.reformatFile(e.project!!, file)
File(chunk.getModifiedFilePath()).writeText(file.text)
changes.add(createChangeVsLocal(chunk.getPath(), chunk.getModifiedFilePath()))
}
}

ShowDiffAction.showDiffForChange(e.project!!, changes)
}

private fun createChangeVsLocal(filePath: String, afterFilePath: String): Change {
val beforeVirtualFile = CurrentContentRevision.create(VcsUtil.getFilePath(filePath))
val afterVirtualFile = CurrentContentRevision.create(VcsUtil.getFilePath(afterFilePath))
return Change(beforeVirtualFile, afterVirtualFile)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ data class PatchHunk(
val INGREDIENT_PARENT: String = ""

) {
fun getPath(): String {
return PATH.replace("\\/", "/")
}
fun getModifiedFilePath(): String {
return MODIFIED_FILE_PATH.replace("\\/", "/")
}
Expand Down

0 comments on commit fa55779

Please sign in to comment.