Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #30 from watermelontools/feature/parity-with-other…
Browse files Browse the repository at this point in the history
…-vscode

Feature/parity with other vscode
  • Loading branch information
Esteban Dalel R committed Sep 5, 2023
2 parents 5019db4 + 5f98c90 commit 070ed14
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 188 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.idea
.qodana
build
.DS_Store
37 changes: 14 additions & 23 deletions gradle.properties
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 modified src/.DS_Store
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.baristageek.watermelonintellij
package com.watermelon.context

import com.intellij.DynamicBundle
import org.jetbrains.annotations.NonNls
Expand All @@ -12,10 +12,10 @@ object MyBundle : DynamicBundle(BUNDLE) {
@Suppress("SpreadOperator")
@JvmStatic
fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
getMessage(key, *params)
getMessage(key, *params)

@Suppress("SpreadOperator", "unused")
@JvmStatic
fun messagePointer(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
getLazyMessage(key, *params)
getLazyMessage(key, *params)
}
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 {}
}
}
}

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 src/main/kotlin/com/watermelon/context/services/MyProjectService.kt
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 }


}
}
Loading

0 comments on commit 070ed14

Please sign in to comment.