Skip to content

Commit 3940197

Browse files
committed
feat: inline edit
1 parent 80ba956 commit 3940197

File tree

55 files changed

+4276
-698
lines changed

Some content is hidden

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

55 files changed

+4276
-698
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ git submodule update
9494

9595
**Tailing logs**
9696
```shell
97-
tail -f build/idea-sandbox/system/log/idea.log
97+
tail -f build/idea-sandbox/IC-2024.1.2/log/idea.log
9898
```
9999

100100
## Privacy

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package ee.carlrobert.codegpt;
22

33
import com.intellij.openapi.util.Key;
4+
import ee.carlrobert.codegpt.inlineedit.InlineEditSession;
5+
import ee.carlrobert.codegpt.inlineedit.InlineEditInlayRenderer;
46
import ee.carlrobert.codegpt.predictions.CodeSuggestionDiffViewer;
57
import ee.carlrobert.codegpt.toolwindow.chat.editor.ToolWindowEditorFileDetails;
68
import ee.carlrobert.llm.client.codegpt.CodeGPTUserDetails;
79
import ee.carlrobert.service.NextEditResponse;
810
import ee.carlrobert.service.PartialCodeCompletionResponse;
11+
import javax.swing.JComponent;
912

1013
public class CodeGPTKeys {
1114

@@ -21,6 +24,12 @@ public class CodeGPTKeys {
2124
Key.create("codegpt.isPromptTextFieldDocument");
2225
public static final Key<CodeSuggestionDiffViewer> EDITOR_PREDICTION_DIFF_VIEWER =
2326
Key.create("codegpt.editorPredictionDiffViewer");
27+
public static final Key<InlineEditSession> EDITOR_INLINE_EDIT_SESSION =
28+
Key.create("codegpt.editorInlineEditSession");
29+
public static final Key<InlineEditInlayRenderer> EDITOR_INLINE_EDIT_RENDERER =
30+
Key.create("codegpt.editorInlineEditRenderer");
31+
public static final Key<JComponent> EDITOR_INLINE_EDIT_COMPARE_LINK =
32+
Key.create("codegpt.editorInlineEditCompareLink");
2433
public static final Key<PartialCodeCompletionResponse> REMAINING_CODE_COMPLETION =
2534
Key.create("codegpt.remainingCodeCompletion");
2635
public static final Key<NextEditResponse> REMAINING_PREDICTION_RESPONSE =

src/main/java/ee/carlrobert/codegpt/actions/editor/BaseEditorAction.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,15 @@ public void actionPerformed(@NotNull AnActionEvent event) {
3737
var project = event.getProject();
3838
var editor = event.getData(PlatformDataKeys.EDITOR);
3939
if (editor != null && project != null) {
40-
actionPerformed(project, editor, editor.getSelectionModel().getSelectedText());
40+
var selectedText = editor.getSelectionModel().getSelectedText();
41+
actionPerformed(project, editor, selectedText != null ? selectedText : "");
4142
}
4243
}
4344

4445
public void update(AnActionEvent event) {
4546
Project project = event.getProject();
4647
Editor editor = event.getData(PlatformDataKeys.EDITOR);
47-
boolean menuAllowed = false;
48-
if (editor != null && project != null) {
49-
menuAllowed = editor.getSelectionModel().getSelectedText() != null;
50-
}
48+
boolean menuAllowed = editor != null && project != null;
5149
event.getPresentation().setEnabled(menuAllowed);
5250
}
5351

src/main/java/ee/carlrobert/codegpt/completions/CompletionRequestService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ public EventSource getCommitMessageAsync(
9393
return getChatCompletionAsync(request, eventListener, serviceType, FeatureType.COMMIT_MESSAGE);
9494
}
9595

96-
public EventSource getEditCodeCompletionAsync(
97-
EditCodeCompletionParameters params,
96+
public EventSource getInlineEditCompletionAsync(
97+
InlineEditCompletionParameters params,
9898
CompletionEventListener<String> eventListener) {
9999
var serviceType =
100-
ModelSelectionService.getInstance().getServiceForFeature(FeatureType.EDIT_CODE);
100+
ModelSelectionService.getInstance().getServiceForFeature(FeatureType.INLINE_EDIT);
101101
var request = CompletionRequestFactory
102102
.getFactory(serviceType)
103-
.createEditCodeRequest(params);
104-
return getChatCompletionAsync(request, eventListener, serviceType, FeatureType.EDIT_CODE);
103+
.createInlineEditRequest(params);
104+
return getChatCompletionAsync(request, eventListener, serviceType, FeatureType.INLINE_EDIT);
105105
}
106106

107107
public EventSource getChatCompletionAsync(

src/main/java/ee/carlrobert/codegpt/settings/service/FeatureType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public enum FeatureType {
55
CODE_COMPLETION,
66
AUTO_APPLY,
77
COMMIT_MESSAGE,
8-
EDIT_CODE,
8+
INLINE_EDIT,
99
NEXT_EDIT,
1010
LOOKUP
1111
}

src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ChatToolWindowTabPanel.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@ public ChatToolWindowTabPanel(@NotNull Project project, @NotNull Conversation co
105105
project,
106106
totalTokensPanel,
107107
this,
108+
FeatureType.CHAT,
108109
tagManager,
109110
this::handleSubmit,
110-
this::handleCancel);
111+
this::handleCancel,
112+
true,
113+
true);
111114
userInputPanel.requestFocus();
112115
rootPanel = createRootPanel();
113116

src/main/java/ee/carlrobert/codegpt/toolwindow/chat/structure/data/PsiStructureRepository.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.intellij.openapi.application.ApplicationManager
55
import com.intellij.openapi.application.ReadAction
66
import com.intellij.openapi.components.service
77
import com.intellij.openapi.diagnostic.thisLogger
8+
import com.intellij.openapi.progress.ProcessCanceledException
89
import com.intellij.openapi.project.Project
910
import com.intellij.openapi.util.Disposer
1011
import com.intellij.openapi.vfs.AsyncFileListener
@@ -181,8 +182,11 @@ class PsiStructureRepository(
181182
coroutineContext.ensureActive()
182183
try {
183184
PsiManager.getInstance(project).findFile(virtualFile)
184-
} catch (exc: Exception) {
185-
logger.warn("Failed to find file ${virtualFile.name}", exc)
185+
} catch (ex: Exception) {
186+
if (ex is ProcessCanceledException) {
187+
throw ex
188+
}
189+
logger.warn("Failed to find file ${virtualFile.name}", ex)
186190
null
187191
}
188192
}
@@ -289,4 +293,4 @@ class PsiStructureRepository(
289293
}
290294
}
291295
.toSet()
292-
}
296+
}

src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/textarea/ModelComboBoxAction.java

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,13 @@ public class ModelComboBoxAction extends ComboBoxAction {
6666
private final Project project;
6767
private final List<ServiceType> availableProviders;
6868
private final boolean showConfigureModels;
69+
private final FeatureType featureType;
6970

7071
public ModelComboBoxAction(
7172
Project project,
7273
Consumer<ServiceType> onModelChange,
7374
ServiceType selectedService) {
74-
this(project, onModelChange, selectedService, Arrays.asList(ServiceType.values()), true);
75+
this(project, onModelChange, selectedService, Arrays.asList(ServiceType.values()), true, FeatureType.CHAT);
7576
}
7677

7778
public ModelComboBoxAction(
@@ -80,10 +81,21 @@ public ModelComboBoxAction(
8081
ServiceType selectedProvider,
8182
List<ServiceType> availableProviders,
8283
boolean showConfigureModels) {
84+
this(project, onModelChange, selectedProvider, availableProviders, showConfigureModels, FeatureType.CHAT);
85+
}
86+
87+
public ModelComboBoxAction(
88+
Project project,
89+
Consumer<ServiceType> onModelChange,
90+
ServiceType selectedProvider,
91+
List<ServiceType> availableProviders,
92+
boolean showConfigureModels,
93+
FeatureType featureType) {
8394
this.project = project;
8495
this.onModelChange = onModelChange;
8596
this.availableProviders = availableProviders;
8697
this.showConfigureModels = showConfigureModels;
98+
this.featureType = featureType;
8799
setSmallVariant(true);
88100
updateTemplatePresentation(selectedProvider);
89101

@@ -92,8 +104,12 @@ public ModelComboBoxAction(
92104
ModelChangeNotifier.getTopic(),
93105
new ModelChangeNotifierAdapter() {
94106
@Override
95-
public void chatModelChanged(@NotNull String newModel, @NotNull ServiceType serviceType) {
96-
updateTemplatePresentation(serviceType);
107+
public void modelChanged(@NotNull FeatureType changedFeature,
108+
@NotNull String newModel,
109+
@NotNull ServiceType serviceType) {
110+
if (changedFeature == featureType) {
111+
updateTemplatePresentation(serviceType);
112+
}
97113
}
98114
});
99115
}
@@ -275,12 +291,13 @@ private void updateTemplatePresentation(ServiceType selectedService) {
275291
var application = ApplicationManager.getApplication();
276292
var templatePresentation = getTemplatePresentation();
277293
var chatModel = application.getService(ModelSettings.class).getState()
278-
.getModelSelection(FeatureType.CHAT);
294+
.getModelSelection(featureType);
279295
var modelCode = chatModel != null ? chatModel.getModel() : null;
280296

281297
switch (selectedService) {
282298
case PROXYAI:
283-
var proxyAIModel = ModelRegistry.getInstance().getProxyAIChatModels().stream()
299+
var proxyAIModel = ModelRegistry.getInstance().getAllModelsForFeature(featureType).stream()
300+
.filter(it -> it.getProvider() == PROXYAI)
284301
.filter(it -> modelCode != null && it.getModel().equals(modelCode))
285302
.findFirst();
286303
templatePresentation.setIcon(
@@ -391,7 +408,7 @@ private AnAction createCodeGPTModelAction(ModelSelection model,
391408
var application = ApplicationManager.getApplication();
392409
application
393410
.getService(ModelSettings.class)
394-
.setModel(FeatureType.CHAT, model.getModel(), PROXYAI);
411+
.setModel(featureType, model.getModel(), PROXYAI);
395412

396413
handleModelChange(PROXYAI);
397414
});
@@ -420,7 +437,7 @@ private AnAction createOllamaModelAction(String model, Presentation comboBoxPres
420437
.setModel(model);
421438
application
422439
.getService(ModelSettings.class)
423-
.setModel(FeatureType.CHAT, model, OLLAMA);
440+
.setModel(featureType, model, OLLAMA);
424441
});
425442
}
426443

@@ -434,7 +451,7 @@ private AnAction createOpenAIModelAction(
434451
Icons.OpenAI,
435452
comboBoxPresentation,
436453
() -> ApplicationManager.getApplication().getService(ModelSettings.class)
437-
.setModel(FeatureType.CHAT, model.getCode(), OPENAI));
454+
.setModel(featureType, model.getCode(), OPENAI));
438455
}
439456

440457
private AnAction createCustomOpenAIModelAction(
@@ -446,7 +463,7 @@ private AnAction createCustomOpenAIModelAction(
446463
Icons.OpenAI,
447464
comboBoxPresentation,
448465
() -> ApplicationManager.getApplication().getService(ModelSettings.class)
449-
.setModel(FeatureType.CHAT, model.getName(), CUSTOM_OPENAI));
466+
.setModel(featureType, model.getName(), CUSTOM_OPENAI));
450467
}
451468

452469
private AnAction createGoogleModelAction(GoogleModel model, Presentation comboBoxPresentation) {
@@ -457,7 +474,7 @@ private AnAction createGoogleModelAction(GoogleModel model, Presentation comboBo
457474
Icons.Google,
458475
comboBoxPresentation,
459476
() -> ApplicationManager.getApplication().getService(ModelSettings.class)
460-
.setModel(FeatureType.CHAT, model.getCode(), GOOGLE));
477+
.setModel(featureType, model.getCode(), GOOGLE));
461478
}
462479

463480
private AnAction createAnthropicModelAction(
@@ -470,7 +487,7 @@ private AnAction createAnthropicModelAction(
470487
Icons.Anthropic,
471488
comboBoxPresentation,
472489
() -> ApplicationManager.getApplication().getService(ModelSettings.class)
473-
.setModel(FeatureType.CHAT, modelCode, ANTHROPIC));
490+
.setModel(featureType, modelCode, ANTHROPIC));
474491
}
475492

476493
private AnAction createLlamaModelAction(Presentation comboBoxPresentation) {
@@ -480,7 +497,7 @@ private AnAction createLlamaModelAction(Presentation comboBoxPresentation) {
480497
Icons.Llama,
481498
comboBoxPresentation,
482499
() -> ApplicationManager.getApplication().getService(ModelSettings.class)
483-
.setModel(FeatureType.CHAT,
500+
.setModel(featureType,
484501
LlamaSettings.getCurrentState().getHuggingFaceModel().getCode(), LLAMA_CPP));
485502
}
486503

@@ -492,12 +509,12 @@ private AnAction createMistralModelAction(String modelCode, Presentation comboBo
492509
Icons.Mistral,
493510
comboBoxPresentation,
494511
() -> ApplicationManager.getApplication().getService(ModelSettings.class)
495-
.setModel(FeatureType.CHAT, modelCode, MISTRAL));
512+
.setModel(featureType, modelCode, MISTRAL));
496513
}
497514

498515
private String getMistralPresentationText() {
499516
var chatModel = ApplicationManager.getApplication().getService(ModelSettings.class).getState()
500-
.getModelSelection(FeatureType.CHAT);
517+
.getModelSelection(featureType);
501518
var modelCode = chatModel != null ? chatModel.getModel() : null;
502519
return ModelRegistry.getInstance().getModelDisplayName(MISTRAL, modelCode);
503520
}

src/main/kotlin/ee/carlrobert/codegpt/CodeGPTEditorFactoryListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ class CodeGPTEditorFactoryListener : EditorFactoryListener {
5656
.syncPublisher(EditorNotifier.Released.TOPIC)
5757
.editorReleased(event.editor)
5858
}
59-
}
59+
}

src/main/kotlin/ee/carlrobert/codegpt/CodeGPTProjectActivity.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import com.intellij.openapi.components.service
77
import com.intellij.openapi.project.Project
88
import com.intellij.openapi.startup.ProjectActivity
99
import ee.carlrobert.codegpt.actions.editor.EditorActionsUtil
10-
import ee.carlrobert.codegpt.settings.GeneralSettings
1110
import ee.carlrobert.codegpt.settings.configuration.ConfigurationSettings
12-
import ee.carlrobert.codegpt.settings.service.ServiceType
1311
import ee.carlrobert.codegpt.settings.service.codegpt.CodeGPTService
1412
import ee.carlrobert.codegpt.toolwindow.chat.ui.textarea.AttachImageNotifier
1513
import ee.carlrobert.codegpt.ui.OverlayUtil

0 commit comments

Comments
 (0)