Skip to content

Commit

Permalink
Merge pull request #1159 from dessina-devasia/intellij-2024.2-support…
Browse files Browse the repository at this point in the history
…-backup

Modifications to merge IntelliJ 2024.2 and 2024.3 support changes to main
  • Loading branch information
dessina-devasia authored Dec 6, 2024
2 parents 1b5d05c + a1e6058 commit 53290a8
Show file tree
Hide file tree
Showing 50 changed files with 827 additions and 632 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ target
video
.gradle
.idea
.intellijPlatform
.DS_Store
bin/
4 changes: 2 additions & 2 deletions .run/liberty-tools-intellij [runIde].run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="liberty-tools-intellij [runIde]" type="GradleRunConfiguration" factoryName="Gradle">
<configuration default="false" name="liberty-tools-intellij [runIdeLocally]" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
Expand All @@ -10,7 +10,7 @@
</option>
<option name="taskNames">
<list>
<option value="runIde" />
<option value="runIdeLocally" />
</list>
</option>
<option name="vmOptions" />
Expand Down
4 changes: 2 additions & 2 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This extension is built using the [gradle-intellij-plugin](https://github.com/Je

1. Clone this repository: `git clone git@github.com:OpenLiberty/liberty-tools-intellij.git`
2. Import this repository as a Gradle project in IntelliJ IDEA
3. Run `./gradlew runIde --stacktrace`. A new IntelliJ IDEA window will launch with the Liberty Tools plugin installed to it. You can connect the IntelliJ IDEA debugger to this process to debug the plugin.
3. Run `./gradlew runIdeLocally --stacktrace`. A new IntelliJ IDEA window will launch with the Liberty Tools plugin installed to it. You can connect the IntelliJ IDEA debugger to this process to debug the plugin.

OR

Expand All @@ -38,7 +38,7 @@ Liberty Tools for IntelliJ consumes the [Liberty Config Language Server](https:/

#### Debugging LemMinX Language Server
To debug the LemMinX Language Server in IntelliJ, complete the following steps.
1. Start Liberty Tools for IntelliJ by creating an IntelliJ debug configuration for the `./gradlew runIde command`.
1. Start Liberty Tools for IntelliJ by creating an IntelliJ debug configuration for the `./gradlew runIdeLocally command`.
2. Create a new debug configuration: _Remote JVM Debug_ --> specify _localhost_, port _1054_ and command line arguments `-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:1054`
3. In `io.openliberty.tools.intellij.liberty.lsp.LibertyXmlServer.LibertyXmlServer()` replace the line ` params.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1054,quiet=y");` with `params.add("-agentlib:jdwp=transport=dt_socket,server=y,address=1054");`.
4. Start the debug configuration created in step 2. You can now step through the LemMinX LS code now with the IntelliJ debugger.
Expand Down
139 changes: 87 additions & 52 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
plugins {
id 'java'
id 'org.jetbrains.intellij' version '1.17.3'
id 'org.jetbrains.kotlin.jvm' version '1.7.22'
id 'org.jetbrains.intellij.platform' version '2.1.0'
id 'org.jetbrains.kotlin.jvm' version '2.0.20'
}

group 'io.openliberty.tools'
version '24.0.12-SNAPSHOT'

sourceCompatibility = 17
targetCompatibility = 17

def remoteRobotVersion = "0.11.18"
def remoteRobotVersion = "0.11.23"
// To switch to nightly version, append "@nightly" to the version number (i.e. 0.4.1-20240828-013108@nightly)
def lsp4ijVersion = '0.8.1'

allprojects {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.fork = true
options.forkOptions.memoryMaximumSize = "2g"
}
}

repositories {
mavenCentral()
maven {
Expand Down Expand Up @@ -43,7 +53,9 @@ repositories {
maven {
url = "https://cache-redirector.jetbrains.com/download-pgp-verifier"
}

intellijPlatform {
defaultRepositories()
}
mavenLocal() // TODO remove once Liberty LS is publicly available
}

Expand All @@ -58,9 +70,9 @@ configurations {
}

// Ensures that the JVM target is set to 17 for all Kotlin compilation tasks, including both main and test sources.
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
tasks.withType(KotlinCompile).all {
kotlinOptions {
jvmTarget = "17"
jvmTarget = javaVersion
}
}
}
Expand Down Expand Up @@ -97,9 +109,7 @@ dependencies {
testImplementation 'com.intellij.remoterobot:remote-robot:' + remoteRobotVersion
testImplementation 'com.intellij.remoterobot:remote-fixtures:' + remoteRobotVersion
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
testImplementation('com.jetbrains.intellij.maven:maven-test-framework:241.15989.150') {
transitive = false
}

testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.9.2'

Expand Down Expand Up @@ -129,43 +139,44 @@ dependencies {
implementation files(new File(buildDir, 'server')) {
builtBy 'copyDeps'
}
}
intellijPlatform {
// For a full list of IntelliJ IDEA releases please see https://www.jetbrains.com/intellij-repository/releases
create(providers.gradleProperty("platformType"), providers.gradleProperty("platformVersion"))
bundledPlugins providers.gradleProperty("platformBundledPlugins").orElse("").get().split(',').toList()

def lsp4ij = providers.gradleProperty('useLocal') && providers.gradleProperty('useLocal') == 'true' ?
file("../lsp4ij/build/distributions/LSP4IJ/") :
'com.redhat.devtools.lsp4ij:' + lsp4ijVersion
plugins lsp4ij
pluginVerifier()
zipSigner()
instrumentationTools()

testFramework TestFrameworkType.Platform.INSTANCE
testFramework TestFrameworkType.Plugin.Java.INSTANCE
testFramework TestFrameworkType.Plugin.Maven.INSTANCE
}
}
task copyDeps(type: Copy) {
from configurations.lsp
into new File(buildDir, 'server/server')
rename '^(.*)(-[0-9]+[.[0-9]+]+(-SNAPSHOT)?)(.*)$', '$1$4'
}

runIde {
jvmArgs '--add-exports', 'java.base/jdk.internal.vm=ALL-UNNAMED'
}

intellij {
// For a full list of IntelliJ IDEA releases please see https://www.jetbrains.com/intellij-repository/releases
version = '2024.1.6'

def lsp4ij = project.hasProperty('useLocal') && project.property('useLocal') == 'true' ?
file("../lsp4ij/build/distributions/LSP4IJ/") :
'com.redhat.devtools.lsp4ij:' + lsp4ijVersion
plugins = ['java', 'maven', 'gradle-java', 'properties', 'terminal', 'org.jetbrains.idea.maven', 'com.intellij.gradle', lsp4ij]
updateSinceUntilBuild = false
}

downloadRobotServerPlugin {
version.set(remoteRobotVersion)
}

runIdeForUiTests {
systemProperty "robot-server.port", "8082"
systemProperty "ide.mac.message.dialogs.as.sheets", "false"
systemProperty "jb.privacy.policy.text", "<!--999.999-->"
systemProperty "jb.consents.confirmation.enabled", "false"
systemProperty "idea.trust.all.projects", "true"
systemProperty "ide.show.tips.on.startup.default.value", "false"
systemProperty "ide.mac.file.chooser.native", "false"
systemProperty "jbScreenMenuBar.enabled", "false"
systemProperty "apple.laf.useScreenMenuBar", "false"
intellijPlatformTesting.runIde {
runIdeLocally {
version = providers.gradleProperty("ideTargetVersion")
type = IntelliJPlatformType.IntellijIdeaCommunity
task {
jvmArgumentProviders.add({
[
"--add-exports",
"java.base/jdk.internal.vm=ALL-UNNAMED"
]
} as CommandLineArgumentProvider)
systemProperty("ide.native.launcher", "true")
}
}
}

test {
Expand All @@ -177,18 +188,41 @@ test {
}
}

tasks {
// Disabling buildSearchableOptions, which runs as part of the buildPlugin task.
// this is to buildSearchableOptions to workaround the "Only one instance of IDEA can be run at a time" problem.
// Per documentation: https://plugins.jetbrains.com/docs/intellij/ide-development-instance.html#the-development-instance-sandbox-directory
buildSearchableOptions {
enabled = false
intellijPlatformTesting.runIde {
runIdeForUiTests {
version = providers.gradleProperty("ideTargetVersion")
type = IntelliJPlatformType.IntellijIdeaCommunity
task {
jvmArgumentProviders.add({
[
"-Drobot-server.port=8082",
"-Dide.mac.message.dialogs.as.sheets=false",
"-Djb.privacy.policy.text=<!--999.999-->",
"-Djb.consents.confirmation.enabled=false",
"-Didea.trust.all.projects=true",
"-Dide.show.tips.on.startup.default.value=false",
"-Dide.mac.file.chooser.native=false",
"-DjbScreenMenuBar.enabled=false",
"-Dapple.laf.useScreenMenuBar=false",
]
} as CommandLineArgumentProvider)
systemProperty("ide.native.launcher", "true")
}
plugins {
robotServerPlugin(remoteRobotVersion)
}
}
}

patchPluginXml {
changeNotes = """
<h2> 24.0.9 </h2>
intellijPlatform {
buildSearchableOptions = false
pluginConfiguration {
ideaVersion {
sinceBuild = providers.gradleProperty("pluginSinceBuild")
untilBuild = providers.gradleProperty("pluginUntilBuild")
}
changeNotes = """
<h2> 24.0.9 </h2>
<p>Version 24.0.9 of Liberty Tools for IntelliJ IDEA contains enhancements and fixes. Version 24.0.9 requires IntelliJ IDEA version 2024.1.* ONLY and a minimum of Java 17.</p>
Notable changes:
<ul>
Expand Down Expand Up @@ -326,5 +360,6 @@ patchPluginXml {
<li> First preview release
</ul>
"""
version project.version
version project.version
}
}
13 changes: 13 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
useLocal=false
pluginSinceBuild=241
pluginUntilBuild=243.*

javaVersion=17

# Target IntelliJ Community by default
platformType=IC
platformVersion=2024.1.7
ideTargetVersion=2024.3

# Example: platformBundledPlugins = com.intellij.java
platformBundledPlugins=com.intellij.java, org.jetbrains.idea.maven, com.intellij.gradle, org.jetbrains.plugins.terminal, com.intellij.properties
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public void invokePopup(Component comp, int x, int y) {

menu.setDataContext(() -> SimpleDataContext.builder()
.add(CommonDataKeys.PROJECT, libertyNode.getProject())
.add(DataKey.create(Constants.LIBERTY_BUILD_FILE), libertyNode.getFilePath()).build());
.add(Constants.LIBERTY_BUILD_FILE_DATAKEY, libertyNode.getFilePath()).build());

menu.getComponent().show(comp, x, y);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ public void actionPerformed(@NotNull AnActionEvent e) {

// Obtain the liberty module associated to the current action.
LibertyModule libertyModule = null;
VirtualFile buildFile = (VirtualFile) e.getDataContext().getData(Constants.LIBERTY_BUILD_FILE);
//Using DataKey instead of a string because the getData(String) method is deprecated
// and does not work as expected in IntelliJ 2024.2 and later versions.
// This ensures compatibility and proper retrieval of the build file across all supported versions.
VirtualFile buildFile = e.getDataContext().getData(Constants.LIBERTY_BUILD_FILE_DATAKEY);
if (buildFile != null) {
// The action is being driven from the project drop-down tree menu or from the project context menu.
libertyModule = LibertyModules.getInstance().getLibertyModule(buildFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2022 IBM Corporation, Lidia Ataupillco Ramos and others.
/* Copyright (c) 2022, 2024 IBM Corporation, Lidia Ataupillco Ramos and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -12,14 +12,14 @@

package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij;

import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.psi.PsiClass;
import io.openliberty.tools.intellij.util.ExceptionUtil;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.Collections;

Expand All @@ -32,16 +32,20 @@
* @return list of recognised defining annotations applied to a class
*/
public class AnnotationUtil {
private static final Logger LOGGER = Logger.getLogger(AnnotationUtil.class.getName());
public static List<String> getScopeAnnotations(PsiClass type, Set<String> scopes) {
try {
// Construct a stream of only the annotations applied to the type that are also
// recognised annotations found in scopes.
return Arrays.stream(type.getAnnotations()).map(annotation -> annotation.getNameReferenceElement().getQualifiedName())
.filter(scopes::contains).distinct().collect(Collectors.toList());
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
return Collections.<String>emptyList();
}
return ExceptionUtil.executeWithExceptionHandling(
// Construct a stream of only the annotations applied to the type that are also
// recognised annotations found in scopes.
() -> Arrays.stream(type.getAnnotations())
.map(annotation -> annotation.getNameReferenceElement().getQualifiedName())
.filter(scopes::contains)
.distinct()
.collect(Collectors.toList()),
e -> {
LOGGER.log(Level.WARNING, "Error while calling getScopeAnnotations", e);
return Collections.<String>emptyList();
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
*******************************************************************************/
package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.annotations;

import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiPrimitiveType;
import com.intellij.psi.PsiTypes;
import com.intellij.psi.util.PsiTreeUtil;
import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.JDTUtils;
Expand All @@ -26,14 +23,12 @@
import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext;
import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext;
import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal;
import io.openliberty.tools.intellij.util.ExceptionUtil;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.WorkspaceEdit;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -74,14 +69,8 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) {
assert parentType != null;
ChangeCorrectionProposal proposal = new ModifyReturnTypeProposal(TITLE_MESSAGE, context.getSource().getCompilationUnit(),
context.getASTRoot(), parentType, 0, PsiTypes.voidType());
try {
WorkspaceEdit we = context.convertToWorkspaceEdit(proposal);
toResolve.setEdit(we);
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to change return type to void", e);
}

ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action to change return type to void");
return toResolve;
}

Expand Down
Loading

0 comments on commit 53290a8

Please sign in to comment.