Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intellij 2023 Support #256

Merged
merged 9 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def versions = [
roomCompilerProcessing: '2.6.0-alpha02',
dokka: '1.4.32',
"gradleIntellijPlugin": [
ide: '2020.1'
ide: '2023.2'
],
]

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-6.9-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
20 changes: 7 additions & 13 deletions intellij/ast/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "org.jetbrains.intellij" version "1.0"
id "org.jetbrains.intellij" version "1.15.0"
id 'org.jetbrains.kotlin.jvm'
id 'org.jetbrains.dokka'
}
Expand All @@ -11,6 +11,12 @@ intellij {
updateSinceUntilBuild = false
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
idanakav marked this conversation as resolved.
Show resolved Hide resolved
}
}

dependencies {
implementation project(':lib')
implementation project(':ast')
Expand All @@ -24,18 +30,6 @@ dependencies {
testImplementation project(':intellij:testing')
}

compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}

compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}

tasks {
buildSearchableOptions {
enabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,24 @@
*/
package motif.ast.intellij

import com.intellij.pom.java.LanguageLevel
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl
import com.intellij.psi.PsiElementFactory
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import motif.intellij.testing.InternalJdk
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import org.assertj.core.api.Assertions.assertThat
import org.intellij.lang.annotations.Language

class IntelliJAnnotationTest : LightCodeInsightFixtureTestCase() {
class IntelliJAnnotationTest : LightJavaCodeInsightFixtureTestCase() {

lateinit var psiElementFactory: PsiElementFactory

override fun setUp() {
super.setUp()

psiElementFactory = PsiElementFactory.SERVICE.getInstance(project)
}

override fun getProjectDescriptor(): LightProjectDescriptor {
return object : ProjectDescriptor(LanguageLevel.HIGHEST) {
override fun getSdk() = InternalJdk.instance
}
override fun getProjectDescriptor() = DefaultLightProjectDescriptor {
JavaAwareProjectJdkTableImpl.getInstanceEx().internalJdk
idanakav marked this conversation as resolved.
Show resolved Hide resolved
}

override fun getTestDataPath(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,25 @@
*/
package motif.ast.intellij

import com.intellij.pom.java.LanguageLevel
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl
import com.intellij.psi.PsiElementFactory
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import motif.intellij.testing.InternalJdk
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import org.assertj.core.api.Assertions.assertThat
import org.intellij.lang.annotations.Language
import org.junit.Test

class IntelliJClassTest : LightCodeInsightFixtureTestCase() {
class IntelliJClassTest : LightJavaCodeInsightFixtureTestCase() {

lateinit var psiElementFactory: PsiElementFactory

override fun setUp() {
super.setUp()

psiElementFactory = PsiElementFactory.SERVICE.getInstance(project)
psiElementFactory = PsiElementFactory.getInstance(project)
}

override fun getProjectDescriptor(): LightProjectDescriptor {
return object : ProjectDescriptor(LanguageLevel.HIGHEST) {
override fun getSdk() = InternalJdk.instance
}
override fun getProjectDescriptor() = DefaultLightProjectDescriptor {
JavaAwareProjectJdkTableImpl.getInstanceEx().internalJdk
}

override fun getTestDataPath(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,26 @@
*/
package motif.ast.intellij

import com.intellij.pom.java.LanguageLevel
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl
import com.intellij.psi.PsiElementFactory
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import motif.intellij.testing.InternalJdk
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.uast.UClass
import org.jetbrains.uast.toUElementOfType

class IntelliJKotlinTest : LightCodeInsightFixtureTestCase() {
class IntelliJKotlinTest : LightJavaCodeInsightFixtureTestCase() {

lateinit var psiElementFactory: PsiElementFactory

override fun setUp() {
super.setUp()

psiElementFactory = PsiElementFactory.SERVICE.getInstance(project)
}

override fun getProjectDescriptor(): LightProjectDescriptor {
return object : ProjectDescriptor(LanguageLevel.HIGHEST) {
override fun getSdk() = InternalJdk.instance
}
override fun getProjectDescriptor() = DefaultLightProjectDescriptor {
JavaAwareProjectJdkTableImpl.getInstanceEx().internalJdk
}

override fun getTestDataPath(): String {
Expand Down
8 changes: 7 additions & 1 deletion intellij/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "org.jetbrains.intellij" version "1.0"
id "org.jetbrains.intellij" version "1.15.0"
id 'org.jetbrains.kotlin.jvm'
id 'org.jetbrains.dokka'
}
Expand All @@ -11,6 +11,12 @@ intellij {
updateSinceUntilBuild = false
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

group 'com.uber.motif'
version '0.0.5' // Plugin version

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2019 Uber Technologies, Inc.
* Copyright (c) 2023 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,12 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package motif.intellij.testing
package motif.intellij

import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.ProjectActivity

object InternalJdk {

val instance: Sdk by lazy { JavaAwareProjectJdkTableImpl.getInstanceEx().internalJdk }
class AttachMotifProjectServiceActivity : ProjectActivity {
override suspend fun execute(project: Project) {
project.service<MotifProjectService>().attach()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import com.intellij.codeInsight.daemon.LineMarkerProviders
import com.intellij.ide.plugins.PluginManager
import com.intellij.lang.Language
import com.intellij.lang.java.JavaLanguage
import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.ProjectComponent
import com.intellij.openapi.components.Service
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task
Expand All @@ -36,15 +37,17 @@ import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.ui.content.Content
import com.intellij.ui.content.ContentFactory
import javax.swing.Icon
import motif.core.ResolvedGraph
import motif.intellij.analytics.AnalyticsProjectComponent
import motif.intellij.analytics.AnalyticsProjectService
import motif.intellij.analytics.MotifAnalyticsActions
import motif.intellij.ui.MotifErrorPanel
import motif.intellij.ui.MotifScopePanel
import motif.intellij.ui.MotifUsagePanel
import org.jetbrains.kotlin.idea.KotlinLanguage

class MotifProjectComponent(val project: Project) : ProjectComponent {
@Service(Service.Level.PROJECT)
class MotifProjectService(val project: Project) : Disposable {
davissuber marked this conversation as resolved.
Show resolved Hide resolved

companion object {
const val TOOL_WINDOW_ID: String = "Motif"
Expand All @@ -61,10 +64,6 @@ class MotifProjectComponent(val project: Project) : ProjectComponent {
"Error computing Motif graph. If error persists after you rebuild your project and restart IDE, please make sure to report the issue."

private val MOTIF_ACTION_IDS = listOf("motif_usage", "motif_graph", "motif_ancestor_graph")

fun getInstance(project: Project): MotifProjectComponent {
return project.getComponent(MotifProjectComponent::class.java)
}
}

private val graphFactory: GraphFactory by lazy { GraphFactory(project) }
Expand All @@ -79,19 +78,22 @@ class MotifProjectComponent(val project: Project) : ProjectComponent {
private var isRefreshing: Boolean = false
private var pendingAction: (() -> Unit)? = null

override fun projectOpened() {
fun attach() {
DumbService.getInstance(project).runWhenSmart {
ApplicationManager.getApplication().runReadAction {
// Initialize plugin with empty graph to avoid IDE startup slowdown
val emptyGraph: ResolvedGraph = ResolvedGraph.create(emptyList())
onGraphUpdated(emptyGraph)

AnalyticsProjectComponent.getInstance(project)
project
.getService(AnalyticsProjectService::class.java)
.logEvent(MotifAnalyticsActions.PROJECT_OPENED)
}
}
}

override fun dispose() {}

fun refreshGraph() {
if (isRefreshing) {
return
Expand All @@ -111,12 +113,13 @@ class MotifProjectComponent(val project: Project) : ProjectComponent {
if (updatedGraph.errors.isNotEmpty())
MotifAnalyticsActions.GRAPH_UPDATE_ERROR
else MotifAnalyticsActions.GRAPH_UPDATE_SUCCESS
AnalyticsProjectComponent.getInstance(project).logEvent(eventName)
project.getService(AnalyticsProjectService::class.java).logEvent(eventName)
} catch (t: Throwable) {
val emptyGraph: ResolvedGraph = ResolvedGraph.create(emptyList())
onGraphUpdated(emptyGraph)

AnalyticsProjectComponent.getInstance(project)
project
.getService(AnalyticsProjectService::class.java)
.logEvent(MotifAnalyticsActions.GRAPH_COMPUTATION_ERROR)
PluginManager.getLogger().error(LABEL_GRAPH_COMPUTATION_ERROR, t)
} finally {
Expand Down Expand Up @@ -166,7 +169,7 @@ class MotifProjectComponent(val project: Project) : ProjectComponent {
if (toolWindowManager.getToolWindow(TOOL_WINDOW_ID) == null) {
val toolWindow: ToolWindow =
toolWindowManager.registerToolWindow(TOOL_WINDOW_ID, true, ToolWindowAnchor.RIGHT)
toolWindow.setIcon(IconLoader.getIcon("/icons/icon.svg"))
toolWindow.setIcon(IconLoader.getIcon("/icons/icon.svg", Icon::class.java))
toolWindow.title = TOOL_WINDOW_TITLE

scopePanel = MotifScopePanel(project, graph)
Expand Down Expand Up @@ -211,24 +214,22 @@ class MotifProjectComponent(val project: Project) : ProjectComponent {
}

private fun createScopeContent(toolWindow: ToolWindow): Content {
val content =
ContentFactory.SERVICE.getInstance().createContent(scopePanel, TAB_NAME_SCOPES, true)
val content = ContentFactory.getInstance().createContent(scopePanel, TAB_NAME_SCOPES, true)
content.isCloseable = false
toolWindow.contentManager.addContent(content)
return content
}

private fun createErrorContent(toolWindow: ToolWindow): Content {
val content =
ContentFactory.SERVICE.getInstance().createContent(errorPanel, TAB_NAME_ERRORS, true)
val content = ContentFactory.getInstance().createContent(errorPanel, TAB_NAME_ERRORS, true)
content.isCloseable = false
toolWindow.contentManager.addContent(content)
return content
}

private fun createUsageContent(toolWindow: ToolWindow): Content {
val content: Content =
ContentFactory.SERVICE.getInstance().createContent(usagePanel, TAB_NAME_USAGE, true)
ContentFactory.getInstance().createContent(usagePanel, TAB_NAME_USAGE, true)
content.description = TAB_NAME_USAGE
content.isCloseable = true
toolWindow.contentManager.addContent(content)
Expand All @@ -237,7 +238,7 @@ class MotifProjectComponent(val project: Project) : ProjectComponent {

private fun createAncestorContent(toolWindow: ToolWindow): Content {
val content: Content =
ContentFactory.SERVICE.getInstance().createContent(ancestorPanel, TAB_NAME_ANCESTOR, true)
ContentFactory.getInstance().createContent(ancestorPanel, TAB_NAME_ANCESTOR, true)
content.description = TAB_NAME_ANCESTOR
content.isCloseable = true
toolWindow.contentManager.addContent(content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import motif.core.ResolvedGraph
import motif.intellij.MotifProjectComponent
import motif.intellij.MotifProjectComponent.Companion.TOOL_WINDOW_ID
import motif.intellij.MotifProjectService
import motif.intellij.MotifProjectService.Companion.TOOL_WINDOW_ID
import motif.intellij.ScopeHierarchyUtils.Companion.getParentScopes
import motif.intellij.ScopeHierarchyUtils.Companion.isInitializedGraph
import motif.intellij.ScopeHierarchyUtils.Companion.isMotifScopeClass
import motif.intellij.analytics.AnalyticsProjectComponent
import motif.intellij.analytics.AnalyticsProjectService
import motif.intellij.analytics.MotifAnalyticsActions

/*
* {@AnAction} used to trigger displaying a particular scope ancestors hierarchy.
*/
class MotifAncestorGraphAction : AnAction(), MotifProjectComponent.Listener {
class MotifAncestorGraphAction : AnAction(), MotifProjectService.Listener {

private var graph: ResolvedGraph? = null

Expand All @@ -48,17 +48,18 @@ class MotifAncestorGraphAction : AnAction(), MotifProjectComponent.Listener {
val graph = graph ?: return

if (!isInitializedGraph(graph)) {
MotifProjectComponent.getInstance(project).refreshGraph { actionPerformed(event) }
project.getService(MotifProjectService::class.java).refreshGraph { actionPerformed(event) }
return
}

val toolWindow: ToolWindow =
ToolWindowManager.getInstance(project).getToolWindow(TOOL_WINDOW_ID) ?: return
toolWindow.activate {
MotifProjectComponent.getInstance(project).onSelectedAncestorScope(element)
project.getService(MotifProjectService::class.java).onSelectedAncestorScope(element)
}

AnalyticsProjectComponent.getInstance(project)
project
.getService(AnalyticsProjectService::class.java)
.logEvent(MotifAnalyticsActions.ANCESTOR_MENU_CLICK)
}

Expand Down
Loading