diff --git a/editors/intellij/.gitignore b/editors/intellij/.gitignore new file mode 100644 index 000000000000..e2e5d94ec76b --- /dev/null +++ b/editors/intellij/.gitignore @@ -0,0 +1,4 @@ +.gradle +.idea +.qodana +build diff --git a/editors/intellij/.run/Run IDE for UI Tests.run.xml b/editors/intellij/.run/Run IDE for UI Tests.run.xml new file mode 100644 index 000000000000..ee99b7edd496 --- /dev/null +++ b/editors/intellij/.run/Run IDE for UI Tests.run.xml @@ -0,0 +1,25 @@ + + + + + + + + true + true + false + false + + + \ No newline at end of file diff --git a/editors/intellij/.run/Run Plugin.run.xml b/editors/intellij/.run/Run Plugin.run.xml new file mode 100644 index 000000000000..d15ff681a0de --- /dev/null +++ b/editors/intellij/.run/Run Plugin.run.xml @@ -0,0 +1,24 @@ + + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/editors/intellij/.run/Run Qodana.run.xml b/editors/intellij/.run/Run Qodana.run.xml new file mode 100644 index 000000000000..c92f33c7cd68 --- /dev/null +++ b/editors/intellij/.run/Run Qodana.run.xml @@ -0,0 +1,30 @@ + + + + + + + + true + true + false + false + + + \ No newline at end of file diff --git a/editors/intellij/.run/Run Tests.run.xml b/editors/intellij/.run/Run Tests.run.xml new file mode 100644 index 000000000000..132d9ad7416f --- /dev/null +++ b/editors/intellij/.run/Run Tests.run.xml @@ -0,0 +1,24 @@ + + + + + + + + true + true + false + + + diff --git a/editors/intellij/.run/Run Verifications.run.xml b/editors/intellij/.run/Run Verifications.run.xml new file mode 100644 index 000000000000..3a8d68859b1d --- /dev/null +++ b/editors/intellij/.run/Run Verifications.run.xml @@ -0,0 +1,26 @@ + + + + + + + + true + true + false + + + + \ No newline at end of file diff --git a/editors/intellij/README.md b/editors/intellij/README.md new file mode 100644 index 000000000000..f46264878588 --- /dev/null +++ b/editors/intellij/README.md @@ -0,0 +1 @@ +# intellij-biome diff --git a/editors/intellij/build.gradle.kts b/editors/intellij/build.gradle.kts new file mode 100644 index 000000000000..1e11685b043a --- /dev/null +++ b/editors/intellij/build.gradle.kts @@ -0,0 +1,127 @@ +import org.jetbrains.changelog.Changelog +import org.jetbrains.changelog.markdownToHTML + +fun properties(key: String) = providers.gradleProperty(key) +fun environment(key: String) = providers.environmentVariable(key) + +plugins { + id("java") // Java support + alias(libs.plugins.kotlin) // Kotlin support + alias(libs.plugins.gradleIntelliJPlugin) // Gradle IntelliJ Plugin + alias(libs.plugins.changelog) // Gradle Changelog Plugin + alias(libs.plugins.qodana) // Gradle Qodana Plugin + alias(libs.plugins.kover) // Gradle Kover Plugin +} + +group = properties("pluginGroup").get() +version = properties("pluginVersion").get() + +// Configure project's dependencies +repositories { + mavenCentral() +} + +// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog +dependencies { +// implementation(libs.annotations) +} + +// Set the JVM language level used to build the project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+. +kotlin { + jvmToolchain(17) +} + +// Configure Gradle IntelliJ Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html +intellij { + pluginName = properties("pluginName") + version = properties("platformVersion") + type = properties("platformType") + + // Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file. + plugins = properties("platformPlugins").map { it.split(',').map(String::trim).filter(String::isNotEmpty) } +} + +// Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin +changelog { + groups.empty() + repositoryUrl = properties("pluginRepositoryUrl") +} + +// Configure Gradle Qodana Plugin - read more: https://github.com/JetBrains/gradle-qodana-plugin +qodana { + cachePath = provider { file(".qodana").canonicalPath } + reportPath = provider { file("build/reports/inspections").canonicalPath } + saveReport = true + showReport = environment("QODANA_SHOW_REPORT").map { it.toBoolean() }.getOrElse(false) +} + +// Configure Gradle Kover Plugin - read more: https://github.com/Kotlin/kotlinx-kover#configuration +koverReport { + defaults { + xml { + onCheck = true + } + } +} + +tasks { + wrapper { + gradleVersion = properties("gradleVersion").get() + } + + patchPluginXml { + version = properties("pluginVersion") + sinceBuild = properties("pluginSinceBuild") + untilBuild = properties("pluginUntilBuild") + + // Extract the section from README.md and provide for the plugin's manifest + pluginDescription = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map { + val start = "" + val end = "" + + with (it.lines()) { + if (!containsAll(listOf(start, end))) { + throw GradleException("Plugin description section not found in README.md:\n$start ... $end") + } + subList(indexOf(start) + 1, indexOf(end)).joinToString("\n").let(::markdownToHTML) + } + } + + val changelog = project.changelog // local variable for configuration cache compatibility + // Get the latest available change notes from the changelog file + changeNotes = properties("pluginVersion").map { pluginVersion -> + with(changelog) { + renderItem( + (getOrNull(pluginVersion) ?: getUnreleased()) + .withHeader(false) + .withEmptySections(false), + Changelog.OutputType.HTML, + ) + } + } + } + + // Configure UI tests plugin + // Read more: https://github.com/JetBrains/intellij-ui-test-robot + runIdeForUiTests { + systemProperty("robot-server.port", "8082") + systemProperty("ide.mac.message.dialogs.as.sheets", "false") + systemProperty("jb.privacy.policy.text", "") + systemProperty("jb.consents.confirmation.enabled", "false") + } + +// signPlugin { +// certificateChain = environment("CERTIFICATE_CHAIN") +// privateKey = environment("PRIVATE_KEY") +// password = environment("PRIVATE_KEY_PASSWORD") +// } + +// publishPlugin { +// dependsOn("patchChangelog") +// token = environment("PUBLISH_TOKEN") +// // The pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3 +// // Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more: +// // https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel +// channels = properties("pluginVersion").map { listOf(it.split('-').getOrElse(1) { "default" }.split('.').first()) } +// } +} diff --git a/editors/intellij/gradle.properties b/editors/intellij/gradle.properties new file mode 100644 index 000000000000..2d039d93d6de --- /dev/null +++ b/editors/intellij/gradle.properties @@ -0,0 +1,34 @@ +# IntelliJ Platform Artifacts Repositories -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html + +pluginGroup = com.github.biomejs.intellijbiome +pluginName = intellij-biome +pluginRepositoryUrl = https://github.com/biomejs/intellij-biome +# SemVer format -> https://semver.org +pluginVersion = 0.0.1 + +# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html +pluginSinceBuild = 232 +pluginUntilBuild = 232.* + +# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension +platformType = IU +platformVersion = 232-EAP-SNAPSHOT + +# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html +# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 +platformPlugins=JavaScript + +# Gradle Releases -> https://github.com/gradle/gradle/releases +gradleVersion = 8.2.1 + +# Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib +kotlin.stdlib.default.dependency = false + +# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html +org.gradle.configuration-cache = true + +# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html +org.gradle.caching = true + +# Enable Gradle Kotlin DSL Lazy Property Assignment -> https://docs.gradle.org/current/userguide/kotlin_dsl.html#kotdsl:assignment +systemProp.org.gradle.unsafe.kotlin.assignment = true diff --git a/editors/intellij/gradle/libs.versions.toml b/editors/intellij/gradle/libs.versions.toml new file mode 100644 index 000000000000..59e576ac9013 --- /dev/null +++ b/editors/intellij/gradle/libs.versions.toml @@ -0,0 +1,20 @@ +[versions] +# libraries +annotations = "24.0.1" + +# plugins +kotlin = "1.9.0" +changelog = "2.1.2" +gradleIntelliJPlugin = "1.15.0" +qodana = "0.1.13" +kover = "0.7.3" + +[libraries] +annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" } + +[plugins] +changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" } +gradleIntelliJPlugin = { id = "org.jetbrains.intellij", version.ref = "gradleIntelliJPlugin" } +kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" } +qodana = { id = "org.jetbrains.qodana", version.ref = "qodana" } \ No newline at end of file diff --git a/editors/intellij/gradle/wrapper/gradle-wrapper.jar b/editors/intellij/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000000..033e24c4cdf4 Binary files /dev/null and b/editors/intellij/gradle/wrapper/gradle-wrapper.jar differ diff --git a/editors/intellij/gradle/wrapper/gradle-wrapper.properties b/editors/intellij/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000000..9f4197d5f4b9 --- /dev/null +++ b/editors/intellij/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/editors/intellij/gradlew b/editors/intellij/gradlew new file mode 100755 index 000000000000..fcb6fca147c0 --- /dev/null +++ b/editors/intellij/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# 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/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +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 +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# 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"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + 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. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/editors/intellij/gradlew.bat b/editors/intellij/gradlew.bat new file mode 100644 index 000000000000..93e3f59f135d --- /dev/null +++ b/editors/intellij/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +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! +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 + +:omega diff --git a/editors/intellij/qodana.yml b/editors/intellij/qodana.yml new file mode 100644 index 000000000000..f388de9a89c4 --- /dev/null +++ b/editors/intellij/qodana.yml @@ -0,0 +1,12 @@ +# Qodana configuration: +# https://www.jetbrains.com/help/qodana/qodana-yaml.html + +version: 1.0 +linter: jetbrains/qodana-jvm-community:latest +projectJDK: 17 +profile: + name: qodana.recommended +exclude: + - name: All + paths: + - .qodana diff --git a/editors/intellij/settings.gradle.kts b/editors/intellij/settings.gradle.kts new file mode 100644 index 000000000000..30eabbe74cd5 --- /dev/null +++ b/editors/intellij/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "intellij-biome" diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/BiomeBundle.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/BiomeBundle.kt new file mode 100644 index 000000000000..f039b999d2b2 --- /dev/null +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/BiomeBundle.kt @@ -0,0 +1,21 @@ +package com.github.biomejs.intellijbiome + +import com.intellij.DynamicBundle +import org.jetbrains.annotations.NonNls +import org.jetbrains.annotations.PropertyKey + +@NonNls +private const val BUNDLE = "messages.BiomeBundle" + +object BiomeBundle : DynamicBundle(BUNDLE) { + + @Suppress("SpreadOperator") + @JvmStatic + fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = + getMessage(key, *params) + + @Suppress("SpreadOperator", "unused") + @JvmStatic + fun messagePointer(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = + getLazyMessage(key, *params) +} diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/BiomeUtils.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/BiomeUtils.kt new file mode 100644 index 000000000000..2ccc8ae84ff6 --- /dev/null +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/BiomeUtils.kt @@ -0,0 +1,71 @@ +package com.github.biomejs.intellijbiome + +import com.github.biomejs.intellijbiome.settings.BiomeSettings +import com.intellij.execution.configurations.GeneralCommandLine +import com.intellij.execution.util.ExecUtil +import com.intellij.javascript.nodejs.library.node_modules.NodeModulesDirectoryManager +import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.fileTypes.FileType +import com.intellij.openapi.project.Project +import com.intellij.util.SmartList +import java.io.File + + +object BiomeUtils { + fun isSupportedFileType(fileType: FileType): Boolean = when (fileType.defaultExtension) { + "js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx" -> true + else -> false + } + + fun getBiomeVersion(project: Project, binaryPath: String): String? { + if(binaryPath.isEmpty()){ + return null + } + + val versionRegex = Regex("\\d{1,2}\\.\\d{1,2}\\.\\d{1,3}") + val commandLine = createVersionCommandLine(project, binaryPath) + + val output = ExecUtil.execAndGetOutput(commandLine) + + val matchResult = versionRegex.find(output.stdout) + + return matchResult?.value + } + + fun getBiomeExecutablePath(project: Project): String? { + val directoryManager = NodeModulesDirectoryManager.getInstance(project) + val executablePath = BiomeSettings.getInstance(project).executablePath + val biomeBinFile = directoryManager.nodeModulesDirs + .asSequence() + .mapNotNull { it.findFileByRelativePath(".bin/biome") } + .filter { it.isValid } + .firstOrNull() + + if (executablePath.isEmpty()) { + return biomeBinFile?.path + } + + return executablePath + } + + fun attachConfigPath(params: SmartList, project: Project, logger: Logger) { + project.basePath?.let { + try { + val file = File(it) + if (file.exists()) { + params.add("--config-path") + params.add(project.basePath) + } + } catch (error: Exception) { + logger.error(error.message) + } + } + } + + private fun createVersionCommandLine(project: Project, binaryPath: String): GeneralCommandLine { + return GeneralCommandLine() + .withWorkDirectory(project.basePath) + .withExePath(binaryPath) + .withParameters("--version") + } +} diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/actions/RestartBiomeServerAction.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/actions/RestartBiomeServerAction.kt new file mode 100644 index 000000000000..3f2c7b178b01 --- /dev/null +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/actions/RestartBiomeServerAction.kt @@ -0,0 +1,10 @@ +package com.github.biomejs.intellijbiome.actions + +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent + +class RestartBiomeServerAction : AnAction() { + override fun actionPerformed(p0: AnActionEvent) { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/formatter/BiomeFormatterProvider.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/formatter/BiomeFormatterProvider.kt new file mode 100644 index 000000000000..69ff16f2a235 --- /dev/null +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/formatter/BiomeFormatterProvider.kt @@ -0,0 +1,78 @@ +package com.github.biomejs.intellijbiome.formatter + +import com.github.biomejs.intellijbiome.BiomeBundle +import com.github.biomejs.intellijbiome.BiomeUtils +import com.intellij.execution.configurations.GeneralCommandLine +import com.intellij.execution.process.CapturingProcessAdapter +import com.intellij.execution.process.OSProcessHandler +import com.intellij.execution.process.ProcessEvent +import com.intellij.formatting.service.AsyncDocumentFormattingService +import com.intellij.formatting.service.AsyncFormattingRequest +import com.intellij.formatting.service.FormattingService.Feature +import com.intellij.openapi.diagnostic.thisLogger +import com.intellij.psi.PsiFile +import com.intellij.util.SmartList +import org.jetbrains.annotations.NotNull +import java.nio.charset.StandardCharsets +import java.util.EnumSet +import com.intellij.execution.ExecutionException + +class BiomeFormatterProvider: AsyncDocumentFormattingService() { + override fun getFeatures(): MutableSet = EnumSet.noneOf(Feature::class.java) + + override fun canFormat(file: PsiFile): Boolean = BiomeUtils.isSupportedFileType(file.fileType) + + override fun getNotificationGroupId(): String = "Biome" + + override fun getName(): String = "Biome" + + override fun createFormattingTask(request: AsyncFormattingRequest): FormattingTask? { + val ioFile = request.ioFile ?: return null + val project = request.context.project + val params = SmartList("format", "--stdin-file-path", ioFile.path) + BiomeUtils.attachConfigPath(params, project, thisLogger()) + val exePath = BiomeUtils.getBiomeExecutablePath(project) + + if(exePath.isNullOrEmpty()) { + throw ExecutionException(BiomeBundle.message("biome.language.server.not.found")) + } + + try { + val commandLine: GeneralCommandLine = GeneralCommandLine() + .withExePath(exePath) + .withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE) + .withInput(ioFile) + .withParameters(params) + + val handler = OSProcessHandler(commandLine.withCharset(StandardCharsets.UTF_8)) + return object : FormattingTask { + override fun run() { + handler.addProcessListener(object : CapturingProcessAdapter() { + override fun processTerminated(@NotNull event: ProcessEvent) { + val exitCode = event.exitCode + if (exitCode == 0) { + request.onTextReady(output.stdout) + } else { + request.onError(BiomeBundle.message("biome.formatting.failure"), output.stderr) + } + } + }) + handler.startNotify() + } + + override fun cancel(): Boolean { + handler.destroyProcess() + return true + } + + override fun isRunUnderProgress(): Boolean { + return true + } + } + } catch (error: ExecutionException) { + val message = error.message ?: "" + request.onError(BiomeBundle.message("biome.formatting.failure"), message) + return null + } + } +} diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/lsp/BiomeLspCodeActionsSupport.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/lsp/BiomeLspCodeActionsSupport.kt new file mode 100644 index 000000000000..a3a985bbf23c --- /dev/null +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/lsp/BiomeLspCodeActionsSupport.kt @@ -0,0 +1,11 @@ +package com.github.biomejs.intellijbiome.lsp + +import com.intellij.platform.lsp.api.LspServer + +import com.intellij.platform.lsp.api.customization.LspCodeActionsSupport +import com.intellij.platform.lsp.api.customization.LspIntentionAction +import org.eclipse.lsp4j.CodeAction + +class BiomeLspCodeActionsSupport : LspCodeActionsSupport() { + +} \ No newline at end of file diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/lsp/BiomeLspDiagnosticsSupport.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/lsp/BiomeLspDiagnosticsSupport.kt new file mode 100644 index 000000000000..3029b8ab615c --- /dev/null +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/lsp/BiomeLspDiagnosticsSupport.kt @@ -0,0 +1,9 @@ +package com.github.biomejs.intellijbiome.lsp + +import com.intellij.lang.annotation.HighlightSeverity +import com.intellij.platform.lsp.api.customization.LspDiagnosticsSupport +import org.eclipse.lsp4j.Diagnostic + +class BiomeLspDiagnosticsSupport : LspDiagnosticsSupport() { + +} \ No newline at end of file diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/lsp/BiomeLspServerSupportProvider.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/lsp/BiomeLspServerSupportProvider.kt new file mode 100644 index 000000000000..3b7b0db050f7 --- /dev/null +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/lsp/BiomeLspServerSupportProvider.kt @@ -0,0 +1,61 @@ +package com.github.biomejs.intellijbiome.lsp + +import com.github.biomejs.intellijbiome.BiomeBundle +import com.github.biomejs.intellijbiome.BiomeUtils +import com.intellij.execution.ExecutionException +import com.intellij.execution.configurations.GeneralCommandLine +import com.intellij.openapi.diagnostic.thisLogger +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.platform.lsp.api.LspServerSupportProvider +import com.intellij.platform.lsp.api.ProjectWideLspServerDescriptor +import com.intellij.platform.lsp.api.customization.LspCodeActionsSupport +import com.intellij.platform.lsp.api.customization.LspDiagnosticsSupport +import com.intellij.util.SmartList +import org.eclipse.lsp4j.* + +@Suppress("UnstableApiUsage") +class BiomeLspServerSupportProvider : LspServerSupportProvider { + override fun fileOpened(project: Project, file: VirtualFile, serverStarter: LspServerSupportProvider.LspServerStarter) { + if (BiomeUtils.isSupportedFileType(file.fileType)) { + val executable = BiomeUtils.getBiomeExecutablePath(project) ?: return + + serverStarter.ensureServerStarted(BiomeLspServerDescriptor(project, executable)) + } + } +} + +@Suppress("UnstableApiUsage") +private class BiomeLspServerDescriptor(project: Project, val executable: String) : ProjectWideLspServerDescriptor(project, "Biome") { + override fun isSupportedFile(file: VirtualFile) = BiomeUtils.isSupportedFileType(file.fileType) + override fun createCommandLine(): GeneralCommandLine { + val params = SmartList("lsp-proxy", "--use-server") + BiomeUtils.attachConfigPath(params, project, thisLogger()) + + if(executable.isEmpty()) { + throw ExecutionException(BiomeBundle.message("biome.language.server.not.found")) + } + + return GeneralCommandLine() + .withExePath(executable) + .withParameters(params) + } + + override val lspGoToDefinitionSupport = false + override val lspCompletionSupport = null + override val lspDiagnosticsSupport: LspDiagnosticsSupport + get() = BiomeLspDiagnosticsSupport() + override val lspCodeActionsSupport: LspCodeActionsSupport + get() = BiomeLspCodeActionsSupport() + + override val clientCapabilities: ClientCapabilities + get() = super.clientCapabilities.apply { + textDocument = TextDocumentClientCapabilities().apply { + codeAction = CodeActionCapabilities().apply { + codeActionLiteralSupport = CodeActionLiteralSupportCapabilities().apply { + codeActionKind = CodeActionKindCapabilities(listOf(CodeActionKind.Empty)) + } + } + } + } +} diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeSettings.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeSettings.kt new file mode 100644 index 000000000000..b61bc307d87e --- /dev/null +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeSettings.kt @@ -0,0 +1,20 @@ +package com.github.biomejs.intellijbiome.settings + +import com.intellij.openapi.components.* +import com.intellij.openapi.project.Project + +@Service(Service.Level.PROJECT) +@State(name = "BiomeSettings", storages = [(Storage("biome.xml"))]) +class BiomeSettings : + SimplePersistentStateComponent(BiomeSettingsState()) { + var executablePath: String + get() = state.executablePath ?: "" + set(value) { + state.executablePath = value + } + + companion object { + @JvmStatic + fun getInstance(project: Project): BiomeSettings = project.service() + } +} diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeSettingsConfigurable.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeSettingsConfigurable.kt new file mode 100644 index 000000000000..e493ff070b6d --- /dev/null +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeSettingsConfigurable.kt @@ -0,0 +1,32 @@ +package com.github.biomejs.intellijbiome.settings + +import com.github.biomejs.intellijbiome.BiomeBundle +import com.github.biomejs.intellijbiome.lsp.BiomeLspServerSupportProvider +import com.intellij.javascript.nodejs.library.node_modules.NodeModulesDirectoryManager +import com.intellij.openapi.options.BoundSearchableConfigurable +import com.intellij.openapi.project.Project +import com.intellij.openapi.ui.DialogPanel +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.platform.lsp.api.LspServerManager +import com.intellij.ui.dsl.builder.bindText +import com.intellij.ui.dsl.builder.panel + +class BiomeSettingsConfigurable(internal val project: Project): BoundSearchableConfigurable(BiomeBundle.message("biome.settings.name"), BiomeBundle.message("biome.settings.name")) { + override fun createPanel(): DialogPanel { + val settings: BiomeSettings = BiomeSettings.getInstance(project) + + return panel { + row { + textFieldWithBrowseButton(BiomeBundle.message("biome.path.label")) { fileChosen(it) } + .bindText(settings::executablePath) + } + + onApply { LspServerManager.getInstance(project).stopAndRestartIfNeeded(BiomeLspServerSupportProvider::class.java) } + } + + } + + fun fileChosen(file: VirtualFile): String { + return file.path + } +} diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeSettingsState.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeSettingsState.kt new file mode 100644 index 000000000000..61e0253f945a --- /dev/null +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeSettingsState.kt @@ -0,0 +1,10 @@ +package com.github.biomejs.intellijbiome.settings +import com.intellij.openapi.components.BaseState +import com.intellij.openapi.components.Service +import org.jetbrains.annotations.ApiStatus + +@Service +@ApiStatus.Internal +class BiomeSettingsState: BaseState() { + var executablePath by string() +} diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/widgets/BiomeStatusBarWidgetFactory.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/widgets/BiomeStatusBarWidgetFactory.kt new file mode 100644 index 000000000000..884b0c85fd2b --- /dev/null +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/widgets/BiomeStatusBarWidgetFactory.kt @@ -0,0 +1,19 @@ +package com.github.biomejs.intellijbiome.widgets + +import com.intellij.openapi.project.Project +import com.intellij.openapi.wm.StatusBarWidget +import com.intellij.openapi.wm.StatusBarWidgetFactory + +class BiomeStatusBarWidgetFactory : StatusBarWidgetFactory { + override fun getId(): String { + return "BiomeWidget" + } + + override fun getDisplayName(): String { + return "Biome" + } + + override fun createWidget(project: Project): StatusBarWidget { + return BiomeWidget(project) + } +} \ No newline at end of file diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/widgets/BiomeWidget.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/widgets/BiomeWidget.kt new file mode 100644 index 000000000000..a75f9c19112d --- /dev/null +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/widgets/BiomeWidget.kt @@ -0,0 +1,15 @@ +package com.github.biomejs.intellijbiome.widgets + +import com.intellij.openapi.project.Project +import com.intellij.openapi.wm.StatusBarWidget +import com.intellij.openapi.wm.impl.status.EditorBasedWidget +class BiomeWidget(myProject: Project) : EditorBasedWidget(myProject) { + + override fun ID(): String { + return "BiomeWidget" + } + + override fun getPresentation(): StatusBarWidget.WidgetPresentation { + return BiomeWidgetPresentation(project) + } +} \ No newline at end of file diff --git a/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/widgets/BiomeWidgetPresentation.kt b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/widgets/BiomeWidgetPresentation.kt new file mode 100644 index 000000000000..192bb915c5b5 --- /dev/null +++ b/editors/intellij/src/main/kotlin/com/github/biomejs/intellijbiome/widgets/BiomeWidgetPresentation.kt @@ -0,0 +1,49 @@ +package com.github.biomejs.intellijbiome.widgets + +import com.github.biomejs.intellijbiome.BiomeBundle +import com.github.biomejs.intellijbiome.BiomeUtils +import com.github.biomejs.intellijbiome.lsp.BiomeLspServerSupportProvider +import com.intellij.openapi.progress.ProgressManager +import com.intellij.openapi.project.Project +import com.intellij.openapi.wm.StatusBarWidget +import com.intellij.platform.lsp.api.LspServerManager +import com.intellij.platform.lsp.impl.LspServerImpl + +@Suppress("UnstableApiUsage") +class BiomeWidgetPresentation(private val project: Project) : StatusBarWidget.MultipleTextValuesPresentation { + override fun getSelectedValue(): String? { + val biomeBin = BiomeUtils.getBiomeExecutablePath(project) + val progressManager = ProgressManager.getInstance() + + if(biomeBin == null) { + return null + } + + val version = progressManager.runProcessWithProgressSynchronously({ + BiomeUtils.getBiomeVersion(project, biomeBin) + }, BiomeBundle.message("biome.loading"), true, project) + + + return "Biome ${version}" + } + + override fun getTooltipText(): String? { + val lspServerManager = LspServerManager.getInstance(project) + val lspServer = lspServerManager.getServersForProvider(BiomeLspServerSupportProvider::class.java).first() + + return when (lspServer) { + is LspServerImpl -> { + if (lspServer.isRunning){ + BiomeBundle.message("biome.language.server.is.running") + } else { + BiomeBundle.message("biome.language.server.is.stopped") + } + } + + else -> { + null + } + } + + } +} \ No newline at end of file diff --git a/editors/intellij/src/main/resources/META-INF/plugin.xml b/editors/intellij/src/main/resources/META-INF/plugin.xml new file mode 100644 index 000000000000..0a8a9b6120db --- /dev/null +++ b/editors/intellij/src/main/resources/META-INF/plugin.xml @@ -0,0 +1,40 @@ + + + com.github.biomejs.intellijbiome + Biome LSP + biomejs + + com.intellij.modules.platform + com.intellij.modules.ultimate + JavaScript + + messages.BiomeBundle + + + + + + + + + + + + + + + diff --git a/editors/intellij/src/main/resources/icons/pluginIcon.svg b/editors/intellij/src/main/resources/icons/pluginIcon.svg new file mode 100644 index 000000000000..bed6c6efcf9d --- /dev/null +++ b/editors/intellij/src/main/resources/icons/pluginIcon.svg @@ -0,0 +1,3 @@ + + + diff --git a/editors/intellij/src/main/resources/messages/BiomeBundle.properties b/editors/intellij/src/main/resources/messages/BiomeBundle.properties new file mode 100644 index 000000000000..ecb1293f4fe7 --- /dev/null +++ b/editors/intellij/src/main/resources/messages/BiomeBundle.properties @@ -0,0 +1,8 @@ +name=Biome +biome.path.label=Biome CLI Path +biome.settings.name=Biome Settings +biome.formatting.failure=Formatting error +biome.language.server.not.found=Biome language server is not found, make sure you have @biomejs/biome installed. +biome.loading=Biome is loading... +biome.language.server.is.running=Biome server is running +biome.language.server.is.stopped=Biome server is stopped \ No newline at end of file diff --git a/editors/intellij/src/test/kotlin/com/github/biomejs/intellijbiome/MyPluginTest.kt b/editors/intellij/src/test/kotlin/com/github/biomejs/intellijbiome/MyPluginTest.kt new file mode 100644 index 000000000000..27a4f7d92ed5 --- /dev/null +++ b/editors/intellij/src/test/kotlin/com/github/biomejs/intellijbiome/MyPluginTest.kt @@ -0,0 +1,11 @@ +package com.github.biomejs.intellijbiome + +import com.intellij.testFramework.TestDataPath +import com.intellij.testFramework.fixtures.BasePlatformTestCase + +@TestDataPath("\$CONTENT_ROOT/src/test/testData") +class MyPluginTest : BasePlatformTestCase() { + fun testExample() { + assert("hello-world" == "hello-world") + } +}