Skip to content

Commit

Permalink
fix: Start/stop actions from language server explorer do nothing.
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Jun 27, 2023
1 parent 0828002 commit 1682c1e
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*******************************************************************************/
package com.redhat.devtools.intellij.lsp4ij.console.explorer;

import com.intellij.ide.DataManager;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.project.Project;
Expand Down Expand Up @@ -48,7 +47,7 @@ public class LanguageServerExplorer extends SimpleToolWindowPanel implements Dis
private boolean disposed;

private TreeSelectionListener treeSelectionListener = event -> {
if(isDisposed()) {
if (isDisposed()) {
return;
}
TreePath selectionPath = event.getPath();
Expand Down Expand Up @@ -107,9 +106,6 @@ private Tree buildTree() {

tree.addTreeSelectionListener(treeSelectionListener);

DataProvider newDataProvider = new LanguageServerExplorerTreeDataProvider(tree);
DataManager.registerDataProvider(tree, newDataProvider);

tree.addMouseListener(new PopupHandler() {
@Override
public void invokePopup(Component comp, int x, int y) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
*******************************************************************************/
package com.redhat.devtools.intellij.lsp4ij.console.explorer.actions;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.redhat.devtools.intellij.lsp4ij.console.explorer.LanguageServerExplorerTreeDataProvider;
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;
Expand All @@ -27,7 +26,7 @@
/**
* Action to restart the selected language server process from the language explorer.
*/
public class RestartServerAction extends AnAction {
public class RestartServerAction extends TreeAction {

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

Expand All @@ -38,11 +37,11 @@ public RestartServerAction() {
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Object lsData = e.getDataContext().getData(LanguageServerExplorerTreeDataProvider.LANGUAGE_SERVER_DATA_ID);
if (lsData instanceof LanguageServerWrapper) {
protected void actionPerformed(@NotNull Tree tree, @NotNull AnActionEvent e) {
LanguageServerWrapper languageServer = getSelectedLanguageServer(tree);
if (languageServer != null) {
try {
((LanguageServerWrapper)lsData).start();
languageServer.start();
} catch (IOException ex) {
LOGGER.error("Failed restarting server", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
*******************************************************************************/
package com.redhat.devtools.intellij.lsp4ij.console.explorer.actions;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.redhat.devtools.intellij.lsp4ij.console.explorer.LanguageServerExplorerTreeDataProvider;
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 StopServerAction extends AnAction {
public class StopServerAction extends TreeAction {

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

Expand All @@ -32,10 +31,11 @@ public StopServerAction() {
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Object lsData = e.getDataContext().getData(LanguageServerExplorerTreeDataProvider.LANGUAGE_SERVER_DATA_ID);
if (lsData instanceof LanguageServerWrapper) {
((LanguageServerWrapper)lsData).stop();
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
@@ -0,0 +1,77 @@
/*******************************************************************************
* 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.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.util.NlsActions;
import com.intellij.ui.treeStructure.Tree;
import com.redhat.devtools.intellij.lsp4ij.LanguageServerWrapper;
import com.redhat.devtools.intellij.lsp4ij.console.explorer.LanguageServerProcessTreeNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.tree.TreePath;
import java.awt.*;

/**
* 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) {
return;
}
actionPerformed(tree, e);
}

/**
* Returns the language server tree and null otherwise.
*
* @param e the action event.
* @return the language server tree and null otherwise.
*/
private Tree getTree(AnActionEvent e) {
Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
if (component instanceof Tree) {
return (Tree) component;
}
return null;
}

/**
* Returns the selected language server tree node and null otherwise.
*
* @param tree the tree.
* @return the selected language server tree node and null otherwise.
*/
protected LanguageServerWrapper getSelectedLanguageServer(Tree tree) {
TreePath path = tree.getSelectionPath();
Object node = path != null ? path.getLastPathComponent() : null;
if (node instanceof LanguageServerProcessTreeNode) {
return ((LanguageServerProcessTreeNode) node).getLanguageServer();
}
return null;
}

protected abstract void actionPerformed(@NotNull Tree tree, @NotNull AnActionEvent e);

}

0 comments on commit 1682c1e

Please sign in to comment.