Skip to content

Commit

Permalink
refactor(eclipse): extract inlne completion item renderer (#3401)
Browse files Browse the repository at this point in the history
* refactor(eclipse): remove unused code.

* refactor(eclipse): extract interface InlineCompletionItemRenderer.

* refactor(eclipse): remove unused code.

* refactor(eclipse): move regex for leading tabs to stringUtils.
  • Loading branch information
icycodes authored Nov 12, 2024
1 parent 03adfaa commit 86f9dc4
Show file tree
Hide file tree
Showing 37 changed files with 197 additions and 151 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.26"
version="0.0.2.27"
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.26"/>
version="0.0.2.27"/>

</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.26
Bundle-Version: 0.0.2.27
Bundle-Activator: com.tabbyml.tabby4eclipse.Activator
Bundle-Vendor: com.tabbyml
Require-Bundle: org.eclipse.ui,
Expand Down
7 changes: 0 additions & 7 deletions clients/eclipse/plugin/chat-panel/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@ <h4>Welcome to Tabby Chat</h4>

// server to client requests
if (event.source === chat.contentWindow) {
// handle copy action
if (typeof event.data === "object" && "action" in event.data && event.data.action === "copy") {
if (navigator.clipboard?.writeText) {
navigator.clipboard.writeText(event.data.data);
}
}

// adapter for @quilted/threads requests
if (Array.isArray(event.data) && event.data.length >= 2) {
const [kind, data] = event.data;
Expand Down
2 changes: 0 additions & 2 deletions clients/eclipse/plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
<command
categoryId="com.tabbyml.tabby4eclipse.commands"
name="Open Tabby Settings"
icon="image/settings.png"
id="com.tabbyml.tabby4eclipse.commands.openPreferences">
</command>
<category
Expand Down Expand Up @@ -152,7 +151,6 @@
<command
categoryId="com.tabbyml.tabby4eclipse.commands.chat"
name="Open Tabby Chat"
icon="images/chat.png"
id="com.tabbyml.tabby4eclipse.commands.chat.openChatView">
</command>
<command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class Activator extends AbstractUIPlugin {

// The shared instance
private static Activator plugin;

public static Activator getDefault() {
return plugin;
}

private Logger logger = new Logger("Activator");

public Activator() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static Image getIcon(String filename) {
}
return icon;
}

private static Image createImageFromFile(String filename) {
String path = "images/" + filename;
URL url = FileLocator.find(bundle, new Path(path));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class Startup implements IStartup {

private Logger logger = new Logger("Startup");

@Override
public void earlyStartup() {
logger.info("Running startup actions.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.tabbyml.tabby4eclipse;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

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");
Expand Down Expand Up @@ -37,4 +39,33 @@ public static String toHsl(RGB rgb) {
l *= 100;
return String.format("%.0f, %.0f%%, %.0f%%", h, s, l);
}

public static class TextWithTabs {
private int tabs;
private String text;

public TextWithTabs(int tabs, String text) {
this.tabs = tabs;
this.text = text;
}

public int getTabs() {
return tabs;
}

public String getText() {
return text;
}
}

static final Pattern PATTERN_LEADING_TABS = Pattern.compile("^(\\t*)(.*)$");

public static TextWithTabs splitLeadingTabs(String text) {
Matcher matcher = PATTERN_LEADING_TABS.matcher(text);
if (matcher.matches()) {
return new TextWithTabs(matcher.group(1).length(), matcher.group(2));
} else {
return new TextWithTabs(0, text);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.eclipse.core.commands.ExecutionException;

import com.tabbyml.tabby4eclipse.Logger;
import com.tabbyml.tabby4eclipse.chat.ChatView;
import com.tabbyml.tabby4eclipse.chat.ChatViewUtils;

public class OpenChatView extends AbstractHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class Dismiss extends AbstractHandler {
private Logger logger = new Logger("Commands.InlineCompletion.Dismiss");

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
logger.debug("Dismiss the current inline completion.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class Trigger extends AbstractHandler {
private Logger logger = new Logger("Commands.InlineCompletion.Trigger");

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
logger.debug("Trigger inline completion manually.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.texteditor.ITextEditor;

import com.tabbyml.tabby4eclipse.chat.ChatMessage.FileContext;

public class EditorUtils {
public static IWorkbenchPage getActiveWorkbenchPage() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.eclipse.ui.texteditor.ITextEditor;

import com.tabbyml.tabby4eclipse.Logger;
import com.tabbyml.tabby4eclipse.inlineCompletion.InlineCompletionTrigger;
import com.tabbyml.tabby4eclipse.inlineCompletion.trigger.InlineCompletionTrigger;
import com.tabbyml.tabby4eclipse.lsp.LanguageServerService;

public class WorkbenchPartListener implements IPartListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static IGitProvider getInstance() {
private static class LazyHolder {
private static final IGitProvider INSTANCE = createInstance();
}

private static Logger logger = new Logger("GitProvider");

public static IGitProvider createInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ public interface IGitProvider {
default public boolean isAvailable() throws NoClassDefFoundError {
return false;
}

default public GitRepository getRepository(GitRepositoryParams params) {
return null;
}

default public GitDiffResult getDiff(GitDiffParams params) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.tabbyml.tabby4eclipse.Logger;
import com.tabbyml.tabby4eclipse.editor.EditorUtils;
import com.tabbyml.tabby4eclipse.inlineCompletion.renderer.InlineCompletionRendererSupport;
import com.tabbyml.tabby4eclipse.lsp.LanguageServerService;
import com.tabbyml.tabby4eclipse.lsp.protocol.CompletionEventId;
import com.tabbyml.tabby4eclipse.lsp.protocol.EventParams;
Expand All @@ -41,7 +42,7 @@ private static class LazyHolder {
private static final String INLINE_COMPLETION_VISIBLE_CONTEXT_ID = "com.tabbyml.tabby4eclipse.inlineCompletionVisible";

private Logger logger = new Logger("InlineCompletionService");
private InlineCompletionRenderer renderer = new InlineCompletionRenderer();
private InlineCompletionRendererSupport renderer = new InlineCompletionRendererSupport();
private InlineCompletionContext current;
private IContextActivation inlineCompletionVisibleContext;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.tabbyml.tabby4eclipse.inlineCompletion.renderer;

import org.eclipse.jface.text.ITextViewer;

import com.tabbyml.tabby4eclipse.inlineCompletion.InlineCompletionItem;

public interface IInlineCompletionItemRenderer {
/**
* Update the inline completion item in the viewer at the current caret
* position.
*
* @param textViewer The viewer to show the inline completion item in.
* @param item The inline completion item to show.
*/
public abstract void updateInlineCompletionItem(ITextViewer textViewer, InlineCompletionItem item);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.tabbyml.tabby4eclipse.inlineCompletion.renderer;

public class InlineCompletionItemRenderer {
public static IInlineCompletionItemRenderer getInstance() {
return LazyHolder.INSTANCE;
}

private static class LazyHolder {
private static final IInlineCompletionItemRenderer INSTANCE = createInstance();
}

public static IInlineCompletionItemRenderer createInstance() {
return new InlineCompletionItemTextPainter();
}
}
Loading

0 comments on commit 86f9dc4

Please sign in to comment.