-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into develop
- Loading branch information
Showing
51 changed files
with
924 additions
and
604 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
codegpt-core/src/main/resources/prompts/default-completion-system-prompt.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
You are an AI programming assistant. | ||
Follow the user's requirements carefully & to the letter. | ||
Your responses should be informative and logical. | ||
You should always adhere to technical information. | ||
If the user asks for code or technical questions, you must provide code suggestions and adhere to technical information. | ||
If the question is related to a developer, you must respond with content related to a developer. | ||
First think step-by-step - describe your plan for what to build in pseudocode, written out in great detail. | ||
Then output the code in a single code block. | ||
Minimize any other prose. | ||
Keep your answers short and impersonal. | ||
Use Markdown formatting in your answers. | ||
Make sure to include the programming language name at the start of the Markdown code blocks. | ||
Avoid wrapping the whole response in triple backticks. | ||
The user works in an IDE built by JetBrains which has a concept for editors with open files, integrated unit test support, and output pane that shows the output of running the code as well as an integrated terminal. | ||
You can only give one reply for each conversation turn. |
3 changes: 3 additions & 0 deletions
3
codegpt-core/src/main/resources/prompts/fix-compile-errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
I will provide you with a snippet of code that is causing a compilation error. | ||
Your task is to identify the potential causes of the compilation error(s) and propose code solutions to fix them. | ||
Please approach this step by step, explaining your reasoning as you go. |
3 changes: 3 additions & 0 deletions
3
codegpt-core/src/main/resources/prompts/generate-commit-message-system-prompt.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Write a short and descriptive git commit message for the following git diff. | ||
Use imperative mood, present tense, active voice and verbs. | ||
Your entire response will be passed directly into git commit. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package ee.carlrobert.codegpt; | ||
|
||
import com.intellij.openapi.util.Key; | ||
import ee.carlrobert.embedding.CheckedFile; | ||
import ee.carlrobert.embedding.ReferencedFile; | ||
import java.util.List; | ||
|
||
public class CodeGPTKeys { | ||
|
||
public static final Key<List<CheckedFile>> SELECTED_FILES = Key.create("selectedFiles"); | ||
public static final Key<List<ReferencedFile>> SELECTED_FILES = Key.create("selectedFiles"); | ||
} |
109 changes: 109 additions & 0 deletions
109
src/main/java/ee/carlrobert/codegpt/ProjectCompilationStatusListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package ee.carlrobert.codegpt; | ||
|
||
import static ee.carlrobert.codegpt.completions.ConversationType.FIX_COMPILE_ERRORS; | ||
import static java.lang.String.format; | ||
import static java.util.stream.Collectors.joining; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
import com.intellij.compiler.CompilerMessageImpl; | ||
import com.intellij.notification.NotificationAction; | ||
import com.intellij.notification.NotificationType; | ||
import com.intellij.openapi.compiler.CompilationStatusListener; | ||
import com.intellij.openapi.compiler.CompileContext; | ||
import com.intellij.openapi.compiler.CompilerMessage; | ||
import com.intellij.openapi.compiler.CompilerMessageCategory; | ||
import com.intellij.openapi.project.Project; | ||
import ee.carlrobert.codegpt.completions.CompletionRequestProvider; | ||
import ee.carlrobert.codegpt.conversations.message.Message; | ||
import ee.carlrobert.codegpt.settings.configuration.ConfigurationState; | ||
import ee.carlrobert.codegpt.toolwindow.chat.standard.StandardChatToolWindowContentManager; | ||
import ee.carlrobert.codegpt.ui.OverlayUtil; | ||
import ee.carlrobert.embedding.ReferencedFile; | ||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ProjectCompilationStatusListener implements CompilationStatusListener { | ||
|
||
private final Project project; | ||
|
||
public ProjectCompilationStatusListener(Project project) { | ||
this.project = project; | ||
} | ||
|
||
@Override | ||
public void compilationFinished( | ||
boolean aborted, | ||
int errors, | ||
int warnings, | ||
@NotNull CompileContext compileContext) { | ||
var configuration = ConfigurationState.getInstance(); | ||
var success = !configuration.isCaptureCompileErrors() | ||
|| (!aborted && errors == 0 && warnings == 0); | ||
if (success) { | ||
return; | ||
} | ||
if (errors > 0) { | ||
OverlayUtil.getDefaultNotification( | ||
CodeGPTBundle.get("notification.compilationError.description"), | ||
NotificationType.INFORMATION) | ||
.addAction(NotificationAction.createSimpleExpiring( | ||
CodeGPTBundle.get("notification.compilationError.okLabel"), | ||
() -> project.getService(StandardChatToolWindowContentManager.class) | ||
.sendMessage(getMultiFileMessage(compileContext), FIX_COMPILE_ERRORS))) | ||
.addAction(NotificationAction.createSimpleExpiring( | ||
CodeGPTBundle.get("checkForUpdatesTask.notification.hideButton"), | ||
() -> ConfigurationState.getInstance().setCaptureCompileErrors(false))) | ||
.notify(project); | ||
} | ||
} | ||
|
||
private Message getMultiFileMessage(CompileContext compileContext) { | ||
var errorMapping = getErrorMapping(compileContext); | ||
var prompt = errorMapping.values().stream() | ||
.flatMap(Collection::stream) | ||
.collect(joining("\n\n")); | ||
|
||
var message = new Message("Fix the following compile errors:\n\n" + prompt); | ||
message.setReferencedFilePaths(errorMapping.keySet().stream() | ||
.map(ReferencedFile::getFilePath) | ||
.collect(toList())); | ||
message.setUserMessage(message.getPrompt()); | ||
message.setPrompt(CompletionRequestProvider.getPromptWithContext( | ||
new ArrayList<>(errorMapping.keySet()), | ||
prompt)); | ||
return message; | ||
} | ||
|
||
private HashMap<ReferencedFile, List<String>> getErrorMapping(CompileContext compileContext) { | ||
var errorMapping = new HashMap<ReferencedFile, List<String>>(); | ||
for (var compilerMessage : compileContext.getMessages(CompilerMessageCategory.ERROR)) { | ||
var key = new ReferencedFile(new File(compilerMessage.getVirtualFile().getPath())); | ||
var prevValue = errorMapping.get(key); | ||
if (prevValue == null) { | ||
prevValue = new ArrayList<>(); | ||
} | ||
prevValue.add(getCompilerErrorDetails(compilerMessage)); | ||
errorMapping.put(key, prevValue); | ||
} | ||
return errorMapping; | ||
} | ||
|
||
private String getCompilerErrorDetails(CompilerMessage compilerMessage) { | ||
if (compilerMessage instanceof CompilerMessageImpl) { | ||
return format( | ||
"%s:%d:%d - `%s`", | ||
compilerMessage.getVirtualFile().getName(), | ||
((CompilerMessageImpl) compilerMessage).getLine(), | ||
((CompilerMessageImpl) compilerMessage).getColumn(), | ||
compilerMessage.getMessage()); | ||
} | ||
return format( | ||
"%s - `%s`", | ||
compilerMessage.getVirtualFile().getName(), | ||
compilerMessage.getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.