Skip to content

Commit ad0b924

Browse files
committed
Add LSP support (#68) [paid versions of IDEA only]
1 parent 27d2110 commit ad0b924

File tree

6 files changed

+66
-5
lines changed

6 files changed

+66
-5
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
### Added
66

7+
- Experimental Language Server support using IDEA's LSP API (#68)
8+
[(Only works for paid versions of IDEA :disappointed:)](https://blog.jetbrains.com/platform/2023/07/lsp-for-plugin-developers/#supported-ides)
9+
710
### Changed
811

912
### Deprecated

build.gradle.kts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import org.jetbrains.changelog.Changelog
22
import org.jetbrains.changelog.markdownToHTML
3-
import org.jetbrains.intellij.tasks.RunPluginVerifierTask
3+
import org.jetbrains.intellij.tasks.RunPluginVerifierTask.FailureLevel
4+
import java.util.EnumSet
45

56
plugins {
67
id("java")
@@ -165,7 +166,7 @@ tasks {
165166
}
166167

167168
runPluginVerifier {
168-
failureLevel = RunPluginVerifierTask.FailureLevel.ALL
169+
failureLevel = EnumSet.complementOf(EnumSet.of(FailureLevel.EXPERIMENTAL_API_USAGES))
169170
// Version 1.364 seems to be broken and always complains about supposedly missing 'plugin.xml':
170171
// https://youtrack.jetbrains.com/issue/MP-6388
171172
verifierVersion = "1.307"

gradle.properties

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
pluginGroup = org.nixos.idea
55
pluginName = NixIDEA
66
pluginVersion = 0.4.0.13
7-
pluginSinceBuild = 231
7+
pluginSinceBuild = 232
88
pluginUntilBuild = 241.*
99

10-
platformType = IC
11-
platformVersion = 2023.1.6
10+
platformType = IU
11+
# TODO Revert to 2023.2.6?
12+
platformVersion = 2024.1
1213

1314
# Gradle Configuration
1415
# -> https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.nixos.idea.lsp;
2+
3+
import com.intellij.execution.ExecutionException;
4+
import com.intellij.execution.configurations.GeneralCommandLine;
5+
import com.intellij.openapi.project.Project;
6+
import com.intellij.openapi.vfs.VirtualFile;
7+
import com.intellij.platform.lsp.api.ProjectWideLspServerDescriptor;
8+
import org.jetbrains.annotations.NotNull;
9+
import org.nixos.idea.file.NixFileType;
10+
11+
@SuppressWarnings("UnstableApiUsage")
12+
final class NixLspServerDescriptor extends ProjectWideLspServerDescriptor {
13+
NixLspServerDescriptor(@NotNull Project project) {
14+
super(project, "Nix");
15+
}
16+
17+
@Override
18+
public @NotNull GeneralCommandLine createCommandLine() throws ExecutionException {
19+
return new GeneralCommandLine("nix", "--extra-experimental-features", "nix-command", "--extra-experimental-features", "flakes", "run", "nixpkgs#nil");
20+
}
21+
22+
@Override
23+
public boolean isSupportedFile(@NotNull VirtualFile virtualFile) {
24+
return virtualFile.getFileType() == NixFileType.INSTANCE;
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.nixos.idea.lsp;
2+
3+
import com.intellij.openapi.project.Project;
4+
import com.intellij.openapi.vfs.VirtualFile;
5+
import com.intellij.platform.lsp.api.LspServer;
6+
import com.intellij.platform.lsp.api.LspServerSupportProvider;
7+
import com.intellij.platform.lsp.api.lsWidget.LspServerWidgetItem;
8+
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
10+
import org.nixos.idea.file.NixFileType;
11+
import org.nixos.idea.icon.NixIcons;
12+
13+
@SuppressWarnings("UnstableApiUsage")
14+
public final class NixLspServerSupportProvider implements LspServerSupportProvider {
15+
@Override
16+
public void fileOpened(@NotNull Project project, @NotNull VirtualFile virtualFile, @NotNull LspServerStarter lspServerStarter) {
17+
if (virtualFile.getFileType() == NixFileType.INSTANCE) {
18+
lspServerStarter.ensureServerStarted(new NixLspServerDescriptor(project));
19+
}
20+
}
21+
22+
@Override
23+
public @NotNull LspServerWidgetItem createLspServerWidgetItem(@NotNull LspServer lspServer, @Nullable VirtualFile currentFile) {
24+
return new LspServerWidgetItem(lspServer, currentFile, NixIcons.FILE, null);
25+
}
26+
}

src/main/resources/META-INF/plugin.xml

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<vendor>NixOS</vendor>
66

77
<depends>com.intellij.modules.lang</depends>
8+
<depends>com.intellij.modules.platform</depends>
89

910
<extensions defaultExtensionNs="com.intellij">
1011

@@ -46,6 +47,9 @@
4647
<colorSettingsPage
4748
implementation="org.nixos.idea.settings.NixColorSettingsPage" />
4849

50+
<platform.lsp.serverSupportProvider
51+
implementation="org.nixos.idea.lsp.NixLspServerSupportProvider"/>
52+
4953
</extensions>
5054

5155
</idea-plugin>

0 commit comments

Comments
 (0)