Skip to content

Commit

Permalink
Bump intellij version (#4983)
Browse files Browse the repository at this point in the history
* Bump intellij version

also closes #4894 and #4741

* Bump sql psi version

* Fixing up errors

* Include sql psi environment for tests

---------

Co-authored-by: Alec Kazakova <[email protected]>
  • Loading branch information
aperfilyev and AlecKazakova committed Apr 5, 2024
1 parent ad70ba1 commit b372df0
Show file tree
Hide file tree
Showing 29 changed files with 77 additions and 84 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ jobs:
matrix:
# https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html
idea:
- 'IC-2022.3.3' # AS: Giraffe | 2022.3.1
- 'IC-2023.1' # IC
- 'IC-2023.2' # IC
- 'IC-2023.2.5' # IC / Iguana
- 'IC-2024.1' # IC
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand Down
2 changes: 2 additions & 0 deletions dialects/hsql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ dependencies {
testFixturesApi testFixtures(libs.sqlPsi)

testImplementation libs.truth
// Remove with next sql-psi release https://github.com/AlecKazakova/sql-psi/pull/619
testImplementation libs.sqlPsiEnvironment
}

apply from: "$rootDir/gradle/gradle-mvn-push.gradle"
2 changes: 2 additions & 0 deletions dialects/mysql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ dependencies {
testFixturesApi testFixtures(libs.sqlPsi)

testImplementation libs.truth
// Remove with next sql-psi release https://github.com/AlecKazakova/sql-psi/pull/619
testImplementation libs.sqlPsiEnvironment
}

apply from: "$rootDir/gradle/gradle-mvn-push.gradle"
2 changes: 2 additions & 0 deletions dialects/postgresql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ dependencies {
testFixturesApi testFixtures(libs.sqlPsi)

testImplementation libs.truth
// Remove with next sql-psi release https://github.com/AlecKazakova/sql-psi/pull/619
testImplementation libs.sqlPsiEnvironment
}

apply from: "$rootDir/gradle/gradle-mvn-push.gradle"
2 changes: 2 additions & 0 deletions dialects/sqlite-3-18/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ dependencies {
testFixturesApi testFixtures(libs.sqlPsi)

testImplementation libs.truth
// Remove with next sql-psi release https://github.com/AlecKazakova/sql-psi/pull/619
testImplementation libs.sqlPsiEnvironment
}

apply from: "$rootDir/gradle/gradle-mvn-push.gradle"
2 changes: 2 additions & 0 deletions dialects/sqlite-3-24/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies {
testFixturesApi testFixtures(projects.dialects.sqlite318)

testImplementation libs.junit
// Remove with next sql-psi release https://github.com/AlecKazakova/sql-psi/pull/619
testImplementation libs.sqlPsiEnvironment
}

apply from: "$rootDir/gradle/gradle-mvn-push.gradle"
2 changes: 2 additions & 0 deletions dialects/sqlite-3-25/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies {
testFixturesApi(testFixtures(libs.sqlPsi))

testImplementation libs.truth
// Remove with next sql-psi release https://github.com/AlecKazakova/sql-psi/pull/619
testImplementation libs.sqlPsiEnvironment
}

apply from: "$rootDir/gradle/gradle-mvn-push.gradle"
2 changes: 2 additions & 0 deletions dialects/sqlite-3-30/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies {
testFixturesApi(testFixtures(libs.sqlPsi))

testImplementation libs.truth
// Remove with next sql-psi release https://github.com/AlecKazakova/sql-psi/pull/619
testImplementation libs.sqlPsiEnvironment
}

apply from: "$rootDir/gradle/gradle-mvn-push.gradle"
2 changes: 2 additions & 0 deletions dialects/sqlite-3-33/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies {
testFixturesApi(testFixtures(libs.sqlPsi))

testImplementation libs.truth
// Remove with next sql-psi release https://github.com/AlecKazakova/sql-psi/pull/619
testImplementation libs.sqlPsiEnvironment
}

apply from: "$rootDir/gradle/gradle-mvn-push.gradle"
2 changes: 2 additions & 0 deletions dialects/sqlite-3-35/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies {
testFixturesApi(testFixtures(libs.sqlPsi))

testImplementation libs.truth
// Remove with next sql-psi release https://github.com/AlecKazakova/sql-psi/pull/619
testImplementation libs.sqlPsiEnvironment
}

apply from: "$rootDir/gradle/gradle-mvn-push.gradle"
2 changes: 2 additions & 0 deletions dialects/sqlite-3-38/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies {
testFixturesApi(testFixtures(libs.sqlPsi))

testImplementation libs.truth
// Remove with next sql-psi release https://github.com/AlecKazakova/sql-psi/pull/619
testImplementation libs.sqlPsiEnvironment
}

apply from: "$rootDir/gradle/gradle-mvn-push.gradle"
2 changes: 2 additions & 0 deletions dialects/sqlite/json-module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies {
testFixturesApi testFixtures(libs.sqlPsi)

testImplementation libs.truth
// Remove with next sql-psi release https://github.com/AlecKazakova/sql-psi/pull/619
testImplementation libs.sqlPsiEnvironment
}

apply from: "$rootDir/gradle/gradle-mvn-push.gradle"
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
kotlin = "1.9.23"
dokka = "1.9.20"
kotlinCoroutines = "1.8.0"
idea = "222.4459.24" # Flamingo | 2022.2.1 (see https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html)
idea = "231.9392.1" # Hedgehog | 2023.1.1 Patch 2 (see https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html)
androidxSqlite = "2.4.0"
schemaCrawler = "16.19.2"
sqliter = "1.3.1"
Expand All @@ -13,7 +13,7 @@ ktlint = "1.2.1"
agp = "8.3.1"
compileSdk = "34"
minSdk = "21"
sqlPsi = "0.4.8"
sqlPsi = "0.4.9"
testContainers = "1.19.7"

[libraries]
Expand Down Expand Up @@ -64,6 +64,7 @@ intellij-utilUi = { module = "com.jetbrains.intellij.platform:util-ui", version.
intellij-util = { module = "com.jetbrains.intellij.platform:util", version.ref = "idea" }

sqlPsi = { module = "com.alecstrong.sql.psi:core", version.ref = "sqlPsi" }
sqlPsiEnvironment = { module = "com.alecstrong.sql.psi:environment", version.ref = "sqlPsi" }
robolectric = { module = "org.robolectric:robolectric", version = "4.12.1" }
rxJava2 = { module = "io.reactivex.rxjava2:rxjava", version = "2.2.21" }
rxJava3 = { module = "io.reactivex.rxjava3:rxjava", version = "3.1.8" }
Expand Down
16 changes: 8 additions & 8 deletions sqldelight-compiler/environment/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,35 +76,35 @@ tasks.named("shadowJar") {
intellij-deps-fastutil-8.5.8-11.jar 3.945,56 kb
ide-222.4459.24.jar 3.860,40 kb
util-222.4459.24.jar 2.385,63 kb
After minimizing: 43 MB, mostly due to minimizing ide-impl
*/
*/
minimize {
// Needed for MockProject and MockModule.
exclude(dependency(libs.intellij.testFramework.get()))

// Needed for general utils like PsiTreeUtil.
exclude(dependency(libs.intellij.util.get()))

// Base intellij platform.
exclude(dependency(libs.intellij.core.get()))
exclude(dependency(libs.intellij.coreImpl.get()))

// Base required language support.
exclude(dependency(libs.intellij.lang.get()))
exclude(dependency(libs.intellij.langImpl.get()))

// Base required analysis support, like resolve references.
exclude(dependency(libs.intellij.analysis.get()))
exclude(dependency(libs.intellij.analysisImpl.get()))

// Needed for resolving files and the file index.
exclude(dependency(libs.intellij.projectModel.get()))
exclude(dependency(libs.intellij.projectModelImpl.get()))

// Don't minimize coroutines support.
exclude(dependency(libs.intellij.utilEx.get()))

// Needed for Icon support.
exclude(dependency(libs.intellij.utilUi.get()))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MigrationParserDefinition : SqlParserDefinition() {

private val FILE = object : ILightStubFileElementType<PsiFileStub<SqlFileBase>>(MigrationLanguage) {
override fun getStubVersion(): Int = this@Companion.stubVersion
override fun getExternalId(): String = "SqlDelight.MIGRATION"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class SqlDelightParserDefinition : SqlParserDefinition() {
}

companion object {
private val FILE = ILightStubFileElementType<PsiFileStub<SqlFileBase>>(SqlDelightLanguage)
private val FILE = object : ILightStubFileElementType<PsiFileStub<SqlFileBase>>(SqlDelightLanguage) {
override fun getExternalId(): String = "SqlDelight"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.tree.TokenSet
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.util.parentOfType
import com.intellij.util.castSafelyTo
import com.intellij.util.asSafely
import com.squareup.kotlinpoet.AnnotationSpec
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.CodeBlock
Expand Down Expand Up @@ -84,10 +84,10 @@ internal abstract class ColumnTypeMixin(
?.columnNameList?.singleOrNull() // Foreign Column

(tableForeignKeyClause ?: columnConstraint)?.reference?.resolve()?.let { resolvedKey -> // Resolved Column
val dialectType = resolvedKey.castSafelyTo<SqlColumnName>() // Column Name
?.parent?.castSafelyTo<SqlColumnDef>() // Column Definition
?.columnType?.castSafelyTo<ColumnTypeMixin>() // Column type
?.type()?.dialectType?.castSafelyTo<ValueTypeDialectType>() ?: return@let // SqlDelight type
val dialectType = resolvedKey.asSafely<SqlColumnName>() // Column Name
?.parent?.asSafely<SqlColumnDef>() // Column Definition
?.columnType?.asSafely<ColumnTypeMixin>() // Column type
?.type()?.dialectType?.asSafely<ValueTypeDialectType>() ?: return@let // SqlDelight type
type = type.copy(
dialectType = dialectType,
javaType = dialectType.javaType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package app.cash.sqldelight.core.lang.validation
import app.cash.sqldelight.core.lang.util.columnDefSource
import app.cash.sqldelight.core.lang.util.findChildrenOfType
import com.alecstrong.sql.psi.core.SqlAnnotationHolder
import com.alecstrong.sql.psi.core.SqlCompilerAnnotator
import com.alecstrong.sql.psi.core.psi.NamedElement
import com.alecstrong.sql.psi.core.psi.Queryable
import com.alecstrong.sql.psi.core.psi.SqlBinaryAddExpr
Expand All @@ -21,17 +20,13 @@ import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.psi.PsiElement
import com.intellij.psi.util.parentOfType

open class OptimisticLockValidator : Annotator, SqlCompilerAnnotator {
open class OptimisticLockValidator : Annotator {
open fun quickFix(element: PsiElement, lock: ColumnDefMixin): IntentionAction? = null

override fun annotate(element: PsiElement, holder: AnnotationHolder) {
annotate(element, holder, null)
}

override fun annotate(element: PsiElement, annotationHolder: SqlAnnotationHolder) {
annotate(element, null, annotationHolder)
}

fun annotate(
element: PsiElement,
holder: AnnotationHolder?,
Expand Down Expand Up @@ -103,7 +98,7 @@ open class OptimisticLockValidator : Annotator, SqlCompilerAnnotator {

val whereExpression = when (element) {
is SqlUpdateStmt -> element.expr
is SqlUpdateStmtLimited -> element.exprList.getOrNull(0) ?: return
is SqlUpdateStmtLimited -> element.expr
else -> throw IllegalStateException()
}

Expand Down
6 changes: 4 additions & 2 deletions sqldelight-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ gradlePlugin {

dependencies {
api projects.sqldelightCompiler

compileOnly(projects.sqldelightCompiler.environment) {
targetConfiguration = "shadow"
}
Expand All @@ -51,6 +52,7 @@ dependencies {
targetConfiguration = "shadow"
}

implementation libs.sqlPsiEnvironment
implementation libs.kotlin.plugin
compileOnly libs.android.plugin

Expand Down Expand Up @@ -104,7 +106,7 @@ tasks.named('test') {
languageVersion = JavaLanguageVersion.of(ToolchainConventions.BUILD_JDK)
}
environment("ORG_GRADLE_PROJECT_sqldelightVersion", project.version)

if (System.getenv("CI")) {
reports.html.required = false
reports.junitXml.required = false
Expand Down Expand Up @@ -141,7 +143,7 @@ tasks.named("grammarkitTest") {
":runtime:publishKotlinMultiplatformPublicationToInstallLocallyRepository",
":runtime:publishJvmPublicationToInstallLocallyRepository",
":drivers:sqlite-driver:publishAllPublicationsToInstallLocallyRepository",
":drivers:jdbc-driver:publishAllPublicationsToInstallLocallyRepository",
":drivers:jdbc-driver:publishAllPublicationsToInstallLocallyRepository",
":sqlite-migrations:publishAllPublicationsToInstallLocallyRepository",
":sqldelight-compiler:publishAllPublicationsToInstallLocallyRepository",
":sqldelight-gradle-plugin:publishAllPublicationsToInstallLocallyRepository",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package app.cash.sqldelight.core

import app.cash.sqldelight.core.annotators.OptimisticLockCompilerAnnotator
import app.cash.sqldelight.core.compiler.SqlDelightCompiler
import app.cash.sqldelight.core.lang.DatabaseFileType
import app.cash.sqldelight.core.lang.DatabaseFileViewProviderFactory
Expand All @@ -26,7 +27,6 @@ import app.cash.sqldelight.core.lang.SqlDelightFileType
import app.cash.sqldelight.core.lang.SqlDelightParserDefinition
import app.cash.sqldelight.core.lang.SqlDelightQueriesFile
import app.cash.sqldelight.core.lang.util.migrationFiles
import app.cash.sqldelight.core.lang.validation.OptimisticLockValidator
import app.cash.sqldelight.core.psi.SqlDelightImportStmt
import app.cash.sqldelight.dialect.api.SqlDelightDialect
import com.alecstrong.sql.psi.core.SqlCoreEnvironment
Expand Down Expand Up @@ -132,7 +132,7 @@ class SqlDelightEnvironment(
*/
fun generateSqlDelightFiles(logger: (String) -> Unit): CompilationStatus {
val errors = sortedMapOf<Long, MutableList<String>>()
val extraAnnotators = listOf(OptimisticLockValidator())
val extraAnnotators = listOf(OptimisticLockCompilerAnnotator())
annotate(
extraAnnotators,
) { element, message ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app.cash.sqldelight.core.annotators

import app.cash.sqldelight.core.lang.validation.OptimisticLockValidator
import com.alecstrong.sql.psi.core.SqlAnnotationHolder
import com.alecstrong.sql.psi.core.SqlCompilerAnnotator
import com.intellij.psi.PsiElement

class OptimisticLockCompilerAnnotator : SqlCompilerAnnotator {
private val optimisticLockValidator = OptimisticLockValidator()

override fun annotate(element: PsiElement, annotationHolder: SqlAnnotationHolder) {
optimisticLockValidator.annotate(element, null, annotationHolder)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import app.cash.sqldelight.core.lang.SqlDelightFileType
import com.intellij.codeInsight.template.TemplateActionContext
import com.intellij.codeInsight.template.TemplateContextType

class SqlDelightLiveTemplateContextType : TemplateContextType("SQLDELIGHT", "SqlDelight") {
class SqlDelightLiveTemplateContextType : TemplateContextType("SqlDelight") {

private val supportedFileTypes = setOf(SqlDelightFileType, MigrationFileType)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import com.intellij.psi.PsiReferenceProvider
import com.intellij.psi.PsiReferenceRegistrar
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.stubs.StubIndex
import com.intellij.psi.stubs.StubIndexKey
import com.intellij.util.ProcessingContext
import kotlin.reflect.full.companionObject
import kotlin.reflect.full.companionObjectInstance
import org.jetbrains.kotlin.idea.stubindex.KotlinFullClassNameIndex
import org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelTypeAliasFqNameIndex
import org.jetbrains.kotlin.psi.KtTypeAlias
Expand Down Expand Up @@ -78,43 +75,3 @@ internal class SqlDelightReferenceContributor : PsiReferenceContributor() {
private fun typeForThisPackage(file: SqlDelightFile) = "${file.packageName}.${element.text}"
}
}

private fun getKotlinTopLevelTypeAliasFqNameIndex(): StubIndexKey<String, KtTypeAlias> {
// read the HELPER variable reflectively (2023.2)
try {
val helperField = KotlinTopLevelTypeAliasFqNameIndex::class.java.getField("Helper")
val helper = helperField.get(null)
if (helper != null) {
val keyMethod = helper.javaClass.getMethod("getIndexKey")
val key = keyMethod.invoke(helper)
@Suppress("UNCHECKED_CAST") // Reflection that will go away when our minimum version is >= 2023.2
if (key != null) return key as StubIndexKey<String, KtTypeAlias>
}
} catch (e: Exception) {
/* intentionally empty, fall back to getInstance() call in case of errors */
}

// read the INSTANCE variable reflectively first (newer Kotlin plugins)
try {
val instanceField = KotlinTopLevelTypeAliasFqNameIndex::class.java.getField("INSTANCE")
val instance = instanceField.get(null)
if (instance is KotlinTopLevelTypeAliasFqNameIndex) {
val keyMethod = instance.javaClass.getMethod("getKEY")
val key = keyMethod.invoke(instance)
@Suppress("UNCHECKED_CAST") // Reflection that will go away when our minimum version is >= 2023.2
if (key != null) return key as StubIndexKey<String, KtTypeAlias>
}
} catch (e: Exception) {
/* intentionally empty, fall back to getInstance() call in case of errors */
}

// Call the method getInstance on the companion type.
val companionMethod =
KotlinTopLevelTypeAliasFqNameIndex::class.companionObject!!.java.getMethod("getInstance")
val instance = companionMethod.invoke(KotlinTopLevelTypeAliasFqNameIndex::class.companionObjectInstance!!)
as KotlinTopLevelTypeAliasFqNameIndex
val keyMethod = instance.javaClass.getMethod("getKEY")
val key = keyMethod.invoke(instance)
@Suppress("UNCHECKED_CAST") // Reflection that will go away when our minimum version is >= 2023.2
return key as StubIndexKey<String, KtTypeAlias>
}
Loading

0 comments on commit b372df0

Please sign in to comment.