generated from redhat-developer/new-project-template
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: provide a base class for LSP command action
Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
341a929
commit d1cb1bd
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/main/java/com/redhat/devtools/lsp4ij/commands/LSPCommandAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.lsp4ij.commands; | ||
|
||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import org.eclipse.lsp4j.Command; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.net.URI; | ||
|
||
/** | ||
* Abstract IJ {@link AnAction} class to execute an LSP {@link Command}. | ||
*/ | ||
public abstract class LSPCommandAction extends AnAction { | ||
|
||
@Override | ||
public final void actionPerformed(@NotNull AnActionEvent e) { | ||
Command command = e.getData(CommandExecutor.LSP_COMMAND); | ||
if (command == null) { | ||
return; | ||
} | ||
commandPerformed(command, e); | ||
} | ||
|
||
/** | ||
* Returns the document URI which performs the action and null otherwise. | ||
* | ||
* @param e the action event. | ||
* | ||
* @return the document URI which performs the action and null otherwise. | ||
*/ | ||
protected @Nullable URI getDocumentUri(@NotNull AnActionEvent e) { | ||
return e.getData(CommandExecutor.LSP_COMMAND_DOCUMENT_URI); | ||
} | ||
|
||
/** | ||
* Performs the LSP command logic. | ||
* | ||
* @param command the LSP command. | ||
* @param e the action event. | ||
*/ | ||
protected abstract void commandPerformed(@NotNull Command command, @NotNull AnActionEvent e); | ||
} |