Skip to content

Commit

Permalink
Add LSP support (#68) [paid versions of IDEA only]
Browse files Browse the repository at this point in the history
  • Loading branch information
JojOatXGME committed Apr 13, 2024
1 parent 27d2110 commit ad0b924
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/nixos/idea/lsp/NixLspServerDescriptor.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
26 changes: 26 additions & 0 deletions src/main/java/org/nixos/idea/lsp/NixLspServerSupportProvider.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
4 changes: 4 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<vendor>NixOS</vendor>

<depends>com.intellij.modules.lang</depends>
<depends>com.intellij.modules.platform</depends>

<extensions defaultExtensionNs="com.intellij">

Expand Down Expand Up @@ -46,6 +47,9 @@
<colorSettingsPage
implementation="org.nixos.idea.settings.NixColorSettingsPage" />

<platform.lsp.serverSupportProvider
implementation="org.nixos.idea.lsp.NixLspServerSupportProvider"/>

</extensions>

</idea-plugin>

0 comments on commit ad0b924

Please sign in to comment.