Skip to content

Commit

Permalink
feat(eclipse): implement statusbar item sync. (#2896)
Browse files Browse the repository at this point in the history
  • Loading branch information
icycodes authored Aug 16, 2024
1 parent c3bc3d1 commit 3c46875
Show file tree
Hide file tree
Showing 27 changed files with 365 additions and 38 deletions.
4 changes: 2 additions & 2 deletions clients/eclipse/feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="com.tabbyml.features.tabby4eclipse"
label="Tabby"
version="0.0.1.10"
version="0.0.1.11"
provider-name="com.tabbyml">

<description url="http://www.example.com/description">
Expand All @@ -19,6 +19,6 @@

<plugin
id="com.tabbyml.tabby4eclipse"
version="0.0.1.10"/>
version="0.0.1.11"/>

</feature>
2 changes: 1 addition & 1 deletion clients/eclipse/plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tabby Plugin for Eclipse
Bundle-SymbolicName: com.tabbyml.tabby4eclipse;singleton:=true
Bundle-Version: 0.0.1.10
Bundle-Version: 0.0.1.11
Bundle-Activator: com.tabbyml.tabby4eclipse.Activator
Bundle-Vendor: com.tabbyml
Require-Bundle: org.eclipse.ui,
Expand Down
Binary file removed clients/eclipse/plugin/images/check-dark.png
Binary file not shown.
Binary file removed clients/eclipse/plugin/images/[email protected]
Binary file not shown.
Binary file removed clients/eclipse/plugin/images/check-light.png
Binary file not shown.
Binary file removed clients/eclipse/plugin/images/[email protected]
Binary file not shown.
Binary file added clients/eclipse/plugin/images/check_tsk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added clients/eclipse/plugin/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added clients/eclipse/plugin/images/hprio_tsk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added clients/eclipse/plugin/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added clients/eclipse/plugin/images/progress_task.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added clients/eclipse/plugin/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added clients/eclipse/plugin/images/warn_tsk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added clients/eclipse/plugin/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 17 additions & 8 deletions clients/eclipse/plugin/src/com/tabbyml/tabby4eclipse/Images.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.ui.PlatformUI;
Expand All @@ -14,30 +15,38 @@
public class Images {
private static Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
private static Logger logger = new Logger("Images");

private static boolean isDark = isDarkTheme();
private static Image iconCheck = null;
private static ImageRegistry icons = Activator.getDefault().getImageRegistry();

public static final String ICON_CHECK = "check_tsk.png";
public static final String ICON_ERROR = "hprio_tsk.png";
public static final String ICON_WARN = "warn_tsk.png";
public static final String ICON_LOADING = "progress_task.png";

public static Image getIconCheck() {
if (iconCheck == null) {
iconCheck = createImage(isDark ? "images/check-dark.png" : "images/check-light.png");
public static Image getIcon(String filename) {
Image icon = icons.get(filename);
if (icon == null) {
icon = createImageFromFile(filename);
icons.put(filename, icon);
}
return iconCheck;
return icon;
}

private static boolean isDarkTheme() {
RGB bgColor = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry()
.getRGB("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START");
if (bgColor != null) {
boolean isBgDark = (bgColor.red + bgColor.green + bgColor.blue) / 3 < 128;
boolean isBgDark = (bgColor.red + bgColor.green + bgColor.blue) / 3 < 128;
logger.info("Detected theme: " + (isBgDark ? "dark" : "light"));
return isBgDark;
}
logger.info("Cannot detect theme. Assuming light.");
return false;
}

private static Image createImage(String path) {
private static Image createImageFromFile(String filename) {
String path = "images/" + filename;
URL url = FileLocator.find(bundle, new Path(path));
ImageDescriptor imageDesc = ImageDescriptor.createFromURL(url);
return imageDesc.createImage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.tabbyml.tabby4eclipse.lsp.LanguageServerService;
import com.tabbyml.tabby4eclipse.lsp.protocol.ILanguageServer;
import com.tabbyml.tabby4eclipse.lsp.protocol.InlineCompletionParams;
import com.tabbyml.tabby4eclipse.lsp.protocol.TextDocumentServiceExt;
import com.tabbyml.tabby4eclipse.lsp.protocol.ITextDocumentServiceExt;

public class InlineCompletionService {
public static InlineCompletionService getInstance() {
Expand Down Expand Up @@ -114,9 +114,9 @@ public void provideInlineCompletion(ITextEditor textEditor, int offset, int offs
}
current = null;
}

ITextViewer textViewer = (ITextViewer) textEditor.getAdapter(ITextViewer.class);

InlineCompletionContext.Request request = new InlineCompletionContext.Request(textEditor, offset);
logger.debug("Request request: " + request.offset + "," + offsetInWidget);
InlineCompletionParams params = request.toInlineCompletionParams();
Expand All @@ -126,7 +126,7 @@ public void provideInlineCompletion(ITextEditor textEditor, int offset, int offs
}
Function<LanguageServer, CompletableFuture<com.tabbyml.tabby4eclipse.lsp.protocol.InlineCompletionList>> jobFn = (
server) -> {
TextDocumentServiceExt textDocumentService = ((ILanguageServer) server).getTextDocumentServiceExt();
ITextDocumentServiceExt textDocumentService = ((ILanguageServer) server).getTextDocumentServiceExt();
return textDocumentService.inlineCompletion(params);
};
CompletableFuture<com.tabbyml.tabby4eclipse.lsp.protocol.InlineCompletionList> job = LanguageServerService
Expand Down Expand Up @@ -283,7 +283,7 @@ private ITextEditor getActiveEditor() {
private boolean isActiveEditor(ITextEditor textEditor) {
return textEditor == getActiveEditor();
}

private class TriggerEvent {
private ITextEditor textEditor;
private long modificationStamp;
Expand Down Expand Up @@ -376,7 +376,7 @@ private static int getDocumentOffset(ITextEditor textEditor, DocumentEvent event
return event.getOffset() + event.getText().length();
}
}

private static long getDocumentModificationStamp(ITextEditor textEditor) {
IDocument document = LSPEclipseUtils.getDocument(textEditor.getEditorInput());
if (document instanceof IDocumentExtension4 documentExt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.tabbyml.tabby4eclipse.lsp.protocol.ClientCapabilities.TextDocumentClientCapabilities;
import com.tabbyml.tabby4eclipse.lsp.protocol.ClientInfo;
import com.tabbyml.tabby4eclipse.lsp.protocol.ClientInfo.TabbyPluginInfo;
import com.tabbyml.tabby4eclipse.statusbar.StatusInfoHolder;
import com.tabbyml.tabby4eclipse.lsp.protocol.ClientProvidedConfig;
import com.tabbyml.tabby4eclipse.lsp.protocol.InitializationOptions;

Expand All @@ -44,13 +45,15 @@ public ConnectionProvider() {
}
}
if (nodeExecutableFile == null) {
StatusInfoHolder.getInstance().setConnectionFailed(true);
logger.error("Cannot find node executable.");
return;
}
// Find tabby-agent script
Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
URL agentScriptUrl = FileLocator.find(bundle, new Path("tabby-agent/dist/node/index.js"));
if (agentScriptUrl == null) {
StatusInfoHolder.getInstance().setConnectionFailed(true);
logger.error("Cannot find tabby-agent script.");
return;
}
Expand All @@ -61,6 +64,7 @@ public ConnectionProvider() {
logger.info("Will use command " + commands.toString() + " to start Tabby language server.");
this.setCommands(commands);
} catch (IOException e) {
StatusInfoHolder.getInstance().setConnectionFailed(true);
logger.error("Failed to setup command to start Tabby language server.", e);
}
}
Expand Down Expand Up @@ -108,6 +112,8 @@ private ClientCapabilities getClientCapabilities() {
textDocumentClientCapabilities.setInlineCompletion(true);

TabbyClientCapabilities tabbyClientCapabilities = new TabbyClientCapabilities();
tabbyClientCapabilities.setConfigDidChangeListener(false);
tabbyClientCapabilities.setStatusDidChangeListener(true);

ClientCapabilities clientCapabilities = new ClientCapabilities();
clientCapabilities.setTextDocument(textDocumentClientCapabilities);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package com.tabbyml.tabby4eclipse.lsp;

public class LanguageClientImpl extends org.eclipse.lsp4e.LanguageClientImpl {
import java.util.concurrent.CompletableFuture;

import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;

import com.tabbyml.tabby4eclipse.lsp.protocol.StatusInfo;
import com.tabbyml.tabby4eclipse.statusbar.StatusInfoHolder;

public class LanguageClientImpl extends org.eclipse.lsp4e.LanguageClientImpl {
@JsonNotification("tabby/status/didChange")
void statusDidChange(StatusInfo params) {
StatusInfoHolder.getInstance().setStatusInfo(params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,38 @@ public void setInlineCompletion(boolean inlineCompletion) {
}

public static class TabbyClientCapabilities {
private boolean agent;
private boolean configDidChangeListener;
private boolean statusDidChangeListener;
private boolean workspaceFileSystem;
private boolean dataStore;
private boolean languageSupport;
private boolean gitProvider;
private boolean editorOptions;

public TabbyClientCapabilities() {
this.agent = false;
this.configDidChangeListener = false;
this.statusDidChangeListener = false;
this.workspaceFileSystem = false;
this.dataStore = false;
this.languageSupport = false;
this.gitProvider = false;
this.editorOptions = false;
}

public boolean getAgent() {
return agent;
public boolean getConfigDidChangeListener() {
return configDidChangeListener;
}

public void setAgent(boolean agent) {
this.agent = agent;
public void setConfigDidChangeListener(boolean configDidChangeListener) {
this.configDidChangeListener = configDidChangeListener;
}

public boolean getStatusDidChangeListener() {
return statusDidChangeListener;
}

public void setStatusDidChangeListener(boolean statusDidChangeListener) {
this.statusDidChangeListener = statusDidChangeListener;
}

public boolean getWorkspaceFileSystem() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@

public interface ILanguageServer extends LanguageServer {
@JsonDelegate
TextDocumentServiceExt getTextDocumentServiceExt();
ITextDocumentServiceExt getTextDocumentServiceExt();

@JsonDelegate
IStatusService getStatusService();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.tabbyml.tabby4eclipse.lsp.protocol;

import java.util.concurrent.CompletableFuture;
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
import org.eclipse.lsp4j.jsonrpc.services.JsonSegment;

@JsonSegment("tabby")
public interface IStatusService {
@JsonRequest("status")
CompletableFuture<StatusInfo> getStatus(StatusRequestParams params);

@JsonRequest("status/showHelpMessage")
CompletableFuture<Boolean> showHelpMessage(Object params);

@JsonRequest("status/ignoredIssues/edit")
CompletableFuture<Boolean> editIngoredIssues(StatusIgnoredIssuesEditParams params);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.eclipse.lsp4j.jsonrpc.services.JsonSegment;

@JsonSegment("textDocument")
public interface TextDocumentServiceExt {
public interface ITextDocumentServiceExt {
@JsonRequest
CompletableFuture<InlineCompletionList> inlineCompletion(InlineCompletionParams params);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.tabbyml.tabby4eclipse.lsp.protocol;

public class StatusIgnoredIssuesEditParams {
private String operation;
private String[] issues;

public StatusIgnoredIssuesEditParams() {
}

public String getOperation() {
return operation;
}

public void setOperation(String operation) {
this.operation = operation;
}

public String[] getIssues() {
return issues;
}

public void setIssues(String[] issues) {
this.issues = issues;
}

public static class Operation {
public static final String ADD = "add";
public static final String REMOVE = "remove";
public static final String REMOVE_ALL = "removeAll";
}

public static class StatusIssuesName {
public static final String COMPLETION_RESPONSE_SLOW = "completionResponseSlow";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.tabbyml.tabby4eclipse.lsp.protocol;

import java.util.Map;

import org.eclipse.lsp4j.Command;

public class StatusInfo {
private String status;
private String tooltip;
private Map<String, Object> serverHealth;
private Command command;

public StatusInfo() {
this.status = Status.NOT_INITIALIZED;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public String getTooltip() {
return tooltip;
}

public void setTooltip(String tooltip) {
this.tooltip = tooltip;
}

public Map<String, Object> getServerHealth() {
return serverHealth;
}

public void setServerHealth(Map<String, Object> serverHealth) {
this.serverHealth = serverHealth;
}

public Command getCommand() {
return command;
}

public void setCommand(Command command) {
this.command = command;
}

public static class Status {
public static final String NOT_INITIALIZED = "notInitialized";
public static final String FINALIZED = "finalized";
public static final String CONNECTING = "connecting";
public static final String UNAUTHORIZED = "unauthorized";
public static final String DISCONNECTED = "disconnected";
public static final String READY = "ready";
public static final String READY_FOR_AUTO_TRIGGER = "readyForAutoTrigger";
public static final String READY_FOR_MANUAL_TRIGGER = "readyForManualTrigger";
public static final String FETCHING = "fetching";
public static final String COMPLETION_RESPONSE_SLOW = "completionResponseSlow";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.tabbyml.tabby4eclipse.lsp.protocol;

public class StatusRequestParams {
private boolean recheckConnection;

public StatusRequestParams() {
}

public boolean getRecheckConnection() {
return recheckConnection;
}

public void setRecheckConnection(boolean recheckConnection) {
this.recheckConnection = recheckConnection;
}
}
Loading

0 comments on commit 3c46875

Please sign in to comment.