feat!(lsp): Temporary way to increasing the timeouts

Also added some Windows-specific command line tweaks, and non-blocking language server setup.
This commit is contained in:
FalsePattern 2023-07-31 14:34:11 +02:00 committed by FalsePattern
parent d18ca32b9b
commit e967b1c5ad
Signed by: falsepattern
GPG key ID: FDF7126A9E124447
5 changed files with 81 additions and 32 deletions

View file

@ -4,6 +4,11 @@
## [Unreleased] ## [Unreleased]
### Added
#### LSP
- Temporary "increase timeout" toggle (currently, it bumps all timeouts to 15 seconds)
### Fixed ### Fixed
#### Highlighting #### Highlighting
@ -12,6 +17,9 @@
#### Folding #### Folding
- Occasional NPE in LSP4IntellIJ - Occasional NPE in LSP4IntellIJ
#### LSP
- (Windows) ZLS binary not executing if the file path has weird characters
## [0.2.0] ## [0.2.0]
### Added ### Added

View file

@ -20,6 +20,7 @@ import com.falsepattern.zigbrains.settings.AppSettingsState;
import com.intellij.notification.Notification; import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType; import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications; import com.intellij.notification.Notifications;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project; 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;
@ -30,41 +31,67 @@ 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; import java.util.ArrayList;
import java.util.concurrent.locks.ReentrantLock;
public class ZLSStartupActivity implements StartupActivity { public class ZLSStartupActivity implements StartupActivity {
private static final ReentrantLock lock = new ReentrantLock();
public static void initZLS() { public static void initZLS() {
var settings = AppSettingsState.getInstance(); ApplicationManager.getApplication().executeOnPooledThread(() -> {
var zlsPath = settings.zlsPath; lock.lock();
if (!validatePath("ZLS Binary", zlsPath, false)) { try {
return; var settings = AppSettingsState.getInstance();
} var zlsPath = settings.zlsPath;
var configPath = settings.zlsConfigPath; if (!validatePath("ZLS Binary", zlsPath, false)) {
boolean configOK = true; return;
if (!"".equals(configPath) && !validatePath("ZLS Config", configPath, false)) { }
configOK = false; var configPath = settings.zlsConfigPath;
Notifications.Bus.notify(new Notification("ZigBrains.Nag", "Using default config path.", boolean configOK = true;
NotificationType.INFORMATION)); if (!"".equals(configPath) && !validatePath("ZLS Config", configPath, false)) {
} configOK = false;
if ("".equals(configPath)) { Notifications.Bus.notify(
configOK = false; new Notification("ZigBrains.Nag", "Using default config path.", NotificationType.INFORMATION));
} }
if ("".equals(configPath)) {
configOK = false;
}
if (IntellijLanguageClient.getExtensionManagerFor("zig") == null) { if (IntellijLanguageClient.getExtensionManagerFor("zig") == null) {
IntellijLanguageClient.addExtensionManager("zig", new ZLSExtensionManager()); IntellijLanguageClient.addExtensionManager("zig", new ZLSExtensionManager());
} }
var cmd = new ArrayList<String>(); var cmd = new ArrayList<String>();
cmd.add(zlsPath); cmd.add(zlsPath);
if (configOK) { if (configOK) {
cmd.add("--config-path"); cmd.add("--config-path");
cmd.add(configPath); cmd.add(configPath);
} }
if (settings.debug) { // TODO make this properly configurable
cmd.add("--enable-debug-log"); if (settings.increaseTimeouts) {
} for (var timeout : IntellijLanguageClient.getTimeouts().keySet()) {
if (settings.messageTrace) { IntellijLanguageClient.setTimeout(timeout, 15000);
cmd.add("--enable-message-tracing"); }
} }
IntellijLanguageClient.addServerDefinition(new RawCommandServerDefinition("zig", cmd.toArray(String[]::new)));
if (settings.debug) {
cmd.add("--enable-debug-log");
}
if (settings.messageTrace) {
cmd.add("--enable-message-tracing");
}
for (var wrapper : IntellijLanguageClient.getAllServerWrappersFor("zig")) {
wrapper.removeServerWrapper();
}
if (System.getProperty("os.name").toLowerCase().contains("win")) {
for (int i = 0; i < cmd.size(); i++) {
if (cmd.get(i).contains(" ")) {
cmd.set(i, '"' + cmd.get(i) + '"');
}
}
}
IntellijLanguageClient.addServerDefinition(new RawCommandServerDefinition("zig", cmd.toArray(String[]::new)));
} finally {
lock.unlock();
}
});
} }
private static boolean validatePath(String name, String pathTxt, boolean dir) { private static boolean validatePath(String name, String pathTxt, boolean dir) {

View file

@ -32,6 +32,7 @@ public class AppSettingsComponent {
private final TextFieldWithBrowseButton zlsConfigPathText = new TextFieldWithBrowseButton(); private final TextFieldWithBrowseButton zlsConfigPathText = new TextFieldWithBrowseButton();
private final JBCheckBox debugCheckBox = new JBCheckBox(); private final JBCheckBox debugCheckBox = new JBCheckBox();
private final JBCheckBox messageTraceCheckBox = new JBCheckBox(); private final JBCheckBox messageTraceCheckBox = new JBCheckBox();
private final JBCheckBox increaseTimeouts = new JBCheckBox();
public AppSettingsComponent() { public AppSettingsComponent() {
zlsPathText.addBrowseFolderListener( zlsPathText.addBrowseFolderListener(
@ -41,8 +42,9 @@ public class AppSettingsComponent {
.addVerticalGap(10) .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) .addLabeledComponent(new JBLabel("ZLS config path (leave empty to use default): "), zlsConfigPathText, 1, false)
.addLabeledComponent(new JBLabel("Increase timeouts"), increaseTimeouts, 1, false)
.addSeparator() .addSeparator()
.addComponent(new JBLabel("Developer settings")) .addComponent(new JBLabel("Developer settings (only usable when the IDE was launched with the runIDE gradle task in ZigBrains!)"))
.addVerticalGap(10) .addVerticalGap(10)
.addLabeledComponent(new JBLabel("ZLS debug log: "), debugCheckBox, 1, false) .addLabeledComponent(new JBLabel("ZLS debug log: "), debugCheckBox, 1, false)
.addLabeledComponent(new JBLabel("ZLS message trace: "), messageTraceCheckBox, 1, false) .addLabeledComponent(new JBLabel("ZLS message trace: "), messageTraceCheckBox, 1, false)
@ -72,6 +74,14 @@ public class AppSettingsComponent {
zlsConfigPathText.setText(newText); zlsConfigPathText.setText(newText);
} }
public boolean getIncreaseTimeouts() {
return increaseTimeouts.isSelected();
}
public void setIncreaseTimeouts(boolean state) {
increaseTimeouts.setSelected(state);
}
public boolean getDebug() { public boolean getDebug() {
return debugCheckBox.isSelected(); return debugCheckBox.isSelected();
} }

View file

@ -43,6 +43,7 @@ public class AppSettingsConfigurable implements Configurable {
modified |= !settings.zlsConfigPath.equals(appSettingsComponent.getZLSConfigPath()); modified |= !settings.zlsConfigPath.equals(appSettingsComponent.getZLSConfigPath());
modified |= settings.debug != appSettingsComponent.getDebug(); modified |= settings.debug != appSettingsComponent.getDebug();
modified |= settings.messageTrace != appSettingsComponent.getMessageTrace(); modified |= settings.messageTrace != appSettingsComponent.getMessageTrace();
modified |= settings.increaseTimeouts != appSettingsComponent.getIncreaseTimeouts();
return modified; return modified;
} }
@ -53,6 +54,7 @@ public class AppSettingsConfigurable implements Configurable {
settings.zlsConfigPath = appSettingsComponent.getZLSConfigPath(); settings.zlsConfigPath = appSettingsComponent.getZLSConfigPath();
settings.debug = appSettingsComponent.getDebug(); settings.debug = appSettingsComponent.getDebug();
settings.messageTrace = appSettingsComponent.getMessageTrace(); settings.messageTrace = appSettingsComponent.getMessageTrace();
settings.increaseTimeouts = appSettingsComponent.getIncreaseTimeouts();
ZLSStartupActivity.initZLS(); ZLSStartupActivity.initZLS();
} }
@ -63,6 +65,7 @@ public class AppSettingsConfigurable implements Configurable {
appSettingsComponent.setZLSConfigPath(settings.zlsConfigPath); appSettingsComponent.setZLSConfigPath(settings.zlsConfigPath);
appSettingsComponent.setDebug(settings.debug); appSettingsComponent.setDebug(settings.debug);
appSettingsComponent.setMessageTrace(settings.messageTrace); appSettingsComponent.setMessageTrace(settings.messageTrace);
appSettingsComponent.setIncreaseTimeouts(settings.increaseTimeouts);
} }
@Override @Override

View file

@ -32,6 +32,7 @@ public final class AppSettingsState implements PersistentStateComponent<AppSetti
public String zlsConfigPath = ""; public String zlsConfigPath = "";
public boolean debug = false; public boolean debug = false;
public boolean messageTrace = false; public boolean messageTrace = false;
public boolean increaseTimeouts = false;
public static AppSettingsState getInstance() { public static AppSettingsState getInstance() {
return ApplicationManager.getApplication().getService(AppSettingsState.class); return ApplicationManager.getApplication().getService(AppSettingsState.class);