Skip to content

Commit 7387cf4

Browse files
PhilKesJames Higginscarlrobertoh
authored
Inline Autocompletion Pt.2 (#333)
* Add first draft of inline code completion with mock text * Adds InsertInlineTextAction for inserting autocomplete suggestion with tab - Changed to disable suggestions when text is selected - Adds and removes the insert action based on when it shows the inlay hint * Request inline code completion * Move inline completion prompt into txt file * Add inline completion settings to ConfigurationState * Fix code style * Use EditorTrackerListener instead of EditorFactoryListener to enable inline completion * Code completion requests synchronously without SSE * Use LlamaClient.getInfill() for inline code completion * support inlay block element rendering, clean up code * Use only enclosed Method or Class contents for code completion if possible * Refactor extracting PsiElement contents in code completion * bump llm-client * fix completion call from triggering on EDT, force method params to be nonnull by default * refactor request building, decrease delay value * Trigger code completion if cursor is not inside a word * Improve inlay rendering * Support cancellable infill requests * add statusbar widget, disable completions by default * Show error notification if code completion failed * Truely disable/enable EditorInlayHandler when completion is turned off/on * Add CodeCompletionEnabledListener Topic to control enabling/disabling code-completion * Add progress indicator for code-completion with option to cancel * Add CodeCompletionServiceTest + refactor inlay ElementRenderers * several improvements - replace timer implementation with call debouncing - use OpenAI /v1/completions API for completions - code refactoring * trigger progress indicator only for llama completions * fix tests --------- Co-authored-by: James Higgins <[email protected]> Co-authored-by: Carl-Robert Linnupuu <[email protected]>
1 parent 390d8cd commit 7387cf4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1461
-21
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ git submodule update
164164
./gradlew runIde -Penv=win-arm64
165165
```
166166

167+
**Tailing logs**
168+
```shell
169+
tail -f build/idea-sandbox/system/log/idea.log
170+
```
171+
167172
## Issues
168173

169174
See the [open issues][open-issues] for a full list of proposed features (and known issues).

buildSrc/src/main/kotlin/codegpt.java-conventions.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ checkstyle {
2323
}
2424

2525
dependencies {
26-
implementation("ee.carlrobert:llm-client:0.2.0")
26+
implementation("ee.carlrobert:llm-client:0.3.1")
2727
}
2828

2929
tasks {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{pre}{codeBefore}{suf}{codeAfter}{mid}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
package ee.carlrobert.codegpt;
22

3+
import com.intellij.openapi.editor.EditorCustomElementRenderer;
4+
import com.intellij.openapi.editor.Inlay;
35
import com.intellij.openapi.util.Key;
46
import ee.carlrobert.embedding.ReferencedFile;
57
import java.util.List;
68

79
public class CodeGPTKeys {
810

9-
public static final Key<List<ReferencedFile>> SELECTED_FILES = Key.create("selectedFiles");
11+
public static final Key<Inlay<EditorCustomElementRenderer>> SINGLE_LINE_INLAY =
12+
Key.create("codegpt.editor.inlay.single-line");
13+
public static final Key<Inlay<EditorCustomElementRenderer>> MULTI_LINE_INLAY =
14+
Key.create("codegpt.editor.inlay.multi-line");
15+
public static final Key<List<ReferencedFile>> SELECTED_FILES =
16+
Key.create("codegpt.selectedFiles");
1017
}

src/main/java/ee/carlrobert/codegpt/EncodingManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public int countTokens(String text) {
4848
try {
4949
return encoding.countTokens(text);
5050
} catch (Exception ex) {
51-
LOG.error(ex);
51+
LOG.warn(ex);
5252
return 0;
5353
}
5454
}

src/main/java/ee/carlrobert/codegpt/PluginStartupActivity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public class PluginStartupActivity implements StartupActivity {
2222
@Override
2323
public void runActivity(@NotNull Project project) {
2424
EditorActionsUtil.refreshActions();
25-
2625
var authenticationResponse = YouUserManager.getInstance().getAuthenticationResponse();
2726
if (authenticationResponse == null) {
2827
handleYouServiceAuthentication();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ee.carlrobert.codegpt.actions;
2+
3+
import com.intellij.util.messages.Topic;
4+
import com.intellij.util.messages.Topic.BroadcastDirection;
5+
import ee.carlrobert.codegpt.settings.configuration.ConfigurationState;
6+
import java.util.EventListener;
7+
8+
/**
9+
* {@link EventListener} for changes of {@link ConfigurationState#isCodeCompletionsEnabled()}.
10+
*
11+
* @see EnableCompletionsAction
12+
* @see DisableCompletionsAction
13+
*/
14+
public interface CodeCompletionEnabledListener extends EventListener {
15+
16+
/**
17+
* Topic for subscribing to {@link ConfigurationState#isCodeCompletionsEnabled()} changes.<br/>
18+
* Broadcasts from Application-Level to all projects.
19+
*/
20+
@Topic.AppLevel
21+
Topic<CodeCompletionEnabledListener> TOPIC = new Topic<>(CodeCompletionEnabledListener.class,
22+
BroadcastDirection.TO_DIRECT_CHILDREN);
23+
24+
void onCodeCompletionsEnabledChange(boolean codeCompletionsEnabled);
25+
}
26+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package ee.carlrobert.codegpt.actions;
2+
3+
import com.intellij.openapi.actionSystem.AnAction;
4+
import com.intellij.openapi.actionSystem.AnActionEvent;
5+
import com.intellij.openapi.application.ApplicationManager;
6+
import ee.carlrobert.codegpt.codecompletions.CodeGPTEditorManager;
7+
import ee.carlrobert.codegpt.settings.configuration.ConfigurationState;
8+
import org.jetbrains.annotations.NotNull;
9+
10+
/**
11+
* Disables code-completion.<br/> Publishes message to {@link CodeCompletionEnabledListener#TOPIC}
12+
*/
13+
public class DisableCompletionsAction extends AnAction {
14+
15+
@Override
16+
public void actionPerformed(@NotNull AnActionEvent e) {
17+
ConfigurationState.getInstance().setCodeCompletionsEnabled(false);
18+
CodeGPTEditorManager.getInstance().disposeAllInlays(e.getProject());
19+
ApplicationManager.getApplication()
20+
.getMessageBus().syncPublisher(CodeCompletionEnabledListener.TOPIC)
21+
.onCodeCompletionsEnabledChange(false);
22+
}
23+
24+
@Override
25+
public void update(@NotNull AnActionEvent e) {
26+
var codeCompletionEnabled = ConfigurationState.getInstance().isCodeCompletionsEnabled();
27+
e.getPresentation().setEnabled(codeCompletionEnabled);
28+
e.getPresentation().setVisible(codeCompletionEnabled);
29+
}
30+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package ee.carlrobert.codegpt.actions;
2+
3+
import com.intellij.openapi.actionSystem.AnAction;
4+
import com.intellij.openapi.actionSystem.AnActionEvent;
5+
import com.intellij.openapi.application.ApplicationManager;
6+
import ee.carlrobert.codegpt.settings.configuration.ConfigurationState;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
/**
10+
* Enables code-completion.<br/> Publishes message to {@link CodeCompletionEnabledListener#TOPIC}
11+
*/
12+
public class EnableCompletionsAction extends AnAction {
13+
14+
@Override
15+
public void actionPerformed(@NotNull AnActionEvent e) {
16+
ConfigurationState.getInstance().setCodeCompletionsEnabled(true);
17+
ApplicationManager.getApplication()
18+
.getMessageBus().syncPublisher(CodeCompletionEnabledListener.TOPIC)
19+
.onCodeCompletionsEnabledChange(true);
20+
}
21+
22+
@Override
23+
public void update(@NotNull AnActionEvent e) {
24+
var codeCompletionEnabled = ConfigurationState.getInstance().isCodeCompletionsEnabled();
25+
e.getPresentation().setEnabled(!codeCompletionEnabled);
26+
e.getPresentation().setVisible(!codeCompletionEnabled);
27+
}
28+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package ee.carlrobert.codegpt.actions;
2+
3+
import com.intellij.icons.AllIcons.General;
4+
import com.intellij.openapi.actionSystem.AnAction;
5+
import com.intellij.openapi.actionSystem.AnActionEvent;
6+
import com.intellij.openapi.options.ShowSettingsUtil;
7+
import ee.carlrobert.codegpt.CodeGPTBundle;
8+
import ee.carlrobert.codegpt.settings.SettingsConfigurable;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
public class OpenSettingsAction extends AnAction {
12+
13+
public OpenSettingsAction() {
14+
super(CodeGPTBundle.get("action.opensettings.title"),
15+
CodeGPTBundle.get("action.opensettings.description"),
16+
General.Settings);
17+
}
18+
19+
@Override
20+
public void actionPerformed(@NotNull AnActionEvent e) {
21+
ShowSettingsUtil.getInstance().showSettingsDialog(e.getProject(), SettingsConfigurable.class);
22+
}
23+
}

0 commit comments

Comments
 (0)