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

View file

@ -20,6 +20,7 @@ import com.falsepattern.zigbrains.settings.AppSettingsState;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import org.jetbrains.annotations.NotNull;
@ -30,9 +31,14 @@ import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.concurrent.locks.ReentrantLock;
public class ZLSStartupActivity implements StartupActivity {
private static final ReentrantLock lock = new ReentrantLock();
public static void initZLS() {
ApplicationManager.getApplication().executeOnPooledThread(() -> {
lock.lock();
try {
var settings = AppSettingsState.getInstance();
var zlsPath = settings.zlsPath;
if (!validatePath("ZLS Binary", zlsPath, false)) {
@ -42,8 +48,8 @@ public class ZLSStartupActivity implements StartupActivity {
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));
Notifications.Bus.notify(
new Notification("ZigBrains.Nag", "Using default config path.", NotificationType.INFORMATION));
}
if ("".equals(configPath)) {
configOK = false;
@ -58,13 +64,34 @@ public class ZLSStartupActivity implements StartupActivity {
cmd.add("--config-path");
cmd.add(configPath);
}
// TODO make this properly configurable
if (settings.increaseTimeouts) {
for (var timeout : IntellijLanguageClient.getTimeouts().keySet()) {
IntellijLanguageClient.setTimeout(timeout, 15000);
}
}
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) {

View file

@ -32,6 +32,7 @@ public class AppSettingsComponent {
private final TextFieldWithBrowseButton zlsConfigPathText = new TextFieldWithBrowseButton();
private final JBCheckBox debugCheckBox = new JBCheckBox();
private final JBCheckBox messageTraceCheckBox = new JBCheckBox();
private final JBCheckBox increaseTimeouts = new JBCheckBox();
public AppSettingsComponent() {
zlsPathText.addBrowseFolderListener(
@ -41,8 +42,9 @@ public class AppSettingsComponent {
.addVerticalGap(10)
.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("Increase timeouts"), increaseTimeouts, 1, false)
.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)
.addLabeledComponent(new JBLabel("ZLS debug log: "), debugCheckBox, 1, false)
.addLabeledComponent(new JBLabel("ZLS message trace: "), messageTraceCheckBox, 1, false)
@ -72,6 +74,14 @@ public class AppSettingsComponent {
zlsConfigPathText.setText(newText);
}
public boolean getIncreaseTimeouts() {
return increaseTimeouts.isSelected();
}
public void setIncreaseTimeouts(boolean state) {
increaseTimeouts.setSelected(state);
}
public boolean getDebug() {
return debugCheckBox.isSelected();
}

View file

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

View file

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