Skip to content

Commit

Permalink
[IJ plugin] Bump platformVersion and pluginSinceBuild from 232 to 233 (
Browse files Browse the repository at this point in the history
  • Loading branch information
BoD committed Mar 14, 2024
1 parent bb19140 commit 0b293be
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 70 deletions.
4 changes: 2 additions & 2 deletions docs/source/testing/android-studio-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ The plugin is available on the JetBrains plugin repository. To install it from t

At the time of writing, the plugin is supported on:

- IntelliJ 2022.3 and above
- Android Studio 2022.3 (Giraffe) and above
- IntelliJ 2023.2 and above
- Android Studio 2023.2 (Iguana) and above

Please check the [plugin page](https://plugins.jetbrains.com/plugin/20645-apollo-graphql) for up to date information.

Expand Down
4 changes: 2 additions & 2 deletions intellij-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ This plugin for Android Studio and IntelliJ helps you work with the

The plugin is supported on:

- IntelliJ 2022.3 and above
- Android Studio 2022.3 (Giraffe) and above
- IntelliJ 2023.2 and above
- Android Studio 2023.2 (Iguana) and above

## Installation instructions

Expand Down
11 changes: 5 additions & 6 deletions intellij-plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ pluginRepositoryUrl=https://github.com/apollographql/apollo-kotlin
# XXX Do update the supported versions in the README.md, and in docs/source/testing/android-studio-plugin.mdx file when updating these values!
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild=223
pluginSinceBuild=232
# This can be kept empty to mean no upper bound, but it's recommended to set it to whatever was tested
pluginUntilBuild=233.*
pluginUntilBuild=241.*
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType=IC
# Corresponds to AS Giraffe 2022.3.1 -> https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html
# Corresponds to AS Iguana 2023.2.1 -> https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html
# and https://developer.android.com/studio/archive (more up to date)
# See also https://plugins.jetbrains.com/docs/intellij/android-studio.html
platformVersion=223.8836.41
platformVersion=232.10227.8


# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# To find the version of a plugin relative to the platoform version, see the plugin's page on the Marketplace,
# e.g. for the toml plugin: https://plugins.jetbrains.com/plugin/8195-toml/versions/stable
# Note: jsgraphql has 2 published versions: one with `pluginSinceBuild` set to latest, and one set to an older (more broadly available) version.
platformPlugins=com.intellij.java, org.jetbrains.kotlin, com.intellij.gradle, com.intellij.lang.jsgraphql:4.0.1-222, org.toml.lang:223.8214.6, org.jetbrains.android
platformPlugins=com.intellij.java, org.jetbrains.kotlin, com.intellij.gradle, com.intellij.lang.jsgraphql:4.0.2, org.toml.lang, org.jetbrains.android

# JVM language level used to build project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+.
javaVersion=17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.apollographql.ijplugin.util.originalClassName
import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo
import com.intellij.codeInsight.daemon.RelatedItemLineMarkerProvider
import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder
import com.intellij.codeInsight.navigation.NavigationUtil
import com.intellij.codeInsight.navigation.getPsiElementPopup
import com.intellij.ide.util.DefaultPsiElementCellRenderer
import com.intellij.ide.util.EditSourceUtil
import com.intellij.psi.PsiElement
Expand Down Expand Up @@ -49,7 +49,7 @@ class KotlinDefinitionMarkerProvider : RelatedItemLineMarkerProvider() {
if (graphQLDefinitions.size == 1) {
graphQLDefinitions[0].navigate()
} else {
val popup = NavigationUtil.getPsiElementPopup(graphQLDefinitions.toTypedArray(), DefaultPsiElementCellRenderer(), "") { element: PsiElement ->
val popup = getPsiElementPopup(graphQLDefinitions.toTypedArray(), DefaultPsiElementCellRenderer(), "") { element: PsiElement ->
element.navigate()
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.apollographql.ijplugin.project.apolloProjectService
import com.intellij.codeInsight.navigation.actions.TypeDeclarationProvider
import com.intellij.lang.jsgraphql.psi.GraphQLNamedElement
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.idea.codeInsight.KotlinTypeDeclarationProvider
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtElement

Expand All @@ -20,9 +19,9 @@ class KotlinTypeDeclarationProvider : TypeDeclarationProvider {
if (symbol !is KtElement) return null

// Get the original declaration(s)
val ktTypeDeclarations = TypeDeclarationProvider.EP_NAME.extensionList.firstOrNull { it is KotlinTypeDeclarationProvider }
?.getSymbolTypeDeclarations(symbol) ?: return null
val ktTypeDeclaration = ktTypeDeclarations.firstOrNull() ?: return null
val ktTypeDeclarations = TypeDeclarationProvider.EP_NAME.extensionList.filterNot { it is KotlinTypeDeclarationProvider }
.map { it.getSymbolTypeDeclarations(symbol) }.filterNotNull().firstOrNull()
val ktTypeDeclaration = ktTypeDeclarations?.firstOrNull() ?: return null

val gqlElements = when {
ktTypeDeclaration is KtClass && ktTypeDeclaration.isApolloOperationOrFragment() -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.apollographql.ijplugin.refactoring

import com.apollographql.ijplugin.util.findFunctionsByName
import com.apollographql.ijplugin.util.logw
import com.intellij.openapi.application.WriteAction
import com.intellij.openapi.project.Project
Expand All @@ -15,7 +16,6 @@ import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.searches.AllClassesSearch
import com.intellij.psi.search.searches.ClassInheritorsSearch
import com.intellij.psi.search.searches.ReferencesSearch
import com.intellij.refactoring.rename.RenamePsiElementProcessor
import org.jetbrains.kotlin.asJava.classes.KtLightClass
import org.jetbrains.kotlin.psi.psiUtil.findPropertyByName

Expand Down Expand Up @@ -45,7 +45,7 @@ fun PsiElement.bindReferencesToElement(element: PsiElement): PsiElement? {
}

fun findReferences(psiElement: PsiElement, project: Project): Collection<PsiReference> {
return ReferencesSearch.search(psiElement, GlobalSearchScope.projectScope(project), false).toList()
return ReferencesSearch.search(psiElement, GlobalSearchScope.projectScope(project), false).findAll()
}

fun findMethodReferences(
Expand All @@ -56,35 +56,36 @@ fun findMethodReferences(
methodPredicate: (PsiMethod) -> Boolean = { true },
): Collection<PsiReference> {
val psiLookupClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project)) ?: return emptyList()
val methods = psiLookupClass.findMethodsByName(methodName, false)
.filter { method ->
if (extensionTargetClassName == null) return@filter methodPredicate(method)
// In Kotlin extensions, the target is passed to the first parameter
if (method.parameterList.parametersCount < 1) return@filter false
val firstParameter = method.parameterList.parameters.first()
val firstParameterType = (firstParameter.type as? PsiClassType)?.rawType()?.canonicalText
firstParameterType == extensionTargetClassName && methodPredicate(method)
}
val methods =
// Try Kotlin first
(psiLookupClass as? KtLightClass)?.kotlinOrigin?.findFunctionsByName(methodName)?.takeIf { it.isNotEmpty() }
// Fallback to Java
?: psiLookupClass.findMethodsByName(methodName, false)
.filter { method ->
if (extensionTargetClassName == null) return@filter methodPredicate(method)
// In Kotlin extensions, the target is passed to the first parameter
if (method.parameterList.parametersCount < 1) return@filter false
val firstParameter = method.parameterList.parameters.first()
val firstParameterType = (firstParameter.type as? PsiClassType)?.rawType()?.canonicalText
firstParameterType == extensionTargetClassName && methodPredicate(method)
}
return methods.flatMap { method ->
val processor = RenamePsiElementProcessor.forElement(method)
processor.findReferences(method, GlobalSearchScope.projectScope(project), false)
findReferences(method, project)
}
}

fun findFieldReferences(project: Project, className: String, fieldName: String): Collection<PsiReference> {
val psiLookupClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project)) ?: return emptyList()
val field = psiLookupClass.findFieldByName(fieldName, true)
// Fallback to Kotlin property
// Fallback to Kotlin property
?: (psiLookupClass as? KtLightClass)?.kotlinOrigin?.findPropertyByName(fieldName)
?: return emptyList()
val processor = RenamePsiElementProcessor.forElement(field)
return processor.findReferences(field, GlobalSearchScope.projectScope(project), false)
return findReferences(field, project)
}

fun findClassReferences(project: Project, className: String): Collection<PsiReference> {
val clazz = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project)) ?: return emptyList()
val processor = RenamePsiElementProcessor.forElement(clazz)
return processor.findReferences(clazz, GlobalSearchScope.projectScope(project), false)
return findReferences(clazz, project)
}

fun findPackageReferences(project: Project, packageName: String): Collection<PsiReference> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.psi.KtBlockExpression
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtConstructor
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtImportList
import org.jetbrains.kotlin.psi.KtLambdaArgument
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.KtReferenceExpression
import org.jetbrains.kotlin.psi.psiUtil.containingClass
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
Expand Down Expand Up @@ -84,3 +86,7 @@ fun KtExpression.type(): KotlinType? = safeAnalyze(getResolutionFacade()).getTyp
fun KtReferenceExpression.resolve() = mainReference.resolve()

fun KotlinType.canBeNull() = isMarkedNullable || isNullabilityFlexible()

fun KtClassOrObject.findFunctionsByName(name: String): List<KtNamedFunction> {
return declarations.filterIsInstance<KtNamedFunction>().filter { it.name == name }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import com.intellij.lang.jsgraphql.psi.GraphQLFragmentDefinition
import com.intellij.lang.jsgraphql.psi.GraphQLIdentifier
import com.intellij.lang.jsgraphql.psi.GraphQLTypeNameDefinition
import com.intellij.lang.jsgraphql.psi.GraphQLTypedOperationDefinition
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.runReadAction
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.psi.KtReferenceExpression
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import java.util.concurrent.Callable

@RunWith(JUnit4::class)
class KotlinTypeDeclarationProviderTest : ApolloTestCase() {
Expand All @@ -34,7 +37,13 @@ class KotlinTypeDeclarationProviderTest : ApolloTestCase() {
val ktElement = fromElement()!!

// Simulate navigation
val foundGqlDeclarationElements = kotlinTypeDeclarationProvider.getSymbolTypeDeclarations(ktElement)!!
// XXX TypeDeclarationProvider.getSymbolTypeDeclarations() throws KtInaccessibleLifetimeOwnerAccessException when called from the EDT
val foundGqlDeclarationElements = ApplicationManager.getApplication().executeOnPooledThread(Callable {
runReadAction {
kotlinTypeDeclarationProvider.getSymbolTypeDeclarations(ktElement)!!
}
}).get()

// We want our target (gql), but also the original targets (Kotlin)
assertTrue(foundGqlDeclarationElements.size > 1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,50 @@ import com.example.generated.type.PersonInput

fun addNameToArgs() {
PersonInput(
firstName = Optional.present("John"),
lastName = Optional.present("Doe"),
age = Optional.present(42),
address = Optional.present(AddressInput(street = Optional.present("street"))),
firstName = Optional.present("John"),
lastName = Optional.present("Doe"),
age = Optional.present(42),
address = Optional.present(AddressInput(street = Optional.present("street"))),
)

PersonInput(
firstName = Optional.Present("John"),
lastName = Optional.present("Doe"),
firstName = Optional.Present("John"),
lastName = Optional.present("Doe"),
)

PersonInput(
firstName = Optional.Absent,
lastName = Optional.absent(),
age = Optional.present(42),
firstName = Optional.Absent,
lastName = Optional.absent(),
age = Optional.present(42),
)

PersonInput(
firstName = Optional.Absent,
lastName = Optional.absent(),
age = getAge(),
firstName = Optional.Absent,
lastName = Optional.absent(),
age = getAge(),
)
}

fun convertToBuilder() {
PersonInput.Builder()
.firstName("John")
.lastName("Doe")
.age(42)
.address(AddressInput(street = Optional.present("street")))
.build()
.firstName("John")
.lastName("Doe")
.age(42)
.address(AddressInput(street = Optional.present("street")))
.build()

PersonInput.Builder()
.firstName("John")
.lastName("Doe")
.build()
.firstName("John")
.lastName("Doe")
.build()

PersonInput.Builder()
.age(42)
.build()
.age(42)
.build()

PersonInput.Builder()
.age(getAge().getOrNull())
.build()
.age(getAge().getOrNull())
.build()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ suspend fun main() {
//@formatter:off
val launch = MyQuery.Launch(
__typename = "Launch",
launchFields = LaunchFields(
id = "id",
site = "site",
mission = LaunchFields.Mission(
name = "name",
missionPatch = "missionPatch",
),
launchFields = LaunchFields(
id = "id",
site = "site",
mission = LaunchFields.Mission(
name = "name",
missionPatch = "missionPatch",
),
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ suspend fun main() {
.build()

val myMutation: Mutation<*, *, *>? = null
apolloClient.mutate(myMutation!!).await()
val call = apolloClient!!.mutate(myMutation!!)
// await() -> execute() doesn't work due to https://youtrack.jetbrains.com/issue/KTIJ-29093/ but actually works in AS
// call.await()

val mySubscription: Subscription<*, *, *>? = null
apolloClient.subscribe(mySubscription!!).toFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ suspend fun main() {
.build()

val myMutation: Mutation<*, *, *>? = null
apolloClient.mutation(myMutation!!).execute()
val call = apolloClient!!.mutation(myMutation!!)
// await() -> execute() doesn't work due to https://youtrack.jetbrains.com/issue/KTIJ-29093/ but actually works in AS
// call.await()

val mySubscription: Subscription<*, *, *>? = null
apolloClient.subscription(mySubscription!!).toFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ suspend fun test() {

apolloClient!!.apolloStore.clearAll()

apolloClient!!.apolloStore().clearAll()
// apolloStore() -> apolloStore doesn't work due to https://youtrack.jetbrains.com/issue/KTIJ-29078/
// apolloClient!!.apolloStore().clearAll()

val cacheHeaders: CacheHeaders = CacheHeaders.NONE.toBuilder().build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ suspend fun test() {

apolloClient!!.apolloStore.clearAll()

apolloClient!!.apolloStore.clearAll()
// apolloStore() -> apolloStore doesn't work due to https://youtrack.jetbrains.com/issue/KTIJ-29078/
// apolloClient!!.apolloStore().clearAll()

val cacheHeaders: CacheHeaders = CacheHeaders.NONE.newBuilder().build()

Expand Down

0 comments on commit 0b293be

Please sign in to comment.