mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-20 17:52:23 +00:00
fix: several minor errors and warnings
This commit is contained in:
parent
c8d27d878f
commit
f8d4338e86
8 changed files with 54 additions and 40 deletions
|
|
@ -1,6 +1,9 @@
|
|||
package ee.carlrobert.codegpt;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtil;
|
||||
import java.io.File;
|
||||
|
|
@ -46,7 +49,8 @@ public record ReferencedFile(String fileName, String filePath, String fileConten
|
|||
}
|
||||
|
||||
var documentManager = FileDocumentManager.getInstance();
|
||||
var document = documentManager.getDocument(virtualFile);
|
||||
var document = ApplicationManager.getApplication()
|
||||
.runReadAction((Computable<Document>) () -> documentManager.getDocument(virtualFile));
|
||||
if (document != null && documentManager.isDocumentUnsaved(document)) {
|
||||
return document.getText();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,7 +173,8 @@ public class IncludeFilesInContextAction extends AnAction {
|
|||
return encodingManager.countTokens(
|
||||
new String(file.contentsToByteArray(), file.getCharset()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to read file content", e);
|
||||
LOG.error("Failed to read file {} content", file.getName());
|
||||
return 0;
|
||||
}
|
||||
})
|
||||
.sum();
|
||||
|
|
|
|||
|
|
@ -368,31 +368,36 @@ public class ChatToolWindowTabPanel implements Disposable {
|
|||
}
|
||||
|
||||
private Unit handleSubmit(String text) {
|
||||
final Set<ClassStructure> psiStructure;
|
||||
if (psiStructureRepository.getStructureState().getValue()
|
||||
instanceof PsiStructureState.Content content) {
|
||||
psiStructure = content.getElements();
|
||||
} else {
|
||||
psiStructure = new HashSet<>();
|
||||
}
|
||||
var application = ApplicationManager.getApplication();
|
||||
application.executeOnPooledThread(() -> {
|
||||
final Set<ClassStructure> psiStructure;
|
||||
if (psiStructureRepository.getStructureState().getValue()
|
||||
instanceof PsiStructureState.Content content) {
|
||||
psiStructure = content.getElements();
|
||||
} else {
|
||||
psiStructure = new HashSet<>();
|
||||
}
|
||||
|
||||
final var appliedTags = tagManager.getTags().stream()
|
||||
.filter(TagDetails::getSelected)
|
||||
.collect(Collectors.toList());
|
||||
final var appliedTags = tagManager.getTags().stream()
|
||||
.filter(TagDetails::getSelected)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
var messageBuilder = new MessageBuilder(project, text).withInlays(appliedTags);
|
||||
var messageBuilder = new MessageBuilder(project, text).withInlays(appliedTags);
|
||||
|
||||
List<ReferencedFile> referencedFiles = getReferencedFiles(appliedTags);
|
||||
if (!referencedFiles.isEmpty()) {
|
||||
messageBuilder.withReferencedFiles(referencedFiles);
|
||||
}
|
||||
List<ReferencedFile> referencedFiles = getReferencedFiles(appliedTags);
|
||||
if (!referencedFiles.isEmpty()) {
|
||||
messageBuilder.withReferencedFiles(referencedFiles);
|
||||
}
|
||||
|
||||
String attachedImagePath = CodeGPTKeys.IMAGE_ATTACHMENT_FILE_PATH.get(project);
|
||||
if (attachedImagePath != null) {
|
||||
messageBuilder.withImage(attachedImagePath);
|
||||
}
|
||||
String attachedImagePath = CodeGPTKeys.IMAGE_ATTACHMENT_FILE_PATH.get(project);
|
||||
if (attachedImagePath != null) {
|
||||
messageBuilder.withImage(attachedImagePath);
|
||||
}
|
||||
|
||||
sendMessage(messageBuilder.build(), ConversationType.DEFAULT, psiStructure);
|
||||
application.invokeLater(() -> {
|
||||
sendMessage(messageBuilder.build(), ConversationType.DEFAULT, psiStructure);
|
||||
});
|
||||
});
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package ee.carlrobert.codegpt.toolwindow.chat.structure.data
|
|||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.ReadAction
|
||||
import com.intellij.openapi.diagnostic.thisLogger
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.vfs.AsyncFileListener
|
||||
|
|
@ -13,20 +14,7 @@ import com.intellij.psi.PsiManager
|
|||
import com.intellij.util.io.await
|
||||
import ee.carlrobert.codegpt.psistructure.PsiStructureProvider
|
||||
import ee.carlrobert.codegpt.settings.configuration.ConfigurationStateListener
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.CurrentGitChangesTagDetails
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.DocumentationTagDetails
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.EditorSelectionTagDetails
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.EditorTagDetails
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.EmptyTagDetails
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.FileTagDetails
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.FolderTagDetails
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.GitCommitTagDetails
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.PersonaTagDetails
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.SelectionTagDetails
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.TagDetails
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.TagManager
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.TagManagerListener
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.WebTagDetails
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.*
|
||||
import ee.carlrobert.codegpt.util.coroutines.CoroutineDispatchers
|
||||
import ee.carlrobert.codegpt.util.coroutines.DisposableCoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
|
|
@ -46,6 +34,10 @@ class PsiStructureRepository(
|
|||
private val dispatchers: CoroutineDispatchers,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
private val logger = thisLogger()
|
||||
}
|
||||
|
||||
private val mutex = Mutex()
|
||||
private val coroutineScope = DisposableCoroutineScope(dispatchers.io())
|
||||
|
||||
|
|
@ -159,7 +151,12 @@ class PsiStructureRepository(
|
|||
tagsVirtualFiles
|
||||
.mapNotNull { virtualFile ->
|
||||
coroutineContext.ensureActive()
|
||||
PsiManager.getInstance(project).findFile(virtualFile)
|
||||
try {
|
||||
PsiManager.getInstance(project).findFile(virtualFile)
|
||||
} catch (exc: Exception) {
|
||||
logger.error("Failed to find file {}", virtualFile.name)
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
.inSmartMode(project)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import ee.carlrobert.codegpt.CodeGPTKeys
|
|||
import ee.carlrobert.codegpt.codecompletions.CompletionProgressNotifier
|
||||
import ee.carlrobert.codegpt.codecompletions.edit.GrpcClientService
|
||||
import ee.carlrobert.codegpt.util.EditorDiffUtil.createDiffRequest
|
||||
import kotlin.coroutines.cancellation.CancellationException
|
||||
|
||||
@Service
|
||||
class PredictionService {
|
||||
|
|
@ -36,6 +37,8 @@ class PredictionService {
|
|||
try {
|
||||
CompletionProgressNotifier.update(project, true)
|
||||
project.service<GrpcClientService>().getNextEdit(editor, isManuallyOpened)
|
||||
} catch (e: CancellationException) {
|
||||
// ignore
|
||||
} catch (ex: Exception) {
|
||||
logger.error("Error communicating with server: ${ex.message}")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,6 @@ class OllamaSettingsForm {
|
|||
getCredential(OllamaApikey)
|
||||
}
|
||||
}
|
||||
refreshModels(settings.model)
|
||||
}
|
||||
|
||||
fun getForm(): JPanel = FormBuilder.createFormBuilder()
|
||||
|
|
|
|||
|
|
@ -108,7 +108,9 @@ class AutoApplyAction(
|
|||
)
|
||||
}
|
||||
OverlayUtil.showNotification(errorMessage, NotificationType.ERROR)
|
||||
resetState(mainEditor, actionsPanel)
|
||||
runInEdt {
|
||||
resetState(mainEditor, actionsPanel)
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,13 +30,16 @@ object GitUtil {
|
|||
?: repositoryManager.repositories.firstOrNull()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getCurrentChanges(project: Project): String? {
|
||||
return getProjectRepository(project)?.let { repository ->
|
||||
try {
|
||||
val repoRootPath = repository.root.toNioPath()
|
||||
val changes = ChangeListManager.getInstance(project).allChanges
|
||||
.filter { change ->
|
||||
change.virtualFile?.let { !it.fileType.isBinary } ?: false
|
||||
}
|
||||
.sortedBy { it.virtualFile?.timeStamp }
|
||||
|
||||
val patches = IdeaTextPatchBuilder.buildPatch(
|
||||
project, changes, repoRootPath, false, true
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue