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