backport: 16.0.0-pre2
This commit is contained in:
parent
c77b50a31d
commit
eaa9547e66
25 changed files with 402 additions and 74 deletions
|
@ -19,8 +19,13 @@ Changelog structure reference:
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Debugger
|
||||||
|
- Added fallback metadata for windows debugger downloading
|
||||||
|
- Automatic exe path discovery for zig build run debugging on windows
|
||||||
|
|
||||||
- Zig
|
- Zig
|
||||||
- Color settings has more accurate color preview text.
|
- Color settings has more accurate color preview text.
|
||||||
|
- Better builtin indentation
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import de.undercouch.gradle.tasks.download.Download
|
||||||
import groovy.xml.XmlParser
|
import groovy.xml.XmlParser
|
||||||
import org.jetbrains.changelog.Changelog
|
import org.jetbrains.changelog.Changelog
|
||||||
import org.jetbrains.changelog.markdownToHTML
|
import org.jetbrains.changelog.markdownToHTML
|
||||||
|
@ -16,6 +17,7 @@ plugins {
|
||||||
id("org.jetbrains.intellij.platform") version("2.0.0-beta8")
|
id("org.jetbrains.intellij.platform") version("2.0.0-beta8")
|
||||||
id("org.jetbrains.changelog") version("2.2.1")
|
id("org.jetbrains.changelog") version("2.2.1")
|
||||||
id("org.jetbrains.grammarkit") version("2022.3.2.2")
|
id("org.jetbrains.grammarkit") version("2022.3.2.2")
|
||||||
|
id("de.undercouch.download") version("5.6.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
val publishVersions = listOf("232", "233", "241", "242")
|
val publishVersions = listOf("232", "233", "241", "242")
|
||||||
|
@ -38,7 +40,7 @@ val clionVersion = properties("clionVersion").get()
|
||||||
val clionPlugins = listOf("com.intellij.clion", "com.intellij.cidr.lang", "com.intellij.cidr.base", "com.intellij.nativeDebug")
|
val clionPlugins = listOf("com.intellij.clion", "com.intellij.cidr.lang", "com.intellij.cidr.base", "com.intellij.nativeDebug")
|
||||||
|
|
||||||
val lsp4jVersion = "0.21.1"
|
val lsp4jVersion = "0.21.1"
|
||||||
val lsp4ijVersion = "0.3.0-20240704-134935"
|
val lsp4ijVersion = "0.3.0-20240718-013045"
|
||||||
|
|
||||||
val lsp4ijNightly = lsp4ijVersion.contains("-")
|
val lsp4ijNightly = lsp4ijVersion.contains("-")
|
||||||
val lsp4ijDepString = "${if (lsp4ijNightly) "nightly." else ""}com.jetbrains.plugins:com.redhat.devtools.lsp4ij:$lsp4ijVersion"
|
val lsp4ijDepString = "${if (lsp4ijNightly) "nightly." else ""}com.jetbrains.plugins:com.redhat.devtools.lsp4ij:$lsp4ijVersion"
|
||||||
|
@ -146,6 +148,7 @@ allprojects {
|
||||||
configure<JavaPluginExtension> {
|
configure<JavaPluginExtension> {
|
||||||
toolchain {
|
toolchain {
|
||||||
languageVersion.set(javaLangVersion)
|
languageVersion.set(javaLangVersion)
|
||||||
|
vendor = JvmVendorSpec.JETBRAINS
|
||||||
}
|
}
|
||||||
sourceCompatibility = javaVersion
|
sourceCompatibility = javaVersion
|
||||||
targetCompatibility = javaVersion
|
targetCompatibility = javaVersion
|
||||||
|
@ -231,6 +234,19 @@ project(":debugger") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val genOutputDir = layout.buildDirectory.dir("generated-resources")
|
||||||
|
sourceSets["main"].resources.srcDir(genOutputDir)
|
||||||
|
tasks {
|
||||||
|
register<Download>("downloadProps") {
|
||||||
|
src("https://falsepattern.com/zigbrains/msvc.properties")
|
||||||
|
dest(genOutputDir.map { it.file("msvc.properties") })
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
dependsOn("downloadProps")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
project(":zon") {
|
project(":zon") {
|
||||||
|
|
|
@ -11,7 +11,7 @@ baseIDE=clion
|
||||||
ideaVersion=2023.3.7
|
ideaVersion=2023.3.7
|
||||||
clionVersion=2023.3.5
|
clionVersion=2023.3.5
|
||||||
|
|
||||||
pluginVersion=16.0.0-pre1
|
pluginVersion=16.0.0-pre2
|
||||||
|
|
||||||
# Gradle Releases -> https://github.com/gradle/gradle/releases
|
# Gradle Releases -> https://github.com/gradle/gradle/releases
|
||||||
gradleVersion=8.8
|
gradleVersion=8.8
|
||||||
|
|
|
@ -18,7 +18,6 @@ package com.falsepattern.zigbrains.common;
|
||||||
|
|
||||||
import com.intellij.openapi.options.Configurable;
|
import com.intellij.openapi.options.Configurable;
|
||||||
import com.intellij.openapi.options.ConfigurationException;
|
import com.intellij.openapi.options.ConfigurationException;
|
||||||
import com.intellij.ui.JBColor;
|
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ import com.intellij.openapi.project.NoAccessDuringPsiEvents;
|
||||||
import com.intellij.openapi.util.Computable;
|
import com.intellij.openapi.util.Computable;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
|
@ -18,10 +18,8 @@ package com.falsepattern.zigbrains.common.util;
|
||||||
|
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class CollectionUtil {
|
public class CollectionUtil {
|
||||||
|
|
||||||
|
|
|
@ -16,17 +16,12 @@
|
||||||
|
|
||||||
package com.falsepattern.zigbrains.common.util.dsl;
|
package com.falsepattern.zigbrains.common.util.dsl;
|
||||||
|
|
||||||
import com.falsepattern.zigbrains.common.util.KtUtil;
|
|
||||||
import com.intellij.openapi.ui.DialogPanel;
|
import com.intellij.openapi.ui.DialogPanel;
|
||||||
import com.intellij.ui.components.JBLabel;
|
|
||||||
import com.intellij.ui.dsl.builder.Align;
|
import com.intellij.ui.dsl.builder.Align;
|
||||||
import com.intellij.ui.dsl.builder.AlignX;
|
|
||||||
import com.intellij.ui.dsl.builder.BuilderKt;
|
import com.intellij.ui.dsl.builder.BuilderKt;
|
||||||
import com.intellij.ui.dsl.builder.Panel;
|
import com.intellij.ui.dsl.builder.Panel;
|
||||||
import com.intellij.ui.dsl.builder.RightGap;
|
import com.intellij.ui.dsl.builder.RightGap;
|
||||||
import com.intellij.ui.dsl.builder.Row;
|
import com.intellij.ui.dsl.builder.Row;
|
||||||
import com.intellij.ui.dsl.builder.RowsRange;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
|
|
@ -14,6 +14,8 @@ notification.title.debugger=Debugger
|
||||||
notification.content.debugger.successfully.downloaded=Debugger successfully downloaded
|
notification.content.debugger.successfully.downloaded=Debugger successfully downloaded
|
||||||
notification.content.debugger.downloading.failed=Debugger downloading failed
|
notification.content.debugger.downloading.failed=Debugger downloading failed
|
||||||
notification.content.debugger.metadata.downloading.failed=Debugger metadata downloading failed
|
notification.content.debugger.metadata.downloading.failed=Debugger metadata downloading failed
|
||||||
|
notification.content.debugger.metadata.fallback.fetch.failed=Debugger fallback metadata fetch failed
|
||||||
|
notification.content.debugger.metadata.fallback.parse.failed=Debugger fallback metadata parse failed
|
||||||
settings.debugger.toolchain.download.debugger.automatically.checkbox=Download and update the debugger automatically
|
settings.debugger.toolchain.download.debugger.automatically.checkbox=Download and update the debugger automatically
|
||||||
settings.debugger.title=Zig
|
settings.debugger.title=Zig
|
||||||
settings.debugger.toolchain.debugger.label=Debugger:
|
settings.debugger.toolchain.debugger.label=Debugger:
|
||||||
|
|
|
@ -23,18 +23,20 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public interface ZigDebuggerDriverConfigurationProvider {
|
public interface ZigDebuggerDriverConfigurationProvider {
|
||||||
ExtensionPointName<ZigDebuggerDriverConfigurationProvider> EXTENSION_POINT_NAME = ExtensionPointName.create("com.falsepattern.zigbrains.debuggerDriverProvider");
|
ExtensionPointName<ZigDebuggerDriverConfigurationProvider> EXTENSION_POINT_NAME = ExtensionPointName.create("com.falsepattern.zigbrains.debuggerDriverProvider");
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
static @NotNull Stream<DebuggerDriverConfiguration> findDebuggerConfigurations(Project project, boolean isElevated, boolean emulateTerminal) {
|
static @NotNull Stream<DebuggerDriverConfiguration> findDebuggerConfigurations(Project project, boolean isElevated, boolean emulateTerminal) {
|
||||||
return EXTENSION_POINT_NAME.getExtensionList()
|
return (Stream<DebuggerDriverConfiguration>) EXTENSION_POINT_NAME.getExtensionList()
|
||||||
.stream()
|
.stream()
|
||||||
.map(it -> it.getDebuggerConfiguration(project, isElevated, emulateTerminal))
|
.map(it -> it.getDebuggerConfiguration(project, isElevated, emulateTerminal))
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.map(Supplier::get);
|
.map((Function<? super Supplier<DebuggerDriverConfiguration>, ?>) Supplier::get);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable Supplier<DebuggerDriverConfiguration> getDebuggerConfiguration(Project project, boolean isElevated, boolean emulateTerminal);
|
@Nullable Supplier<DebuggerDriverConfiguration> getDebuggerConfiguration(Project project, boolean isElevated, boolean emulateTerminal);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import com.falsepattern.zigbrains.debugger.runner.base.ZigDebugParametersBase;
|
||||||
import com.falsepattern.zigbrains.project.execution.build.ProfileStateBuild;
|
import com.falsepattern.zigbrains.project.execution.build.ProfileStateBuild;
|
||||||
import com.falsepattern.zigbrains.project.toolchain.AbstractZigToolchain;
|
import com.falsepattern.zigbrains.project.toolchain.AbstractZigToolchain;
|
||||||
import com.intellij.execution.ExecutionException;
|
import com.intellij.execution.ExecutionException;
|
||||||
|
import com.intellij.openapi.util.SystemInfo;
|
||||||
import com.jetbrains.cidr.execution.Installer;
|
import com.jetbrains.cidr.execution.Installer;
|
||||||
import com.jetbrains.cidr.execution.debugger.backend.DebuggerDriverConfiguration;
|
import com.jetbrains.cidr.execution.debugger.backend.DebuggerDriverConfiguration;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
|
@ -32,6 +33,8 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class ZigDebugParametersBuild extends ZigDebugParametersBase<ProfileStateBuild> implements PreLaunchAware {
|
public class ZigDebugParametersBuild extends ZigDebugParametersBase<ProfileStateBuild> implements PreLaunchAware {
|
||||||
private static final String BoilerplateNotice = "\nPlease edit this intellij build configuration and specify the path of the executable created by \"zig build\" directly!";
|
private static final String BoilerplateNotice = "\nPlease edit this intellij build configuration and specify the path of the executable created by \"zig build\" directly!";
|
||||||
|
@ -61,11 +64,7 @@ public class ZigDebugParametersBuild extends ZigDebugParametersBase<ProfileState
|
||||||
throw new ExecutionException("Could not auto-detect default executable output directory \"zig-out/bin\"!" + BoilerplateNotice);
|
throw new ExecutionException("Could not auto-detect default executable output directory \"zig-out/bin\"!" + BoilerplateNotice);
|
||||||
}
|
}
|
||||||
try (val filesInOutput = Files.list(expectedOutputDir)) {
|
try (val filesInOutput = Files.list(expectedOutputDir)) {
|
||||||
val executables = filesInOutput.filter(Files::isRegularFile).filter(Files::isExecutable).toList();
|
exe = getExe(filesInOutput);
|
||||||
if (executables.size() > 1) {
|
|
||||||
throw new ExecutionException("Multiple executables found!" + BoilerplateNotice);
|
|
||||||
}
|
|
||||||
exe = executables.get(0);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ExecutionException("Could not scan output directory \"" + expectedOutputDir + "\"!" + BoilerplateNotice);
|
throw new ExecutionException("Could not scan output directory \"" + expectedOutputDir + "\"!" + BoilerplateNotice);
|
||||||
}
|
}
|
||||||
|
@ -82,6 +81,20 @@ public class ZigDebugParametersBuild extends ZigDebugParametersBase<ProfileState
|
||||||
return exe.toFile();
|
return exe.toFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static @NotNull Path getExe(Stream<Path> files) throws ExecutionException {
|
||||||
|
files = files.filter(Files::isRegularFile);
|
||||||
|
if (SystemInfo.isWindows) {
|
||||||
|
files = files.filter(file -> file.getFileName().toString().endsWith(".exe"));
|
||||||
|
} else {
|
||||||
|
files = files.filter(Files::isExecutable);
|
||||||
|
}
|
||||||
|
val executables = files.toList();
|
||||||
|
if (executables.size() > 1) {
|
||||||
|
throw new ExecutionException("Multiple executables found!" + BoilerplateNotice);
|
||||||
|
}
|
||||||
|
return executables.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preLaunch() throws Exception {
|
public void preLaunch() throws Exception {
|
||||||
this.executableFile = compileExe();
|
this.executableFile = compileExe();
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
@ -371,11 +372,34 @@ public final class ZigDebuggerToolchainService {
|
||||||
//TODO logging
|
//TODO logging
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Notifications.Bus.notify(new Notification(
|
Notifications.Bus.notify(new Notification(
|
||||||
"Zig Debugger",
|
"ZigBrains.Debugger.Error",
|
||||||
ZigBundle.message("notification.title.debugger"),
|
ZigBundle.message("notification.title.debugger"),
|
||||||
ZigBundle.message("notification.content.debugger.metadata.downloading.failed"),
|
ZigBundle.message("notification.content.debugger.metadata.downloading.failed"),
|
||||||
NotificationType.ERROR
|
NotificationType.ERROR
|
||||||
));
|
));
|
||||||
|
//Try to load fallback file
|
||||||
|
try {
|
||||||
|
@Cleanup val resource = ZigDebuggerToolchainService.class.getResourceAsStream("msvc.properties");
|
||||||
|
if (resource == null) {
|
||||||
|
Notifications.Bus.notify(new Notification(
|
||||||
|
"ZigBrains.Debugger.Error",
|
||||||
|
ZigBundle.message("notification.title.debugger"),
|
||||||
|
ZigBundle.message("notification.content.debugger.metadata.fallback.fetch.failed"),
|
||||||
|
NotificationType.ERROR
|
||||||
|
));
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
val reader = new InputStreamReader(resource);
|
||||||
|
prop.load(reader);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
Notifications.Bus.notify(new Notification(
|
||||||
|
"ZigBrains.Debugger.Error",
|
||||||
|
ZigBundle.message("notification.title.debugger"),
|
||||||
|
ZigBundle.message("notification.content.debugger.metadata.fallback.parse.failed"),
|
||||||
|
NotificationType.ERROR
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
|
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
|
@ -1,5 +1,5 @@
|
||||||
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
|
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
|
||||||
<idea-plugin xmlns:xi="http://www.w3.org/2001/XInclude" require-restart="true">
|
<idea-plugin require-restart="true">
|
||||||
<resource-bundle>zigbrains.Bundle</resource-bundle>
|
<resource-bundle>zigbrains.Bundle</resource-bundle>
|
||||||
<id>com.falsepattern.zigbrains</id>
|
<id>com.falsepattern.zigbrains</id>
|
||||||
<name>ZigBrains</name>
|
<name>ZigBrains</name>
|
||||||
|
@ -32,6 +32,13 @@
|
||||||
|
|
||||||
<lang.formatter language="Zig" implementationClass="com.falsepattern.zigbrains.zig.formatter.ZigFormattingModelBuilder"/>
|
<lang.formatter language="Zig" implementationClass="com.falsepattern.zigbrains.zig.formatter.ZigFormattingModelBuilder"/>
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
TODO remove these two once https://github.com/redhat-developer/lsp4ij/issues/424 is resolved
|
||||||
|
-->
|
||||||
|
<formattingService id = "ZigLSPFormattingOnlyServiceProxy" implementation="com.falsepattern.zigbrains.zig.formatter.ZigLSPFormattingOnlyServiceProxy"/>
|
||||||
|
<formattingService id = "ZigLSPFormattingAndRangeBothServiceProxy" implementation="com.falsepattern.zigbrains.zig.formatter.ZigLSPFormattingAndRangeBothServiceProxy"/>
|
||||||
|
|
||||||
<postStartupActivity implementation="com.falsepattern.zigbrains.zig.lsp.ZLSStartupActivity"/>
|
<postStartupActivity implementation="com.falsepattern.zigbrains.zig.lsp.ZLSStartupActivity"/>
|
||||||
|
|
||||||
<!-- LSP textDocument/signatureHelp -->
|
<!-- LSP textDocument/signatureHelp -->
|
||||||
|
|
|
@ -22,7 +22,6 @@ import com.intellij.ide.NewProjectWizardLegacy;
|
||||||
import com.intellij.ide.util.projectWizard.ModuleBuilder;
|
import com.intellij.ide.util.projectWizard.ModuleBuilder;
|
||||||
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
|
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
|
||||||
import com.intellij.ide.util.projectWizard.WizardContext;
|
import com.intellij.ide.util.projectWizard.WizardContext;
|
||||||
import com.intellij.ide.wizard.CommitStepException;
|
|
||||||
import com.intellij.openapi.Disposable;
|
import com.intellij.openapi.Disposable;
|
||||||
import com.intellij.openapi.module.ModuleType;
|
import com.intellij.openapi.module.ModuleType;
|
||||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||||
|
|
|
@ -33,16 +33,12 @@ import com.intellij.openapi.util.Disposer;
|
||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
import com.intellij.ui.JBColor;
|
import com.intellij.ui.JBColor;
|
||||||
import com.intellij.ui.components.JBCheckBox;
|
import com.intellij.ui.components.JBCheckBox;
|
||||||
import com.intellij.ui.components.JBLabel;
|
|
||||||
import com.intellij.ui.dsl.builder.AlignX;
|
import com.intellij.ui.dsl.builder.AlignX;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
|
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.event.ChangeEvent;
|
|
||||||
import javax.swing.event.ChangeListener;
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static com.falsepattern.zigbrains.common.util.KtUtil.$f;
|
import static com.falsepattern.zigbrains.common.util.KtUtil.$f;
|
||||||
|
|
|
@ -168,9 +168,9 @@
|
||||||
Root ::= CONTAINER_DOC_COMMENT? ContainerMembers?
|
Root ::= CONTAINER_DOC_COMMENT? ContainerMembers?
|
||||||
|
|
||||||
// *** Top level ***
|
// *** Top level ***
|
||||||
private ContainerMembers ::= ContainerDeclarations (ContainerField COMMA)* (ContainerField | ContainerDeclarations)?
|
ContainerMembers ::= ContainerDeclarations? (ContainerField COMMA)* (ContainerField | ContainerDeclarations)?
|
||||||
|
|
||||||
ContainerDeclarations ::= (TestDecl | ComptimeDecl | DOC_COMMENT? KEYWORD_PUB? Decl)*
|
ContainerDeclarations ::= (TestDecl | ComptimeDecl | DOC_COMMENT? KEYWORD_PUB? Decl)+
|
||||||
|
|
||||||
TestDecl ::= DOC_COMMENT? KEYWORD_TEST (STRING_LITERAL_SINGLE | IDENTIFIER)? Block {pin=2}
|
TestDecl ::= DOC_COMMENT? KEYWORD_TEST (STRING_LITERAL_SINGLE | IDENTIFIER)? Block {pin=2}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
package com.falsepattern.zigbrains.zig.formatter;
|
||||||
|
|
||||||
|
import com.falsepattern.zigbrains.zig.ZigLanguage;
|
||||||
|
import com.intellij.formatting.FormattingRangesInfo;
|
||||||
|
import com.intellij.formatting.service.FormattingService;
|
||||||
|
import com.intellij.lang.ImportOptimizer;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.util.TextRange;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.psi.PsiFile;
|
||||||
|
import com.redhat.devtools.lsp4ij.LanguageServersRegistry;
|
||||||
|
import com.redhat.devtools.lsp4ij.LanguageServiceAccessor;
|
||||||
|
import com.redhat.devtools.lsp4ij.features.formatting.AbstractLSPFormattingService;
|
||||||
|
import lombok.val;
|
||||||
|
import org.eclipse.lsp4j.ServerCapabilities;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO remove once https://github.com/redhat-developer/lsp4ij/issues/424 is resolved
|
||||||
|
*/
|
||||||
|
public abstract class ZigAbstractLSPFormattingServiceProxy implements FormattingService {
|
||||||
|
protected abstract AbstractLSPFormattingService getProxiedService();
|
||||||
|
protected abstract boolean canSupportFormatting(@Nullable ServerCapabilities var1);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Set<Feature> getFeatures() {
|
||||||
|
return getProxiedService().getFeatures();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canFormat(@NotNull PsiFile file) {
|
||||||
|
val language = file.getLanguage();
|
||||||
|
if (language != ZigLanguage.INSTANCE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!LanguageServersRegistry.getInstance().isFileSupported(file)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
Project project = file.getProject();
|
||||||
|
return LanguageServiceAccessor.getInstance(project).hasAny(file.getVirtualFile(), (ls) -> this.canSupportFormatting(ls.getServerCapabilitiesSync()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull PsiElement formatElement(@NotNull PsiElement psiElement, boolean b) {
|
||||||
|
return getProxiedService().formatElement(psiElement, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull PsiElement formatElement(@NotNull PsiElement psiElement, @NotNull TextRange textRange, boolean b) {
|
||||||
|
return getProxiedService().formatElement(psiElement, textRange, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void formatRanges(@NotNull PsiFile psiFile, FormattingRangesInfo formattingRangesInfo, boolean b, boolean b1) {
|
||||||
|
getProxiedService().formatRanges(psiFile, formattingRangesInfo, b, b1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Set<ImportOptimizer> getImportOptimizers(@NotNull PsiFile psiFile) {
|
||||||
|
return getProxiedService().getImportOptimizers(psiFile);
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,7 +33,16 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.ADDITION_EXPR;
|
||||||
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.ASM_EXPR;
|
||||||
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.ASM_INPUT_LIST;
|
||||||
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.ASM_OUTPUT_LIST;
|
||||||
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.BITWISE_EXPR;
|
||||||
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.BIT_SHIFT_EXPR;
|
||||||
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.BLOCK;
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.BLOCK;
|
||||||
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.BOOL_AND_EXPR;
|
||||||
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.BOOL_OR_EXPR;
|
||||||
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.COMPARE_EXPR;
|
||||||
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.CONTAINER_DECL_AUTO;
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.CONTAINER_DECL_AUTO;
|
||||||
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.CONTAINER_DECL_TYPE;
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.CONTAINER_DECL_TYPE;
|
||||||
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.CONTAINER_DOC_COMMENT;
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.CONTAINER_DOC_COMMENT;
|
||||||
|
@ -44,9 +53,12 @@ import static com.falsepattern.zigbrains.zig.psi.ZigTypes.IF_EXPR;
|
||||||
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.IF_PREFIX;
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.IF_PREFIX;
|
||||||
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.IF_STATEMENT;
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.IF_STATEMENT;
|
||||||
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.INIT_LIST;
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.INIT_LIST;
|
||||||
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.KEYWORD_ASM;
|
||||||
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.KEYWORD_ELSE;
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.KEYWORD_ELSE;
|
||||||
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.KEYWORD_VOLATILE;
|
||||||
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.LBRACE;
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.LBRACE;
|
||||||
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.LPAREN;
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.LPAREN;
|
||||||
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.MULTIPLY_EXPR;
|
||||||
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.PARAM_DECL_LIST;
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.PARAM_DECL_LIST;
|
||||||
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.RBRACE;
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.RBRACE;
|
||||||
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.RPAREN;
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.RPAREN;
|
||||||
|
@ -92,14 +104,16 @@ public class ZigBlock extends AbstractBlock {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected @Nullable Indent getChildIndent() {
|
protected @Nullable Indent getChildIndent() {
|
||||||
return getIndentBasedOnParentType(getNode().getElementType(), PLACEHOLDER);
|
val node = getNode();
|
||||||
|
return getIndentBasedOnParentType(node, null, node.getElementType(), PLACEHOLDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Indent getIndent() {
|
public Indent getIndent() {
|
||||||
val parent = getNode().getTreeParent();
|
val node = getNode();
|
||||||
|
val parent = node.getTreeParent();
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
return getIndentBasedOnParentType(parent.getElementType(), getNode().getElementType());
|
return getIndentBasedOnParentType(parent, node, parent.getElementType(), node.getElementType());
|
||||||
}
|
}
|
||||||
return Indent.getNoneIndent();
|
return Indent.getNoneIndent();
|
||||||
}
|
}
|
||||||
|
@ -112,8 +126,12 @@ public class ZigBlock extends AbstractBlock {
|
||||||
return element == LPAREN || element == RPAREN;
|
return element == LPAREN || element == RPAREN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isEmpty(ASTNode child) {
|
||||||
|
return child.getFirstChildNode() == null;
|
||||||
|
}
|
||||||
|
|
||||||
private static Indent getIndentBasedOnParentType(IElementType parentElementType, IElementType childElementType) {
|
|
||||||
|
private static @NotNull Indent getIndentBasedOnParentType(@NotNull ASTNode parent, @Nullable ASTNode child, @NotNull IElementType parentElementType, @NotNull IElementType childElementType) {
|
||||||
//Statement blocks
|
//Statement blocks
|
||||||
if (parentElementType == BLOCK && !isBrace(childElementType))
|
if (parentElementType == BLOCK && !isBrace(childElementType))
|
||||||
return Indent.getNormalIndent();
|
return Indent.getNormalIndent();
|
||||||
|
@ -132,6 +150,17 @@ public class ZigBlock extends AbstractBlock {
|
||||||
parentElementType == FN_PROTO && childElementType == PLACEHOLDER)
|
parentElementType == FN_PROTO && childElementType == PLACEHOLDER)
|
||||||
return Indent.getNormalIndent();
|
return Indent.getNormalIndent();
|
||||||
|
|
||||||
|
//Chained operations on newlines
|
||||||
|
if ((parentElementType == BOOL_OR_EXPR ||
|
||||||
|
parentElementType == BOOL_AND_EXPR ||
|
||||||
|
parentElementType == COMPARE_EXPR ||
|
||||||
|
parentElementType == BITWISE_EXPR ||
|
||||||
|
parentElementType == BIT_SHIFT_EXPR ||
|
||||||
|
parentElementType == ADDITION_EXPR ||
|
||||||
|
parentElementType == MULTIPLY_EXPR) &&
|
||||||
|
parent.getFirstChildNode() != child)
|
||||||
|
return Indent.getNormalIndent();
|
||||||
|
|
||||||
//Switch prongs
|
//Switch prongs
|
||||||
if (parentElementType == SWITCH_PRONG_LIST ||
|
if (parentElementType == SWITCH_PRONG_LIST ||
|
||||||
parentElementType == SWITCH_EXPR && childElementType == PLACEHOLDER)
|
parentElementType == SWITCH_EXPR && childElementType == PLACEHOLDER)
|
||||||
|
@ -141,9 +170,18 @@ public class ZigBlock extends AbstractBlock {
|
||||||
if ((parentElementType == IF_EXPR || parentElementType == IF_STATEMENT) && childElementType != KEYWORD_ELSE && childElementType != IF_PREFIX)
|
if ((parentElementType == IF_EXPR || parentElementType == IF_STATEMENT) && childElementType != KEYWORD_ELSE && childElementType != IF_PREFIX)
|
||||||
return Indent.getNormalIndent();
|
return Indent.getNormalIndent();
|
||||||
|
|
||||||
|
//Struct members
|
||||||
if (parentElementType == CONTAINER_DECL_AUTO && childElementType != CONTAINER_DECL_TYPE && childElementType != CONTAINER_DOC_COMMENT && !isBrace(childElementType))
|
if (parentElementType == CONTAINER_DECL_AUTO && childElementType != CONTAINER_DECL_TYPE && childElementType != CONTAINER_DOC_COMMENT && !isBrace(childElementType))
|
||||||
return Indent.getNormalIndent();
|
return Indent.getNormalIndent();
|
||||||
|
|
||||||
|
//Inline assembly body
|
||||||
|
if (parentElementType == ASM_EXPR && childElementType != KEYWORD_ASM && childElementType != KEYWORD_VOLATILE && !isParen(childElementType))
|
||||||
|
return Indent.getNormalIndent();
|
||||||
|
|
||||||
|
//Assembly params
|
||||||
|
if (parentElementType == ASM_INPUT_LIST || parentElementType == ASM_OUTPUT_LIST)
|
||||||
|
return Indent.getSpaceIndent(2);
|
||||||
|
|
||||||
return Indent.getNoneIndent();
|
return Indent.getNoneIndent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.falsepattern.zigbrains.zig.formatter;
|
||||||
|
|
||||||
|
import com.intellij.formatting.service.FormattingService;
|
||||||
|
import com.redhat.devtools.lsp4ij.LanguageServerItem;
|
||||||
|
import com.redhat.devtools.lsp4ij.features.formatting.AbstractLSPFormattingService;
|
||||||
|
import com.redhat.devtools.lsp4ij.features.formatting.LSPFormattingAndRangeBothService;
|
||||||
|
import org.eclipse.lsp4j.ServerCapabilities;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO remove once https://github.com/redhat-developer/lsp4ij/issues/424 is resolved
|
||||||
|
*/
|
||||||
|
public class ZigLSPFormattingAndRangeBothServiceProxy extends ZigAbstractLSPFormattingServiceProxy {
|
||||||
|
@Override
|
||||||
|
protected AbstractLSPFormattingService getProxiedService() {
|
||||||
|
return FormattingService.EP_NAME.findExtension(LSPFormattingAndRangeBothService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean canSupportFormatting(@Nullable ServerCapabilities serverCapabilities) {
|
||||||
|
return LanguageServerItem.isDocumentRangeFormattingSupported(serverCapabilities);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.falsepattern.zigbrains.zig.formatter;
|
||||||
|
|
||||||
|
import com.intellij.formatting.service.FormattingService;
|
||||||
|
import com.redhat.devtools.lsp4ij.LanguageServerItem;
|
||||||
|
import com.redhat.devtools.lsp4ij.features.formatting.AbstractLSPFormattingService;
|
||||||
|
import com.redhat.devtools.lsp4ij.features.formatting.LSPFormattingOnlyService;
|
||||||
|
import org.eclipse.lsp4j.ServerCapabilities;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO remove once https://github.com/redhat-developer/lsp4ij/issues/424 is resolved
|
||||||
|
*/
|
||||||
|
public class ZigLSPFormattingOnlyServiceProxy extends ZigAbstractLSPFormattingServiceProxy {
|
||||||
|
@Override
|
||||||
|
protected AbstractLSPFormattingService getProxiedService() {
|
||||||
|
return FormattingService.EP_NAME.findExtension(LSPFormattingOnlyService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean canSupportFormatting(@Nullable ServerCapabilities serverCapabilities) {
|
||||||
|
return LanguageServerItem.isDocumentFormattingSupported(serverCapabilities) && !LanguageServerItem.isDocumentRangeFormattingSupported(serverCapabilities);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,8 +3,6 @@ package com.falsepattern.zigbrains.zig.lsp;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.redhat.devtools.lsp4ij.client.LanguageClientImpl;
|
import com.redhat.devtools.lsp4ij.client.LanguageClientImpl;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
public class ZLSLanguageClient extends LanguageClientImpl {
|
public class ZLSLanguageClient extends LanguageClientImpl {
|
||||||
public ZLSLanguageClient(Project project) {
|
public ZLSLanguageClient(Project project) {
|
||||||
super(project);
|
super(project);
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.falsepattern.zigbrains.zig.lsp;
|
||||||
|
|
||||||
|
import org.eclipse.lsp4j.SemanticTokenModifiers;
|
||||||
|
|
||||||
|
public class ZLSSemanticTokenModifiers {
|
||||||
|
public static final String Declaration = SemanticTokenModifiers.Declaration;
|
||||||
|
public static final String Definition = SemanticTokenModifiers.Definition;
|
||||||
|
public static final String Readonly = SemanticTokenModifiers.Readonly;
|
||||||
|
public static final String Static = SemanticTokenModifiers.Static;
|
||||||
|
public static final String Deprecated = SemanticTokenModifiers.Deprecated;
|
||||||
|
public static final String Abstract = SemanticTokenModifiers.Abstract;
|
||||||
|
public static final String Async = SemanticTokenModifiers.Async;
|
||||||
|
public static final String Modification = SemanticTokenModifiers.Modification;
|
||||||
|
public static final String Documentation = SemanticTokenModifiers.Documentation;
|
||||||
|
public static final String DefaultLibrary = SemanticTokenModifiers.DefaultLibrary;
|
||||||
|
/** non standard token modifier */
|
||||||
|
public static final String Generic = "generic";
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.falsepattern.zigbrains.zig.lsp;
|
||||||
|
|
||||||
|
import org.eclipse.lsp4j.SemanticTokenTypes;
|
||||||
|
|
||||||
|
public final class ZLSSemanticTokenTypes {
|
||||||
|
public static final String Namespace = SemanticTokenTypes.Namespace;
|
||||||
|
public static final String Type = SemanticTokenTypes.Type;
|
||||||
|
public static final String Class = SemanticTokenTypes.Class;
|
||||||
|
public static final String Enum = SemanticTokenTypes.Enum;
|
||||||
|
public static final String Interface = SemanticTokenTypes.Interface;
|
||||||
|
public static final String Struct = SemanticTokenTypes.Struct;
|
||||||
|
public static final String TypeParameter = SemanticTokenTypes.TypeParameter;
|
||||||
|
public static final String Parameter = SemanticTokenTypes.Parameter;
|
||||||
|
public static final String Variable = SemanticTokenTypes.Variable;
|
||||||
|
public static final String Property = SemanticTokenTypes.Property;
|
||||||
|
public static final String EnumMember = SemanticTokenTypes.EnumMember;
|
||||||
|
public static final String Event = SemanticTokenTypes.Event;
|
||||||
|
public static final String Function = SemanticTokenTypes.Function;
|
||||||
|
public static final String Method = SemanticTokenTypes.Method;
|
||||||
|
public static final String Macro = SemanticTokenTypes.Macro;
|
||||||
|
public static final String Keyword = SemanticTokenTypes.Keyword;
|
||||||
|
public static final String Modifier = SemanticTokenTypes.Modifier;
|
||||||
|
public static final String Comment = SemanticTokenTypes.Comment;
|
||||||
|
public static final String String = SemanticTokenTypes.String;
|
||||||
|
public static final String Number = SemanticTokenTypes.Number;
|
||||||
|
public static final String Regexp = SemanticTokenTypes.Regexp;
|
||||||
|
public static final String Operator = SemanticTokenTypes.Operator;
|
||||||
|
public static final String Decorator = SemanticTokenTypes.Decorator;
|
||||||
|
/** non standard token type */
|
||||||
|
public static final String ErrorTag = "errorTag";
|
||||||
|
/** non standard token type */
|
||||||
|
public static final String Builtin = "builtin";
|
||||||
|
/** non standard token type */
|
||||||
|
public static final String Label = "label";
|
||||||
|
/** non standard token type */
|
||||||
|
public static final String KeywordLiteral = "keywordLiteral";
|
||||||
|
|
||||||
|
private ZLSSemanticTokenTypes() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,69 +7,132 @@ import lombok.val;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.*;
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.BUILTIN;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.COMMENT;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.COMMENT_DOC;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.ENUM_DECL;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.ENUM_MEMBER_DECL;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.ENUM_MEMBER_REF;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.ENUM_REF;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.ERROR_TAG_DECL;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.ERROR_TAG_REF;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.FUNCTION_DECL;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.FUNCTION_DECL_GEN;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.FUNCTION_REF;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.FUNCTION_REF_GEN;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.KEYWORD;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.LABEL_DECL;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.LABEL_REF;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.METHOD_DECL;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.METHOD_DECL_GEN;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.METHOD_REF;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.METHOD_REF_GEN;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.NAMESPACE_DECL;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.NAMESPACE_REF;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.NUMBER;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.OPERATOR;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.PARAMETER;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.PROPERTY_DECL;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.PROPERTY_REF;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.STRING;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.STRUCT_DECL;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.STRUCT_REF;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.TYPE_DECL;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.TYPE_DECL_GEN;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.TYPE_PARAM;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.TYPE_PARAM_DECL;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.TYPE_REF;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.TYPE_REF_GEN;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.VARIABLE_DECL;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.VARIABLE_DECL_DEPR;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.VARIABLE_REF;
|
||||||
|
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.VARIABLE_REF_DEPR;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenModifiers.Declaration;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenModifiers.Definition;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenModifiers.Deprecated;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenModifiers.Documentation;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenModifiers.Generic;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.Builtin;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.Comment;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.Enum;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.EnumMember;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.ErrorTag;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.Function;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.Keyword;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.KeywordLiteral;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.Label;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.Method;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.Namespace;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.Number;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.Operator;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.Parameter;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.Property;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.String;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.Struct;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.Type;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.TypeParameter;
|
||||||
|
import static com.falsepattern.zigbrains.zig.lsp.ZLSSemanticTokenTypes.Variable;
|
||||||
|
|
||||||
public class ZLSSemanticTokensColorsProvider extends DefaultSemanticTokensColorsProvider {
|
public class ZLSSemanticTokensColorsProvider extends DefaultSemanticTokensColorsProvider {
|
||||||
private record TokenHelper(List<String> tokenModifiers) {
|
private record TokenHelper(List<String> tokenModifiers) {
|
||||||
public boolean hasAny(String... keys) {
|
public boolean hasAny(String... keys) {
|
||||||
if (tokenModifiers.isEmpty())
|
if (tokenModifiers.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
for (val key: keys) {
|
}
|
||||||
if (tokenModifiers.contains(key))
|
for (val key : keys) {
|
||||||
|
if (tokenModifiers.contains(key)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean has(String... keys) {
|
public boolean has(String... keys) {
|
||||||
if (tokenModifiers.isEmpty())
|
if (tokenModifiers.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
for (val key: keys) {
|
}
|
||||||
if (!tokenModifiers.contains(key))
|
for (val key : keys) {
|
||||||
|
if (!tokenModifiers.contains(key)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDecl() {
|
public boolean isDecl() {
|
||||||
return hasAny("declaration", "definition");
|
return hasAny(Declaration, Definition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable TextAttributesKey getTextAttributesKey(@NotNull String tokenType,
|
public @Nullable TextAttributesKey getTextAttributesKey(@NotNull String tokenType, @NotNull List<String> tokenModifiers, @NotNull PsiFile file) {
|
||||||
@NotNull List<String> tokenModifiers,
|
|
||||||
@NotNull PsiFile file) {
|
|
||||||
val tok = new TokenHelper(tokenModifiers);
|
val tok = new TokenHelper(tokenModifiers);
|
||||||
val res = switch (tokenType) {
|
val res = switch (tokenType) {
|
||||||
case "builtin" -> BUILTIN;
|
case Builtin -> BUILTIN;
|
||||||
case "comment" -> tok.has("documentation") ? COMMENT_DOC : COMMENT;
|
case Comment -> tok.has(Documentation) ? COMMENT_DOC : COMMENT;
|
||||||
case "enum" -> tok.isDecl() ? ENUM_DECL : ENUM_REF;
|
case Enum -> tok.isDecl() ? ENUM_DECL : ENUM_REF;
|
||||||
case "enumMember" -> tok.isDecl() ? ENUM_MEMBER_DECL : ENUM_MEMBER_REF;
|
case EnumMember -> tok.isDecl() ? ENUM_MEMBER_DECL : ENUM_MEMBER_REF;
|
||||||
case "errorTag" -> tok.isDecl() ? ERROR_TAG_DECL : ERROR_TAG_REF;
|
case ErrorTag -> tok.isDecl() ? ERROR_TAG_DECL : ERROR_TAG_REF;
|
||||||
case "property" -> tok.isDecl() ? PROPERTY_DECL : PROPERTY_REF;
|
case Property -> tok.isDecl() ? PROPERTY_DECL : PROPERTY_REF;
|
||||||
case "function" -> tok.isDecl() ? (tok.has("generic") ? FUNCTION_DECL_GEN : FUNCTION_DECL)
|
case Function -> tok.isDecl() ? (tok.has(Generic) ? FUNCTION_DECL_GEN : FUNCTION_DECL)
|
||||||
: (tok.has("generic") ? FUNCTION_REF_GEN : FUNCTION_REF);
|
: (tok.has(Generic) ? FUNCTION_REF_GEN : FUNCTION_REF);
|
||||||
case "keyword", "keywordLiteral" -> KEYWORD;
|
case Keyword, KeywordLiteral -> KEYWORD;
|
||||||
case "label" -> tok.isDecl() ? LABEL_DECL : LABEL_REF;
|
case Label -> tok.isDecl() ? LABEL_DECL : LABEL_REF;
|
||||||
case "method" -> tok.isDecl() ? (tok.has("generic") ? METHOD_DECL_GEN : METHOD_DECL)
|
case Method -> tok.isDecl() ? (tok.has(Generic) ? METHOD_DECL_GEN : METHOD_DECL)
|
||||||
: (tok.has("generic") ? METHOD_REF_GEN : METHOD_REF);
|
: (tok.has(Generic) ? METHOD_REF_GEN : METHOD_REF);
|
||||||
case "namespace" -> tok.isDecl() ? NAMESPACE_DECL : NAMESPACE_REF;
|
case Namespace -> tok.isDecl() ? NAMESPACE_DECL : NAMESPACE_REF;
|
||||||
case "number" -> NUMBER;
|
case Number -> NUMBER;
|
||||||
case "operator" -> OPERATOR;
|
case Operator -> OPERATOR;
|
||||||
case "parameter" -> PARAMETER;
|
case Parameter -> PARAMETER;
|
||||||
case "string" -> STRING;
|
case String -> STRING;
|
||||||
case "struct" -> tok.isDecl() ? STRUCT_DECL : STRUCT_REF;
|
case Struct -> tok.isDecl() ? STRUCT_DECL : STRUCT_REF;
|
||||||
case "type" -> tok.isDecl() ? (tok.has("generic") ? TYPE_DECL_GEN : TYPE_DECL)
|
case Type -> tok.isDecl() ? (tok.has(Generic) ? TYPE_DECL_GEN : TYPE_DECL)
|
||||||
: (tok.has("generic") ? TYPE_REF_GEN : TYPE_REF);
|
: (tok.has(Generic) ? TYPE_REF_GEN : TYPE_REF);
|
||||||
case "typeParameter" -> tok.isDecl() ? TYPE_PARAM_DECL : TYPE_PARAM;
|
case TypeParameter -> tok.isDecl() ? TYPE_PARAM_DECL : TYPE_PARAM;
|
||||||
case "variable" -> tok.isDecl() ? (tok.has("deprecated") ? VARIABLE_DECL_DEPR : VARIABLE_DECL)
|
case Variable -> tok.isDecl() ? (tok.has(Deprecated) ? VARIABLE_DECL_DEPR : VARIABLE_DECL)
|
||||||
: (tok.has("deprecated") ? VARIABLE_REF_DEPR : VARIABLE_REF);
|
: (tok.has(Deprecated) ? VARIABLE_REF_DEPR : VARIABLE_REF);
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
return res != null ? res : super.getTextAttributesKey(tokenType, tokenModifiers, file);
|
return res != null ? res : super.getTextAttributesKey(tokenType, tokenModifiers, file);
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
plugins {
|
||||||
|
id("org.gradle.toolchains.foojay-resolver-convention") version("0.8.0")
|
||||||
|
}
|
||||||
rootProject.name = "ZigBrains"
|
rootProject.name = "ZigBrains"
|
||||||
|
|
||||||
File(rootDir, "modules").eachDir { dir ->
|
File(rootDir, "modules").eachDir { dir ->
|
||||||
|
|
Loading…
Add table
Reference in a new issue