fix: Bypass LSP4IJ's formatter validity checks for Zig.
This commit is contained in:
parent
020dfaab7e
commit
c3cea6003a
5 changed files with 117 additions and 0 deletions
|
@ -32,6 +32,9 @@
|
|||
|
||||
<lang.formatter language="Zig" implementationClass="com.falsepattern.zigbrains.zig.formatter.ZigFormattingModelBuilder"/>
|
||||
|
||||
<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 -->
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.falsepattern.zigbrains.zig.formatter;
|
||||
|
||||
import com.intellij.formatting.FormattingRangesInfo;
|
||||
import com.intellij.formatting.service.FormattingService;
|
||||
import com.intellij.lang.ImportOptimizer;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
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.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
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,21 @@
|
|||
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 com.redhat.devtools.lsp4ij.features.formatting.LSPFormattingOnlyService;
|
||||
import org.eclipse.lsp4j.ServerCapabilities;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -23,6 +23,8 @@ import com.intellij.openapi.project.Project;
|
|||
import lombok.val;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
|
||||
public class ZLSSettingsConfigurable implements SubConfigurable {
|
||||
private ZLSSettingsPanel appSettingsComponent;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue