diff --git a/.github/workflows/jetbrains.yaml b/.github/workflows/jetbrains.yaml new file mode 100644 index 0000000..46897dc --- /dev/null +++ b/.github/workflows/jetbrains.yaml @@ -0,0 +1,101 @@ + +name: JetBrains +on: + push: + branches: [ main ] + pull_request: + +jobs: + + build: + name: Build + runs-on: ubuntu-latest + outputs: + version: ${{ steps.properties.outputs.version }} + changelog: ${{ steps.properties.outputs.changelog }} + pluginVerifierHomeDir: ${{ steps.properties.outputs.pluginVerifierHomeDir }} + steps: + + - name: Fetch Sources + uses: actions/checkout@v4 + + - name: Gradle Wrapper Validation + uses: gradle/wrapper-validation-action@v1.1.0 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: 17 + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + with: + gradle-home-cache-cleanup: true + + - name: Install Bun + uses: oven-sh/setup-bun@a1800f471a0bc25cddac36bb13e6f436ddf341d7 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Install wasm-pack + uses: jetli/wasm-pack-action@0d096b08b4e5a7de8c28de67e11e945404e9eefa + with: + version: 'latest' + + - name: Install dependencies + run: bun install + + - name: Build With Bun + run: bun run build + + # Set environment variables + - name: Export Properties + id: properties + shell: bash + working-directory: ./jetbrains + run: | + PROPERTIES="$(./gradlew properties --console=plain -q)" + VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')" + CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)" + + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "pluginVerifierHomeDir=~/.pluginVerifier" >> $GITHUB_OUTPUT + + echo "changelog<> $GITHUB_OUTPUT + echo "$CHANGELOG" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + ./gradlew listProductsReleases # prepare list of IDEs for Plugin Verifier + + - name: Build IDE plugin + working-directory: ./jetbrains + run: ./gradlew buildPlugin + + test: + name: Test + runs-on: ubuntu-latest + steps: + + - name: Fetch Sources + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: 17 + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + with: + gradle-home-cache-cleanup: true + + - name: Run Tests + working-directory: ./jetbrains + run: ./gradlew check diff --git a/.gitignore b/.gitignore index 90fbbc5..19eba7b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,7 @@ node_modules/ .DS_Store .env -*.tgz \ No newline at end of file +*.tgz +.idea +*.pem +*.crt \ No newline at end of file diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 48b0023..c5ed62d 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -2,5 +2,6 @@ "crates/does-it-throw": "0.1.15", "crates/does-it-throw-wasm": "0.1.15", ".": "0.3.3", - "server": "0.3.3" + "server": "0.3.3", + "jetbrains": "0.3.3" } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 2e7e910..de3803b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,5 +17,16 @@ "[typescriptreact]": { "editor.defaultFormatter": "biomejs.biome" }, - "doesItThrow.trace.server": "verbose" + "doesItThrow.trace.server": "verbose", + "files.exclude": { + "**/.git": true, + "**/.svn": true, + "**/.hg": true, + "**/CVS": true, + "**/.DS_Store": true, + "**/Thumbs.db": true, + "intellij/.gradle/**/*": true, + "intellij/.idea/**/*": true, + "intellij/build/**/*": true + } } \ No newline at end of file diff --git a/README.md b/README.md index 6972661..052abbc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +

@@ -69,3 +70,4 @@ Please use the GitHub discussions tab to provide feedback and suggestions. Thank ## License MIT - See [LICENSE](https://github.com/michaelangeloio/does-it-throw/blob/main/LICENSE.txt) for more information. + \ No newline at end of file diff --git a/jetbrains/.gitignore b/jetbrains/.gitignore new file mode 100644 index 0000000..e2e5d94 --- /dev/null +++ b/jetbrains/.gitignore @@ -0,0 +1,4 @@ +.gradle +.idea +.qodana +build diff --git a/jetbrains/.run/Run IDE for UI Tests.run.xml b/jetbrains/.run/Run IDE for UI Tests.run.xml new file mode 100644 index 0000000..ee99b7e --- /dev/null +++ b/jetbrains/.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/jetbrains/.run/Run Plugin.run.xml b/jetbrains/.run/Run Plugin.run.xml new file mode 100644 index 0000000..d15ff68 --- /dev/null +++ b/jetbrains/.run/Run Plugin.run.xml @@ -0,0 +1,24 @@ + + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/jetbrains/.run/Run Tests.run.xml b/jetbrains/.run/Run Tests.run.xml new file mode 100644 index 0000000..ea8eb7a --- /dev/null +++ b/jetbrains/.run/Run Tests.run.xml @@ -0,0 +1,26 @@ + + + + + + + + true + true + false + false + + + \ No newline at end of file diff --git a/jetbrains/.run/Run Verifications.run.xml b/jetbrains/.run/Run Verifications.run.xml new file mode 100644 index 0000000..3a8d688 --- /dev/null +++ b/jetbrains/.run/Run Verifications.run.xml @@ -0,0 +1,26 @@ + + + + + + + + true + true + false + + + + \ No newline at end of file diff --git a/jetbrains/CHANGELOG.md b/jetbrains/CHANGELOG.md new file mode 100644 index 0000000..50ec527 --- /dev/null +++ b/jetbrains/CHANGELOG.md @@ -0,0 +1,35 @@ +# Changelog + +## Unreleased + +## 0.3.3(https://github.com/michaelangeloio/does-it-throw/compare/does-it-throw-lsp-v0.3.2...does-it-throw-lsp-v0.3.3) (2023-12-24) + +### Bug Fixes + +- catch with throw statement not included ([#95](https://github.com/michaelangeloio/does-it-throw/issues/95)) ([fd223db](https://github.com/michaelangeloio/does-it-throw/commit/fd223db4f56e87439999b9b33a393769bd2b7c5b)) +- **deps-dev:** remove remaining eslint dev dependencies ([#97](https://github.com/michaelangeloio/does-it-throw/issues/97)) ([5f173a6](https://github.com/michaelangeloio/does-it-throw/commit/5f173a69cb86570a526a665d453b86ae776538d0)) + +## 0.3.2(https://github.com/michaelangeloio/does-it-throw/compare/does-it-throw-lsp-v0.3.1...does-it-throw-lsp-v0.3.2) (2023-12-17) + +### Bug Fixes + +- update server package.json keywords ([#87](https://github.com/michaelangeloio/does-it-throw/issues/87)) ([c19717d](https://github.com/michaelangeloio/does-it-throw/commit/c19717d96a09152d959bfd7d5c3a34ac62f5e26d)) + +## 0.3.1(https://github.com/michaelangeloio/does-it-throw/compare/does-it-throw-lsp-v0.3.0...does-it-throw-lsp-v0.3.1) (2023-12-17) + +### Bug Fixes + +- functions and throw statements are underlined even if caught ([#81](https://github.com/michaelangeloio/does-it-throw/issues/81)) ([16adf85](https://github.com/michaelangeloio/does-it-throw/commit/16adf85b05b92542fa6c09ac1611dd56c7603c99)) + +## 0.3.0(https://github.com/michaelangeloio/does-it-throw/compare/does-it-throw-lsp-v0.2.5...does-it-throw-lsp-v0.3.0) (2023-12-16) + +### Features + +- neovim support ([#78](https://github.com/michaelangeloio/does-it-throw/issues/78)) ([6152786](https://github.com/michaelangeloio/does-it-throw/commit/61527869e70f54e99616375f7efd53b24e0fa01a)) + +### Bug Fixes + +- add biome for standardization, ensure the builder reports errors correctly ([#72](https://github.com/michaelangeloio/does-it-throw/issues/72)) ([0d18392](https://github.com/michaelangeloio/does-it-throw/commit/0d18392268516abb79d015f90495dd331e7ef998)) +- re-organize primary crate into modules ([#42](https://github.com/michaelangeloio/does-it-throw/issues/42)) ([badb106](https://github.com/michaelangeloio/does-it-throw/commit/badb1061d0dfc679458d55609e43cccfdca01794)) +- results should still show even if file cannot resolve (calls to throws) ([#76](https://github.com/michaelangeloio/does-it-throw/issues/76)) ([f908556](https://github.com/michaelangeloio/does-it-throw/commit/f908556dfda8eca9195c87269fac71bc6d3e8bf9)) +- update details, fix logic in some call expressions, including spread operators ([#40](https://github.com/michaelangeloio/does-it-throw/issues/40)) ([cdfdf47](https://github.com/michaelangeloio/does-it-throw/commit/cdfdf47a2d657364abc1b3b3ce97e89405b842b3)) diff --git a/jetbrains/build.gradle.kts b/jetbrains/build.gradle.kts new file mode 100644 index 0000000..0dd1b58 --- /dev/null +++ b/jetbrains/build.gradle.kts @@ -0,0 +1,154 @@ +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() +} + +tasks.test { + useJUnitPlatform() +} + +// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog +dependencies { +// implementation(libs.annotations) + testImplementation("org.junit.jupiter:junit-jupiter:5.8.1") + + // Mockito for mocking in tests + testImplementation("org.mockito:mockito-core:4.5.1") // adjust the version as needed + testImplementation("org.mockito.kotlin:mockito-kotlin:5.2.1") + +} +// Set the JVM language level used to build the project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+. +kotlin { + @Suppress("UnstableApiUsage") + jvmToolchain { + languageVersion = JavaLanguageVersion.of(17) + vendor = JvmVendorSpec.JETBRAINS + } +} + +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 Kover Plugin - read more: https://github.com/Kotlin/kotlinx-kover#configuration +koverReport { + defaults { + xml { + onCheck = true + } + } +} + +tasks { + + prepareSandbox { + doLast { + val pluginName = project.ext.get("pluginName") ?: throw GradleException("Plugin name not set.") + + val sourceDir = file("${project.projectDir}/../server/out") + println("language server sourceDir: $sourceDir") + val destDir = file("${destinationDir.path}/${pluginName}/language-server") + println("language server destDir: $destDir") + + if (sourceDir.exists()) { + copy { + from(sourceDir) + into(destDir) + } + } else { + throw GradleException("Source directory does not exist: $sourceDir") + } + } + } + + wrapper { + gradleVersion = properties("gradleVersion").get() + } + + patchPluginXml { + sinceBuild.set("233") + untilBuild.set("240.*") + + // Extract the section from README.md and provide for the plugin's manifest + val readMe = layout.projectDirectory.file(file("${project.projectDir}/../server/README.md").path) + println("readMe sourceDir: $readMe") + pluginDescription = providers.fileContents(readMe).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(true), + 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("JETBRAINS_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 + } + +} diff --git a/jetbrains/gradle.properties b/jetbrains/gradle.properties new file mode 100644 index 0000000..b2a5afc --- /dev/null +++ b/jetbrains/gradle.properties @@ -0,0 +1,16 @@ +# IntelliJ Platform Artifacts Repositories -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html + +pluginGroup=github.com.michaelangelio.does-it-throw +pluginName=Does it Throw? +# x-release-please-start-version +pluginVersion=0.3.3 +# x-release-please-end +pluginSinceBuild=223 +pluginUntilBuild=223.* +platformType=IU +platformVersion=2023.3 +platformPlugins=JavaScript +pluginVerifierIdeVersions=IU-2022.3 +gradleVersion=7.5.1 +kotlin.stdlib.default.dependency = false +jvmVersion=17 diff --git a/jetbrains/gradle/libs.versions.toml b/jetbrains/gradle/libs.versions.toml new file mode 100644 index 0000000..febb8cd --- /dev/null +++ b/jetbrains/gradle/libs.versions.toml @@ -0,0 +1,20 @@ +[versions] +# libraries +annotations = "24.1.0" + +# plugins +kotlin = "1.9.21" +changelog = "2.2.0" +gradleIntelliJPlugin = "1.16.1" +qodana = "0.1.13" +kover = "0.7.5" + +[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" } diff --git a/jetbrains/gradle/wrapper/gradle-wrapper.jar b/jetbrains/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..d64cd49 Binary files /dev/null and b/jetbrains/gradle/wrapper/gradle-wrapper.jar differ diff --git a/jetbrains/gradle/wrapper/gradle-wrapper.properties b/jetbrains/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..1af9e09 --- /dev/null +++ b/jetbrains/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/jetbrains/gradlew b/jetbrains/gradlew new file mode 100755 index 0000000..1aa94a4 --- /dev/null +++ b/jetbrains/gradlew @@ -0,0 +1,249 @@ +#!/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##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && 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=SC2039,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=SC2039,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, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +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/jetbrains/gradlew.bat b/jetbrains/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/jetbrains/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/jetbrains/qodana.yml b/jetbrains/qodana.yml new file mode 100644 index 0000000..cbf640f --- /dev/null +++ b/jetbrains/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/jetbrains/settings.gradle.kts b/jetbrains/settings.gradle.kts new file mode 100644 index 0000000..495b8cc --- /dev/null +++ b/jetbrains/settings.gradle.kts @@ -0,0 +1,5 @@ +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0" +} + +rootProject.name = "Does it Throw" diff --git a/jetbrains/src/main/kotlin/org/michaelangeloio/plugins/dit/DoesItThrowUtils.kt b/jetbrains/src/main/kotlin/org/michaelangeloio/plugins/dit/DoesItThrowUtils.kt new file mode 100644 index 0000000..3e29a62 --- /dev/null +++ b/jetbrains/src/main/kotlin/org/michaelangeloio/plugins/dit/DoesItThrowUtils.kt @@ -0,0 +1,10 @@ +package org.michaelangeloio.plugins.dit + +import com.intellij.openapi.vfs.VirtualFile + +object DoesItThrowUtils { + fun isSupportedFileType(file: VirtualFile): Boolean = when (file.extension) { + "js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx", "d.ts", "json", "jsonc" -> true + else -> false + } +} diff --git a/jetbrains/src/main/kotlin/org/michaelangeloio/plugins/dit/lsp/LspServerDescriptor.kt b/jetbrains/src/main/kotlin/org/michaelangeloio/plugins/dit/lsp/LspServerDescriptor.kt new file mode 100644 index 0000000..521ef19 --- /dev/null +++ b/jetbrains/src/main/kotlin/org/michaelangeloio/plugins/dit/lsp/LspServerDescriptor.kt @@ -0,0 +1,54 @@ +package org.michaelangeloio.plugins.dit.lsp + +import com.intellij.execution.ExecutionException +import com.intellij.execution.configurations.GeneralCommandLine +import com.intellij.javascript.nodejs.interpreter.NodeCommandLineConfigurator +import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterManager +import com.intellij.javascript.nodejs.interpreter.local.NodeJsLocalInterpreter +import com.intellij.javascript.nodejs.interpreter.wsl.WslNodeInterpreter +import com.intellij.lang.javascript.service.JSLanguageServiceUtil +import com.intellij.openapi.diagnostic.thisLogger +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.platform.lsp.api.ProjectWideLspServerDescriptor +import org.michaelangeloio.plugins.dit.DoesItThrowUtils + +class DoesItThrowLspServerDescriptor(project: Project) : ProjectWideLspServerDescriptor(project, "Does it Throw?") { + + override fun isSupportedFile(file: VirtualFile) = DoesItThrowUtils.isSupportedFileType(file) + + override fun createCommandLine(): GeneralCommandLine { + val interpreter = NodeJsInterpreterManager.getInstance(project).interpreter + if (interpreter !is NodeJsLocalInterpreter && interpreter !is WslNodeInterpreter) { + // shouldn't happen + throw ExecutionException("no local node interpreter ") + } + + val lsp = JSLanguageServiceUtil.getPluginDirectory(javaClass, "language-server/server.js") + thisLogger().info("language server loaded") + thisLogger().info(lsp.path) + if (lsp == null || !lsp.exists()) { + // broken plugin installation? + throw ExecutionException("could not find language server") + } + + return GeneralCommandLine().apply { + withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE) + withCharset(Charsets.UTF_8) + addParameter(lsp.path) + addParameter("--stdio") + + NodeCommandLineConfigurator.find(interpreter) + .configure(this, NodeCommandLineConfigurator.defaultOptions(project)) + } + } + + // references resolution is implemented without using the LSP server + override val lspGoToDefinitionSupport = false + + // code completion is implemented without using the LSP server + override val lspCompletionSupport = null + + // code formatting is implemented without using the LSP server + override val lspFormattingSupport = null +} diff --git a/jetbrains/src/main/kotlin/org/michaelangeloio/plugins/dit/lsp/LspServerSupportProvider.kt b/jetbrains/src/main/kotlin/org/michaelangeloio/plugins/dit/lsp/LspServerSupportProvider.kt new file mode 100644 index 0000000..af4e8dc --- /dev/null +++ b/jetbrains/src/main/kotlin/org/michaelangeloio/plugins/dit/lsp/LspServerSupportProvider.kt @@ -0,0 +1,21 @@ +package org.michaelangeloio.plugins.dit.lsp + +import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterManager +import com.intellij.javascript.nodejs.interpreter.local.NodeJsLocalInterpreter +import com.intellij.javascript.nodejs.interpreter.wsl.WslNodeInterpreter +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.platform.lsp.api.LspServerSupportProvider +import org.michaelangeloio.plugins.dit.DoesItThrowUtils + + +class DoesItThrowLspServerSupportProvider : LspServerSupportProvider { + override fun fileOpened(project: Project, file: VirtualFile, serverStarter: LspServerSupportProvider.LspServerStarter) { + if (!DoesItThrowUtils.isSupportedFileType(file)) return + + val node = NodeJsInterpreterManager.getInstance(project).interpreter + if (node !is NodeJsLocalInterpreter && node !is WslNodeInterpreter) return + + serverStarter.ensureServerStarted(DoesItThrowLspServerDescriptor(project)) + } +} \ No newline at end of file diff --git a/jetbrains/src/main/resources/META-INF/plugin.xml b/jetbrains/src/main/resources/META-INF/plugin.xml new file mode 100644 index 0000000..f4276ad --- /dev/null +++ b/jetbrains/src/main/resources/META-INF/plugin.xml @@ -0,0 +1,18 @@ + + + com.intellij.modules.platform + com.intellij.modules.ultimate + JavaScript + + org.michaelangeloio.plugins.dit + Does it Throw? + michaelangeloio + + messages.MyBundle + + + + + + + diff --git a/jetbrains/src/main/resources/META-INF/pluginIcon.svg b/jetbrains/src/main/resources/META-INF/pluginIcon.svg new file mode 100644 index 0000000..cc94f5d --- /dev/null +++ b/jetbrains/src/main/resources/META-INF/pluginIcon.svg @@ -0,0 +1,246 @@ + + + + +Created by potrace 1.10, written by Peter Selinger 2001-2011 + + + + + + + + + + + + + + + + + diff --git a/jetbrains/src/test/kotlin/org/michaelangeloio/plugins/dit/DoesItThrowUtils.kt b/jetbrains/src/test/kotlin/org/michaelangeloio/plugins/dit/DoesItThrowUtils.kt new file mode 100644 index 0000000..5b36bdd --- /dev/null +++ b/jetbrains/src/test/kotlin/org/michaelangeloio/plugins/dit/DoesItThrowUtils.kt @@ -0,0 +1,43 @@ +import com.intellij.openapi.vfs.VirtualFile +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test +import org.michaelangeloio.plugins.dit.DoesItThrowUtils +import org.mockito.kotlin.mock +import org.mockito.kotlin.whenever + +class DoesItThrowUtilsTest { + + private val mockFile: VirtualFile = mock() + + @Test + fun `should return true for supported file extensions`() { + val supportedExtensions = listOf("js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx", "d.ts", "json", "jsonc") + supportedExtensions.forEach { extension -> + whenever(mockFile.extension).thenReturn(extension) + assertTrue(DoesItThrowUtils.isSupportedFileType(mockFile)) + } + } + + @Test + fun `should return false for unsupported file extensions`() { + whenever(mockFile.extension).thenReturn("unsupported") + assertFalse(DoesItThrowUtils.isSupportedFileType(mockFile)) + } + + @Test + fun `should return false for null or empty extensions`() { + whenever(mockFile.extension).thenReturn(null) + assertFalse(DoesItThrowUtils.isSupportedFileType(mockFile)) + + whenever(mockFile.extension).thenReturn("") + assertFalse(DoesItThrowUtils.isSupportedFileType(mockFile)) + } + + @Test + fun `should correctly handle case sensitivity`() { + // Assuming the function is case-insensitive + whenever(mockFile.extension).thenReturn("JS") + assertFalse(DoesItThrowUtils.isSupportedFileType(mockFile)) + } +} diff --git a/jetbrains/version.txt b/jetbrains/version.txt new file mode 100644 index 0000000..87a0871 --- /dev/null +++ b/jetbrains/version.txt @@ -0,0 +1 @@ +0.3.3 \ No newline at end of file diff --git a/release-please-config.json b/release-please-config.json index faea58a..06e6825 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -22,6 +22,11 @@ }, "crates/does-it-throw-wasm": { "release-type": "rust" + }, + "jetbrains": { + "release-type": "simple", + "package-name": "does-it-throw-jetbrains", + "extra-files": ["gradle.properties"] } }, "bootstrap-sha": "89c1833c752211c7e712ef926c3d14f85ac1a779",