~damien/jedit-lsp

f21036ad8ea786b1d2cc83278631b1f1e00407af — Damien Radtke 4 months ago 2a469e8
Temporarily disable any server that is stopped
3 files changed, 16 insertions(+), 5 deletions(-)

M actions.xml
M lsp/LanguageServerPlugin.java
M lsp/Server.java
M actions.xml => actions.xml +1 -1
@@ 35,7 35,7 @@
      server = lsp.LanguageServerPlugin.get().getServer(buffer);
      if (server != null) {
        if (!server.isRunning()) {
          server.startIfNeeded(buffer);
          server.startIfNeeded(buffer, true);
        } else {
          Macros.message(view, "Server is already running");
        }

M lsp/LanguageServerPlugin.java => lsp/LanguageServerPlugin.java +3 -3
@@ 71,7 71,7 @@ public class LanguageServerPlugin extends EBPlugin {
			for (Buffer buffer : view.getBuffers()) {
				Server server = this.registeredServers.get(buffer.getMode());
				if (server != null) {
					server.startIfNeeded(buffer);
					server.startIfNeeded(buffer, false);
				}
			}
		}


@@ 139,7 139,7 @@ public class LanguageServerPlugin extends EBPlugin {
			Server server = registeredServers.get(message.getBuffer().getMode());
			if (server != null) {
				if (!server.isRunning()) {
					server.startIfNeeded(message.getBuffer());
					server.startIfNeeded(message.getBuffer(), false);
				}
				message.getBuffer().addBufferListener(new BufferChangeListener(executorService, server, message.getBuffer()));
			}


@@ 165,7 165,7 @@ public class LanguageServerPlugin extends EBPlugin {
			for (Buffer buffer : viewUpdate.getView().getBuffers()) {
				Server server = this.registeredServers.get(buffer.getMode());
				if (server != null) {
					server.startIfNeeded(buffer);
					server.startIfNeeded(buffer, false);
				}
			}
		}

M lsp/Server.java => lsp/Server.java +12 -1
@@ 97,6 97,7 @@ public class Server {
	private volatile Launcher<LanguageServer> handle;
	private InitializeResult initResult;
	private volatile boolean starting;
	private String isDisabledProp;

	public Server(Mode mode, ServerDefinition serverDefinition) {
		this.mode = mode;


@@ 106,6 107,7 @@ public class Server {
		this.workspaceFolders = new ArrayList<>();
		this.handle = new NoopHandle();
		this.initResult = null;
		this.isDisabledProp = "lsp.server." + this.getName() + ".disabled";
	}

	public ServerDefinition getDefinition() {


@@ 136,10 138,18 @@ public class Server {
		return this.client;
	}

	public void startIfNeeded(Buffer buffer) {
	public void startIfNeeded(Buffer buffer, boolean force) {
		if (starting || isRunning()) {
			return;
		}
		if (jEdit.getBooleanProperty(isDisabledProp)) {
			if (force) {
				jEdit.unsetProperty(isDisabledProp);
			} else {
				Log.log(Log.DEBUG, this, "Not starting server because it was explicitly stopped; run the 'Start server' action to start it again");
				return;
			}
		}
		start(buffer);
	}



@@ 181,6 191,7 @@ public class Server {
				log(Log.NOTICE, "Stopped server: " + this.process.getName());
				Utils.showTemporaryMessage("Stopped " + process.getName());
			}
			jEdit.setTemporaryProperty(this.isDisabledProp, "true");
			this.client.unpaintDiagnostics();
			this.client.getErrorSource().clear();
			errorlist.ErrorSource.unregisterErrorSource(this.client.getErrorSource());