fix: remove hacky LSP4IJ formatter workaround
This commit is contained in:
parent
91ad1f7b7a
commit
948d566b9b
6 changed files with 16 additions and 120 deletions
|
@ -40,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 lsp4jVersion = "0.21.1"
|
||||
val lsp4ijVersion = "0.6.0"
|
||||
val lsp4ijVersion = "0.6.1-20241003-152535"
|
||||
|
||||
val lsp4ijNightly = lsp4ijVersion.contains("-")
|
||||
val lsp4ijDepString = "${if (lsp4ijNightly) "nightly." else ""}com.jetbrains.plugins:com.redhat.devtools.lsp4ij:$lsp4ijVersion"
|
||||
|
|
|
@ -32,13 +32,6 @@
|
|||
|
||||
<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"/>
|
||||
|
||||
<!-- LSP textDocument/signatureHelp -->
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,12 @@
|
|||
package com.falsepattern.zigbrains.zig.lsp;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.redhat.devtools.lsp4ij.LanguageServerEnablementSupport;
|
||||
import com.redhat.devtools.lsp4ij.LanguageServerFactory;
|
||||
import com.redhat.devtools.lsp4ij.client.LanguageClientImpl;
|
||||
import com.redhat.devtools.lsp4ij.client.features.LSPClientFeatures;
|
||||
import com.redhat.devtools.lsp4ij.client.features.LSPFormattingFeature;
|
||||
import com.redhat.devtools.lsp4ij.server.StreamConnectionProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -14,6 +17,18 @@ public class ZLSLanguageServerFactory implements LanguageServerFactory, Language
|
|||
return new ZLSStreamConnectionProvider(project);
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
@Override
|
||||
public @NotNull LSPClientFeatures createClientFeatures() {
|
||||
return new LSPClientFeatures()
|
||||
.setFormattingFeature(new LSPFormattingFeature() {
|
||||
@Override
|
||||
protected boolean isExistingFormatterOverrideable(@NotNull PsiFile file) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull LanguageClientImpl createLanguageClient(@NotNull Project project) {
|
||||
return new ZLSLanguageClient(project);
|
||||
|
|
Loading…
Add table
Reference in a new issue