diff --git a/CHANGELOG.md b/CHANGELOG.md
index 937902e8..7cc657a0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,9 @@
### Added
+- Experimental Language Server support using IDEA's LSP API (#68)
+ [(Only works for paid versions of IDEA :disappointed:)](https://blog.jetbrains.com/platform/2023/07/lsp-for-plugin-developers/#supported-ides)
+
### Changed
### Deprecated
diff --git a/build.gradle.kts b/build.gradle.kts
index 6f954a2a..82429715 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,6 +1,7 @@
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
-import org.jetbrains.intellij.tasks.RunPluginVerifierTask
+import org.jetbrains.intellij.tasks.RunPluginVerifierTask.FailureLevel
+import java.util.EnumSet
plugins {
id("java")
@@ -165,7 +166,7 @@ tasks {
}
runPluginVerifier {
- failureLevel = RunPluginVerifierTask.FailureLevel.ALL
+ failureLevel = EnumSet.complementOf(EnumSet.of(FailureLevel.EXPERIMENTAL_API_USAGES))
// Version 1.364 seems to be broken and always complains about supposedly missing 'plugin.xml':
// https://youtrack.jetbrains.com/issue/MP-6388
verifierVersion = "1.307"
diff --git a/gradle.properties b/gradle.properties
index b4cee76d..d6e6f945 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -4,11 +4,12 @@
pluginGroup = org.nixos.idea
pluginName = NixIDEA
pluginVersion = 0.4.0.13
-pluginSinceBuild = 231
+pluginSinceBuild = 232
pluginUntilBuild = 241.*
-platformType = IC
-platformVersion = 2023.1.6
+platformType = IU
+# TODO Revert to 2023.2.6?
+platformVersion = 2024.1
# Gradle Configuration
# -> https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
diff --git a/src/main/java/org/nixos/idea/lsp/NixLspServerDescriptor.java b/src/main/java/org/nixos/idea/lsp/NixLspServerDescriptor.java
new file mode 100644
index 00000000..1abbdedb
--- /dev/null
+++ b/src/main/java/org/nixos/idea/lsp/NixLspServerDescriptor.java
@@ -0,0 +1,26 @@
+package org.nixos.idea.lsp;
+
+import com.intellij.execution.ExecutionException;
+import com.intellij.execution.configurations.GeneralCommandLine;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.platform.lsp.api.ProjectWideLspServerDescriptor;
+import org.jetbrains.annotations.NotNull;
+import org.nixos.idea.file.NixFileType;
+
+@SuppressWarnings("UnstableApiUsage")
+final class NixLspServerDescriptor extends ProjectWideLspServerDescriptor {
+ NixLspServerDescriptor(@NotNull Project project) {
+ super(project, "Nix");
+ }
+
+ @Override
+ public @NotNull GeneralCommandLine createCommandLine() throws ExecutionException {
+ return new GeneralCommandLine("nix", "--extra-experimental-features", "nix-command", "--extra-experimental-features", "flakes", "run", "nixpkgs#nil");
+ }
+
+ @Override
+ public boolean isSupportedFile(@NotNull VirtualFile virtualFile) {
+ return virtualFile.getFileType() == NixFileType.INSTANCE;
+ }
+}
diff --git a/src/main/java/org/nixos/idea/lsp/NixLspServerSupportProvider.java b/src/main/java/org/nixos/idea/lsp/NixLspServerSupportProvider.java
new file mode 100644
index 00000000..6416bde0
--- /dev/null
+++ b/src/main/java/org/nixos/idea/lsp/NixLspServerSupportProvider.java
@@ -0,0 +1,26 @@
+package org.nixos.idea.lsp;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.platform.lsp.api.LspServer;
+import com.intellij.platform.lsp.api.LspServerSupportProvider;
+import com.intellij.platform.lsp.api.lsWidget.LspServerWidgetItem;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.nixos.idea.file.NixFileType;
+import org.nixos.idea.icon.NixIcons;
+
+@SuppressWarnings("UnstableApiUsage")
+public final class NixLspServerSupportProvider implements LspServerSupportProvider {
+ @Override
+ public void fileOpened(@NotNull Project project, @NotNull VirtualFile virtualFile, @NotNull LspServerStarter lspServerStarter) {
+ if (virtualFile.getFileType() == NixFileType.INSTANCE) {
+ lspServerStarter.ensureServerStarted(new NixLspServerDescriptor(project));
+ }
+ }
+
+ @Override
+ public @NotNull LspServerWidgetItem createLspServerWidgetItem(@NotNull LspServer lspServer, @Nullable VirtualFile currentFile) {
+ return new LspServerWidgetItem(lspServer, currentFile, NixIcons.FILE, null);
+ }
+}
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index 1fd59e5b..e7b4fb1a 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -5,6 +5,7 @@
NixOS
com.intellij.modules.lang
+ com.intellij.modules.platform
@@ -46,6 +47,9 @@
+
+