Skip to content

Commit

Permalink
feat(eclipse): add preferences page. (#3225)
Browse files Browse the repository at this point in the history
  • Loading branch information
icycodes authored Sep 30, 2024
1 parent 7219f6e commit aa6b933
Show file tree
Hide file tree
Showing 17 changed files with 327 additions and 30 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.20"
version="0.0.2.21"
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.20"/>
version="0.0.2.21"/>

</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.20
Bundle-Version: 0.0.2.21
Bundle-Activator: com.tabbyml.tabby4eclipse.Activator
Bundle-Vendor: com.tabbyml
Require-Bundle: org.eclipse.ui,
Expand Down
Binary file added clients/eclipse/plugin/images/settings.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/settings@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions clients/eclipse/plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
</contentTypeMapping>
</extension>

<extension
point="org.eclipse.ui.preferencePages">
<page
id="com.tabbyml.tabby4eclipse.preferences.main"
name="Tabby"
class="com.tabbyml.tabby4eclipse.preferences.MainPreferencesPage">
</page>
</extension>

<extension point="org.eclipse.ui.views">
<category
name="Tabby"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Images {
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 final String ICON_SETTINGS = "settings.png";

public static Image getIcon(String filename) {
Image icon = icons.get(filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.tabbyml.tabby4eclipse.editor.WorkbenchPartListener;
import com.tabbyml.tabby4eclipse.lsp.LanguageServerService;
import com.tabbyml.tabby4eclipse.preferences.PreferencesService;

public class Startup implements IStartup {

Expand All @@ -16,6 +17,8 @@ public void earlyStartup() {
lsService.init();
WorkbenchPartListener workbenchPartListener = WorkbenchPartListener.getInstance();
workbenchPartListener.init();
PreferencesService preferenceService = PreferencesService.getInstance();
preferenceService.init();
logger.info("Finished running startup actions.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.tabbyml.tabby4eclipse.commands;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

import com.tabbyml.tabby4eclipse.preferences.MainPreferencesPage;

public class OpenPreferences extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
MainPreferencesPage.openPreferences();
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void handleEvent() {
logger.debug("offset cahnged, check next...");
if (modificationStamp != lastModificationStamp) {
logger.debug("modificationStamp changed, trigger inline completion.");
inlineCompletionService.trigger();
inlineCompletionService.trigger(false);
} else {
logger.debug("modificationStamp not changed, dismiss inline completion.");
inlineCompletionService.dismiss();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void unregister(ITextEditor textEditor) {
try {
EditorUtils.syncExec(() -> {
logger.debug("Trigger inline completion after debouncing.");
inlineCompletionService.trigger();
inlineCompletionService.trigger(false);
});
} catch (Exception e) {
logger.error("Failed to handle documentChangedRunnable after debouncing.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public interface IInlineCompletionService {

/**
* Trigger an inline completion request at the current caret position of the
* active text editor.
* active text editor.
*
* @param isManualTrigger whether to trigger manually or automatically
*/
public void trigger();
public void trigger(boolean isManualTrigger);

/**
* Accept the current completion item ghost text.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.tabbyml.tabby4eclipse.lsp.protocol.ITelemetryService;
import com.tabbyml.tabby4eclipse.lsp.protocol.ITextDocumentServiceExt;
import com.tabbyml.tabby4eclipse.lsp.protocol.InlineCompletionParams;
import com.tabbyml.tabby4eclipse.preferences.PreferencesService;

public class InlineCompletionService implements IInlineCompletionService {
public static IInlineCompletionService getInstance() {
Expand Down Expand Up @@ -62,7 +63,11 @@ public boolean isValid() {
}

@Override
public void trigger() {
public void trigger(boolean isManualTrigger) {
boolean autoTriggerEnabled = PreferencesService.getInstance().getInlineCompletionTriggerAuto();
if (!autoTriggerEnabled && !isManualTrigger) {
return;
}
ITextEditor textEditor = EditorUtils.getActiveTextEditor();
int offset = EditorUtils.getCurrentOffsetInDocument(textEditor);
long modificationStamp = EditorUtils.getDocumentModificationStamp(textEditor);
Expand All @@ -79,7 +84,7 @@ public void trigger() {

ITextViewer textViewer = EditorUtils.getTextViewer(textEditor);
InlineCompletionContext.Request request = new InlineCompletionContext.Request(textEditor, offset,
modificationStamp);
modificationStamp, isManualTrigger);
InlineCompletionParams params = request.toInlineCompletionParams();
if (params == null) {
return;
Expand Down Expand Up @@ -118,7 +123,7 @@ public void accept() {
int offset = current.request.offset;
InlineCompletionItem item = current.response.getActiveCompletionItem();
EventParams eventParams = buildTelemetryEventParams(EventParams.Type.SELECT);

renderer.hide();
current = null;

Expand Down Expand Up @@ -162,7 +167,7 @@ public void dismiss() {
private EventParams buildTelemetryEventParams(String type) {
return buildTelemetryEventParams(type, null);
}

private EventParams buildTelemetryEventParams(String type, String selectKind) {
InlineCompletionItem item = this.renderer.getCurrentCompletionItem();
if (item != null && item == current.response.getActiveCompletionItem()) {
Expand All @@ -176,12 +181,11 @@ private EventParams buildTelemetryEventParams(String type, String selectKind) {
}
return null;
}

private void postTelemetryEvent(EventParams params) {
if (params != null) {
LanguageServerService.getInstance().getServer().execute((server) -> {
ITelemetryService telemetryService = ((ILanguageServer) server)
.getTelemetryService();
ITelemetryService telemetryService = ((ILanguageServer) server).getTelemetryService();
telemetryService.event(params);
return null;
});
Expand All @@ -198,12 +202,12 @@ private static class Request {
private long modificationStamp;
private boolean manually;

public Request(ITextEditor textEditor, int offset, long modificationStamp) {
public Request(ITextEditor textEditor, int offset, long modificationStamp, boolean manually) {
this.textEditor = textEditor;
this.document = EditorUtils.getDocument(textEditor);
this.offset = offset;
this.modificationStamp = modificationStamp;
this.manually = false;
this.manually = manually;
}

public InlineCompletionParams toInlineCompletionParams() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void handleCaretMoved(ITextEditor textEditor, CaretEvent event) {
if (pendingEvent != null && pendingEvent.textEditor == textEditor) {
if (pendingEvent.documentEvent != null && pendingEvent.modificationStamp == modificationStamp) {
logger.debug("Received caretEvent with paired documentEvent, trigger inline completion.");
inlineCompletionService.trigger();
inlineCompletionService.trigger(false);
pendingEvent = null;
} else {
logger.debug("Received caretEvent, waiting for paired documentEvent.");
Expand Down Expand Up @@ -130,7 +130,7 @@ private void handleDocumentChanged(ITextEditor textEditor, DocumentEvent event)
if (pendingEvent != null && pendingEvent.textEditor == textEditor) {
if (pendingEvent.caretEvent != null && pendingEvent.modificationStamp == modificationStamp) {
logger.debug("Received documentEvent with paired caretEvent, trigger inline completion.");
inlineCompletionService.trigger();
inlineCompletionService.trigger(false);
pendingEvent = null;
} else {
logger.debug("Received documentEvent, waiting for paired caretEvent.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.tabbyml.tabby4eclipse.lsp.protocol.ClientInfo.TabbyPluginInfo;
import com.tabbyml.tabby4eclipse.lsp.protocol.ClientProvidedConfig;
import com.tabbyml.tabby4eclipse.lsp.protocol.InitializationOptions;
import com.tabbyml.tabby4eclipse.preferences.PreferencesService;

public class ConnectionProvider extends ProcessStreamConnectionProvider {
private Logger logger = new Logger("ConnectionProvider");
Expand All @@ -31,24 +32,42 @@ public ConnectionProvider() {
try {
// Find node executable
File nodeExecutableFile = null;
String systemPath = System.getenv("PATH");
logger.debug("System env PATH: " + systemPath);
if (systemPath != null) {
String[] paths = systemPath.split(File.pathSeparator);
for (String p : paths) {
File file = new File(p, Utils.isWindows() ? "node.exe" : "node");
if (file.exists() && file.canExecute()) {
nodeExecutableFile = file;
logger.debug("Node executable: " + file.getAbsolutePath());
break;

String nodePathFromPreference = PreferencesService.getInstance().getNodeBinaryPath();
if (nodePathFromPreference != null && !nodePathFromPreference.isEmpty()) {
String nodePath = nodePathFromPreference.replaceFirst("~", System.getProperty("user.home"));
logger.info("Node executable path from preference: " + nodePath);
File file = new File(nodePath);
if (file.exists() && file.canExecute()) {
nodeExecutableFile = file;
} else {
logger.info("Cannot find node executable in: " + nodePath);
}
}

if (nodeExecutableFile == null) {
String systemPath = System.getenv("PATH");
logger.info("Finding node executable in system paths: " + systemPath);
if (systemPath != null) {
String[] paths = systemPath.split(File.pathSeparator);
for (String p : paths) {
File file = new File(p, Utils.isWindows() ? "node.exe" : "node");
if (file.exists() && file.canExecute()) {
nodeExecutableFile = file;
break;
}
}
}
}

if (nodeExecutableFile == null) {
StatusInfoHolder.getInstance().setConnectionFailed(true);
logger.error("Cannot find node executable.");
return;
} else {
logger.info("Using node executable: " + nodeExecutableFile.getAbsolutePath());
}

// Find tabby-agent script
Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
URL agentScriptUrl = FileLocator.find(bundle, new Path("tabby-agent/dist/node/index.js"));
Expand Down Expand Up @@ -87,8 +106,7 @@ public void stop() {
}

private ClientProvidedConfig getProvidedConfig() {
ClientProvidedConfig config = new ClientProvidedConfig();
return config;
return PreferencesService.getInstance().buildClientProvidedConfig();
}

private ClientInfo getClientInfo() {
Expand Down
Loading

0 comments on commit aa6b933

Please sign in to comment.