Skip to content

Commit

Permalink
Merge pull request #88 from ng-galien/222-dev
Browse files Browse the repository at this point in the history
222.2.1
  • Loading branch information
ng-galien authored Oct 29, 2022
2 parents d545ab3 + 5b3e82a commit 6d5eb26
Show file tree
Hide file tree
Showing 25 changed files with 414 additions and 160 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
.gradle
.idea
.fleet
.qodana
build
.vscode
.DS_Store
bin/
build/
.run/


2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
# idea-plpgdebugger Changelog

## [Unreleased]
### Bugfixes
- Incorrect line position [#86](https://github.com/ng-galien/idea-plpgdebugger/issues/86)

## [222.2.0]
### Features
- Tree support for JSON variables
- RECORD type is managed as JSON
- Update Dockerfile to use latest version of plpgdebugger
### Features
- Tree support for JSON variables
- RECORD type is managed as JSON
- Update Dockerfile to use latest version of plpgdebugger

### Breaking changes
### Breaking changes
- Update the postgres plugin for proper RECORD handling

## [222.1.0]
Expand Down
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
[![Downloads](https://img.shields.io/jetbrains/plugin/d/18419-postgresql-debugger.svg)](https://plugins.jetbrains.com/plugin/18419-postgresql-debugger)

<!-- Plugin description -->
Debug PL/pg SQL with Intellij Database Tools<br/><br/>
Debug PL/pg SQL with Intellij Database Tools

## Features

- Debug queries from editor
- Debug routines and triggers from database explorer
- Full support for variables inspection with [Docker custom debugger](https://github.com/ng-galien/idea-plpgdebugger/blob/221/docker/README.md)
Expand All @@ -28,7 +29,6 @@ Run this script on your database
To build your own image instructions are [here](docker/README.md)


### Debug a routine from the editor

Just write a statement using the function you want to debug
Expand All @@ -47,8 +47,8 @@ Choose Debug routine action in the database tree and run it in a console

(Composite types are not returned by the extension see [Limitation](#limitation))

* Basic variables
* Arrays(including array of composite)
- Basic variables
- Arrays(including array of composite)

![](img/inspect-variables.png)

Expand All @@ -73,10 +73,10 @@ At the moment indirect debugging is not supported but will be available soon.
## Installation

### Server

You must first install the debugger extension and activate the shared library onto the server.
Follow these [instructions for PgAdmin](https://www.pgadmin.org/docs/pgadmin4/development/debugger.html)


### IDE

- Using IDE built-in plugin system:
Expand All @@ -89,10 +89,7 @@ Follow these [instructions for PgAdmin](https://www.pgadmin.org/docs/pgadmin4/de
Download the [latest release](https://github.com/ng-galien/idea-plpgdebugger/releases/latest) and install it manually using
<kbd>Settings/Preferences</kbd> > <kbd>Plugins</kbd> > <kbd>⚙️</kbd> > <kbd>Install plugin from disk...</kbd>


---
Plugin based on the [IntelliJ Platform Plugin Template][template].



[template]: https://github.com/JetBrains/intellij-platform-plugin-template
49 changes: 33 additions & 16 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

fun properties(key: String) = project.findProperty(key).toString()

Expand All @@ -9,7 +8,7 @@ plugins {
// Kotlin support
id("org.jetbrains.kotlin.jvm") version "1.6.21"
// Gradle IntelliJ Plugin
id("org.jetbrains.intellij") version "1.8.0"
id("org.jetbrains.intellij") version "1.9.0"
// Gradle Changelog Plugin
id("org.jetbrains.changelog") version "1.3.1"
// Gradle Qodana Plugin
Expand All @@ -25,10 +24,38 @@ repositories {
}

dependencies {

// Kotlin and logging
testImplementation(kotlin("test"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation(platform("org.junit:junit-bom:5.9.0"))
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.9.0")
testImplementation(kotlin("reflect"))
testRuntimeOnly("ch.qos.logback:logback-classic:1.4.4")
testRuntimeOnly("org.fusesource.jansi:jansi:2.4.0")

// Junit 5 for IntelliJ
testImplementation("org.junit.platform:junit-platform-runner:1.9.0")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.1")
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.9.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.1")
// Postgres container and driver
testImplementation("org.testcontainers:testcontainers:1.17.5")
testImplementation("org.testcontainers:junit-jupiter:1.17.5")
testImplementation("org.jdbi:jdbi3-kotlin:3.34.0")
testImplementation("org.jdbi:jdbi3-kotlin-sqlobject:3.34.0")
testImplementation("org.postgresql:postgresql:42.5.0")
// JDBI
testImplementation("org.jdbi:jdbi3-postgres:3.34.0")
testImplementation("org.jdbi:jdbi3-testing:3.34.0")
// Guava
testImplementation("com.google.guava:guava:31.0.1-jre")
}

kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(properties("javaVersion")))
}
}

// Configure Gradle IntelliJ Plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
Expand Down Expand Up @@ -56,16 +83,6 @@ qodana {
}

tasks {
// Set the JVM compatibility versions
properties("javaVersion").let {
withType<JavaCompile> {
sourceCompatibility = it
targetCompatibility = it
}
withType<KotlinCompile> {
kotlinOptions.jvmTarget = it
}
}

wrapper {
gradleVersion = properties("gradleVersion")
Expand Down Expand Up @@ -123,7 +140,7 @@ tasks {

test {
useJUnitPlatform {
includeEngines("junit-vintage")
includeEngines("junit-vintage", "junit-jupiter")
}
}
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pluginGroup = net.plpgsql.ideadebugger
pluginName = idea-plpgdebugger
# SemVer format -> https://semver.org
pluginVersion = 222.2.0
pluginVersion = 222.2.1

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand All @@ -22,7 +22,7 @@ platformVersion = 2022.2
platformPlugins = DatabaseTools

# Java language level used to compile sources and to generate the files for - Java 11 is required since 2020.3
javaVersion = 11
javaVersion = 17

# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 7.5.1
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
39 changes: 18 additions & 21 deletions src/main/kotlin/net/plpgsql/ideadebugger/PlController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.openapi.wm.ex.ToolWindowManagerListener
import com.intellij.ui.content.Content
import com.intellij.xdebugger.XDebugProcess
import com.intellij.xdebugger.XDebugSession
import net.plpgsql.ideadebugger.command.PlExecutor
Expand All @@ -32,24 +32,22 @@ class PlController(

private lateinit var plProcess: PlProcess
lateinit var xSession: XDebugSession
internal val windowLister = ToolListener()
private val settings = PlDebuggerSettingsState.getInstance().state
private var executor: PlExecutor? = null


override fun getReady() {
console("Controller: getReady")
executor?.let { Disposer.register(xSession.consoleView, it) }
val windowLister = ToolListener()
project.messageBus.connect(xSession.consoleView).subscribe(ToolWindowManagerListener.TOPIC, windowLister)
}


override fun initLocal(session: XDebugSession): XDebugProcess {
xSession = session
executor = PlExecutor(getAuxiliaryConnection(project, connectionPoint, searchPath))

plProcess = PlProcess(session, executor!!)

@Suppress("DialogTitleCapitalization")
if (!callDefinition.canDebug()) {
val notification = Notification(
"PL/pg Notifications",
Expand Down Expand Up @@ -113,40 +111,39 @@ class PlController(
override fun close() {
console("Controller: close")
if (callDefinition.debugMode == DebugMode.DIRECT) {
windowLister.close()
closeDebugWindow(xSession.sessionName)
Disposer.dispose(DatabaseSessionManager.getSession(project, connectionPoint))
}
}

inner class ToolListener : ToolWindowManagerListener {
private fun closeDebugWindow(sessionName: String) {
runInEdt {
ToolWindowManager.getInstance(project).getToolWindow("Debug")?.let { toolWindow ->
toolWindow.contentManager.contents.first {
it.tabName == sessionName
}.let {
it.manager?.removeContent(it, true)
}
}
}
}

inner class ToolListener() : ToolWindowManagerListener {

private var debugWindow: ToolWindow? = null
private var first: Boolean = false
private var acutal: Content? = null
private var hasShown = false

override fun toolWindowShown(toolWindow: ToolWindow) {

if (toolWindow.id == "Debug") {
debugWindow = toolWindow
first = true
}
if (first && toolWindow.id != "Debug") {
debugWindow?.show()
acutal = debugWindow?.contentManager?.contents?.find {
it.tabName == xSession.sessionName
}
first = false
hasShown = true
}
}

fun close() {
runInEdt {
windowLister.acutal?.let { debugWindow?.contentManager?.removeContent(it, true) }
}
}
}

}


2 changes: 1 addition & 1 deletion src/main/kotlin/net/plpgsql/ideadebugger/XStack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class XStack(process: PlProcess) : XExecutionStack("") {
return XDebuggerUtil.getInstance().createPosition(file, getSourceLine())
}

fun getSourceLine(): Int = plFrame.line + file.start
fun getSourceLine(): Int = file.positionToLine(plFrame.line)

override fun computeChildren(node: XCompositeNode) {
val list = XValueChildrenList()
Expand Down
16 changes: 11 additions & 5 deletions src/main/kotlin/net/plpgsql/ideadebugger/vfs/PlFunctionSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class PlFunctionSource(project: Project, def: PlApiFunctionDef) : LightVirtualFi
val oid: Long = def.oid
private var isTrigger = false
var start: Int = 0
private var end: Int = 0
var codeRange = Pair(0, 0)
val lineRangeCount: Int by lazy {
codeRange.second - codeRange.first
Expand All @@ -42,7 +41,6 @@ class PlFunctionSource(project: Project, def: PlApiFunctionDef) : LightVirtualFi
val psiVariables = mutableMapOf<String, PsiElement>()
val psiUse = mutableMapOf<String, MutableList<Pair<Int, PsiElement>>>()


init {
runReadAction {
PsiManager.getInstance(project).findFile(this)?.let { psi ->
Expand All @@ -59,11 +57,15 @@ class PlFunctionSource(project: Project, def: PlApiFunctionDef) : LightVirtualFi
psiVariables[unquote(v.text)] = v
}
}
PsiTreeUtil.collectElements(psi){
it is SqlTokenElement && it.text.lowercase() == "\$function\$"
}.firstOrNull()?.let { el ->
PsiDocumentManager.getInstance(psi.project).getDocument(psi)?.let { doc ->
start = doc.getLineNumber(el.textOffset) - 1
}
}
PsiTreeUtil.findChildOfType(psi, SqlBlockStatement::class.java)?.let { block ->
PsiDocumentManager.getInstance(psi.project).getDocument(psi)?.let { doc ->
start = doc.getLineNumber(block.textOffset) - 2
end = doc.getLineNumber(block.textOffset + block.textLength) - 2

val beginEl = PsiTreeUtil.collectElements(block){
it is SqlTokenElement && it.text.uppercase() == "BEGIN"
}.firstOrNull()
Expand Down Expand Up @@ -106,6 +108,10 @@ class PlFunctionSource(project: Project, def: PlApiFunctionDef) : LightVirtualFi
}
}

fun positionToLine(position: Int): Int {
return position + start
}

override fun getCharset(): Charset = Charsets.UTF_8

override fun getFileSystem(): VirtualFileSystem = PlVirtualFileSystem.getInstance()
Expand Down
Loading

0 comments on commit 6d5eb26

Please sign in to comment.