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 org.jetbrains.annotations.NotNull;
|
||||
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.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ZLSStartupActivity implements StartupActivity {
|
||||
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;
|
||||
try {
|
||||
path = Path.of(pathTxt);
|
||||
} catch (InvalidPathException e) {
|
||||
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));
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
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));
|
||||
if (!Files.exists(path)) {
|
||||
Notifications.Bus.notify(new Notification("ZigBrains.Nag", "No " + name,
|
||||
"The " + name + " at \"" + pathTxt +
|
||||
"\" doesn't exist!", NotificationType.ERROR));
|
||||
return false;
|
||||
}
|
||||
if (IntellijLanguageClient.getExtensionManagerFor("zig") == null) {
|
||||
IntellijLanguageClient.addExtensionManager("zig", new ZLSExtensionManager());
|
||||
if (Files.isDirectory(path) != dir) {
|
||||
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();
|
||||
procBuilder.command(pathTxt, "--enable-message-tracing");
|
||||
IntellijLanguageClient.addServerDefinition(new ProcessBuilderServerDefinition("zig", procBuilder));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,7 @@ package com.falsepattern.zigbrains.settings;
|
|||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.ui.TextBrowseFolderListener;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.util.ui.FormBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -28,12 +29,23 @@ import javax.swing.JPanel;
|
|||
public class AppSettingsComponent {
|
||||
private final JPanel myMainPanel;
|
||||
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() {
|
||||
zlsPathText.addBrowseFolderListener(
|
||||
new TextBrowseFolderListener(new FileChooserDescriptor(true, false, false, false, false, false)));
|
||||
myMainPanel = FormBuilder.createFormBuilder()
|
||||
.addComponent(new JBLabel("Regular settings"))
|
||||
.addVerticalGap(10)
|
||||
.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)
|
||||
.getPanel();
|
||||
}
|
||||
|
@ -43,11 +55,36 @@ public class AppSettingsComponent {
|
|||
}
|
||||
|
||||
@NotNull
|
||||
public String getZlsPathText() {
|
||||
public String getZLSPath() {
|
||||
return zlsPathText.getText();
|
||||
}
|
||||
|
||||
public void setZlsPathText(@NotNull String newText) {
|
||||
public void setZLSPath(@NotNull String 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
|
||||
public boolean isModified() {
|
||||
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
|
||||
public void apply() {
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
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
|
||||
|
|
|
@ -23,13 +23,15 @@ import com.intellij.openapi.components.State;
|
|||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||
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",
|
||||
storages = @Storage("ZigBrainsSettings.xml"))
|
||||
public final class AppSettingsState implements PersistentStateComponent<AppSettingsState> {
|
||||
public String zlsPath = "";
|
||||
public String zlsConfigPath = "";
|
||||
public boolean debug = false;
|
||||
public boolean messageTrace = false;
|
||||
|
||||
public static AppSettingsState getInstance() {
|
||||
return ApplicationManager.getApplication().getService(AppSettingsState.class);
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
|
||||
<colorSettingsPage implementation="com.falsepattern.zigbrains.ide.ZigColorSettingsPage"/>
|
||||
|
||||
<projectConfigurable parentId="language"
|
||||
<applicationConfigurable parentId="language"
|
||||
instance="com.falsepattern.zigbrains.settings.AppSettingsConfigurable"
|
||||
id="com.falsepattern.zigbrains.settings.AppSettingsConfigurable"
|
||||
displayName="Zig"/>
|
||||
|
|
Loading…
Add table
Reference in a new issue