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 3, 2023
1 parent 7ffb092 commit a15ef96
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 40 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 @@ -34,7 +34,7 @@ public class AutoFoldingAction extends ToggleAction implements DumbAware {
public AutoFoldingAction(@NotNull final Editor editor) {
super();
myEditor = editor;
final String message = LanguageServerBundle.message("lsp.console.actions.folding");
final String message = LanguageServerBundle.message("action.lsp.console.folding.text");
getTemplatePresentation().setDescription(message);
getTemplatePresentation().setText(message);
getTemplatePresentation().setIcon(AllIcons.Actions.Expandall);
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.PauseServerAction;
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 (Boolean.getBoolean("idea.is.internal")) {
// In dev mode, enable the "Pause" action
AnAction pauseServerAction = ActionManager.getInstance().getAction(PauseServerAction.ACTION_ID);
group.add(pauseServerAction);
}
break;
case stopping:
case stopped:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public ServerStatus getServerStatus() {

public Icon getIcon() {
if (!languageServer.isEnabled()) {
return AllIcons.RunConfigurations.TestFailed;
return AllIcons.Actions.Cancel;
}
boolean hasError = languageServer.getServerError() != null;
switch (serverStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@
*/
public class CopyStartServerCommandAction extends TreeAction implements DumbAware {

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

public CopyStartServerCommandAction() {
super(LanguageServerBundle.message("lsp.console.explorer.actions.copy.command"));
}
public static final String ACTION_ID = "lsp.console.explorer.copy.command";

@Override
protected void actionPerformed(@NotNull Tree tree, @NotNull AnActionEvent e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* 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 PauseServerAction extends TreeAction implements DumbAware {

public static final String ACTION_ID = "lsp.console.explorer.pause";
@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 @@ -29,23 +29,13 @@
*/
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() {
super(LanguageServerBundle.message("lsp.console.explorer.actions.restart"));
}
public static final String ACTION_ID = "lsp.console.explorer.restart";

@Override
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
Expand Up @@ -21,21 +21,17 @@
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 {

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

public StopServerAction() {
super(LanguageServerBundle.message("lsp.console.explorer.actions.stop"));
}
public static final String ACTION_ID = "lsp.console.explorer.stop";

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
* Base class for Actions processed from the Language Server tree.
*/
public abstract class TreeAction extends AnAction {

protected TreeAction(@Nullable @NlsActions.ActionText String text) {
super(text);
}

public final void actionPerformed(@NotNull AnActionEvent e) {
Tree tree = getTree(e);
if (tree == null) {
Expand Down
9 changes: 6 additions & 3 deletions src/main/resources/META-INF/lsp4ij.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@
</extensions>

<actions resource-bundle="messages.LanguageServerBundle">
<action id="com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.RestartServerAction"
<action id="lsp.console.explorer.restart"
class="com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.RestartServerAction"
icon="AllIcons.Actions.Restart" />
<action id="com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.StopServerAction"
<action id="lsp.console.explorer.stop"
class="com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.StopServerAction"
icon="AllIcons.Actions.Suspend" />
<action id="com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.CopyStartServerCommandAction"
<action id="lsp.console.explorer.pause"
class="com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.PauseServerAction"
icon="AllIcons.Actions.Pause" />
<action id="lsp.console.explorer.copy.command"
class="com.redhat.devtools.intellij.lsp4ij.console.explorer.actions.CopyStartServerCommandAction"
icon="AllIcons.Actions.Copy" />
</actions>
Expand Down
13 changes: 9 additions & 4 deletions src/main/resources/messages/LanguageServerBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ language.server.trace=Trace:

## LSP console
lsp.console.title=LSP Consoles
lsp.console.explorer.actions.restart=Restart
lsp.console.explorer.actions.stop=Stop
lsp.console.explorer.actions.copy.command=Copy Start Command
lsp.console.actions.folding=Collapse/Expand All
action.lsp.console.explorer.restart.text=Restart
action.lsp.console.explorer.restart.description=Restart the language server
action.lsp.console.explorer.stop.text=Stop
action.lsp.console.explorer.stop.description=Stop and disable the language server
action.lsp.console.explorer.pause.text=Pause
action.lsp.console.explorer.pause.description=Pause the language server
action.lsp.console.explorer.copy.command.text=Copy Start Command
action.lsp.console.explorer.copy.command.description=Copy the command which starts the language server
action.lsp.console.folding.text=Collapse/Expand All

## Dialog
lsp.create.file.confirm.dialog.title=Create file?
Expand Down

0 comments on commit a15ef96

Please sign in to comment.