better config
This commit is contained in:
parent
41cbe48ce2
commit
df2f732db9
5 changed files with 111 additions and 24 deletions
|
@ -24,35 +24,73 @@ import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.startup.StartupActivity;
|
import com.intellij.openapi.startup.StartupActivity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.wso2.lsp4intellij.IntellijLanguageClient;
|
import org.wso2.lsp4intellij.IntellijLanguageClient;
|
||||||
import org.wso2.lsp4intellij.client.languageserver.serverdefinition.ProcessBuilderServerDefinition;
|
import org.wso2.lsp4intellij.client.languageserver.serverdefinition.RawCommandServerDefinition;
|
||||||
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.InvalidPathException;
|
import java.nio.file.InvalidPathException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ZLSStartupActivity implements StartupActivity {
|
public class ZLSStartupActivity implements StartupActivity {
|
||||||
public static void initZLS() {
|
public static void initZLS() {
|
||||||
var pathTxt = AppSettingsState.getInstance().zlsPath;
|
var settings = AppSettingsState.getInstance();
|
||||||
|
var zlsPath = settings.zlsPath;
|
||||||
|
if (!validatePath("ZLS Binary", zlsPath, false)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var configPath = settings.zlsConfigPath;
|
||||||
|
boolean configOK = true;
|
||||||
|
if (!"".equals(configPath) && !validatePath("ZLS Config", configPath, false)) {
|
||||||
|
configOK = false;
|
||||||
|
Notifications.Bus.notify(new Notification("ZigBrains.Nag", "Using default config path.",
|
||||||
|
NotificationType.INFORMATION));
|
||||||
|
}
|
||||||
|
if ("".equals(configPath)) {
|
||||||
|
configOK = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IntellijLanguageClient.getExtensionManagerFor("zig") == null) {
|
||||||
|
IntellijLanguageClient.addExtensionManager("zig", new ZLSExtensionManager());
|
||||||
|
}
|
||||||
|
var cmd = new ArrayList<String>();
|
||||||
|
cmd.add(zlsPath);
|
||||||
|
if (configOK) {
|
||||||
|
cmd.add("--config-path");
|
||||||
|
cmd.add(configPath);
|
||||||
|
}
|
||||||
|
if (settings.debug) {
|
||||||
|
cmd.add("--enable-debug-log");
|
||||||
|
}
|
||||||
|
if (settings.messageTrace) {
|
||||||
|
cmd.add("--enable-message-tracing");
|
||||||
|
}
|
||||||
|
IntellijLanguageClient.addServerDefinition(new RawCommandServerDefinition("zig", cmd.toArray(String[]::new)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean validatePath(String name, String pathTxt, boolean dir) {
|
||||||
Path path;
|
Path path;
|
||||||
try {
|
try {
|
||||||
path = Path.of(pathTxt);
|
path = Path.of(pathTxt);
|
||||||
} catch (InvalidPathException e) {
|
} catch (InvalidPathException e) {
|
||||||
Notifications.Bus.notify(
|
Notifications.Bus.notify(
|
||||||
new Notification("ZigBrains.Nag", "No ZLS binary", "Invalid ZLS binary path \"" + pathTxt + "\"",
|
new Notification("ZigBrains.Nag", "No " + name, "Invalid " + name + " path \"" + pathTxt + "\"",
|
||||||
NotificationType.ERROR));
|
NotificationType.ERROR));
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Files.exists(path) || Files.isDirectory(path)) {
|
if (!Files.exists(path)) {
|
||||||
Notifications.Bus.notify(new Notification("ZigBrains.Nag", "No ZLS binary",
|
Notifications.Bus.notify(new Notification("ZigBrains.Nag", "No " + name,
|
||||||
"The ZLS binary at \"" + pathTxt +
|
"The " + name + " at \"" + pathTxt +
|
||||||
"\" doesn't exist or is a directory!", NotificationType.ERROR));
|
"\" doesn't exist!", NotificationType.ERROR));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (IntellijLanguageClient.getExtensionManagerFor("zig") == null) {
|
if (Files.isDirectory(path) != dir) {
|
||||||
IntellijLanguageClient.addExtensionManager("zig", new ZLSExtensionManager());
|
Notifications.Bus.notify(new Notification("ZigBrains.Nag", "No " + name,
|
||||||
|
"The " + name + " at \"" + pathTxt +
|
||||||
|
"\" is a " + (Files.isDirectory(path) ? "directory": "file") +
|
||||||
|
" , expected a " + (dir ? "directory" : "file"), NotificationType.ERROR));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
var procBuilder = new ProcessBuilder();
|
return true;
|
||||||
procBuilder.command(pathTxt, "--enable-message-tracing");
|
|
||||||
IntellijLanguageClient.addServerDefinition(new ProcessBuilderServerDefinition("zig", procBuilder));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,6 +19,7 @@ package com.falsepattern.zigbrains.settings;
|
||||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||||
import com.intellij.openapi.ui.TextBrowseFolderListener;
|
import com.intellij.openapi.ui.TextBrowseFolderListener;
|
||||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||||
|
import com.intellij.ui.components.JBCheckBox;
|
||||||
import com.intellij.ui.components.JBLabel;
|
import com.intellij.ui.components.JBLabel;
|
||||||
import com.intellij.util.ui.FormBuilder;
|
import com.intellij.util.ui.FormBuilder;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -28,12 +29,23 @@ 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();
|
||||||
|
private final TextFieldWithBrowseButton zlsConfigPathText = new TextFieldWithBrowseButton();
|
||||||
|
private final JBCheckBox debugCheckBox = new JBCheckBox();
|
||||||
|
private final JBCheckBox messageTraceCheckBox = new JBCheckBox();
|
||||||
|
|
||||||
public AppSettingsComponent() {
|
public AppSettingsComponent() {
|
||||||
zlsPathText.addBrowseFolderListener(
|
zlsPathText.addBrowseFolderListener(
|
||||||
new TextBrowseFolderListener(new FileChooserDescriptor(true, false, false, false, false, false)));
|
new TextBrowseFolderListener(new FileChooserDescriptor(true, false, false, false, false, false)));
|
||||||
myMainPanel = FormBuilder.createFormBuilder()
|
myMainPanel = FormBuilder.createFormBuilder()
|
||||||
|
.addComponent(new JBLabel("Regular settings"))
|
||||||
|
.addVerticalGap(10)
|
||||||
.addLabeledComponent(new JBLabel("ZLS path: "), zlsPathText, 1, false)
|
.addLabeledComponent(new JBLabel("ZLS path: "), zlsPathText, 1, false)
|
||||||
|
.addLabeledComponent(new JBLabel("ZLS config path (leave empty to use default): "), zlsConfigPathText, 1, false)
|
||||||
|
.addSeparator()
|
||||||
|
.addComponent(new JBLabel("Developer settings"))
|
||||||
|
.addVerticalGap(10)
|
||||||
|
.addLabeledComponent(new JBLabel("ZLS debug log: "), debugCheckBox, 1, false)
|
||||||
|
.addLabeledComponent(new JBLabel("ZLS message trace: "), messageTraceCheckBox, 1, false)
|
||||||
.addComponentFillVertically(new JPanel(), 0)
|
.addComponentFillVertically(new JPanel(), 0)
|
||||||
.getPanel();
|
.getPanel();
|
||||||
}
|
}
|
||||||
|
@ -43,11 +55,36 @@ public class AppSettingsComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getZlsPathText() {
|
public String getZLSPath() {
|
||||||
return zlsPathText.getText();
|
return zlsPathText.getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setZlsPathText(@NotNull String newText) {
|
public void setZLSPath(@NotNull String newText) {
|
||||||
zlsPathText.setText(newText);
|
zlsPathText.setText(newText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public String getZLSConfigPath() {
|
||||||
|
return zlsConfigPathText.getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setZLSConfigPath(@NotNull String newText) {
|
||||||
|
zlsConfigPathText.setText(newText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getDebug() {
|
||||||
|
return debugCheckBox.isSelected();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDebug(boolean state) {
|
||||||
|
debugCheckBox.setSelected(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getMessageTrace() {
|
||||||
|
return messageTraceCheckBox.isSelected();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessageTrace(boolean state) {
|
||||||
|
messageTraceCheckBox.setSelected(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,20 +39,30 @@ public class AppSettingsConfigurable implements Configurable {
|
||||||
@Override
|
@Override
|
||||||
public boolean isModified() {
|
public boolean isModified() {
|
||||||
var settings = AppSettingsState.getInstance();
|
var settings = AppSettingsState.getInstance();
|
||||||
return !settings.zlsPath.equals(appSettingsComponent.getZlsPathText());
|
boolean modified = !settings.zlsPath.equals(appSettingsComponent.getZLSPath());
|
||||||
|
modified |= !settings.zlsConfigPath.equals(appSettingsComponent.getZLSConfigPath());
|
||||||
|
modified |= settings.debug != appSettingsComponent.getDebug();
|
||||||
|
modified |= settings.messageTrace != appSettingsComponent.getMessageTrace();
|
||||||
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply() {
|
public void apply() {
|
||||||
var settings = AppSettingsState.getInstance();
|
var settings = AppSettingsState.getInstance();
|
||||||
settings.zlsPath = appSettingsComponent.getZlsPathText();
|
settings.zlsPath = appSettingsComponent.getZLSPath();
|
||||||
|
settings.zlsConfigPath = appSettingsComponent.getZLSConfigPath();
|
||||||
|
settings.debug = appSettingsComponent.getDebug();
|
||||||
|
settings.messageTrace = appSettingsComponent.getMessageTrace();
|
||||||
ZLSStartupActivity.initZLS();
|
ZLSStartupActivity.initZLS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
var settings = AppSettingsState.getInstance();
|
var settings = AppSettingsState.getInstance();
|
||||||
appSettingsComponent.setZlsPathText(settings.zlsPath);
|
appSettingsComponent.setZLSPath(settings.zlsPath);
|
||||||
|
appSettingsComponent.setZLSConfigPath(settings.zlsConfigPath);
|
||||||
|
appSettingsComponent.setDebug(settings.debug);
|
||||||
|
appSettingsComponent.setMessageTrace(settings.messageTrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -23,13 +23,15 @@ import com.intellij.openapi.components.State;
|
||||||
import com.intellij.openapi.components.Storage;
|
import com.intellij.openapi.components.Storage;
|
||||||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
@Service(Service.Level.PROJECT)
|
@Service(Service.Level.APP)
|
||||||
@State(name = "com.falsepattern.zigbrains.settings.AppSettingsState",
|
@State(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 = "";
|
||||||
|
public String zlsConfigPath = "";
|
||||||
|
public boolean debug = false;
|
||||||
|
public boolean messageTrace = false;
|
||||||
|
|
||||||
public static AppSettingsState getInstance() {
|
public static AppSettingsState getInstance() {
|
||||||
return ApplicationManager.getApplication().getService(AppSettingsState.class);
|
return ApplicationManager.getApplication().getService(AppSettingsState.class);
|
||||||
|
|
|
@ -55,10 +55,10 @@
|
||||||
|
|
||||||
<colorSettingsPage implementation="com.falsepattern.zigbrains.ide.ZigColorSettingsPage"/>
|
<colorSettingsPage implementation="com.falsepattern.zigbrains.ide.ZigColorSettingsPage"/>
|
||||||
|
|
||||||
<projectConfigurable parentId="language"
|
<applicationConfigurable 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"/>
|
||||||
|
|
||||||
<postStartupActivity implementation="com.falsepattern.zigbrains.lsp.ZLSStartupActivity"/>
|
<postStartupActivity implementation="com.falsepattern.zigbrains.lsp.ZLSStartupActivity"/>
|
||||||
<notificationGroup displayType="BALLOON" id="ZigBrains.Nag"/>
|
<notificationGroup displayType="BALLOON" id="ZigBrains.Nag"/>
|
||||||
|
|
Loading…
Add table
Reference in a new issue