Skip to content

Commit

Permalink
feat(eclipse): add right click menu actions to send message to chat p…
Browse files Browse the repository at this point in the history
…anel (#3266)

* feat(eclipse): update chat panel to compatible with server 0.18.0.

* feat(eclipse): add right click menu actions to send message to chat panel.

* chore(eclipse): update comments.
  • Loading branch information
icycodes authored Oct 13, 2024
1 parent f754e0f commit c1b464e
Show file tree
Hide file tree
Showing 20 changed files with 1,017 additions and 388 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.2.21"
version="0.0.2.24"
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.2.21"/>
version="0.0.2.24"/>

</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.2.21
Bundle-Version: 0.0.2.24
Bundle-Activator: com.tabbyml.tabby4eclipse.Activator
Bundle-Vendor: com.tabbyml
Require-Bundle: org.eclipse.ui,
Expand Down
34 changes: 11 additions & 23 deletions clients/eclipse/plugin/chat-panel/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
color: hsl(var(--primary));
}

#message div h4 {
margin: 16px 0;
#message div {
margin: 16px;
}

#message div p {
Expand Down Expand Up @@ -85,27 +85,6 @@ <h4>Welcome to Tabby Chat</h4>
chat.src = url;
}

getChatPanel().addEventListener('load', function () {
setTimeout(() => {
// handleChatPanelLoaded is a function injected by the client
handleChatPanelLoaded();

const chat = getChatPanel();
// override iframe style
const theme = document.documentElement.className;
const css = document.documentElement.style.cssText;
chat.contentWindow.postMessage({ style: css, themeClass: theme, }, new URL(chat.src).origin);
// alternatively:
// const chatDocument = chat.contentWindow.document;
// chatDocument.documentElement.className = theme;
// chatDocument.documentElement.style.cssText = css;
// chatDocument.body.style.cssText = css;

// handleChatPanelStyleApplied is a function injected by the client
setTimeout(handleChatPanelStyleApplied, 100);
}, 300);
});

function applyStyle(style) {
const { theme, css } = JSON.parse(style);
document.documentElement.className = theme;
Expand All @@ -132,6 +111,15 @@ <h4>Welcome to Tabby Chat</h4>
);
}

window.addEventListener("focus", (event) => {
const chat = getChatPanel();
if (chat.style.cssText == "display: block;") {
setTimeout(() => {
chat.contentWindow.focus();
}, 1);
}
});

window.addEventListener("message", (event) => {
const chat = getChatPanel();

Expand Down
127 changes: 121 additions & 6 deletions clients/eclipse/plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,43 @@
</control>
</toolbar>
</menuContribution>
<menuContribution
locationURI="popup:org.eclipse.ui.popup.any">
<menu
id="com.tabbyml.tabby4eclipse.textEditorContextMenu"
label="Tabby">
<visibleWhen>
<with variable="activePart">
<instanceof value="org.eclipse.ui.IEditorPart" />
</with>
</visibleWhen>
<command
commandId="com.tabbyml.tabby4eclipse.commands.chat.addSelectionToChat"
label="Add Selection to Chat">
</command>
<command
commandId="com.tabbyml.tabby4eclipse.commands.chat.addFileToChat"
label="Add File to Chat">
</command>
<separator name="separator0" visible="true" />
<command
commandId="com.tabbyml.tabby4eclipse.commands.chat.explain"
label="Explain">
</command>
<command
commandId="com.tabbyml.tabby4eclipse.commands.chat.fix"
label="Fix">
</command>
<command
commandId="com.tabbyml.tabby4eclipse.commands.chat.generateDocs"
label="Generate Docs">
</command>
<command
commandId="com.tabbyml.tabby4eclipse.commands.chat.generateTests"
label="Generate Tests">
</command>
</menu>
</menuContribution>
</extension>

<extension point="org.eclipse.ui.commands">
Expand All @@ -65,12 +102,13 @@
</category>
<command
categoryId="com.tabbyml.tabby4eclipse.commands"
name="Open Tabby Chat"
id="com.tabbyml.tabby4eclipse.commands.openChatView">
name="Open Settings"
icon="image/settings.png"
id="com.tabbyml.tabby4eclipse.commands.openPreferences">
</command>
<category
id="com.tabbyml.tabby4eclipse.commands.inlineCompletion"
name="Tabby">
name="Code Completion">
</category>
<command
categoryId="com.tabbyml.tabby4eclipse.commands.inlineCompletion"
Expand All @@ -82,12 +120,57 @@
name="Dismiss"
id="com.tabbyml.tabby4eclipse.commands.inlineCompletion.dismiss">
</command>
<category
id="com.tabbyml.tabby4eclipse.commands.chat"
name="Chat">
</category>
<command
categoryId="com.tabbyml.tabby4eclipse.commands.chat"
name="Open Tabby Chat"
icon="images/chat.png"
id="com.tabbyml.tabby4eclipse.commands.chat.openChatView">
</command>
<command
categoryId="com.tabbyml.tabby4eclipse.commands.chat"
name="Toggle Tabby Chat"
id="com.tabbyml.tabby4eclipse.commands.chat.toggleChatView">
</command>
<command
categoryId="com.tabbyml.tabby4eclipse.commands.chat"
name="Add Selection to Chat"
id="com.tabbyml.tabby4eclipse.commands.chat.addSelectionToChat">
</command>
<command
categoryId="com.tabbyml.tabby4eclipse.commands.chat"
name="Add File to Chat"
id="com.tabbyml.tabby4eclipse.commands.chat.addFileToChat">
</command>
<command
categoryId="com.tabbyml.tabby4eclipse.commands.chat"
name="Explain"
id="com.tabbyml.tabby4eclipse.commands.chat.explain">
</command>
<command
categoryId="com.tabbyml.tabby4eclipse.commands.chat"
name="Fix"
id="com.tabbyml.tabby4eclipse.commands.chat.fix">
</command>
<command
categoryId="com.tabbyml.tabby4eclipse.commands.chat"
name="Generate Docs"
id="com.tabbyml.tabby4eclipse.commands.chat.generateDocs">
</command>
<command
categoryId="com.tabbyml.tabby4eclipse.commands.chat"
name="Generate Tests"
id="com.tabbyml.tabby4eclipse.commands.chat.generateTests">
</command>
</extension>

<extension point="org.eclipse.ui.handlers">
<handler
class="com.tabbyml.tabby4eclipse.commands.OpenChatView"
commandId="com.tabbyml.tabby4eclipse.commands.openChatView">
class="com.tabbyml.tabby4eclipse.commands.OpenPreferences"
commandId="com.tabbyml.tabby4eclipse.commands.openPreferences">
</handler>
<handler
class="com.tabbyml.tabby4eclipse.commands.inlineCompletion.Accept"
Expand All @@ -97,11 +180,43 @@
class="com.tabbyml.tabby4eclipse.commands.inlineCompletion.Dismiss"
commandId="com.tabbyml.tabby4eclipse.commands.inlineCompletion.dismiss">
</handler>
<handler
class="com.tabbyml.tabby4eclipse.commands.chat.OpenChatView"
commandId="com.tabbyml.tabby4eclipse.commands.chat.openChatView">
</handler>
<handler
class="com.tabbyml.tabby4eclipse.commands.chat.ToggleChatView"
commandId="com.tabbyml.tabby4eclipse.commands.chat.toggleChatView">
</handler>
<handler
class="com.tabbyml.tabby4eclipse.commands.chat.AddSelectionToChat"
commandId="com.tabbyml.tabby4eclipse.commands.chat.addSelectionToChat">
</handler>
<handler
class="com.tabbyml.tabby4eclipse.commands.chat.AddFileToChat"
commandId="com.tabbyml.tabby4eclipse.commands.chat.addFileToChat">
</handler>
<handler
class="com.tabbyml.tabby4eclipse.commands.chat.Explain"
commandId="com.tabbyml.tabby4eclipse.commands.chat.explain">
</handler>
<handler
class="com.tabbyml.tabby4eclipse.commands.chat.Fix"
commandId="com.tabbyml.tabby4eclipse.commands.chat.fix">
</handler>
<handler
class="com.tabbyml.tabby4eclipse.commands.chat.GenerateDocs"
commandId="com.tabbyml.tabby4eclipse.commands.chat.generateDocs">
</handler>
<handler
class="com.tabbyml.tabby4eclipse.commands.chat.GenerateTests"
commandId="com.tabbyml.tabby4eclipse.commands.chat.generateTests">
</handler>
</extension>

<extension point="org.eclipse.ui.bindings">
<key
commandId="com.tabbyml.tabby4eclipse.commands.openChatView"
commandId="com.tabbyml.tabby4eclipse.commands.chat.toggleChatView"
contextId="org.eclipse.ui.contexts.window"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+M3+L">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.tabbyml.tabby4eclipse;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

public class DebouncedRunnable {
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
private ScheduledFuture<?> future;
private final long delay;
private final Runnable task;

public DebouncedRunnable(Runnable task, long delay) {
this.task = task;
this.delay = delay;
}

public synchronized void call() {
if (future != null && !future.isDone()) {
future.cancel(true);
}
future = scheduler.schedule(task, delay, TimeUnit.MILLISECONDS);
}

// FIXME: scheduler shutdown not called
public void shutdown() {
scheduler.shutdown();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.tabbyml.tabby4eclipse;

import org.eclipse.swt.graphics.RGB;

public class StringUtils {

public static String escapeCharacters(String jsonString) {
return jsonString.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n").replace("\r", "\\r")
.replace("\t", "\\t");
}

public static String toHsl(RGB rgb) {
double r = rgb.red / 255.0;
double g = rgb.green / 255.0;
double b = rgb.blue / 255.0;
double max = Math.max(r, Math.max(g, b));
double min = Math.min(r, Math.min(g, b));
double l = (max + min) / 2.0;
double h, s;
if (max == min) {
h = 0;
s = 0;
} else {
double delta = max - min;
s = l > 0.5 ? delta / (2.0 - max - min) : delta / (max + min);
if (max == r) {
h = (g - b) / delta + (g < b ? 6 : 0);
} else if (max == g) {
h = (b - r) / delta + 2;
} else {
h = (r - g) / delta + 4;
}
h /= 6;
}
h *= 360;
s *= 100;
l *= 100;
return String.format("%.0f, %.0f%%, %.0f%%", h, s, l);
}
}
77 changes: 77 additions & 0 deletions clients/eclipse/plugin/src/com/tabbyml/tabby4eclipse/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.tabbyml.tabby4eclipse;

public class Version {
private int major;
private int minor;
private int patch;

public Version(String versionStr) {
int startIndex = 0;
while (startIndex < versionStr.length() && !Character.isDigit(versionStr.charAt(startIndex))) {
startIndex++;
}
if (startIndex >= versionStr.length()) {
return;
}
int endIndex = versionStr.indexOf("-");
String numPart = (endIndex != -1) ? versionStr.substring(startIndex, endIndex)
: versionStr.substring(startIndex);

String[] parts = numPart.split("\\.");
if (parts.length > 0) {
this.major = parseInt(parts[0]);
}
if (parts.length > 1) {
this.minor = parseInt(parts[1]);
}
if (parts.length > 2) {
this.patch = parseInt(parts[2]);
}
}

public int getMajor() {
return major;
}

public int getMinor() {
return minor;
}

public int getPatch() {
return patch;
}

public boolean isGreaterOrEqualThan(Version other) {
if (this.major > other.major) {
return true;
} else if (this.major < other.major) {
return false;
} else {
if (this.minor > other.minor) {
return true;
} else if (this.minor < other.minor) {
return false;
} else {
return this.patch >= other.patch;
}
}
}

public boolean isEqual(Version other, boolean ignorePatch) {
if (this.major != other.major || this.minor != other.minor) {
return false;
}
if (ignorePatch) {
return true;
}
return this.patch == other.patch;
}

private int parseInt(String str) {
try {
return Integer.parseInt(str);
} catch (NumberFormatException e) {
return 0;
}
}
}
Loading

0 comments on commit c1b464e

Please sign in to comment.