Skip to content

Commit

Permalink
feat: provide a stop process action (dev mode) in the console
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Aug 2, 2023
1 parent 7ffb092 commit acee927
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,12 @@ private List<WorkspaceFolder> getRelevantWorkspaceFolders() {
return folders;
}

public synchronized void restart() throws IOException {
public synchronized void stopAndDisable() {
setEnabled(false);
stop();
}

public synchronized void restart() {
numberOfRestartAttempts = 0;
setEnabled(true);
stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.redhat.devtools.intellij.lsp4ij.console.LSPConsoleToolWindowPanel;
import com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.CopyStartServerCommandAction;
import com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.RestartServerAction;
import com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.StopProcessServerAction;
import com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.StopServerAction;
import com.redhat.devtools.intellij.lsp4ij.lifecycle.LanguageServerLifecycleManager;

Expand Down Expand Up @@ -124,10 +125,15 @@ public void invokePopup(Component comp, int x, int y) {
switch (processTreeNode.getServerStatus()) {
case starting:
case started:
// Stop language server action
// Stop and disable the language server action
group = new DefaultActionGroup();
AnAction stopServerAction = ActionManager.getInstance().getAction(StopServerAction.ACTION_ID);
group.add(stopServerAction);
if ("true".equals(System.getProperty("idea.is.internal"))) {
// In dev mode, enable the "Stop Process" action
AnAction stopProcessServerAction = ActionManager.getInstance().getAction(StopProcessServerAction.ACTION_ID);
group.add(stopProcessServerAction);
}
break;
case stopping:
case stopped:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
*/
public class RestartServerAction extends TreeAction implements DumbAware {

private static final Logger LOGGER = LoggerFactory.getLogger(RestartServerAction.class);//$NON-NLS-1$

public static final String ACTION_ID = "com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.RestartServerAction";

public RestartServerAction() {
Expand All @@ -41,11 +39,7 @@ public RestartServerAction() {
protected void actionPerformed(@NotNull Tree tree, @NotNull AnActionEvent e) {
LanguageServerWrapper languageServer = getSelectedLanguageServer(tree);
if (languageServer != null) {
try {
languageServer.restart();
} catch (IOException ex) {
LOGGER.error("Failed restarting server", ex);
}
languageServer.restart();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.devtools.intellij.lsp4ij.console.explorer.actions;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAware;
import com.intellij.ui.treeStructure.Tree;
import com.redhat.devtools.intellij.lsp4ij.LanguageServerBundle;
import com.redhat.devtools.intellij.lsp4ij.LanguageServerWrapper;
import org.jetbrains.annotations.NotNull;

/**
* Action to stop the selected language server process from the language explorer.
*/
public class StopProcessServerAction extends TreeAction implements DumbAware {

public static final String ACTION_ID = "com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.StopProcessServerAction";

public StopProcessServerAction() {
super(LanguageServerBundle.message("lsp.console.explorer.actions.stop.process"));
}

@Override
protected void actionPerformed(@NotNull Tree tree, @NotNull AnActionEvent e) {
LanguageServerWrapper languageServer = getSelectedLanguageServer(tree);
if (languageServer != null) {
languageServer.stop();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.jetbrains.annotations.NotNull;

/**
* Action to stop the selected language server process from the language explorer.
* Action to stop the selected language server process and disable it from the language explorer.
*/
public class StopServerAction extends TreeAction implements DumbAware {

Expand All @@ -35,7 +35,7 @@ public StopServerAction() {
protected void actionPerformed(@NotNull Tree tree, @NotNull AnActionEvent e) {
LanguageServerWrapper languageServer = getSelectedLanguageServer(tree);
if (languageServer != null) {
languageServer.stop();
languageServer.stopAndDisable();
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/lsp4ij.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<action id="com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.StopServerAction"
class="com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.StopServerAction"
icon="AllIcons.Actions.Suspend" />
<action id="com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.StopProcessServerAction"
class="com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.StopProcessServerAction"
icon="AllIcons.Actions.Suspend" />
<action id="com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.CopyStartServerCommandAction"
class="com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.CopyStartServerCommandAction"
icon="AllIcons.Actions.Copy" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ language.server.trace=Trace:
lsp.console.title=LSP Consoles
lsp.console.explorer.actions.restart=Restart
lsp.console.explorer.actions.stop=Stop
lsp.console.explorer.actions.stop.process=Stop Process
lsp.console.explorer.actions.copy.command=Copy Start Command
lsp.console.actions.folding=Collapse/Expand All

Expand Down

0 comments on commit acee927

Please sign in to comment.