This repository has been archived by the owner on Mar 12, 2024. It is now read-only.
generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from watermelontools/feature/parity-with-other…
…-vscode Feature/parity with other vscode
- Loading branch information
Showing
14 changed files
with
214 additions
and
188 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.idea | ||
.qodana | ||
build | ||
.DS_Store |
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 |
---|---|---|
@@ -1,34 +1,25 @@ | ||
# IntelliJ Platform Artifacts Repositories -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html | ||
|
||
pluginGroup = com.github.baristageek.watermelonintellij | ||
pluginName = watermelon-intellij | ||
pluginRepositoryUrl = https://github.com/watermelontools/watermelon-intellij | ||
pluginGroup=com.watermelon.context | ||
pluginName=watermelon-context | ||
pluginRepositoryUrl=https://github.com/watermelontools/watermelon-intellij | ||
# SemVer format -> https://semver.org | ||
pluginVersion = 0.0.1 | ||
|
||
pluginVersion=0.0.1 | ||
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html | ||
pluginSinceBuild = 222 | ||
pluginUntilBuild = 232.* | ||
|
||
pluginSinceBuild=222 | ||
pluginUntilBuild=232.* | ||
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension | ||
platformType = IC | ||
platformVersion = 2022.2.5 | ||
|
||
platformType=IC | ||
platformVersion=2022.2.5 | ||
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html | ||
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 | ||
platformPlugins = Git4Idea | ||
|
||
platformPlugins=Git4Idea | ||
# Gradle Releases -> https://github.com/gradle/gradle/releases | ||
gradleVersion = 8.2.1 | ||
|
||
gradleVersion=8.2.1 | ||
# Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib | ||
kotlin.stdlib.default.dependency = false | ||
|
||
kotlin.stdlib.default.dependency=false | ||
# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html | ||
org.gradle.configuration-cache = true | ||
|
||
org.gradle.configuration-cache=true | ||
# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html | ||
org.gradle.caching = true | ||
|
||
org.gradle.caching=true | ||
# Enable Gradle Kotlin DSL Lazy Property Assignment -> https://docs.gradle.org/current/userguide/kotlin_dsl.html#kotdsl:assignment | ||
systemProp.org.gradle.unsafe.kotlin.assignment = true | ||
systemProp.org.gradle.unsafe.kotlin.assignment=true |
Binary file not shown.
33 changes: 0 additions & 33 deletions
33
src/main/kotlin/com/github/baristageek/watermelonintellij/actions/GitBlameAction.kt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/main/kotlin/com/github/baristageek/watermelonintellij/actions/HelloWorld.kt
This file was deleted.
Oops, something went wrong.
55 changes: 0 additions & 55 deletions
55
src/main/kotlin/com/github/baristageek/watermelonintellij/services/MyProjectService.kt
This file was deleted.
Oops, something went wrong.
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
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/com/watermelon/context/actions/ContextMenuButton.kt
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,34 @@ | ||
package com.watermelon.context.actions | ||
|
||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.fileEditor.FileEditorManager | ||
import com.intellij.openapi.wm.ToolWindow | ||
import com.intellij.openapi.wm.ToolWindowManager | ||
import com.watermelon.context.toolWindow.MyToolWindowFactory | ||
|
||
class ContextMenuButton : AnAction() { | ||
override fun actionPerformed(e: AnActionEvent) { | ||
val project = e.project | ||
val editor = FileEditorManager.getInstance(project!!).selectedTextEditor | ||
if (editor != null) { | ||
val selectionModel = editor.selectionModel | ||
val startLine = selectionModel.selectionStartPosition?.line | ||
val endLine = selectionModel.selectionEndPosition?.line | ||
val toolWindowManager = ToolWindowManager.getInstance(project) | ||
val toolWindow: ToolWindow? = toolWindowManager.getToolWindow("🍉 Watermelon") | ||
val toolWindowFactory = MyToolWindowFactory() | ||
|
||
if (startLine != null) { | ||
if (endLine != null) { | ||
println("Start line : $startLine") | ||
println("End line : $endLine") | ||
toolWindowFactory.createToolWindowContent(project, toolWindow!!, startLine, endLine) | ||
} | ||
} | ||
|
||
toolWindow?.show {} | ||
} | ||
} | ||
} | ||
|
4 changes: 1 addition & 3 deletions
4
...teners/MyApplicationActivationListener.kt → ...teners/MyApplicationActivationListener.kt
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 |
---|---|---|
@@ -1,12 +1,10 @@ | ||
package com.github.baristageek.watermelonintellij.listeners | ||
package com.watermelon.context.listeners | ||
|
||
import com.intellij.openapi.application.ApplicationActivationListener | ||
import com.intellij.openapi.diagnostic.thisLogger | ||
import com.intellij.openapi.wm.IdeFrame | ||
|
||
internal class MyApplicationActivationListener : ApplicationActivationListener { | ||
|
||
override fun applicationActivated(ideFrame: IdeFrame) { | ||
thisLogger().warn("Don't forget to remove all non-needed sample code files with their corresponding registration entries in `plugin.xml`.") | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
src/main/kotlin/com/watermelon/context/services/MyProjectService.kt
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,118 @@ | ||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.fileEditor.FileDocumentManager | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.vcsUtil.VcsUtil | ||
import com.intellij.openapi.fileEditor.FileEditorManager | ||
import git4idea.commands.Git | ||
import git4idea.commands.GitCommand | ||
import git4idea.commands.GitCommandResult | ||
import git4idea.commands.GitLineHandler | ||
|
||
@Service(Service.Level.PROJECT) | ||
class MyProjectService(private val project: Project) { | ||
data class CommitDetails( | ||
val hash: String, | ||
val author: String, | ||
val date: String, | ||
val lineNumber: Int, | ||
val message: String, | ||
val content: String | ||
) | ||
|
||
private fun runCommand(lineHandler: GitLineHandler): GitCommandResult { | ||
return Git.getInstance().runCommand(lineHandler) | ||
} | ||
|
||
fun getGitBlame(): List<CommitDetails>? { | ||
val editor = FileEditorManager.getInstance(project).selectedTextEditor ?: return null | ||
val document = editor.document | ||
val file = FileDocumentManager.getInstance().getFile(document) ?: return null | ||
val directory = file.parent ?: return null | ||
val filePath = VcsUtil.getFilePath(file) | ||
println("File path : $filePath") | ||
val blameRun = GitLineHandler(project, directory, GitCommand.BLAME).apply { | ||
addParameters(filePath.path) | ||
} | ||
|
||
val blameCommandResponse = runCommand(blameRun) | ||
|
||
// Use regex to extract details from git blame | ||
val regex = """(\w+) \((.+?)\s+([\d-]+ [\d:]+ [+-]\d+)\s+(\d+)\)\s*(.*)""".toRegex() | ||
|
||
val commitsDetailsList = mutableListOf<CommitDetails>() | ||
|
||
// Extract details and map to a list of CommitDetails | ||
blameCommandResponse.output.forEach { line -> | ||
regex.find(line)?.let { matchResult -> | ||
val hash = matchResult.groups[1]?.value.orEmpty() | ||
val author = matchResult.groups[2]?.value.orEmpty() | ||
val date = matchResult.groups[3]?.value.orEmpty() | ||
val lineNumber = matchResult.groups[4]?.value?.toIntOrNull() ?: 0 | ||
val content = matchResult.groups[5]?.value.orEmpty() | ||
|
||
// Fetch commit message for unique hashes | ||
val logRun = GitLineHandler(project, directory, GitCommand.LOG).apply { | ||
addParameters("-1", "--pretty=format:%s", hash) | ||
} | ||
val logCommandResponse = runCommand(logRun) | ||
val message = logCommandResponse.output.firstOrNull().orEmpty() | ||
|
||
commitsDetailsList.add( | ||
CommitDetails(hash, author, date, lineNumber, message, content) | ||
) | ||
} | ||
} | ||
|
||
return commitsDetailsList.distinctBy { it.hash } | ||
|
||
} | ||
|
||
fun getPartialGitBlame(startLine: Int, endLine: Int): List<CommitDetails>? { | ||
val editor = FileEditorManager.getInstance(project).selectedTextEditor ?: return null | ||
val document = editor.document | ||
val file = FileDocumentManager.getInstance().getFile(document) ?: return null | ||
val directory = file.parent ?: return null | ||
val filePath = VcsUtil.getFilePath(file) | ||
// Adjust the line numbers to be 1-indexed | ||
val adjustedStartLine = startLine + 1 | ||
val adjustedEndLine = endLine + 1 | ||
|
||
val blameRun = GitLineHandler(project, directory, GitCommand.BLAME).apply { | ||
addParameters("-L$adjustedStartLine,$adjustedEndLine", filePath.path) | ||
} | ||
|
||
val blameCommandResponse = runCommand(blameRun) | ||
|
||
|
||
// Use regex to extract details from git blame | ||
val regex = """(\w+) \((.+?)\s+([\d-]+ [\d:]+ [+-]\d+)\s+(\d+)\)\s*(.*)""".toRegex() | ||
|
||
val commitsDetailsList = mutableListOf<CommitDetails>() | ||
|
||
// Extract details and map to a list of CommitDetails | ||
blameCommandResponse.output.forEach { line -> | ||
regex.find(line)?.let { matchResult -> | ||
val hash = matchResult.groups[1]?.value.orEmpty() | ||
val author = matchResult.groups[2]?.value.orEmpty() | ||
val date = matchResult.groups[3]?.value.orEmpty() | ||
val lineNumber = matchResult.groups[4]?.value?.toIntOrNull() ?: 0 | ||
val content = matchResult.groups[5]?.value.orEmpty() | ||
|
||
// Fetch commit message for unique hashes | ||
val logRun = GitLineHandler(project, directory, GitCommand.LOG).apply { | ||
addParameters("-1", "--pretty=format:%s", hash) | ||
} | ||
val logCommandResponse = runCommand(logRun) | ||
val message = logCommandResponse.output.firstOrNull().orEmpty() | ||
|
||
commitsDetailsList.add( | ||
CommitDetails(hash, author, date, lineNumber, message, content) | ||
) | ||
} | ||
} | ||
|
||
return commitsDetailsList.distinctBy { it.hash } | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.