Skip to content

Commit

Permalink
Add compatibility for 2024.1 IDEs (KronicDeth#3569)
Browse files Browse the repository at this point in the history
* Update gradlewrapper to v7.6.4
./gradlew wrapper --gradle-version=7.6.4
To fix gradle issue: gradle/gradle#27156

* Remove use of `FileUtil.FILE_HASHING_STRATEGY` from Intellij FileUtil, it was removed in 2024.1. (Note, this is only used in the jps-build test suite).
This also removes references to Trove THashSet, and no longer stores File directly in sets or collections.
See JetBrains/intellij-community@560e8fc

* Add support for 2024.1 IDEs (and runs tests correctly against 2024.1)

* Update usages group wording for 2024.1

* Fix more sdk configuration commits in application RW thread, fixes compatibility with IDEs v2024.1

* Fix whitespace in tests due to 2024.1 change

I believe 2024.1 changed how the Usages work.

In 2023.x:
```kotlin
val usages =
myFixture.testFindUsagesUsingAction("module_attribute_usage.ex",
"kernel.ex")
.map { it as UsageInfo2UsageAdapter }
```

In the debugger shows:
```
0 = {ReadWriteAccessUsageInfo2UsageAdapter@19239} "4|def usage, |do|:
|@|module_attribute"
1 = {ReadWriteAccessUsageInfo2UsageAdapter@19240} "2|@|module_attribute|
|1"
```

For 2024.1, this shows:
```
0 = {ReadWriteAccessUsageInfo2UsageAdapter@19421} "2|
|@module_attribute| 1"
1 = {ReadWriteAccessUsageInfo2UsageAdapter@19422} "4|  def usage, do:
|@module_attribute"
```

I believe it not shows the whitespace for the file, where previously it
didn't.

* pin versions

* use BasePlatformTestCase to stop warning

* add do block match test

* set 241.0 as the version, to fix certain intellij warnings

* fix key

* revert tests

* use thread

---------

Co-authored-by: Josh Taylor <joshuataylorx@gmail.com>
  • Loading branch information
2 people authored and rNoz committed Jul 27, 2024
1 parent b5a7938 commit f7ebb3b
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
ideaVersion: [ "2023.3" ]
ideaVersion: [ "2024.1" ]

steps:
- uses: actions/checkout@v2
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "org.jetbrains.intellij" version "1.13.3"
id "org.jetbrains.intellij" version "1.17.3"
id "org.jetbrains.kotlin.jvm" version "1.9.10"
id "de.undercouch.download" version "4.1.2"
}
Expand Down Expand Up @@ -69,8 +69,8 @@ allprojects {
changeNotes.set(bodyInnerHTML("resources/META-INF/changelog.html"))
pluginDescription.set(bodyInnerHTML("resources/META-INF/description.html"))

sinceBuild = "233.11799.241"
untilBuild = "233.*"
sinceBuild = "241.*"
untilBuild = "241.*"
}

publishPlugin {
Expand All @@ -82,7 +82,7 @@ allprojects {
}

runPluginVerifier {
ideVersions = ["2023.3"]
ideVersions = ["2024.1"]
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://www.jetbrains.com/intellij-repository/releases
# https://www.jetbrains.com/intellij-repository/snapshots
baseVersion=17.0.1
ideaVersion=2023.3
ideaVersion=2024.1
# MUST stay at 1.8 for JPS (Build/Compile Project) compatibility even if JRE/JBR is newer
javaVersion=17
javaTargetVersion=17
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
18 changes: 14 additions & 4 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,10 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
Expand Down Expand Up @@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -205,6 +209,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
15 changes: 9 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
32 changes: 20 additions & 12 deletions jps-builder/tests/org/elixir_lang/jps/TestProjectBuilderLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,40 @@

import com.intellij.openapi.util.io.FileUtil;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.util.containers.MultiMap;
import gnu.trove.THashSet;
import com.intellij.util.containers.CollectionFactory;
import org.jetbrains.jps.builders.impl.logging.ProjectBuilderLoggerBase;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.HashMap;
import java.util.Set;



/**
* Created by zyuyou on 15/7/17.
*/
public class TestProjectBuilderLogger extends ProjectBuilderLoggerBase {
private MultiMap<String, File> myCompiledFiles = new MultiMap<String, File>();
private Set<File> myDeletedFiles = new THashSet<File>(FileUtil.FILE_HASHING_STRATEGY);
private HashMap<String, Set<String>> myCompiledFiles = new HashMap<String, Set<String>>();
private Set<String> myDeletedFiles = CollectionFactory.createFilePathSet();

@Override
public void logDeletedFiles(Collection<String> paths) {
for (String path:paths){
myDeletedFiles.add(new File(path));
myDeletedFiles.add(new File(path).getAbsolutePath());
}
}

@Override
public void logCompiledFiles(Collection<File> files, String builderName, String description) throws IOException {
myCompiledFiles.putValues(builderName, files);
List<String> paths = new ArrayList<String>();
for (File file: files) {
paths.add(file.getPath());
}
myCompiledFiles.put(builderName, CollectionFactory.createFilePathSet(paths));
}

@Override
Expand All @@ -54,17 +60,19 @@ public void assertDeleted(File[] baseDirs, String... paths){
assertRelativePaths(baseDirs, myDeletedFiles, paths);
}

private static void assertRelativePaths(File[] baseDirs, Collection<File> files, String[] expected){
private static void assertRelativePaths(File[] baseDirs, Set<String> files, String[] expected){
List<String> relativePaths = new ArrayList<String>();
for (File file: files){
String path = file.getAbsolutePath();
for (String file: files) {
String path = new File(file).getAbsolutePath();
for(File baseDir:baseDirs){
if(baseDir != null && FileUtil.isAncestor(baseDir, file, false)){
path = FileUtil.getRelativePath(baseDir, file);
if(baseDir != null && FileUtil.isAncestor(baseDir.getPath(), file, false)){
path = FileUtil.getRelativePath(baseDir.getPath(), file, File.separatorChar);
break;
}
}
relativePaths.add(FileUtil.toSystemIndependentName(path));
if (path != null) {
relativePaths.add(FileUtil.toSystemIndependentName(path));
}
}
UsefulTestCase.assertSameElements(relativePaths, expected);

Expand Down
7 changes: 4 additions & 3 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<vendor email="Kronic.Deth@gmail.com">Elle Imhoff</vendor>

<!-- please see http://confluence.jetbrains.com/display/IDEADEV/Build+Number+Ranges for description -->
<idea-version since-build="201.6668.113"/>
<idea-version since-build="241.0"/>

<!-- please see http://confluence.jetbrains.com/display/IDEADEV/Plugin+Compatibility+with+IntelliJ+Platform+Products
on how to target different products -->
Expand Down Expand Up @@ -213,8 +213,9 @@
<lang.parserDefinition language="Elixir" implementationClass="org.elixir_lang.ElixirParserDefinition"/>
<lang.psiStructureViewFactory language="Elixir" implementationClass="org.elixir_lang.structure_view.Factory"/>
<lang.quoteHandler language="Elixir" implementationClass="org.elixir_lang.QuoteHandler"/>
<lang.syntaxHighlighterFactory key="Elixir"
implementationClass="org.elixir_lang.ElixirSyntaxHighlighterFactory"/>
<lang.syntaxHighlighterFactory
implementationClass="org.elixir_lang.ElixirSyntaxHighlighterFactory"
language="Elixir"/>
<localInspection displayName="Ambiguous nested calls" enabledByDefault="true" groupName="Elixir"
implementationClass="org.elixir_lang.inspection.NoParenthesesManyStrict" language="Elixir"
level="ERROR" shortName="NoParenthesesManyStrict"/>
Expand Down
38 changes: 22 additions & 16 deletions src/org/elixir_lang/sdk/elixir/Type.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.*
import com.intellij.openapi.util.InvalidDataException
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.Version
import com.intellij.openapi.util.WriteExternalException
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
Expand Down Expand Up @@ -44,6 +47,7 @@ import java.nio.file.Path
import java.nio.file.Paths
import java.util.*
import javax.swing.Icon
import java.util.concurrent.Callable

class Type : org.elixir_lang.sdk.erlang_dependent.Type(SerializerExtension.ELIXIR_SDK_TYPE_ID) {
/**
Expand Down Expand Up @@ -303,7 +307,7 @@ ELIXIR_SDK_HOME
addDocumentationPaths(sdkModificator)
addSourcePaths(sdkModificator)
configureInternalErlangSdk(sdk, sdkModificator)
sdkModificator.commitChanges()
ApplicationManager.getApplication().runWriteAction { sdkModificator.commitChanges() }
}

private fun configureInternalErlangSdk(elixirSdk: Sdk, elixirSdkModificator: SdkModificator): Sdk? {
Expand Down Expand Up @@ -415,7 +419,7 @@ ELIXIR_SDK_HOME
sdkModificator.homePath = sdkHome
sdkModificator.versionString =
getVersionString(release) // must be set after home path, otherwise setting home path clears the version string
sdkModificator.commitChanges()
ApplicationManager.getApplication().runWriteAction { sdkModificator.commitChanges() }
configureSdkPaths(sdk)
return sdk
}
Expand Down Expand Up @@ -527,21 +531,23 @@ ELIXIR_SDK_HOME
return if (!project.isDisposed) {
/* ModuleUtilCore.findModuleForPsiElement can fail with NullPointerException if the
ProjectFileIndex.SERVICE.getInstance(Project) returns {@code null}, so check that the
ProjectFileIndex is available first */
ProjectFileIndex is available first
*/
if (ProjectFileIndex.SERVICE.getInstance(project) != null) {
val module = try {
ReadAction.compute<Module, Throwable> {
ModuleUtilCore.findModuleForPsiElement(psiElement)
ApplicationManager.getApplication().executeOnPooledThread(Callable {
ReadAction.compute<Sdk?, Throwable> {
try {
val module = ModuleUtilCore.findModuleForPsiElement(psiElement)
if (module != null) {
mostSpecificSdk(module)
} else {
mostSpecificSdk(project)
}
} catch (_: AlreadyDisposedException) {
null
}
}
} catch (_: AlreadyDisposedException) {
null
}

if (module != null) {
mostSpecificSdk(module)
} else {
mostSpecificSdk(project)
}
}).get()
} else {
mostSpecificSdk(project)
}
Expand Down
4 changes: 2 additions & 2 deletions src/org/elixir_lang/sdk/erlang/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.intellij.execution.ExecutionException;
import com.intellij.execution.process.ProcessOutput;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkModel;
Expand Down Expand Up @@ -155,8 +156,7 @@ public boolean isRootTypeApplicable(@NotNull OrderRootType type) {
public void setupSdkPaths(@NotNull Sdk sdk) {
SdkModificator sdkModificator = sdk.getSdkModificator();
addCodePaths(sdkModificator);

sdkModificator.commitChanges();
ApplicationManager.getApplication().runWriteAction(sdkModificator::commitChanges);
}

/**
Expand Down
12 changes: 9 additions & 3 deletions tests/org/elixir_lang/FindUsagesTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.elixir_lang

import com.intellij.openapi.application.ex.ApplicationInfoEx
import com.intellij.openapi.util.Version
import com.intellij.psi.PsiPolyVariantReference
import com.intellij.usages.UsageInfo2UsageAdapter
import org.elixir_lang.find_usages.handler.AlreadyResolved
Expand Down Expand Up @@ -650,10 +651,15 @@ class FindUsagesTest : PlatformTestCase() {
)
}

private fun usages(): String =
if (ApplicationInfoEx.getInstance().fullVersion == "2021.1.3") {
private fun usages(): String {
val ideVersion = Version.parseVersion(ApplicationInfoEx.getInstance().fullVersion)
val usagesString = if (ideVersion === null || ideVersion.lessThan(2021,2,0)) {
"Found usages"
} else {
} else if (ideVersion.lessThan(2024,1,0)) {
"Usages in"
} else {
"Usages"
}
return usagesString
}
}
Loading

0 comments on commit f7ebb3b

Please sign in to comment.