Skip to content

Commit 08c82bd

Browse files
committed
feat(database): add SQL living documentation support
This commit adds support for generating living documentation for SQL files. It includes a new class `SqlLivingDocumentationProvider` that implements the `LivingDocumentation` interface. The class provides methods for generating documentation comments, finding documentation targets, and updating documentation. Additionally, a new XML file `cc.unitmesh.database.xml` is added to configure the plugin and specify the implementation class for SQL living documentation. The build.gradle.kts file is modified to include the `com.intellij.database` plugin as a dependency for the `exts:database` project. Finally, the `BasedDocumentationIntention.kt` file is modified to remove the `getClosestNamedElement` method and update the `getClosestToCaretNamedElement` method accordingly.
1 parent 210942c commit 08c82bd

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

build.gradle.kts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ plugins {
4141
alias(libs.plugins.serialization)
4242

4343
kotlin("jvm") version "1.8.22"
44-
id("org.jetbrains.intellij") version "1.16.1"
44+
id("org.jetbrains.intellij") version "1.15.0"
4545
id("net.saliman.properties") version "1.5.2"
4646
}
4747

@@ -544,6 +544,16 @@ project(":goland") {
544544
}
545545
}
546546

547+
project(":exts:database") {
548+
intellij {
549+
version.set(ideaVersion)
550+
plugins.set(ideaPlugins + "com.intellij.database")
551+
}
552+
dependencies {
553+
implementation(project(":"))
554+
}
555+
}
556+
547557
fun File.isPluginJar(): Boolean {
548558
if (!isFile) return false
549559
if (extension != "jar") return false
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cc.unitmesh.database.provider
2+
3+
import cc.unitmesh.devti.custom.document.LivingDocumentationType
4+
import cc.unitmesh.devti.provider.LivingDocumentation
5+
import com.intellij.openapi.editor.Editor
6+
import com.intellij.openapi.editor.SelectionModel
7+
import com.intellij.psi.PsiElement
8+
import com.intellij.psi.PsiNameIdentifierOwner
9+
import com.intellij.sql.psi.SqlDdlStatement
10+
import com.intellij.sql.psi.SqlDeclareStatement
11+
import com.intellij.sql.psi.SqlFile
12+
13+
class SqlLivingDocumentationProvider : LivingDocumentation {
14+
override val forbiddenRules: List<String>
15+
get() = TODO("Not yet implemented")
16+
17+
override fun startEndString(type: LivingDocumentationType): Pair<String, String> {
18+
return Pair("--", "--")
19+
}
20+
21+
override fun updateDoc(target: PsiElement, newDoc: String, type: LivingDocumentationType, editor: Editor) {
22+
TODO("Not yet implemented")
23+
}
24+
25+
override fun findNearestDocumentationTarget(psiElement: PsiElement): PsiNameIdentifierOwner? {
26+
return null
27+
}
28+
29+
override fun findDocTargetsInSelection(
30+
root: PsiElement,
31+
selectionModel: SelectionModel
32+
): List<PsiNameIdentifierOwner> {
33+
return emptyList()
34+
}
35+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<idea-plugin package="cc.unitmesh.database">
2+
<!--suppress PluginXmlValidity -->
3+
<dependencies>
4+
<plugin id="com.intellij.database"/>
5+
</dependencies>
6+
7+
<extensions defaultExtensionNs="cc.unitmesh">
8+
<livingDocumentation
9+
language="SQL"
10+
implementationClass="cc.unitmesh.database.provider.SqlLivingDocumentationProvider"/>
11+
</extensions>
12+
</idea-plugin>

src/main/kotlin/cc/unitmesh/devti/intentions/action/base/BasedDocumentationIntention.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ abstract class BasedDocumentationIntention : AbstractChatIntention() {
5151

5252
private fun getClosestToCaretNamedElement(editor: Editor): PsiNameIdentifierOwner? {
5353
val element = PsiUtilBase.getElementAtCaret(editor) ?: return null
54-
return getClosestNamedElement(element)
55-
}
56-
57-
private fun getClosestNamedElement(element: PsiElement): PsiNameIdentifierOwner? {
5854
val support = LivingDocumentation.forLanguage(element.language) ?: return null
5955
return support.findNearestDocumentationTarget(element)
6056
}

0 commit comments

Comments
 (0)