Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

WIP: integration of Language Server Protocol #172

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ kotlin.code.style=official
baseIDE=idea

# if you change the version of ide, also change psiViewerPluginVersion accordingly (cf https://plugins.jetbrains.com/plugin/227-psiviewer/versions)
ideaVersion=IC-2023.3
ideaVersion=IU-2023.3.5
pycharmCommunityVersion=PC-2023.3
psiViewerPluginVersion=233.2

Expand All @@ -30,4 +30,5 @@ enableBuildSearchableOptions=false
# Opt-out flag for bundling Kotlin standard library.
# See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details.
# suppress inspection "UnusedProperty"
kotlin.stdlib.default.dependency = false
kotlin.stdlib.default.dependency = false
kotlin.incremental.useClasspathSnapshot=false
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 4 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
12 changes: 8 additions & 4 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
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"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -133,10 +130,13 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
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.
Expand Down Expand Up @@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
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
Expand Down
1 change: 1 addition & 0 deletions plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
on how to target different products -->
<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.modules.lang</depends>
<depends>com.intellij.modules.ultimate</depends>

<xi:include href="/META-INF/opa-core.xml" xpointer="xpointer(/idea-plugin/*)"/>

Expand Down
27 changes: 27 additions & 0 deletions src/main/kotlin/org/openpolicyagent/ideaplugin/ide/lsp/RegalLsp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Use of this source code is governed by the MIT license that can be
* found in the LICENSE file.
*/

package org.openpolicyagent.ideaplugin.ide.lsp

import com.intellij.execution.configurations.GeneralCommandLine
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 org.openpolicyagent.ideaplugin.lang.psi.isRegoFile


internal class RegalLspServerSupportProvider : LspServerSupportProvider {
override fun fileOpened(project: Project, file: VirtualFile, serverStarter: LspServerSupportProvider.LspServerStarter) {
if (file.isRegoFile) {
serverStarter.ensureServerStarted(RegalLspServerDescriptor(project))
}
}
}

private class RegalLspServerDescriptor(project: Project) : ProjectWideLspServerDescriptor(project, "Foo") {
override fun isSupportedFile(file: VirtualFile) = file.isRegoFile
override fun createCommandLine() = GeneralCommandLine("/usr/local/bin/regal", "language-server")
}
5 changes: 4 additions & 1 deletion src/main/resources/META-INF/opa-core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
displayName="Open Policy Agent"
instance="org.openpolicyagent.ideaplugin.opa.project.settings.OpaOptionsConfigurable"/>

</extensions>
<!-- LSP -->
<platform.lsp.serverSupportProvider implementation="org.openpolicyagent.ideaplugin.ide.lsp.RegalLspServerSupportProvider"/>

</extensions>

<actions>

Expand Down
Loading