code cleanup
This commit is contained in:
parent
365bcbbd93
commit
623dc2aca7
14 changed files with 245 additions and 266 deletions
|
@ -2,7 +2,8 @@
|
|||
<g fill="#F7A41D">
|
||||
<g>
|
||||
<polygon points="46,22 28,44 19,30"/>
|
||||
<polygon points="46,22 33,33 28,44 22,44 22,95 31,95 20,100 12,117 0,117 0,22" shape-rendering="crispEdges"/>
|
||||
<polygon points="46,22 33,33 28,44 22,44 22,95 31,95 20,100 12,117 0,117 0,22"
|
||||
shape-rendering="crispEdges"/>
|
||||
<polygon points="31,95 12,117 4,106"/>
|
||||
</g>
|
||||
<g>
|
||||
|
@ -14,7 +15,8 @@
|
|||
</g>
|
||||
<g>
|
||||
<polygon points="141,22 140,40 122,45"/>
|
||||
<polygon points="153,22 153,117 106,117 120,105 125,95 131,95 131,45 122,45 132,36 141,22" shape-rendering="crispEdges"/>
|
||||
<polygon points="153,22 153,117 106,117 120,105 125,95 131,95 131,45 122,45 132,36 141,22"
|
||||
shape-rendering="crispEdges"/>
|
||||
<polygon points="125,95 130,110 106,117"/>
|
||||
</g>
|
||||
</g>
|
||||
|
|
Before Width: | Height: | Size: 831 B After Width: | Height: | Size: 1 KiB |
|
@ -41,7 +41,8 @@ public class HighlightingUtil {
|
|||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
markup.removeAllHighlighters();
|
||||
for (var range : highlightRanges) {
|
||||
markup.addRangeHighlighter(range.color(), range.start(), range.end(), HighlighterLayer.SYNTAX, HighlighterTargetArea.EXACT_RANGE);
|
||||
markup.addRangeHighlighter(range.color(), range.start(), range.end(), HighlighterLayer.SYNTAX,
|
||||
HighlighterTargetArea.EXACT_RANGE);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -46,8 +46,7 @@ public enum ZigAttributes {
|
|||
Label(LABEL),
|
||||
KeywordLiteral(KEYWORD),
|
||||
Namespace(CLASS_NAME),
|
||||
Struct(CLASS_NAME)
|
||||
;
|
||||
Struct(CLASS_NAME);
|
||||
public final TextAttributesKey KEY;
|
||||
public final String type;
|
||||
public final @Unmodifiable Set<String> modifiers;
|
||||
|
@ -65,7 +64,8 @@ public enum ZigAttributes {
|
|||
return Optional.empty();
|
||||
}
|
||||
for (var known : values()) {
|
||||
if (known.type.equals(type) && ((modifiers != null && modifiers.containsAll(known.modifiers)) || (modifiers == null && known.modifiers.size() == 0))) {
|
||||
if (known.type.equals(type) && ((modifiers != null && modifiers.containsAll(known.modifiers)) ||
|
||||
(modifiers == null && known.modifiers.size() == 0))) {
|
||||
return Optional.of(known.KEY);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ import java.util.Map;
|
|||
|
||||
public class ZigColorSettingsPage implements ColorSettingsPage {
|
||||
|
||||
private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[]{
|
||||
new AttributesDescriptor("Type", ZigAttributes.Type.KEY),
|
||||
private static final AttributesDescriptor[] DESCRIPTORS =
|
||||
new AttributesDescriptor[]{new AttributesDescriptor("Type", ZigAttributes.Type.KEY),
|
||||
new AttributesDescriptor("Parameter", ZigAttributes.Parameter.KEY),
|
||||
new AttributesDescriptor("Variable", ZigAttributes.Variable.KEY),
|
||||
new AttributesDescriptor("Enum member", ZigAttributes.EnumMember.KEY),
|
||||
|
@ -45,8 +45,7 @@ public class ZigColorSettingsPage implements ColorSettingsPage {
|
|||
new AttributesDescriptor("Number", ZigAttributes.Number.KEY),
|
||||
new AttributesDescriptor("Operator", ZigAttributes.Operator.KEY),
|
||||
new AttributesDescriptor("Builtin", ZigAttributes.Builtin.KEY),
|
||||
new AttributesDescriptor("Label", ZigAttributes.Label.KEY),
|
||||
};
|
||||
new AttributesDescriptor("Label", ZigAttributes.Label.KEY),};
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
|
|
@ -26,6 +26,7 @@ import javax.swing.Icon;
|
|||
|
||||
public class ZigFileType extends LanguageFileType {
|
||||
public static final ZigFileType INSTANCE = new ZigFileType();
|
||||
|
||||
private ZigFileType() {
|
||||
super(ZigLanguage.INSTANCE);
|
||||
}
|
||||
|
|
|
@ -41,22 +41,9 @@ import java.util.concurrent.TimeoutException;
|
|||
import static org.wso2.lsp4intellij.requests.Timeout.getTimeout;
|
||||
|
||||
public class ZLSEditorEventManager extends EditorEventManager {
|
||||
public ZLSEditorEventManager(Editor editor,
|
||||
DocumentListener documentListener,
|
||||
EditorMouseListener mouseListener,
|
||||
EditorMouseMotionListener mouseMotionListener,
|
||||
LSPCaretListenerImpl caretListener,
|
||||
RequestManager requestmanager,
|
||||
ServerOptions serverOptions,
|
||||
LanguageServerWrapper wrapper) {
|
||||
super(editor,
|
||||
documentListener,
|
||||
mouseListener,
|
||||
mouseMotionListener,
|
||||
caretListener,
|
||||
requestmanager,
|
||||
serverOptions,
|
||||
wrapper);
|
||||
public ZLSEditorEventManager(Editor editor, DocumentListener documentListener, EditorMouseListener mouseListener, EditorMouseMotionListener mouseMotionListener, LSPCaretListenerImpl caretListener, RequestManager requestmanager, ServerOptions serverOptions, LanguageServerWrapper wrapper) {
|
||||
super(editor, documentListener, mouseListener, mouseMotionListener, caretListener, requestmanager,
|
||||
serverOptions, wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,23 +34,14 @@ import org.wso2.lsp4intellij.listeners.LSPCaretListenerImpl;
|
|||
|
||||
public class ZLSExtensionManager implements LSPExtensionManager {
|
||||
@Override
|
||||
public <T extends DefaultRequestManager> T getExtendedRequestManagerFor(LanguageServerWrapper wrapper,
|
||||
LanguageServer server,
|
||||
LanguageClient client,
|
||||
ServerCapabilities serverCapabilities) {
|
||||
public <T extends DefaultRequestManager> T getExtendedRequestManagerFor(LanguageServerWrapper wrapper, LanguageServer server, LanguageClient client, ServerCapabilities serverCapabilities) {
|
||||
return (T) new ZLSRequestManager(wrapper, server, client, serverCapabilities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends EditorEventManager> T getExtendedEditorEventManagerFor(Editor editor,
|
||||
DocumentListener documentListener,
|
||||
EditorMouseListenerImpl mouseListener,
|
||||
EditorMouseMotionListenerImpl mouseMotionListener,
|
||||
LSPCaretListenerImpl caretListener,
|
||||
RequestManager requestManager,
|
||||
ServerOptions serverOptions,
|
||||
LanguageServerWrapper wrapper) {
|
||||
return (T) new ZLSEditorEventManager(editor, documentListener, mouseListener, mouseMotionListener, caretListener, requestManager, serverOptions, wrapper);
|
||||
public <T extends EditorEventManager> T getExtendedEditorEventManagerFor(Editor editor, DocumentListener documentListener, EditorMouseListenerImpl mouseListener, EditorMouseMotionListenerImpl mouseMotionListener, LSPCaretListenerImpl caretListener, RequestManager requestManager, ServerOptions serverOptions, LanguageServerWrapper wrapper) {
|
||||
return (T) new ZLSEditorEventManager(editor, documentListener, mouseListener, mouseMotionListener,
|
||||
caretListener, requestManager, serverOptions, wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -36,17 +36,15 @@ import java.util.concurrent.CompletableFuture;
|
|||
public class ZLSRequestManager extends DefaultRequestManager {
|
||||
private static final Logger LOG = Logger.getInstance(ZLSRequestManager.class);
|
||||
|
||||
public ZLSRequestManager(LanguageServerWrapper wrapper,
|
||||
LanguageServer server,
|
||||
LanguageClient client,
|
||||
ServerCapabilities serverCapabilities) {
|
||||
public ZLSRequestManager(LanguageServerWrapper wrapper, LanguageServer server, LanguageClient client, ServerCapabilities serverCapabilities) {
|
||||
super(wrapper, server, client, serverCapabilities);
|
||||
}
|
||||
|
||||
public CompletableFuture<SemanticTokens> semanticTokens(SemanticTokensParams params) {
|
||||
if (checkStatus()) {
|
||||
try {
|
||||
return (getServerCapabilities().getSemanticTokensProvider() != null) ? getTextDocumentService().semanticTokensFull(params) : null;
|
||||
return (getServerCapabilities().getSemanticTokensProvider() != null)
|
||||
? getTextDocumentService().semanticTokensFull(params) : null;
|
||||
} catch (Exception e) {
|
||||
crashed(e);
|
||||
return null;
|
||||
|
|
|
@ -37,17 +37,15 @@ public class ZLSStartupActivity implements StartupActivity {
|
|||
try {
|
||||
path = Path.of(pathTxt);
|
||||
} catch (InvalidPathException e) {
|
||||
Notifications.Bus.notify(new Notification("ZigBrains.Nag",
|
||||
"No ZLS binary",
|
||||
"Invalid ZLS binary path \"" + pathTxt + "\"",
|
||||
Notifications.Bus.notify(
|
||||
new Notification("ZigBrains.Nag", "No ZLS binary", "Invalid ZLS binary path \"" + pathTxt + "\"",
|
||||
NotificationType.ERROR));
|
||||
return;
|
||||
}
|
||||
if (!Files.exists(path) || Files.isDirectory(path)) {
|
||||
Notifications.Bus.notify(new Notification("ZigBrains.Nag",
|
||||
"No ZLS binary",
|
||||
"The ZLS binary at \"" + pathTxt + "\" doesn't exist or is a directory!",
|
||||
NotificationType.ERROR));
|
||||
Notifications.Bus.notify(new Notification("ZigBrains.Nag", "No ZLS binary",
|
||||
"The ZLS binary at \"" + pathTxt +
|
||||
"\" doesn't exist or is a directory!", NotificationType.ERROR));
|
||||
}
|
||||
if (IntellijLanguageClient.getExtensionManagerFor("zig") == null) {
|
||||
IntellijLanguageClient.addExtensionManager("zig", new ZLSExtensionManager());
|
||||
|
@ -61,8 +59,7 @@ public class ZLSStartupActivity implements StartupActivity {
|
|||
public void runActivity(@NotNull Project project) {
|
||||
var path = AppSettingsState.getInstance().zlsPath;
|
||||
if ("".equals(path)) {
|
||||
Notifications.Bus.notify(new Notification("ZigBrains.Nag",
|
||||
"No ZLS binary",
|
||||
Notifications.Bus.notify(new Notification("ZigBrains.Nag", "No ZLS binary",
|
||||
"Please configure the path to the zls executable in the Zig language configuration menu!",
|
||||
NotificationType.INFORMATION));
|
||||
return;
|
||||
|
|
|
@ -28,8 +28,10 @@ import javax.swing.JPanel;
|
|||
public class AppSettingsComponent {
|
||||
private final JPanel myMainPanel;
|
||||
private final TextFieldWithBrowseButton zlsPathText = new TextFieldWithBrowseButton();
|
||||
|
||||
public AppSettingsComponent() {
|
||||
zlsPathText.addBrowseFolderListener(new TextBrowseFolderListener(new FileChooserDescriptor(true, false, false, false, false, false)));
|
||||
zlsPathText.addBrowseFolderListener(
|
||||
new TextBrowseFolderListener(new FileChooserDescriptor(true, false, false, false, false, false)));
|
||||
myMainPanel = FormBuilder.createFormBuilder()
|
||||
.addLabeledComponent(new JBLabel("ZLS path: "), zlsPathText, 1, false)
|
||||
.addComponentFillVertically(new JPanel(), 0)
|
||||
|
|
|
@ -26,10 +26,8 @@ import org.jetbrains.annotations.NotNull;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Service(Service.Level.PROJECT)
|
||||
@State(
|
||||
name = "com.falsepattern.zigbrains.settings.AppSettingsState",
|
||||
storages = @Storage("ZigBrainsSettings.xml")
|
||||
)
|
||||
@State(name = "com.falsepattern.zigbrains.settings.AppSettingsState",
|
||||
storages = @Storage("ZigBrainsSettings.xml"))
|
||||
public final class AppSettingsState implements PersistentStateComponent<AppSettingsState> {
|
||||
public String zlsPath = "";
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ public class TokenDecoder {
|
|||
return new Token(line, start, data.get(index + 2), data.get(index + 3), data.get(index + 4));
|
||||
}
|
||||
}
|
||||
|
||||
public static List<SemaRange> decodePayload(Editor editor, SemanticTokensLegend legend, List<Integer> responseData) {
|
||||
var result = new ArrayList<SemaRange>();
|
||||
var application = ApplicationManager.getApplication();
|
||||
|
@ -55,7 +56,8 @@ public class TokenDecoder {
|
|||
for (int i = 0; i < dataSize - 5; i += 5) {
|
||||
var token = Token.from(prevToken, responseData, i);
|
||||
var logiPosStart = new LogicalPosition(token.line(), token.start());
|
||||
int tokenStartOffset = application.runReadAction((Computable<Integer>) () -> editor.logicalPositionToOffset(logiPosStart));
|
||||
int tokenStartOffset =
|
||||
application.runReadAction((Computable<Integer>) () -> editor.logicalPositionToOffset(logiPosStart));
|
||||
var type = types.size() > token.type() ? types.get(token.type()) : null;
|
||||
Set<String> modifierSet = null;
|
||||
if (token.modifiers() != 0) {
|
||||
|
|
|
@ -40,8 +40,10 @@
|
|||
id="LSPSymbolContributor"/>
|
||||
|
||||
<!-- needed for renaming -->
|
||||
<renameHandler implementation="org.wso2.lsp4intellij.contributors.rename.LSPRenameHandler" id="LSPRenameHandler" order="first"/>
|
||||
<renamePsiElementProcessor implementation="org.wso2.lsp4intellij.contributors.rename.LSPRenameProcessor" id="LSPRenameProcessor" order="first"/>
|
||||
<renameHandler implementation="org.wso2.lsp4intellij.contributors.rename.LSPRenameHandler" id="LSPRenameHandler"
|
||||
order="first"/>
|
||||
<renamePsiElementProcessor implementation="org.wso2.lsp4intellij.contributors.rename.LSPRenameProcessor"
|
||||
id="LSPRenameProcessor" order="first"/>
|
||||
|
||||
<!-- endregion LSP4IntelliJ -->
|
||||
|
||||
|
@ -53,8 +55,7 @@
|
|||
|
||||
<colorSettingsPage implementation="com.falsepattern.zigbrains.ide.ZigColorSettingsPage"/>
|
||||
|
||||
<projectConfigurable
|
||||
parentId="language"
|
||||
<projectConfigurable parentId="language"
|
||||
instance="com.falsepattern.zigbrains.settings.AppSettingsConfigurable"
|
||||
id="com.falsepattern.zigbrains.settings.AppSettingsConfigurable"
|
||||
displayName="Zig"/>
|
||||
|
|
Loading…
Add table
Reference in a new issue