├── src ├── me │ └── masecla │ │ └── copilot │ │ ├── extra │ │ ├── Pair.java │ │ └── Logger.java │ │ ├── Activator.java │ │ └── CopilotActionSet.java └── com │ └── github │ └── copilot │ ├── actions │ ├── CopilotAction.java │ ├── DisableGlobalCopilotCompletionsAction.java │ ├── LoginToGitHubAction.java │ ├── DisableFileCopilotCompletionsAction.java │ ├── CopilotToggleCacheAction.java │ ├── CycleNextEditorInlays.java │ ├── CyclePreviousEditorInlays.java │ ├── OpenCopilotAction.java │ ├── LogoutFromGitHubAction.java │ ├── CopilotRequestCompletionsAction.java │ ├── RefreshCopilotToolWindowAction.java │ ├── CopilotDisposeInlaysAction.java │ ├── CopilotActionPromoter.java │ └── EnableCopilotCompletionsAction.java │ ├── lang │ ├── prompt │ │ ├── PathMarker.java │ │ ├── LanguageMarker.java │ │ ├── LocalImportContext.java │ │ ├── SiblingOption.java │ │ └── PromptLanguageSupport.java │ ├── agent │ │ ├── commands │ │ │ ├── SignInInitiateSignedInResult.java │ │ │ ├── SignOutCommand.java │ │ │ ├── SignInConfirmCommand.java │ │ │ ├── SignInInitiateCommand.java │ │ │ ├── RecordTelemetryConsentCommand.java │ │ │ ├── GetCompletionsCyclingCommand.java │ │ │ ├── CheckStatusCommand.java │ │ │ ├── NotifyShownCommand.java │ │ │ ├── NotifyAcceptedCommand.java │ │ │ ├── NotifyRejectedCommand.java │ │ │ ├── SignInInitiateResult.java │ │ │ ├── Range.java │ │ │ ├── Position.java │ │ │ └── GetCompletionsCommand.java │ │ ├── rpc │ │ │ ├── JsonRpcNotification.java │ │ │ ├── JsonRpcMessageHandler.java │ │ │ ├── JsonRpcCommand.java │ │ │ ├── JsonRpcMessageParser.java │ │ │ ├── JsonRpcCommandSender.java │ │ │ ├── NullCommandSender.java │ │ │ ├── StoringJsonRpcMessageHandler.java │ │ │ ├── JsonRpcErrorException.java │ │ │ ├── JsonRpcResponse.java │ │ │ └── JsonRPC.java │ │ ├── NotAuthenticatedException.java │ │ ├── CopilotAgent.java │ │ ├── CopilotAgentProcessService.java │ │ ├── ToggleAgentServiceAction.java │ │ ├── GitHubDelegatingTestService.java │ │ ├── CopilotAgentUtil.java │ │ ├── AgentCompletion.java │ │ └── vscodeRpc │ │ │ ├── VSCodeJsonRpcCommandSender.java │ │ │ ├── VSCodeJsonRpcParser.java │ │ │ └── ByteArray.java │ ├── IsValidBlockFunction.java │ ├── CommonLanguageSupport.java │ ├── fallback │ │ └── VSCodeLanguageMap.java │ └── LanguageSupport.java │ ├── completions │ ├── CopilotCompletionType.java │ ├── CopilotCompletion.java │ ├── CopilotEditorInlay.java │ ├── CopilotInlayList.java │ ├── CompletionCache.java │ ├── CopilotCompletionService.java │ └── DefaultCopilotEditorInlay.java │ ├── CopilotBuildConfig.java │ ├── CopilotSessionId.java │ ├── util │ ├── ObjectToIntFunction.java │ ├── RequestTimeoutException.java │ ├── RequestCancelledException.java │ ├── Cancellable.java │ ├── CharSequenceUtil.java │ ├── ApplicationUtil.java │ ├── Maps.java │ ├── VfsUtil.java │ └── String2DoubleMap.java │ ├── CopilotExecutors.java │ ├── editor │ ├── InlayDisposeContext.java │ ├── InlayMessage.java │ ├── CopilotInlayRenderer.java │ ├── InlayUtils.java │ ├── CopilotEditorSupport.java │ ├── CompletionPopupInhibitor.java │ ├── CopilotLookupListener.java │ ├── EditorSelectionListener.java │ ├── CopilotDisposeInlaysEditorHandler.java │ └── CopilotEditorTestManager.java │ ├── request │ ├── RequestId.java │ ├── LanguageEditorRequest.java │ ├── BlockMode.java │ ├── CompletionType.java │ ├── EditorRequestUtil.java │ └── EditorRequest.java │ ├── github │ ├── UnauthorizedTokenCallback.java │ ├── GitHubSession.java │ ├── GitHubAuthUtil.java │ ├── GitHubService.java │ ├── DeviceLoginDialog.java │ └── GitHubCopilotToken.java │ ├── CopilotLifecycleService.java │ ├── status │ ├── CopilotStatusListener.java │ ├── CopilotStatus.java │ └── CopilotStatusService.java │ ├── openai │ ├── IncompatibleCopilotClientException.java │ ├── CopilotLanguage.java │ ├── OpenAIService.java │ ├── APIJsonDataStreaming.java │ ├── APIChoice.java │ ├── TelemetryUtil.java │ ├── OpenAI.java │ ├── StringDoublePair.java │ └── OpenAITestService.java │ ├── toolWindow │ ├── SmallButton.java │ ├── ToolWindowUtil.java │ ├── OpenCopilotDisableReaderModeMatcher.java │ ├── OpenCopilotEditorManagerListener.java │ └── DataProviderPanel.java │ ├── settings │ ├── ColorConverter.java │ ├── UpdateChannel.java │ ├── ZonedDateTimeConverter.java │ ├── LanguageChoice.java │ ├── CopilotLocalApplicationSettings.java │ └── CopilotLocalApplicationState.java │ ├── CopilotIcons.java │ ├── CopilotBundle.java │ ├── telemetry │ ├── CopilotTestExceptionAction.java │ ├── CopilotActionListener.java │ ├── TelemetryService.java │ └── CopilotContextInitializer.java │ ├── statusBar │ └── CopilotWidgetFactory.java │ ├── update │ ├── CopilotUpdateStartupActivity.java │ └── CopilotEarlyBirdChannelStartupActivity.java │ ├── CopilotNotifications.java │ ├── CopilotPlugin.java │ └── intentions │ └── OpenCopilotIntention.java ├── icons └── copilot │ ├── copilot16.png │ ├── copilot32.png │ └── copilot64.png ├── README.md ├── .gitignore ├── META-INF └── MANIFEST.MF ├── LICENSE └── plugin.xml /src/me/masecla/copilot/extra/Pair.java: -------------------------------------------------------------------------------- 1 | package me.masecla.copilot.extra; 2 | 3 | public class Pair { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /icons/copilot/copilot16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masecla22/eclipse-github-copilot-integration/HEAD/icons/copilot/copilot16.png -------------------------------------------------------------------------------- /icons/copilot/copilot32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masecla22/eclipse-github-copilot-integration/HEAD/icons/copilot/copilot32.png -------------------------------------------------------------------------------- /icons/copilot/copilot64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masecla22/eclipse-github-copilot-integration/HEAD/icons/copilot/copilot64.png -------------------------------------------------------------------------------- /src/com/github/copilot/actions/CopilotAction.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.actions; 2 | 3 | public interface CopilotAction { 4 | } 5 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/prompt/PathMarker.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.lang.prompt; 2 | 3 | public enum PathMarker { 4 | NoMarker, Top, Always; 5 | 6 | } 7 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/prompt/LanguageMarker.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.lang.prompt; 2 | 3 | public enum LanguageMarker { 4 | NoMarker, Top, Always; 5 | 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # eclipse-github-copilot-integration 2 | This is an open source implementation of the Github Copilot AI Model based on reverse engineering of the VSCode and IDEA plugins. 3 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/prompt/LocalImportContext.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.lang.prompt; 2 | 3 | public enum LocalImportContext { 4 | NoContext, Declarations; 5 | 6 | } 7 | -------------------------------------------------------------------------------- /src/com/github/copilot/completions/CopilotCompletionType.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.completions; 2 | 3 | public enum CopilotCompletionType { 4 | Inline, AfterLineEnd, Block; 5 | 6 | } 7 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/prompt/SiblingOption.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.lang.prompt; 2 | 3 | public enum SiblingOption { 4 | NoSiblings, SiblingsOverContext, ContextOverSiblings; 5 | 6 | } 7 | -------------------------------------------------------------------------------- /src/com/github/copilot/CopilotBuildConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot; 2 | 3 | public final class CopilotBuildConfig { 4 | public static final boolean AGENT_ENABLED = false; 5 | 6 | private CopilotBuildConfig() { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/com/github/copilot/CopilotSessionId.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot; 2 | 3 | import java.util.UUID; 4 | 5 | public final class CopilotSessionId { 6 | public static final String SESSION_ID = UUID.randomUUID().toString(); 7 | 8 | private CopilotSessionId() { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/commands/SignInInitiateSignedInResult.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.lang.agent.commands; 2 | 3 | public class SignInInitiateSignedInResult implements SignInInitiateResult { 4 | @Override 5 | public boolean isAlreadySignedIn() { 6 | return true; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/rpc/JsonRpcNotification.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | */ 7 | package com.github.copilot.lang.agent.rpc; 8 | 9 | public interface JsonRpcNotification { 10 | public String getCommandName(); 11 | } 12 | -------------------------------------------------------------------------------- /src/com/github/copilot/util/ObjectToIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | */ 7 | package com.github.copilot.util; 8 | 9 | @FunctionalInterface 10 | public interface ObjectToIntFunction { 11 | public int apply(T var1); 12 | } 13 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/rpc/JsonRpcMessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | */ 7 | package com.github.copilot.lang.agent.rpc; 8 | 9 | public interface JsonRpcMessageHandler { 10 | public void handleJsonMessage(String var1); 11 | } 12 | -------------------------------------------------------------------------------- /src/com/github/copilot/util/RequestTimeoutException.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.util; 2 | 3 | public class RequestTimeoutException extends RuntimeException { 4 | /** 5 | * 6 | */ 7 | private static final long serialVersionUID = 3700784861493313857L; 8 | 9 | public RequestTimeoutException(String message) { 10 | super(message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/com/github/copilot/util/RequestCancelledException.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.util; 2 | 3 | public class RequestCancelledException extends RuntimeException { 4 | /** 5 | * 6 | */ 7 | private static final long serialVersionUID = -7197561304457046782L; 8 | 9 | public RequestCancelledException(String message) { 10 | super(message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/rpc/JsonRpcCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | */ 7 | package com.github.copilot.lang.agent.rpc; 8 | 9 | public interface JsonRpcCommand { 10 | public String getCommandName(); 11 | 12 | public Class getResponseType(); 13 | } 14 | -------------------------------------------------------------------------------- /src/com/github/copilot/actions/DisableGlobalCopilotCompletionsAction.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.actions; 2 | 3 | import com.github.copilot.actions.AbstractDisableCopilotCompletionsAction; 4 | 5 | public class DisableGlobalCopilotCompletionsAction extends AbstractDisableCopilotCompletionsAction { 6 | public DisableGlobalCopilotCompletionsAction() { 7 | super(false); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/com/github/copilot/util/Cancellable.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.util; 2 | 3 | public interface Cancellable { 4 | public static final Cancellable DUMB = new Cancellable() { 5 | 6 | @Override 7 | public boolean isCancelled() { 8 | return false; 9 | } 10 | 11 | @Override 12 | public void cancel() { 13 | } 14 | }; 15 | 16 | public boolean isCancelled(); 17 | 18 | public void cancel(); 19 | } 20 | -------------------------------------------------------------------------------- /src/com/github/copilot/CopilotExecutors.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot; 2 | 3 | import java.util.concurrent.Executor; 4 | import java.util.concurrent.Executors; 5 | 6 | public final class CopilotExecutors { 7 | private static final Executor EXECUTOR = Executors.newFixedThreadPool(5); 8 | 9 | private CopilotExecutors() { 10 | } 11 | 12 | public static Executor getExecutor() { 13 | return EXECUTOR; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/rpc/JsonRpcMessageParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * javax.annotation.concurrent.NotThreadSafe 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.lang.agent.rpc; 9 | 10 | public interface JsonRpcMessageParser { 11 | public void append(String var1); 12 | 13 | public void close(); 14 | } 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | .project 25 | .classpath 26 | bin/ 27 | .settings/ 28 | -------------------------------------------------------------------------------- /src/com/github/copilot/editor/InlayDisposeContext.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.editor; 2 | 3 | public enum InlayDisposeContext { 4 | UserAction, IdeCompletion, CaretChange, SettingsChange, Cycling, TypingAsSuggested, Typing, Applied; 5 | 6 | public boolean isResetLastRequest() { 7 | return this == SettingsChange || this == Applied; 8 | } 9 | 10 | public boolean isSendRejectedTelemetry() { 11 | return this == UserAction; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/IsValidBlockFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.psi.PsiElement 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.lang; 9 | 10 | import com.intellij.psi.PsiElement; 11 | 12 | @FunctionalInterface 13 | public interface IsValidBlockFunction { 14 | public boolean isValidBlock(PsiElement var1, boolean var2); 15 | } 16 | -------------------------------------------------------------------------------- /src/com/github/copilot/request/RequestId.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.request; 2 | 3 | import java.util.concurrent.atomic.AtomicInteger; 4 | 5 | public final class RequestId { 6 | private static final AtomicInteger REQUEST_ID_SEQUENCE = new AtomicInteger(); 7 | 8 | public static int currentRequestId() { 9 | return REQUEST_ID_SEQUENCE.get(); 10 | } 11 | 12 | public static int incrementAndGet() { 13 | return REQUEST_ID_SEQUENCE.incrementAndGet(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/com/github/copilot/github/UnauthorizedTokenCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.project.Project 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.github; 9 | 10 | import com.intellij.openapi.project.Project; 11 | 12 | @FunctionalInterface 13 | public interface UnauthorizedTokenCallback { 14 | public void onUnauthorizedToken(Project var1, String var2); 15 | } 16 | -------------------------------------------------------------------------------- /src/com/github/copilot/editor/InlayMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * javax.annotation.concurrent.Immutable 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.editor; 9 | 10 | import com.github.copilot.request.EditorRequest; 11 | import javax.annotation.concurrent.Immutable; 12 | 13 | @Immutable 14 | public interface InlayMessage { 15 | public void inlaysUpdated(EditorRequest var1); 16 | } 17 | -------------------------------------------------------------------------------- /META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Copilot 4 | Bundle-SymbolicName: me.masecla.copilot;singleton:=true 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-Activator: me.masecla.copilot.Activator 7 | Require-Bundle: org.eclipse.ui, 8 | org.eclipse.core.runtime, 9 | org.apache.felix.scr, 10 | org.eclipse.equinox.event 11 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 12 | Automatic-Module-Name: me.masecla.copilot 13 | Import-Package: javax.inject 14 | Bundle-ActivationPolicy: lazy 15 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/NotAuthenticatedException.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.lang.agent; 2 | 3 | public class NotAuthenticatedException extends RuntimeException { 4 | /** 5 | * 6 | */ 7 | private static final long serialVersionUID = 7892010992008546360L; 8 | private final int requestId; 9 | 10 | public NotAuthenticatedException(int requestId) { 11 | super("Not signed in to Copilot agent"); 12 | this.requestId = requestId; 13 | } 14 | 15 | public int getRequestId() { 16 | return this.requestId; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/rpc/JsonRpcCommandSender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * javax.annotation.concurrent.ThreadSafe 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.lang.agent.rpc; 9 | 10 | import java.io.IOException; 11 | 12 | public interface JsonRpcCommandSender { 13 | public void sendCommand(int var1, JsonRpcCommand var2) throws IOException; 14 | 15 | public void sendNotification(JsonRpcNotification var1) throws IOException; 16 | } 17 | -------------------------------------------------------------------------------- /src/com/github/copilot/CopilotLifecycleService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.Disposable 6 | * me.masecla.copilot.extra.Logger 7 | */ 8 | package com.github.copilot; 9 | 10 | import com.intellij.openapi.Disposable; 11 | import me.masecla.copilot.extra.Logger; 12 | 13 | public class CopilotLifecycleService implements Disposable { 14 | public void dispose() { 15 | Logger.getInstance(CopilotLifecycleService.class).warn("Disposing Copilot lifecycle service"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/github/copilot/completions/CopilotCompletion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | * org.jetbrains.annotations.Nullable 7 | */ 8 | package com.github.copilot.completions; 9 | 10 | import java.util.List; 11 | 12 | public interface CopilotCompletion { 13 | public List getCompletion(); 14 | 15 | public CopilotCompletion asCached(); 16 | 17 | public CopilotCompletion withoutPrefix(String var1); 18 | 19 | public CopilotCompletion withCompletion(List var1); 20 | } 21 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/commands/SignOutCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | */ 7 | package com.github.copilot.lang.agent.commands; 8 | 9 | import com.github.copilot.lang.agent.rpc.JsonRpcCommand; 10 | 11 | public class SignOutCommand implements JsonRpcCommand { 12 | @Override 13 | public String getCommandName() { 14 | return "signOut"; 15 | } 16 | 17 | @Override 18 | public Class getResponseType() { 19 | return AuthStatusResult.class; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/github/copilot/request/LanguageEditorRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.psi.PsiFile 6 | * org.jetbrains.annotations.NotNull 7 | * org.jetbrains.annotations.Nullable 8 | */ 9 | package com.github.copilot.request; 10 | 11 | import com.github.copilot.lang.LanguageSupport; 12 | import com.github.copilot.request.EditorRequest; 13 | import com.intellij.psi.PsiFile; 14 | 15 | public interface LanguageEditorRequest extends EditorRequest { 16 | public LanguageSupport getLanguage(); 17 | 18 | public PsiFile createFile(); 19 | } 20 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/commands/SignInConfirmCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | */ 7 | package com.github.copilot.lang.agent.commands; 8 | 9 | import com.github.copilot.lang.agent.rpc.JsonRpcCommand; 10 | 11 | public class SignInConfirmCommand implements JsonRpcCommand { 12 | @Override 13 | public String getCommandName() { 14 | return "signInConfirm"; 15 | } 16 | 17 | @Override 18 | public Class getResponseType() { 19 | return AuthStatusResult.class; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/commands/SignInInitiateCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | */ 7 | package com.github.copilot.lang.agent.commands; 8 | 9 | import com.github.copilot.lang.agent.rpc.JsonRpcCommand; 10 | 11 | public class SignInInitiateCommand implements JsonRpcCommand { 12 | @Override 13 | public String getCommandName() { 14 | return "signInInitiate"; 15 | } 16 | 17 | @Override 18 | public Class getResponseType() { 19 | return SignInInitiateResult.class; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/github/copilot/status/CopilotStatusListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.util.messages.Topic 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.status; 9 | 10 | import com.github.copilot.status.CopilotStatus; 11 | import com.intellij.util.messages.Topic; 12 | 13 | @FunctionalInterface 14 | public interface CopilotStatusListener { 15 | public static final Topic TOPIC = Topic.create((String) "copilot.status", 16 | CopilotStatusListener.class); 17 | 18 | public void onCopilotStatus(CopilotStatus var1); 19 | } 20 | -------------------------------------------------------------------------------- /src/com/github/copilot/completions/CopilotEditorInlay.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | */ 7 | package com.github.copilot.completions; 8 | 9 | import java.util.List; 10 | 11 | public interface CopilotEditorInlay { 12 | public CopilotCompletionType getType(); 13 | 14 | public List getLines(); 15 | 16 | public int getEditorOffset(); 17 | 18 | default public boolean isEmptyCompletion() { 19 | List completion = this.getLines(); 20 | return completion.isEmpty() || completion.size() == 1 && completion.get(0).isEmpty(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/commands/RecordTelemetryConsentCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | */ 7 | package com.github.copilot.lang.agent.commands; 8 | 9 | import com.github.copilot.lang.agent.rpc.JsonRpcCommand; 10 | 11 | public class RecordTelemetryConsentCommand implements JsonRpcCommand { 12 | @Override 13 | public String getCommandName() { 14 | return "recordTelemetryConsent"; 15 | } 16 | 17 | @Override 18 | public Class getResponseType() { 19 | return AuthStatusResult.class; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/github/copilot/util/CharSequenceUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | */ 7 | package com.github.copilot.util; 8 | 9 | public final class CharSequenceUtil { 10 | public static int lastIndexOf(CharSequence text, char ch) { 11 | if (text == null) { 12 | throw new IllegalStateException("text cannot be null!"); 13 | } 14 | if (text instanceof String) { 15 | return ((String) text).lastIndexOf(ch); 16 | } 17 | for (int i = text.length() - 1; i >= 0; --i) { 18 | if (text.charAt(i) != ch) 19 | continue; 20 | return i; 21 | } 22 | return -1; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/com/github/copilot/openai/IncompatibleCopilotClientException.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.openai; 2 | 3 | public class IncompatibleCopilotClientException extends RuntimeException { 4 | /** 5 | * 6 | */ 7 | private static final long serialVersionUID = -2534703696185010188L; 8 | private final int statusCode; 9 | 10 | public IncompatibleCopilotClientException(int statusCode) { 11 | super("plugin outdated"); 12 | this.statusCode = statusCode; 13 | } 14 | 15 | public int getStatusCode() { 16 | return this.statusCode; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return "IncompatibleCopilotClientException(statusCode=" + this.getStatusCode() + ")"; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/commands/GetCompletionsCyclingCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | * org.jetbrains.annotations.Nullable 7 | */ 8 | package com.github.copilot.lang.agent.commands; 9 | 10 | import java.util.Map; 11 | 12 | public class GetCompletionsCyclingCommand extends GetCompletionsCommand { 13 | public GetCompletionsCyclingCommand(Document doc, Map options) { 14 | super(doc, options); 15 | if (doc == null) { 16 | throw new IllegalStateException("doc cannot be null!"); 17 | } 18 | } 19 | 20 | @Override 21 | public String getCommandName() { 22 | return "getCompletionsCycling"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/me/masecla/copilot/extra/Logger.java: -------------------------------------------------------------------------------- 1 | package me.masecla.copilot.extra; 2 | 3 | public class Logger { 4 | public static Logger getInstance(Class clazz) { 5 | return new Logger(); 6 | } 7 | 8 | public void warn(String s, Throwable e) { 9 | 10 | } 11 | 12 | public void debug(String string) { 13 | 14 | } 15 | 16 | public void error(String string, Throwable e) { 17 | 18 | } 19 | 20 | public void trace(String format) { 21 | 22 | } 23 | 24 | public boolean isTraceEnabled() { 25 | return true; 26 | } 27 | 28 | public void error(String string) { 29 | 30 | } 31 | 32 | public void warn(String string) { 33 | 34 | } 35 | 36 | public boolean isDebugEnabled() { 37 | return true; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/github/copilot/editor/CopilotInlayRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.editor.EditorCustomElementRenderer 6 | * com.intellij.openapi.editor.Inlay 7 | * org.jetbrains.annotations.NotNull 8 | */ 9 | package com.github.copilot.editor; 10 | 11 | import com.github.copilot.completions.CopilotCompletionType; 12 | import com.intellij.openapi.editor.EditorCustomElementRenderer; 13 | import com.intellij.openapi.editor.Inlay; 14 | import java.util.List; 15 | 16 | public interface CopilotInlayRenderer extends EditorCustomElementRenderer { 17 | public List getContentLines(); 18 | 19 | public Inlay getInlay(); 20 | 21 | public CopilotCompletionType getType(); 22 | } 23 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/CopilotAgent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.application.ApplicationManager 6 | * org.jetbrains.annotations.Nullable 7 | */ 8 | package com.github.copilot.lang.agent; 9 | 10 | import com.intellij.openapi.application.ApplicationManager; 11 | 12 | public final class CopilotAgent { 13 | public static volatile Boolean override; 14 | 15 | private CopilotAgent() { 16 | } 17 | 18 | public static boolean isAgentSupportedAndEnabled() { 19 | Boolean currentOverride = override; 20 | if (currentOverride != null) { 21 | return currentOverride; 22 | } 23 | if (ApplicationManager.getApplication().isUnitTestMode()) { 24 | return false; 25 | } 26 | return false; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/rpc/NullCommandSender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | */ 7 | package com.github.copilot.lang.agent.rpc; 8 | 9 | import java.io.IOException; 10 | 11 | public class NullCommandSender implements JsonRpcCommandSender { 12 | @Override 13 | public void sendCommand(int id, JsonRpcCommand command) throws IOException { 14 | if (command == null) { 15 | throw new IllegalStateException("command cannot be null!"); 16 | } 17 | } 18 | 19 | @Override 20 | public void sendNotification(JsonRpcNotification notification) throws IOException { 21 | if (notification == null) { 22 | throw new IllegalStateException("notification cannot be null!"); 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/com/github/copilot/completions/CopilotInlayList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.util.TextRange 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.completions; 9 | 10 | import com.github.copilot.completions.CopilotCompletion; 11 | import com.github.copilot.completions.CopilotEditorInlay; 12 | import com.intellij.openapi.util.TextRange; 13 | import java.util.List; 14 | 15 | public interface CopilotInlayList extends Iterable { 16 | public boolean isEmpty(); 17 | 18 | public CopilotCompletion getCopilotCompletion(); 19 | 20 | public TextRange getReplacementRange(); 21 | 22 | public String getReplacementText(); 23 | 24 | public List getInlays(); 25 | } 26 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/rpc/StoringJsonRpcMessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.apache.commons.compress.utils.Lists 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.lang.agent.rpc; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | public class StoringJsonRpcMessageHandler implements JsonRpcMessageHandler { 14 | private final List messages = new ArrayList<>(); 15 | 16 | @Override 17 | public void handleJsonMessage(String message) { 18 | if (message == null) { 19 | throw new IllegalStateException("message cannot be null!"); 20 | } 21 | this.messages.add(message); 22 | } 23 | 24 | public List getMessages() { 25 | return this.messages; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/rpc/JsonRpcErrorException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | */ 7 | package com.github.copilot.lang.agent.rpc; 8 | 9 | public class JsonRpcErrorException extends RuntimeException { 10 | private static final long serialVersionUID = 2251191382389572540L; 11 | private final int requestId; 12 | 13 | public JsonRpcErrorException(int requestId, String message) { 14 | super(message); 15 | if (message == null) { 16 | throw new IllegalStateException("message cannot be null!"); 17 | } 18 | this.requestId = requestId; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "JsonRpcErrorException(requestId=" + this.getRequestId() + ")"; 24 | } 25 | 26 | public int getRequestId() { 27 | return this.requestId; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/com/github/copilot/completions/CompletionCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * javax.annotation.concurrent.ThreadSafe 6 | * org.jetbrains.annotations.NotNull 7 | * org.jetbrains.annotations.Nullable 8 | */ 9 | package com.github.copilot.completions; 10 | 11 | import com.github.copilot.completions.CopilotCompletion; 12 | import java.util.List; 13 | import javax.annotation.concurrent.ThreadSafe; 14 | 15 | @ThreadSafe 16 | public interface CompletionCache { 17 | public boolean isLatestPrefix(String var1); 18 | 19 | public List get(String var1, boolean var2); 20 | 21 | public List getLatest(String var1); 22 | 23 | public void add(String var1, String var2, boolean var3, CopilotCompletion var4); 24 | 25 | public void updateLatest(String var1, String var2, boolean var3); 26 | 27 | public void clear(); 28 | } 29 | -------------------------------------------------------------------------------- /src/com/github/copilot/request/BlockMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | */ 7 | package com.github.copilot.request; 8 | 9 | public enum BlockMode { 10 | Client, ServerSideIndentation; 11 | 12 | public boolean isAlwaysMultilineCompletion() { 13 | return this == ServerSideIndentation; 14 | } 15 | 16 | public boolean isSupportingOnDemandCompletions() { 17 | return this == ServerSideIndentation; 18 | } 19 | 20 | public int getMaxCompletions() { 21 | if (this == ServerSideIndentation) { 22 | return 1; 23 | } 24 | return 10; 25 | } 26 | 27 | public String getTelemetryValue() { 28 | switch (this) { 29 | case Client: { 30 | return "parsing"; 31 | } 32 | case ServerSideIndentation: { 33 | return "server"; 34 | } 35 | } 36 | throw new IllegalStateException("Unexpected block mode: " + this); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/com/github/copilot/editor/InlayUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.editor.InlayProperties 6 | */ 7 | package com.github.copilot.editor; 8 | 9 | import com.intellij.openapi.editor.InlayProperties; 10 | 11 | class InlayUtils { 12 | InlayUtils() { 13 | } 14 | 15 | static InlayProperties createInlineProperties(int n) { 16 | return new InlayProperties().relatesToPrecedingText(true).showAbove(false).priority(Integer.MAX_VALUE - n); 17 | } 18 | 19 | static InlayProperties createAfterLineEndProperties(int n) { 20 | return new InlayProperties().relatesToPrecedingText(true).showAbove(false).priority(Integer.MAX_VALUE - n); 21 | } 22 | 23 | static InlayProperties createBlockProperties(int n) { 24 | return new InlayProperties().relatesToPrecedingText(true).showAbove(false).priority(Integer.MAX_VALUE - n); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/com/github/copilot/status/CopilotStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.util.ui.PresentableEnum 6 | */ 7 | package com.github.copilot.status; 8 | 9 | import com.github.copilot.CopilotBundle; 10 | import com.intellij.util.ui.PresentableEnum; 11 | 12 | public enum CopilotStatus implements PresentableEnum { 13 | Ready, TermsNotAccepted, NotSignedIn, UnknownError; 14 | 15 | public String getPresentableText() { 16 | switch (this) { 17 | case Ready: { 18 | return CopilotBundle.get("copilotStatus.ready"); 19 | } 20 | case TermsNotAccepted: { 21 | return CopilotBundle.get("copilotStatus.termsNotAccepted"); 22 | } 23 | case NotSignedIn: { 24 | return CopilotBundle.get("copilotStatus.notSignedIn"); 25 | } 26 | case UnknownError: { 27 | return CopilotBundle.get("copilotStatus.unknownError"); 28 | } 29 | } 30 | throw new IllegalStateException("Unexpected value:" + this); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/github/copilot/toolWindow/SmallButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.util.ui.JBUI 6 | * com.intellij.util.ui.JBUI$Fonts 7 | * org.jetbrains.annotations.NotNull 8 | */ 9 | package com.github.copilot.toolWindow; 10 | 11 | import com.intellij.util.ui.JBUI; 12 | import java.awt.Font; 13 | import java.awt.Insets; 14 | import javax.swing.JButton; 15 | 16 | class SmallButton extends JButton { 17 | /** 18 | * 19 | */ 20 | private static final long serialVersionUID = 7243341939381218642L; 21 | 22 | public SmallButton(String label) { 23 | if (label == null) { 24 | throw new IllegalStateException("label cannot be null!"); 25 | } 26 | super(label); 27 | this.setFont((Font) JBUI.Fonts.smallFont()); 28 | } 29 | 30 | @Override 31 | public Insets getInsets(Insets insets) { 32 | return this.getInsets(); 33 | } 34 | 35 | @Override 36 | public Insets getInsets() { 37 | return JBUI.emptyInsets(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/github/copilot/github/GitHubSession.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.github; 2 | 3 | public final class GitHubSession { 4 | private final String token; 5 | 6 | public GitHubSession(String token) { 7 | this.token = token; 8 | } 9 | 10 | public String getToken() { 11 | return this.token; 12 | } 13 | 14 | public boolean equals(Object o) { 15 | if (o == this) { 16 | return true; 17 | } 18 | if (!(o instanceof GitHubSession)) { 19 | return false; 20 | } 21 | GitHubSession other = (GitHubSession) o; 22 | String this$token = this.getToken(); 23 | String other$token = other.getToken(); 24 | return !(this$token == null ? other$token != null : !this$token.equals(other$token)); 25 | } 26 | 27 | public int hashCode() { 28 | int result = 1; 29 | String $token = this.getToken(); 30 | result = result * 59 + ($token == null ? 43 : $token.hashCode()); 31 | return result; 32 | } 33 | 34 | public String toString() { 35 | return "GitHubSession(token=" + this.getToken() + ")"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/github/copilot/settings/ColorConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.ui.ColorUtil 6 | * com.intellij.util.xmlb.Converter 7 | * org.jetbrains.annotations.NotNull 8 | * org.jetbrains.annotations.Nullable 9 | */ 10 | package com.github.copilot.settings; 11 | 12 | import com.intellij.ui.ColorUtil; 13 | import com.intellij.util.xmlb.Converter; 14 | import java.awt.Color; 15 | 16 | public class ColorConverter extends Converter { 17 | public Color fromString(String value) { 18 | if (value == null) { 19 | throw new IllegalStateException("value cannot be null!"); 20 | } 21 | try { 22 | return ColorUtil.fromHex((String) value); 23 | } catch (Exception e) { 24 | return null; 25 | } 26 | } 27 | 28 | public String toString(Color value) { 29 | if (value == null) { 30 | throw new IllegalStateException("value cannot be null!"); 31 | } 32 | return ColorUtil.toHtmlColor((Color) value); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/com/github/copilot/openai/CopilotLanguage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | */ 7 | package com.github.copilot.openai; 8 | 9 | public enum CopilotLanguage { 10 | Python, Java, Unknown; 11 | 12 | private final String enginePath; 13 | 14 | private CopilotLanguage() { 15 | this("/v1/engines/copilot-codex"); 16 | } 17 | 18 | private CopilotLanguage(String enginePath) { 19 | if (enginePath == null) { 20 | throw new IllegalStateException("enginePath cannot be null!"); 21 | } 22 | this.enginePath = enginePath; 23 | } 24 | 25 | public String getEngineName() { 26 | String path = this.getEnginePath(); 27 | int index = path.lastIndexOf(47); 28 | return index == -1 ? path : path.substring(index + 1); 29 | } 30 | 31 | public String getEnginePath() { 32 | String string = this.enginePath; 33 | if (string == null) { 34 | throw new IllegalStateException("string cannot be null!"); 35 | } 36 | return string; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/com/github/copilot/editor/CopilotEditorSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.editor.Editor 6 | * com.intellij.openapi.extensions.ExtensionPointName 7 | * org.jetbrains.annotations.NotNull 8 | */ 9 | package com.github.copilot.editor; 10 | 11 | import com.intellij.openapi.editor.Editor; 12 | import com.intellij.openapi.extensions.ExtensionPointName; 13 | 14 | public interface CopilotEditorSupport { 15 | public static final ExtensionPointName EP = ExtensionPointName 16 | .create((String) "com.github.copilot.editorSupport"); 17 | 18 | public static boolean isEditorCompletionsSupported(Editor editor) { 19 | if (editor == null) { 20 | throw new IllegalStateException("editor cannot be null!"); 21 | } 22 | if (!EP.hasAnyExtensions()) { 23 | return true; 24 | } 25 | return EP.findFirstSafe(editorSupport -> !editorSupport.isCompletionsEnabled(editor)) == null; 26 | } 27 | 28 | public boolean isCompletionsEnabled(Editor var1); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/me/masecla/copilot/Activator.java: -------------------------------------------------------------------------------- 1 | package me.masecla.copilot; 2 | 3 | import org.eclipse.ui.plugin.AbstractUIPlugin; 4 | import org.osgi.framework.BundleContext; 5 | 6 | /** 7 | * The activator class controls the plug-in life cycle 8 | */ 9 | public class Activator extends AbstractUIPlugin { 10 | 11 | // The plug-in ID 12 | public static final String PLUGIN_ID = "me.masecla.copilot"; //$NON-NLS-1$ 13 | 14 | // The shared instance 15 | private static Activator plugin; 16 | 17 | /** 18 | * The constructor 19 | */ 20 | public Activator() { 21 | } 22 | 23 | @Override 24 | public void start(BundleContext context) throws Exception { 25 | super.start(context); 26 | plugin = this; 27 | } 28 | 29 | @Override 30 | public void stop(BundleContext context) throws Exception { 31 | plugin = null; 32 | super.stop(context); 33 | } 34 | 35 | /** 36 | * Returns the shared instance 37 | * 38 | * @return the shared instance 39 | */ 40 | public static Activator getDefault() { 41 | return plugin; 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/com/github/copilot/CopilotIcons.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.util.IconLoader 6 | */ 7 | package com.github.copilot; 8 | 9 | import com.intellij.openapi.util.IconLoader; 10 | import javax.swing.Icon; 11 | import javax.swing.ImageIcon; 12 | 13 | public final class CopilotIcons { 14 | public static final Icon COPILOT; 15 | public static final Icon StatusBarIcon; 16 | public static final Icon StatusBarIconDisabled; 17 | public static final Icon StatusBarIconError; 18 | public static final Icon ToolWindowIcon; 19 | 20 | private CopilotIcons() { 21 | } 22 | 23 | static { 24 | StatusBarIcon = COPILOT = IconLoader.getIcon((String) "icons/copilot.svg", CopilotIcons.class); 25 | StatusBarIconDisabled = IconLoader.getIcon((String) "icons/copilot_disabled.svg", CopilotIcons.class); 26 | StatusBarIconError = IconLoader.getIcon((String) "icons/copilot_error.svg", CopilotIcons.class); 27 | ToolWindowIcon = IconLoader.getIcon((String) "icons/copilot_toolwindow.svg", CopilotIcons.class); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/com/github/copilot/settings/UpdateChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.util.ui.PresentableEnum 6 | * org.jetbrains.annotations.Nullable 7 | */ 8 | package com.github.copilot.settings; 9 | 10 | import com.github.copilot.CopilotBundle; 11 | import com.intellij.util.ui.PresentableEnum; 12 | 13 | public enum UpdateChannel implements PresentableEnum { 14 | Stable(null), Nightly("https://plugins.jetbrains.com/plugins/nightly/17718"); 15 | 16 | private final String channelUrl; 17 | 18 | public String getPresentableText() { 19 | switch (this) { 20 | case Stable: { 21 | return CopilotBundle.get("applicationConfigurable.channel.stableChannel"); 22 | } 23 | case Nightly: { 24 | return CopilotBundle.get("applicationConfigurable.channel.nightlyChannel"); 25 | } 26 | } 27 | throw new IllegalStateException("Unexpected channel: " + this); 28 | } 29 | 30 | private UpdateChannel(String channelUrl) { 31 | this.channelUrl = channelUrl; 32 | } 33 | 34 | public String getChannelUrl() { 35 | return this.channelUrl; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 masecla22 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/com/github/copilot/request/CompletionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | * org.jetbrains.annotations.Nullable 7 | */ 8 | package com.github.copilot.request; 9 | 10 | public enum CompletionType { 11 | GhostText, OpenCopilot; 12 | 13 | public String getTelemetryPrefix() { 14 | switch (this) { 15 | case GhostText: { 16 | return "ghostText"; 17 | } 18 | case OpenCopilot: { 19 | return "solution"; 20 | } 21 | } 22 | throw new IllegalStateException("Unknown completion type: " + this); 23 | } 24 | 25 | public String getTelemetryPropertyValue() { 26 | switch (this) { 27 | case GhostText: { 28 | return "ghostText"; 29 | } 30 | case OpenCopilot: { 31 | return "synthesize"; 32 | } 33 | } 34 | throw new IllegalStateException("Unknown completion type: " + this); 35 | } 36 | 37 | public String getOpenAiIntent() { 38 | switch (this) { 39 | case GhostText: { 40 | return "copilot-ghost"; 41 | } 42 | case OpenCopilot: { 43 | return "copilot-panel"; 44 | } 45 | } 46 | return null; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 16 | 19 | 20 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/com/github/copilot/openai/OpenAIService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.application.ApplicationManager 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.openai; 9 | 10 | import com.github.copilot.openai.APIChoice; 11 | import com.github.copilot.request.BlockMode; 12 | import com.github.copilot.request.LanguageEditorRequest; 13 | import com.github.copilot.telemetry.TelemetryData; 14 | import com.intellij.openapi.application.ApplicationManager; 15 | import java.util.concurrent.Flow; 16 | 17 | public interface OpenAIService { 18 | public static OpenAIService getInstance() { 19 | OpenAIService openAIService = (OpenAIService) ApplicationManager.getApplication() 20 | .getService(OpenAIService.class); 21 | if (openAIService == null) { 22 | throw new IllegalStateException("openAIService cannot be null!"); 23 | } 24 | return openAIService; 25 | } 26 | 27 | public void fetchCompletions(String var1, LanguageEditorRequest var2, String var3, int var4, double var5, int var7, 28 | int var8, BlockMode var9, boolean var10, TelemetryData var11, Flow.Subscriber var12); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/com/github/copilot/actions/LoginToGitHubAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.actionSystem.AnAction 6 | * com.intellij.openapi.actionSystem.AnActionEvent 7 | * com.intellij.openapi.project.DumbAware 8 | * org.jetbrains.annotations.NotNull 9 | */ 10 | package com.github.copilot.actions; 11 | 12 | import com.github.copilot.actions.CopilotAction; 13 | import com.github.copilot.github.GitHubService; 14 | import com.intellij.openapi.actionSystem.AnAction; 15 | import com.intellij.openapi.actionSystem.AnActionEvent; 16 | import com.intellij.openapi.project.DumbAware; 17 | import java.util.Objects; 18 | 19 | public class LoginToGitHubAction extends AnAction implements DumbAware, CopilotAction { 20 | public void update(AnActionEvent e) { 21 | if (e == null) { 22 | throw new IllegalStateException("e cannot be null!"); 23 | } 24 | e.getPresentation().setEnabled(e.getProject() != null); 25 | } 26 | 27 | public void actionPerformed(AnActionEvent e) { 28 | if (e == null) { 29 | throw new IllegalStateException("e cannot be null!"); 30 | } 31 | GitHubService.getInstance().loginInteractive(Objects.requireNonNull(e.getProject())); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/github/copilot/CopilotBundle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.DynamicBundle 6 | * org.jetbrains.annotations.NotNull 7 | * org.jetbrains.annotations.PropertyKey 8 | */ 9 | package com.github.copilot; 10 | 11 | import com.intellij.DynamicBundle; 12 | import org.jetbrains.annotations.PropertyKey; 13 | 14 | public final class CopilotBundle extends DynamicBundle { 15 | public static final CopilotBundle INSTANCE = new CopilotBundle(); 16 | 17 | private CopilotBundle() { 18 | super("copilot.copilot"); 19 | } 20 | 21 | public static String get( 22 | @PropertyKey(resourceBundle = "copilot.copilot") @PropertyKey(resourceBundle = "copilot.copilot") String key) { 23 | if (key == null) { 24 | throw new IllegalStateException("key cannot be null!"); 25 | } 26 | return INSTANCE.getMessage(key, new Object[0]); 27 | } 28 | 29 | public static String get( 30 | @PropertyKey(resourceBundle = "copilot.copilot") @PropertyKey(resourceBundle = "copilot.copilot") String key, 31 | Object... params) { 32 | if (key == null) { 33 | throw new IllegalStateException("key cannot be null!"); 34 | } 35 | return INSTANCE.getMessage(key, params); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/com/github/copilot/openai/APIJsonDataStreaming.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * it.unimi.dsi.fastutil.doubles.DoubleList 6 | * it.unimi.dsi.fastutil.ints.IntList 7 | */ 8 | package com.github.copilot.openai; 9 | 10 | import com.github.copilot.util.String2DoubleMap; 11 | import it.unimi.dsi.fastutil.doubles.DoubleList; 12 | import it.unimi.dsi.fastutil.ints.IntList; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | class APIJsonDataStreaming { 17 | private final List text = new ArrayList(); 18 | private final StringBuilder joinedText = new StringBuilder(); 19 | List> tokens = new ArrayList>(); 20 | List textOffset = new ArrayList(); 21 | List logprobs = new ArrayList(); 22 | List> topLogprobs = new ArrayList>(); 23 | 24 | APIJsonDataStreaming() { 25 | } 26 | 27 | void appendText(String text) { 28 | this.text.add(text); 29 | this.joinedText.append(text); 30 | } 31 | 32 | List getText() { 33 | return this.text; 34 | } 35 | 36 | String getJoinedText() { 37 | return this.joinedText.toString(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/github/copilot/telemetry/CopilotTestExceptionAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.actionSystem.AnAction 6 | * com.intellij.openapi.actionSystem.AnActionEvent 7 | * com.intellij.openapi.application.ApplicationManager 8 | * org.jetbrains.annotations.NotNull 9 | */ 10 | package com.github.copilot.telemetry; 11 | 12 | import com.intellij.openapi.actionSystem.AnAction; 13 | import com.intellij.openapi.actionSystem.AnActionEvent; 14 | import com.intellij.openapi.application.ApplicationManager; 15 | import java.util.UUID; 16 | 17 | public class CopilotTestExceptionAction extends AnAction { 18 | public void update(AnActionEvent e) { 19 | if (e == null) { 20 | throw new IllegalStateException("e cannot be null!"); 21 | } 22 | e.getPresentation().setEnabledAndVisible(ApplicationManager.getApplication().isInternal()); 23 | } 24 | 25 | public boolean isDumbAware() { 26 | return true; 27 | } 28 | 29 | public void actionPerformed(AnActionEvent e) { 30 | if (e == null) { 31 | throw new IllegalStateException("e cannot be null!"); 32 | } 33 | throw new RuntimeException("Test exception by GitHub Copilot plugin, " + UUID.randomUUID()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/CopilotAgentProcessService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.application.ApplicationManager 6 | * org.jetbrains.annotations.NotNull 7 | * org.jetbrains.concurrency.Promise 8 | */ 9 | package com.github.copilot.lang.agent; 10 | 11 | import com.github.copilot.lang.agent.rpc.JsonRpcCommand; 12 | import com.github.copilot.lang.agent.rpc.JsonRpcNotification; 13 | import com.intellij.openapi.application.ApplicationManager; 14 | import org.jetbrains.concurrency.Promise; 15 | 16 | public interface CopilotAgentProcessService { 17 | public static CopilotAgentProcessService getInstance() { 18 | CopilotAgentProcessService copilotAgentProcessService = (CopilotAgentProcessService) ApplicationManager 19 | .getApplication().getService(CopilotAgentProcessService.class); 20 | if (copilotAgentProcessService == null) { 21 | throw new IllegalStateException("copilotAgentProcessService cannot be null!"); 22 | } 23 | return copilotAgentProcessService; 24 | } 25 | 26 | public boolean isSupported(); 27 | 28 | public Promise executeCommand(JsonRpcCommand var1); 29 | 30 | public void executeNotification(JsonRpcNotification var1); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/com/github/copilot/util/ApplicationUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.application.Application 6 | * com.intellij.openapi.application.ApplicationManager 7 | * com.intellij.openapi.diagnostic.Attachment 8 | * com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments 9 | * com.intellij.openapi.util.ShutDownTracker 10 | */ 11 | package com.github.copilot.util; 12 | 13 | import com.intellij.openapi.application.Application; 14 | import com.intellij.openapi.application.ApplicationManager; 15 | import com.intellij.openapi.diagnostic.Attachment; 16 | import com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments; 17 | import com.intellij.openapi.util.ShutDownTracker; 18 | 19 | public final class ApplicationUtil { 20 | private ApplicationUtil() { 21 | } 22 | 23 | public static void assertIsNonDispatchThread() { 24 | Application app = ApplicationManager.getApplication(); 25 | if (app.isUnitTestMode() || app.isHeadlessEnvironment()) { 26 | return; 27 | } 28 | if (!app.isDispatchThread()) { 29 | return; 30 | } 31 | if (ShutDownTracker.isShutdownHookRunning()) { 32 | return; 33 | } 34 | throw new RuntimeExceptionWithAttachments("Access from event dispatch thread is not allowed.", 35 | new Attachment[0]); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/github/copilot/toolWindow/ToolWindowUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.wm.ToolWindow 6 | * com.intellij.util.ui.StatusText 7 | * org.jetbrains.annotations.NotNull 8 | * org.jetbrains.annotations.Nullable 9 | */ 10 | package com.github.copilot.toolWindow; 11 | 12 | import com.intellij.openapi.wm.ToolWindow; 13 | import com.intellij.util.ui.StatusText; 14 | import java.lang.reflect.InvocationTargetException; 15 | import java.lang.reflect.Method; 16 | 17 | final class ToolWindowUtil { 18 | ToolWindowUtil() { 19 | } 20 | 21 | static StatusText getEmptyText(ToolWindow toolWindow) { 22 | Method method; 23 | if (toolWindow == null) { 24 | throw new IllegalStateException("toolWindow cannot be null!"); 25 | } 26 | if ((method = ToolWindowUtil.getEmptyText(toolWindow.getClass())) == null) { 27 | return null; 28 | } 29 | try { 30 | return (StatusText) method.invoke(toolWindow, new Object[0]); 31 | } catch (IllegalAccessException | InvocationTargetException e) { 32 | return null; 33 | } 34 | } 35 | 36 | static Method getEmptyText(Class klazz) { 37 | try { 38 | return klazz.getMethod("getEmptyText", new Class[0]); 39 | } catch (NoSuchMethodException e) { 40 | return null; 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/ToggleAgentServiceAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.actionSystem.AnAction 6 | * com.intellij.openapi.actionSystem.AnActionEvent 7 | * com.intellij.openapi.application.ApplicationManager 8 | * com.intellij.openapi.project.DumbAware 9 | * org.jetbrains.annotations.NotNull 10 | */ 11 | package com.github.copilot.lang.agent; 12 | 13 | import com.github.copilot.lang.agent.CopilotAgent; 14 | import com.intellij.openapi.actionSystem.AnAction; 15 | import com.intellij.openapi.actionSystem.AnActionEvent; 16 | import com.intellij.openapi.application.ApplicationManager; 17 | import com.intellij.openapi.project.DumbAware; 18 | 19 | public class ToggleAgentServiceAction extends AnAction implements DumbAware { 20 | public void update(AnActionEvent e) { 21 | if (e == null) { 22 | throw new IllegalStateException("e cannot be null!"); 23 | } 24 | e.getPresentation().setEnabledAndVisible(ApplicationManager.getApplication().isInternal()); 25 | } 26 | 27 | public void actionPerformed(AnActionEvent e) { 28 | Boolean current; 29 | if (e == null) { 30 | throw new IllegalStateException("e cannot be null!"); 31 | } 32 | CopilotAgent.override = (current = CopilotAgent.override) == null ? Boolean.valueOf(true) : null; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/com/github/copilot/actions/DisableFileCopilotCompletionsAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.actionSystem.AnActionEvent 6 | * com.intellij.openapi.actionSystem.CommonDataKeys 7 | * com.intellij.psi.PsiFile 8 | * org.jetbrains.annotations.NotNull 9 | */ 10 | package com.github.copilot.actions; 11 | 12 | import com.github.copilot.CopilotBundle; 13 | import com.github.copilot.actions.AbstractDisableCopilotCompletionsAction; 14 | import com.intellij.openapi.actionSystem.AnActionEvent; 15 | import com.intellij.openapi.actionSystem.CommonDataKeys; 16 | import com.intellij.psi.PsiFile; 17 | 18 | public class DisableFileCopilotCompletionsAction extends AbstractDisableCopilotCompletionsAction { 19 | public DisableFileCopilotCompletionsAction() { 20 | super(true); 21 | } 22 | 23 | @Override 24 | public void update(AnActionEvent e) { 25 | PsiFile file; 26 | if (e == null) { 27 | throw new IllegalStateException("e cannot be null!"); 28 | } 29 | super.update(e); 30 | if (e.getPresentation().isEnabledAndVisible() 31 | && (file = (PsiFile) e.getData(CommonDataKeys.PSI_FILE)) != null) { 32 | String language = file.getLanguage().getDisplayName(); 33 | e.getPresentation().setText(CopilotBundle.get("action.copilot.disableCopilotLanguage.text", language)); 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/com/github/copilot/settings/ZonedDateTimeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * me.masecla.copilot.extra.Logger 6 | * com.intellij.util.xmlb.Converter 7 | * org.jetbrains.annotations.NotNull 8 | * org.jetbrains.annotations.Nullable 9 | */ 10 | package com.github.copilot.settings; 11 | 12 | import me.masecla.copilot.extra.Logger; 13 | import com.intellij.util.xmlb.Converter; 14 | import java.time.ZonedDateTime; 15 | import java.time.format.DateTimeFormatter; 16 | import java.time.format.DateTimeParseException; 17 | 18 | public final class ZonedDateTimeConverter extends Converter { 19 | private static final Logger LOG = Logger.getInstance(ZonedDateTimeConverter.class); 20 | 21 | public ZonedDateTime fromString(String value) { 22 | if (value == null) { 23 | throw new IllegalStateException("value cannot be null!"); 24 | } 25 | try { 26 | return ZonedDateTime.parse(value, DateTimeFormatter.ISO_ZONED_DATE_TIME); 27 | } catch (DateTimeParseException e) { 28 | LOG.warn("Failed to parse LocalDateTime from string: " + value); 29 | return null; 30 | } 31 | } 32 | 33 | public String toString(ZonedDateTime value) { 34 | if (value == null) { 35 | throw new IllegalStateException("value cannot be null!"); 36 | } 37 | return value.format(DateTimeFormatter.ISO_ZONED_DATE_TIME); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/me/masecla/copilot/CopilotActionSet.java: -------------------------------------------------------------------------------- 1 | package me.masecla.copilot; 2 | 3 | import org.eclipse.jface.action.IAction; 4 | import org.eclipse.jface.viewers.ISelection; 5 | import org.eclipse.swt.SWT; 6 | import org.eclipse.swt.widgets.Control; 7 | import org.eclipse.swt.widgets.Menu; 8 | import org.eclipse.swt.widgets.MenuItem; 9 | import org.eclipse.ui.IWorkbenchWindow; 10 | import org.eclipse.ui.IWorkbenchWindowPulldownDelegate; 11 | 12 | public class CopilotActionSet implements IWorkbenchWindowPulldownDelegate { 13 | 14 | @Override 15 | public void dispose() { 16 | } 17 | 18 | @Override 19 | public void init(IWorkbenchWindow window) { 20 | } 21 | 22 | @Override 23 | public void run(IAction action) { 24 | } 25 | 26 | @Override 27 | public void selectionChanged(IAction action, ISelection selection) { 28 | 29 | } 30 | 31 | @Override 32 | public Menu getMenu(Control parent) { 33 | Menu result = new Menu(parent); 34 | 35 | MenuItem settingsItem = new MenuItem(result, SWT.NONE); 36 | settingsItem.setText("Settings"); 37 | MenuItem solutionsItem = new MenuItem(result, SWT.NONE); 38 | solutionsItem.setText("Synthesize 10 Solutions"); 39 | MenuItem aboutItem = new MenuItem(result, SWT.NONE); 40 | aboutItem.setText("About"); 41 | MenuItem helpItem = new MenuItem(result, SWT.NONE); 42 | helpItem.setText("Help"); 43 | 44 | return result; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/com/github/copilot/openai/APIChoice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.util.text.StringUtil 6 | * org.jetbrains.annotations.NotNull 7 | * org.jetbrains.annotations.Nullable 8 | */ 9 | package com.github.copilot.openai; 10 | 11 | import com.github.copilot.completions.CopilotCompletion; 12 | import com.github.copilot.openai.CompletionResponseInfo; 13 | import com.github.copilot.telemetry.TelemetryData; 14 | import com.intellij.openapi.util.text.StringUtil; 15 | 16 | public interface APIChoice extends CopilotCompletion { 17 | public CompletionResponseInfo getResponseInfo(); 18 | 19 | default public int getCompletionTextLength() { 20 | int sum = 0; 21 | for (String line : this.getCompletion()) { 22 | sum += line.length(); 23 | } 24 | return sum; 25 | } 26 | 27 | default public String getCompletionText() { 28 | String string = StringUtil.join(this.getCompletion(), (String) "\n"); 29 | if (string == null) { 30 | throw new IllegalStateException("string cannot be null!"); 31 | } 32 | return string; 33 | } 34 | 35 | public int getChoiceIndex(); 36 | 37 | public int getNumTokens(); 38 | 39 | public int getRequestID(); 40 | 41 | public String getCompletionId(); 42 | 43 | public int getCreatedTimestamp(); 44 | 45 | public Double getMeanLogProb(); 46 | 47 | public TelemetryData getTelemetryData(); 48 | 49 | public boolean isCached(); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/com/github/copilot/request/EditorRequestUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.util.text.StringUtil 6 | * com.intellij.openapi.util.text.Strings 7 | * org.jetbrains.annotations.NotNull 8 | */ 9 | package com.github.copilot.request; 10 | 11 | import com.intellij.openapi.util.text.StringUtil; 12 | import com.intellij.openapi.util.text.Strings; 13 | import java.util.List; 14 | import java.util.stream.Collectors; 15 | 16 | public final class EditorRequestUtil { 17 | private EditorRequestUtil() { 18 | } 19 | 20 | public static List fixIndentation(List lines, boolean useTabIndents, int tabWidth) { 21 | if (lines == null) { 22 | throw new IllegalStateException("lines cannot be null!"); 23 | } 24 | if (useTabIndents) { 25 | return lines.stream().map(line -> { 26 | int tabs = Strings.countChars((CharSequence) line, (char) ' ', (int) 0, (boolean) true) / tabWidth; 27 | int spaces = tabs * tabWidth; 28 | return StringUtil.repeatSymbol((char) '\t', (int) tabs) + line.substring(spaces); 29 | }).collect(Collectors.toList()); 30 | } 31 | return lines.stream().map(line -> { 32 | int tabs = Strings.countChars((CharSequence) line, (char) '\t', (int) 0, (boolean) true); 33 | int spaces = tabs * tabWidth; 34 | return StringUtil.repeatSymbol((char) ' ', (int) spaces) + line.substring(tabs); 35 | }).collect(Collectors.toList()); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/CommonLanguageSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | * org.jetbrains.annotations.Nullable 7 | */ 8 | package com.github.copilot.lang; 9 | 10 | import java.util.regex.Pattern; 11 | 12 | public final class CommonLanguageSupport { 13 | private static final Pattern EOL_PATTERN = Pattern.compile("^\\s*[)}\\]\"'`]*\\s*[:{;,]?\\s*$"); 14 | 15 | private CommonLanguageSupport() { 16 | } 17 | 18 | public static boolean isMiddleOfTheLine(String lineSuffix) { 19 | if (lineSuffix == null) { 20 | throw new IllegalStateException("lineSuffix cannot be null!"); 21 | } 22 | return !lineSuffix.trim().isEmpty(); 23 | } 24 | 25 | public static boolean isValidMiddleOfTheLinePosition(String lineSuffix) { 26 | if (lineSuffix == null) { 27 | throw new IllegalStateException("lineSuffix cannot be null!"); 28 | } 29 | return EOL_PATTERN.matcher(lineSuffix.trim()).matches(); 30 | } 31 | 32 | public static Boolean isInlineSuggestion(String lineSuffix) { 33 | if (lineSuffix == null) { 34 | throw new IllegalStateException("lineSuffix cannot be null!"); 35 | } 36 | boolean isMiddleOfLine = CommonLanguageSupport.isMiddleOfTheLine(lineSuffix); 37 | boolean isValidMiddleOfLine = CommonLanguageSupport.isValidMiddleOfTheLinePosition(lineSuffix); 38 | if (isMiddleOfLine && !isValidMiddleOfLine) { 39 | return null; 40 | } 41 | return isMiddleOfLine; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/com/github/copilot/actions/CopilotToggleCacheAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.actionSystem.AnAction 6 | * com.intellij.openapi.actionSystem.AnActionEvent 7 | * com.intellij.openapi.application.ApplicationManager 8 | * org.jetbrains.annotations.NotNull 9 | */ 10 | package com.github.copilot.actions; 11 | 12 | import com.github.copilot.actions.CopilotAction; 13 | import com.github.copilot.settings.CopilotApplicationSettings; 14 | import com.intellij.openapi.actionSystem.AnAction; 15 | import com.intellij.openapi.actionSystem.AnActionEvent; 16 | import com.intellij.openapi.application.ApplicationManager; 17 | 18 | public class CopilotToggleCacheAction extends AnAction implements CopilotAction { 19 | public void actionPerformed(AnActionEvent e) { 20 | if (e == null) { 21 | throw new IllegalStateException("e cannot be null!"); 22 | } 23 | CopilotApplicationSettings 24 | .settings().internalDisableHttpCache = !CopilotApplicationSettings.settings().internalDisableHttpCache; 25 | } 26 | 27 | public void update(AnActionEvent e) { 28 | if (e == null) { 29 | throw new IllegalStateException("e cannot be null!"); 30 | } 31 | e.getPresentation().setEnabledAndVisible(ApplicationManager.getApplication().isInternal()); 32 | if (CopilotApplicationSettings.settings().internalDisableHttpCache) { 33 | e.getPresentation().setText("Copilot: Enable OpenAI caching"); 34 | } else { 35 | e.getPresentation().setText("Copilot: Disable OpenAI caching"); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/com/github/copilot/toolWindow/OpenCopilotDisableReaderModeMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.codeInsight.actions.ReaderModeMatcher 6 | * com.intellij.codeInsight.actions.ReaderModeProvider$ReaderMode 7 | * com.intellij.openapi.editor.Editor 8 | * com.intellij.openapi.project.Project 9 | * com.intellij.openapi.vfs.VirtualFile 10 | * org.jetbrains.annotations.NotNull 11 | * org.jetbrains.annotations.Nullable 12 | */ 13 | package com.github.copilot.toolWindow; 14 | 15 | import com.github.copilot.toolWindow.OpenCopilotHandler; 16 | import com.intellij.codeInsight.actions.ReaderModeMatcher; 17 | import com.intellij.codeInsight.actions.ReaderModeProvider; 18 | import com.intellij.openapi.editor.Editor; 19 | import com.intellij.openapi.project.Project; 20 | import com.intellij.openapi.vfs.VirtualFile; 21 | 22 | public class OpenCopilotDisableReaderModeMatcher implements ReaderModeMatcher { 23 | public Boolean matches(Project project, VirtualFile virtualFile, Editor editor, 24 | ReaderModeProvider.ReaderMode readerMode) { 25 | if (project == null) { 26 | throw new IllegalStateException("project cannot be null!"); 27 | } 28 | if (virtualFile == null) { 29 | throw new IllegalStateException("virtualFile cannot be null!"); 30 | } 31 | if (readerMode == null) { 32 | throw new IllegalStateException("readerMode cannot be null!"); 33 | } 34 | if (OpenCopilotHandler.isCopilotSnippetFile(virtualFile)) { 35 | return false; 36 | } 37 | return null; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/com/github/copilot/actions/CycleNextEditorInlays.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.actionSystem.AnAction 6 | * com.intellij.openapi.actionSystem.AnActionEvent 7 | * com.intellij.openapi.actionSystem.CommonDataKeys 8 | * com.intellij.openapi.editor.Editor 9 | * com.intellij.openapi.project.DumbAware 10 | * org.jetbrains.annotations.NotNull 11 | */ 12 | package com.github.copilot.actions; 13 | 14 | import com.github.copilot.actions.CopilotAction; 15 | import com.github.copilot.editor.CopilotEditorManager; 16 | import com.intellij.openapi.actionSystem.AnAction; 17 | import com.intellij.openapi.actionSystem.AnActionEvent; 18 | import com.intellij.openapi.actionSystem.CommonDataKeys; 19 | import com.intellij.openapi.editor.Editor; 20 | import com.intellij.openapi.project.DumbAware; 21 | 22 | public class CycleNextEditorInlays extends AnAction implements DumbAware, CopilotAction { 23 | public void update(AnActionEvent e) { 24 | if (e == null) { 25 | throw new IllegalStateException("e cannot be null!"); 26 | } 27 | Editor editor = (Editor) e.getData(CommonDataKeys.EDITOR); 28 | e.getPresentation().setEnabled(editor != null && CopilotEditorManager.getInstance().hasNextInlaySet(editor)); 29 | } 30 | 31 | public void actionPerformed(AnActionEvent e) { 32 | Editor editor; 33 | if (e == null) { 34 | throw new IllegalStateException("e cannot be null!"); 35 | } 36 | if ((editor = (Editor) e.getData(CommonDataKeys.EDITOR)) != null) { 37 | CopilotEditorManager.getInstance().showNextInlaySet(editor); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/com/github/copilot/actions/CyclePreviousEditorInlays.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.actionSystem.AnAction 6 | * com.intellij.openapi.actionSystem.AnActionEvent 7 | * com.intellij.openapi.actionSystem.CommonDataKeys 8 | * com.intellij.openapi.editor.Editor 9 | * com.intellij.openapi.project.DumbAware 10 | * org.jetbrains.annotations.NotNull 11 | */ 12 | package com.github.copilot.actions; 13 | 14 | import com.github.copilot.actions.CopilotAction; 15 | import com.github.copilot.editor.CopilotEditorManager; 16 | import com.intellij.openapi.actionSystem.AnAction; 17 | import com.intellij.openapi.actionSystem.AnActionEvent; 18 | import com.intellij.openapi.actionSystem.CommonDataKeys; 19 | import com.intellij.openapi.editor.Editor; 20 | import com.intellij.openapi.project.DumbAware; 21 | 22 | public class CyclePreviousEditorInlays extends AnAction implements DumbAware, CopilotAction { 23 | public void update(AnActionEvent e) { 24 | if (e == null) { 25 | throw new IllegalStateException("e cannot be null!"); 26 | } 27 | Editor editor = (Editor) e.getData(CommonDataKeys.EDITOR); 28 | e.getPresentation() 29 | .setEnabled(editor != null && CopilotEditorManager.getInstance().hasPreviousInlaySet(editor)); 30 | } 31 | 32 | public void actionPerformed(AnActionEvent e) { 33 | Editor editor; 34 | if (e == null) { 35 | throw new IllegalStateException("e cannot be null!"); 36 | } 37 | if ((editor = (Editor) e.getData(CommonDataKeys.EDITOR)) != null) { 38 | CopilotEditorManager.getInstance().showPreviousInlaySet(editor); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/rpc/JsonRpcResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.google.gson.JsonElement 6 | */ 7 | package com.github.copilot.lang.agent.rpc; 8 | 9 | import com.google.gson.JsonElement; 10 | 11 | public final class JsonRpcResponse { 12 | private final int requestId; 13 | private final JsonElement response; 14 | 15 | public JsonRpcResponse(int requestId, JsonElement response) { 16 | this.requestId = requestId; 17 | this.response = response; 18 | } 19 | 20 | public int getRequestId() { 21 | return this.requestId; 22 | } 23 | 24 | public JsonElement getResponse() { 25 | return this.response; 26 | } 27 | 28 | public boolean equals(Object o) { 29 | if (o == this) { 30 | return true; 31 | } 32 | if (!(o instanceof JsonRpcResponse)) { 33 | return false; 34 | } 35 | JsonRpcResponse other = (JsonRpcResponse) o; 36 | if (this.getRequestId() != other.getRequestId()) { 37 | return false; 38 | } 39 | JsonElement this$response = this.getResponse(); 40 | JsonElement other$response = other.getResponse(); 41 | return !(this$response == null ? other$response != null : !this$response.equals(other$response)); 42 | } 43 | 44 | public int hashCode() { 45 | int result = 1; 46 | result = result * 59 + this.getRequestId(); 47 | JsonElement $response = this.getResponse(); 48 | result = result * 59 + ($response == null ? 43 : $response.hashCode()); 49 | return result; 50 | } 51 | 52 | public String toString() { 53 | return "JsonRpcResponse(requestId=" + this.getRequestId() + ", response=" + this.getResponse() + ")"; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/com/github/copilot/request/EditorRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.lang.Language 6 | * com.intellij.openapi.Disposable 7 | * com.intellij.openapi.project.Project 8 | * org.jetbrains.annotations.NotNull 9 | * org.jetbrains.annotations.Nullable 10 | */ 11 | package com.github.copilot.request; 12 | 13 | import com.github.copilot.request.CompletionType; 14 | import com.github.copilot.request.LineInfo; 15 | import com.github.copilot.util.Cancellable; 16 | import com.intellij.lang.Language; 17 | import com.intellij.openapi.Disposable; 18 | import com.intellij.openapi.project.Project; 19 | 20 | public interface EditorRequest extends Cancellable { 21 | public LineInfo getLineInfo(); 22 | 23 | public boolean equalsRequest(EditorRequest var1); 24 | 25 | default public String getCurrentDocumentPrefix() { 26 | String string = this.getDocumentContent().substring(0, this.getOffset()); 27 | if (string == null) { 28 | throw new IllegalStateException("string cannot be null!"); 29 | } 30 | return string; 31 | } 32 | 33 | public String getDocumentContent(); 34 | 35 | public Language getFileLanguage(); 36 | 37 | public String getRelativeFilePath(); 38 | 39 | public Project getProject(); 40 | 41 | public CompletionType getCompletionType(); 42 | 43 | public int getOffset(); 44 | 45 | public boolean isUseTabIndents(); 46 | 47 | public int getTabWidth(); 48 | 49 | public int getRequestId(); 50 | 51 | public Disposable getDisposable(); 52 | 53 | public long getRequestTimestamp(); 54 | 55 | public Integer getDocumentModificationSequence(); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/commands/CheckStatusCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.google.gson.annotations.SerializedName 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.lang.agent.commands; 9 | 10 | import com.github.copilot.lang.agent.rpc.JsonRpcCommand; 11 | import com.google.gson.annotations.SerializedName; 12 | 13 | public final class CheckStatusCommand 14 | implements JsonRpcCommand { 15 | @SerializedName(value="localChecksOnly") 16 | private final boolean localChecksOnly = false; 17 | 18 | @Override 19 | public String getCommandName() { 20 | return "checkStatus"; 21 | } 22 | 23 | @Override 24 | public Class getResponseType() { 25 | return AuthStatusResult.class; 26 | } 27 | 28 | public boolean isLocalChecksOnly() { 29 | return this.localChecksOnly; 30 | } 31 | 32 | public boolean equals(Object o) { 33 | if (o == this) { 34 | return true; 35 | } 36 | if (!(o instanceof CheckStatusCommand)) { 37 | return false; 38 | } 39 | CheckStatusCommand other = (CheckStatusCommand)o; 40 | return this.isLocalChecksOnly() == other.isLocalChecksOnly(); 41 | } 42 | 43 | public int hashCode() { 44 | int result = 1; 45 | result = result * 59 + (this.isLocalChecksOnly() ? 79 : 97); 46 | return result; 47 | } 48 | 49 | public String toString() { 50 | return "CheckStatusCommand(localChecksOnly=" + this.isLocalChecksOnly() + ")"; 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /src/com/github/copilot/util/Maps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.util.containers.ContainerUtil$ImmutableMapBuilder 6 | */ 7 | package com.github.copilot.util; 8 | 9 | import com.intellij.util.containers.ContainerUtil; 10 | import java.util.Collections; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | public final class Maps { 15 | private Maps() { 16 | } 17 | 18 | public static Map of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, 19 | V v7, K k8, V v8, K k9, V v9, K k10, V v10, K k11, V v11) { 20 | ContainerUtil.ImmutableMapBuilder map = new ContainerUtil.ImmutableMapBuilder(); 21 | map.put(k1, v1); 22 | map.put(k2, v2); 23 | map.put(k3, v3); 24 | map.put(k4, v4); 25 | map.put(k5, v5); 26 | map.put(k6, v6); 27 | map.put(k7, v7); 28 | map.put(k8, v8); 29 | map.put(k9, v9); 30 | map.put(k10, v10); 31 | map.put(k11, v11); 32 | return map.build(); 33 | } 34 | 35 | @SafeVarargs 36 | public static Map merge(Map... maps) { 37 | if (maps == null) { 38 | throw new IllegalStateException("maps cannot be null!"); 39 | } 40 | if (maps.length == 0) { 41 | return Collections.emptyMap(); 42 | } 43 | if (maps.length == 1) { 44 | return Map.copyOf(maps[0]); 45 | } 46 | HashMap all = null; 47 | for (Map map : maps) { 48 | if (map.isEmpty()) 49 | continue; 50 | if (all == null) { 51 | all = new HashMap(); 52 | } 53 | all.putAll(map); 54 | } 55 | return all == null ? Collections.emptyMap() : Collections.unmodifiableMap(all); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/com/github/copilot/statusBar/CopilotWidgetFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.project.Project 6 | * com.intellij.openapi.wm.StatusBarWidget 7 | * com.intellij.openapi.wm.impl.status.widget.StatusBarEditorBasedWidgetFactory 8 | * org.jetbrains.annotations.Nls 9 | * org.jetbrains.annotations.NonNls 10 | * org.jetbrains.annotations.NotNull 11 | */ 12 | package com.github.copilot.statusBar; 13 | 14 | import com.github.copilot.CopilotBundle; 15 | import com.github.copilot.statusBar.CopilotStatusBarWidget; 16 | import com.intellij.openapi.project.Project; 17 | import com.intellij.openapi.wm.StatusBarWidget; 18 | import com.intellij.openapi.wm.impl.status.widget.StatusBarEditorBasedWidgetFactory; 19 | import org.jetbrains.annotations.Nls; 20 | import org.jetbrains.annotations.NonNls; 21 | 22 | public class CopilotWidgetFactory extends StatusBarEditorBasedWidgetFactory { 23 | @NonNls 24 | public String getId() { 25 | return "com.github.copilot"; 26 | } 27 | 28 | @Nls 29 | public String getDisplayName() { 30 | String string = CopilotBundle.get("statusBar.displayName"); 31 | if (string == null) { 32 | throw new IllegalStateException("string cannot be null!"); 33 | } 34 | return string; 35 | } 36 | 37 | public StatusBarWidget createWidget(Project project) { 38 | if (project == null) { 39 | throw new IllegalStateException("project cannot be null!"); 40 | } 41 | return new CopilotStatusBarWidget(project); 42 | } 43 | 44 | public void disposeWidget(StatusBarWidget widget) { 45 | if (widget == null) { 46 | throw new IllegalStateException("widget cannot be null!"); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/com/github/copilot/actions/OpenCopilotAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.actionSystem.AnAction 6 | * com.intellij.openapi.actionSystem.AnActionEvent 7 | * com.intellij.openapi.actionSystem.CommonDataKeys 8 | * com.intellij.openapi.editor.Editor 9 | * org.jetbrains.annotations.NotNull 10 | */ 11 | package com.github.copilot.actions; 12 | 13 | import com.github.copilot.actions.CopilotAction; 14 | import com.github.copilot.editor.CopilotEditorManager; 15 | import com.github.copilot.toolWindow.CopilotSplitEditorManager; 16 | import com.intellij.openapi.actionSystem.AnAction; 17 | import com.intellij.openapi.actionSystem.AnActionEvent; 18 | import com.intellij.openapi.actionSystem.CommonDataKeys; 19 | import com.intellij.openapi.editor.Editor; 20 | 21 | public class OpenCopilotAction extends AnAction implements CopilotAction { 22 | public void update(AnActionEvent e) { 23 | if (e == null) { 24 | throw new IllegalStateException("e cannot be null!"); 25 | } 26 | Editor editor = (Editor) e.getData(CommonDataKeys.EDITOR); 27 | e.getPresentation().setEnabled(editor != null && CopilotEditorManager.getInstance().isAvailable(editor)); 28 | } 29 | 30 | public boolean isDumbAware() { 31 | return true; 32 | } 33 | 34 | public void actionPerformed(AnActionEvent e) { 35 | Editor editor; 36 | if (e == null) { 37 | throw new IllegalStateException("e cannot be null!"); 38 | } 39 | if ((editor = (Editor) e.getData(CommonDataKeys.EDITOR)) == null 40 | || !CopilotEditorManager.getInstance().isAvailable(editor)) { 41 | return; 42 | } 43 | CopilotSplitEditorManager.getInstance().openCopilot(editor, true); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/com/github/copilot/toolWindow/OpenCopilotEditorManagerListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.fileEditor.FileEditor 6 | * com.intellij.openapi.fileEditor.FileEditorManagerEvent 7 | * com.intellij.openapi.fileEditor.FileEditorManagerListener 8 | * com.intellij.openapi.fileEditor.TextEditor 9 | * com.intellij.openapi.project.Project 10 | * org.jetbrains.annotations.NotNull 11 | */ 12 | package com.github.copilot.toolWindow; 13 | 14 | import com.github.copilot.toolWindow.OpenCopilotToolWindowFactory; 15 | import com.intellij.openapi.fileEditor.FileEditor; 16 | import com.intellij.openapi.fileEditor.FileEditorManagerEvent; 17 | import com.intellij.openapi.fileEditor.FileEditorManagerListener; 18 | import com.intellij.openapi.fileEditor.TextEditor; 19 | import com.intellij.openapi.project.Project; 20 | 21 | public class OpenCopilotEditorManagerListener implements FileEditorManagerListener { 22 | private final Project project; 23 | 24 | public OpenCopilotEditorManagerListener(Project project) { 25 | if (project == null) { 26 | throw new IllegalStateException("project cannot be null!"); 27 | } 28 | this.project = project; 29 | } 30 | 31 | public void selectionChanged(FileEditorManagerEvent event) { 32 | FileEditor newEditor; 33 | if (event == null) { 34 | throw new IllegalStateException("event cannot be null!"); 35 | } 36 | if ((newEditor = event.getNewEditor()) instanceof TextEditor) { 37 | OpenCopilotToolWindowFactory.editorSelectionChanged(this.project, ((TextEditor) newEditor).getEditor()); 38 | } else { 39 | OpenCopilotToolWindowFactory.editorSelectionChanged(this.project, null); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/com/github/copilot/util/VfsUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.application.ApplicationManager 6 | * me.masecla.copilot.extra.Logger 7 | * com.intellij.openapi.vfs.VirtualFile 8 | * com.intellij.testFramework.LightVirtualFile 9 | * org.jetbrains.annotations.NotNull 10 | */ 11 | package com.github.copilot.util; 12 | 13 | import com.intellij.openapi.application.ApplicationManager; 14 | import me.masecla.copilot.extra.Logger; 15 | import com.intellij.openapi.vfs.VirtualFile; 16 | import com.intellij.testFramework.LightVirtualFile; 17 | import java.io.IOException; 18 | 19 | public class VfsUtil { 20 | private static final Logger LOG = Logger.getInstance(VfsUtil.class); 21 | 22 | public static void safeDelete(VirtualFile file) { 23 | if (file == null) { 24 | throw new IllegalStateException("file cannot be null!"); 25 | } 26 | if (file instanceof LightVirtualFile) { 27 | ((LightVirtualFile) file).setValid(false); 28 | return; 29 | } 30 | if (!file.isValid()) { 31 | return; 32 | } 33 | if (ApplicationManager.getApplication().isWriteAccessAllowed()) { 34 | VfsUtil.doSafeDelete(file); 35 | } else { 36 | ApplicationManager.getApplication().runWriteAction(() -> VfsUtil.doSafeDelete(file)); 37 | } 38 | } 39 | 40 | private static void doSafeDelete(VirtualFile file) { 41 | if (file == null) { 42 | throw new IllegalStateException("file cannot be null!"); 43 | } 44 | ApplicationManager.getApplication().assertWriteAccessAllowed(); 45 | try { 46 | file.delete(VfsUtil.class); 47 | } catch (IOException e) { 48 | LOG.debug("Exception deleting VirtualFile", (Throwable) e); 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/com/github/copilot/actions/LogoutFromGitHubAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.actionSystem.AnAction 6 | * com.intellij.openapi.actionSystem.AnActionEvent 7 | * com.intellij.openapi.project.DumbAware 8 | * com.intellij.openapi.project.Project 9 | * com.intellij.openapi.ui.Messages 10 | * org.jetbrains.annotations.NotNull 11 | */ 12 | package com.github.copilot.actions; 13 | 14 | import com.github.copilot.CopilotBundle; 15 | import com.github.copilot.actions.CopilotAction; 16 | import com.github.copilot.github.GitHubService; 17 | import com.github.copilot.status.CopilotStatus; 18 | import com.github.copilot.status.CopilotStatusService; 19 | import com.intellij.openapi.actionSystem.AnAction; 20 | import com.intellij.openapi.actionSystem.AnActionEvent; 21 | import com.intellij.openapi.project.DumbAware; 22 | import com.intellij.openapi.project.Project; 23 | import com.intellij.openapi.ui.Messages; 24 | 25 | public class LogoutFromGitHubAction extends AnAction implements DumbAware, CopilotAction { 26 | public void update(AnActionEvent e) { 27 | if (e == null) { 28 | throw new IllegalStateException("e cannot be null!"); 29 | } 30 | e.getPresentation().setEnabled(GitHubService.getInstance().isSignedIn()); 31 | } 32 | 33 | public void actionPerformed(AnActionEvent e) { 34 | if (e == null) { 35 | throw new IllegalStateException("e cannot be null!"); 36 | } 37 | GitHubService.getInstance().logout(); 38 | CopilotStatusService.notifyApplication(CopilotStatus.NotSignedIn); 39 | Messages.showInfoMessage((Project) e.getProject(), (String) CopilotBundle.get("github.logout.success.message"), 40 | (String) CopilotBundle.get("github.logout.success.title")); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/GitHubDelegatingTestService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.application.ApplicationManager 6 | * org.jetbrains.annotations.Nullable 7 | * org.jetbrains.annotations.TestOnly 8 | */ 9 | package com.github.copilot.lang.agent; 10 | 11 | import com.github.copilot.github.GitHubCopilotToken; 12 | import com.github.copilot.github.GitHubService; 13 | import com.github.copilot.lang.agent.CopilotAgent; 14 | import com.github.copilot.lang.agent.DelegatingGitHubService; 15 | import com.intellij.openapi.application.ApplicationManager; 16 | import java.util.concurrent.TimeUnit; 17 | import org.jetbrains.annotations.TestOnly; 18 | 19 | @TestOnly 20 | public class GitHubDelegatingTestService extends DelegatingGitHubService { 21 | public static GitHubDelegatingTestService getInstance() { 22 | return (GitHubDelegatingTestService) ApplicationManager.getApplication().getService(GitHubService.class); 23 | } 24 | 25 | @TestOnly 26 | public void setCopilotTokenString(String token) { 27 | GitHubCopilotToken copilotToken = token == null ? null 28 | : new GitHubCopilotToken(token, System.currentTimeMillis() / 1000L + TimeUnit.HOURS.toSeconds(1L)); 29 | this.setCopilotToken(copilotToken); 30 | } 31 | 32 | @TestOnly 33 | public void refreshGitHubSession() { 34 | if (CopilotAgent.isAgentSupportedAndEnabled()) { 35 | throw new UnsupportedOperationException("todo"); 36 | } 37 | this.defaultService.refreshStatus(); 38 | } 39 | 40 | @TestOnly 41 | public void setCopilotToken(GitHubCopilotToken token) { 42 | if (CopilotAgent.isAgentSupportedAndEnabled()) { 43 | throw new UnsupportedOperationException("todo"); 44 | } 45 | this.defaultService.setCopilotToken(token); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/com/github/copilot/openai/TelemetryUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * it.unimi.dsi.fastutil.objects.Object2DoubleMap 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.openai; 9 | 10 | import com.github.copilot.openai.APIChoice; 11 | import com.github.copilot.telemetry.TelemetryData; 12 | import com.github.copilot.util.String2DoubleMap; 13 | import it.unimi.dsi.fastutil.objects.Object2DoubleMap; 14 | import java.util.Map; 15 | 16 | class TelemetryUtil { 17 | TelemetryUtil() { 18 | } 19 | 20 | static TelemetryData createChoiceTelemetry(APIChoice choice, TelemetryData base) { 21 | if (choice == null) { 22 | throw new IllegalStateException("choice cannot be null!"); 23 | } 24 | if (base == null) { 25 | throw new IllegalStateException("base cannot be null!"); 26 | } 27 | Object2DoubleMap metrics = String2DoubleMap.of("numTokens", choice.getNumTokens(), "compCharLen", 28 | choice.getCompletionTextLength(), "numLines", choice.getCompletion().size()); 29 | Double meanLogProb = choice.getMeanLogProb(); 30 | if (meanLogProb != null) { 31 | metrics.put((Object) "meanLogProb", choice.getMeanLogProb().doubleValue()); 32 | } 33 | TelemetryData telemetryData = TelemetryData.extend(base, 34 | Map.of("headerRequestId", choice.getResponseInfo().getHeaderRequestId(), "completionId", 35 | choice.getCompletionId(), "choiceIndex", String.valueOf(choice.getChoiceIndex()), "created", 36 | String.valueOf(choice.getCreatedTimestamp()), "serverExperiments", 37 | choice.getResponseInfo().getServerExperiments()), 38 | metrics); 39 | if (telemetryData == null) { 40 | throw new IllegalStateException("telemetryData cannot be null!"); 41 | } 42 | return telemetryData; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/com/github/copilot/toolWindow/DataProviderPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.Disposable 6 | * com.intellij.openapi.actionSystem.DataProvider 7 | * com.intellij.openapi.actionSystem.PlatformDataKeys 8 | * com.intellij.ui.components.JBPanelWithEmptyText 9 | * com.intellij.ui.components.panels.VerticalLayout 10 | * org.jetbrains.annotations.NonNls 11 | * org.jetbrains.annotations.NotNull 12 | * org.jetbrains.annotations.Nullable 13 | */ 14 | package com.github.copilot.toolWindow; 15 | 16 | import com.intellij.openapi.Disposable; 17 | import com.intellij.openapi.actionSystem.DataProvider; 18 | import com.intellij.openapi.actionSystem.PlatformDataKeys; 19 | import com.intellij.ui.components.JBPanelWithEmptyText; 20 | import com.intellij.ui.components.panels.VerticalLayout; 21 | import java.awt.LayoutManager; 22 | import java.awt.event.ActionListener; 23 | import javax.swing.KeyStroke; 24 | import org.jetbrains.annotations.NonNls; 25 | 26 | class DataProviderPanel extends JBPanelWithEmptyText implements DataProvider { 27 | private final Disposable parentDisposable; 28 | 29 | public void registerKeyboardAction(ActionListener anAction, String aCommand, KeyStroke aKeyStroke, int aCondition) { 30 | super.registerKeyboardAction(anAction, aCommand, aKeyStroke, aCondition); 31 | } 32 | 33 | DataProviderPanel(Disposable parentDisposable) { 34 | super((LayoutManager) new VerticalLayout(5)); 35 | this.parentDisposable = parentDisposable; 36 | } 37 | 38 | public Object getData(@NonNls String dataId) { 39 | if (dataId == null) { 40 | throw new IllegalStateException("dataId cannot be null!"); 41 | } 42 | if (PlatformDataKeys.UI_DISPOSABLE.is(dataId)) { 43 | return this.parentDisposable; 44 | } 45 | return null; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/com/github/copilot/actions/CopilotRequestCompletionsAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.actionSystem.AnAction 6 | * com.intellij.openapi.actionSystem.AnActionEvent 7 | * com.intellij.openapi.actionSystem.CommonDataKeys 8 | * com.intellij.openapi.editor.Editor 9 | * com.intellij.openapi.project.DumbAware 10 | * org.jetbrains.annotations.NotNull 11 | */ 12 | package com.github.copilot.actions; 13 | 14 | import com.github.copilot.actions.CopilotAction; 15 | import com.github.copilot.editor.CopilotEditorManager; 16 | import com.github.copilot.editor.CopilotEditorUtil; 17 | import com.intellij.openapi.actionSystem.AnAction; 18 | import com.intellij.openapi.actionSystem.AnActionEvent; 19 | import com.intellij.openapi.actionSystem.CommonDataKeys; 20 | import com.intellij.openapi.editor.Editor; 21 | import com.intellij.openapi.project.DumbAware; 22 | 23 | public class CopilotRequestCompletionsAction extends AnAction implements DumbAware, CopilotAction { 24 | public void update(AnActionEvent e) { 25 | if (e == null) { 26 | throw new IllegalStateException("e cannot be null!"); 27 | } 28 | Editor editor = (Editor) e.getData(CommonDataKeys.EDITOR); 29 | e.getPresentation().setEnabled(editor != null && CopilotEditorUtil.isSelectedEditor(editor)); 30 | } 31 | 32 | public void actionPerformed(AnActionEvent e) { 33 | if (e == null) { 34 | throw new IllegalStateException("e cannot be null!"); 35 | } 36 | CopilotEditorManager editorManager = CopilotEditorManager.getInstance(); 37 | Editor editor = (Editor) e.getData(CommonDataKeys.EDITOR); 38 | if (editor == null || !CopilotEditorUtil.isSelectedEditor(editor) || !editorManager.isAvailable(editor)) { 39 | return; 40 | } 41 | editorManager.editorModified(editor, true); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/commands/NotifyShownCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.google.gson.annotations.SerializedName 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.lang.agent.commands; 9 | 10 | import com.github.copilot.lang.agent.rpc.JsonRpcCommand; 11 | import com.google.gson.annotations.SerializedName; 12 | 13 | public final class NotifyShownCommand implements JsonRpcCommand { 14 | @SerializedName(value = "uuid") 15 | private final String uuid; 16 | 17 | @Override 18 | public String getCommandName() { 19 | return "notifyShown"; 20 | } 21 | 22 | @Override 23 | public Class getResponseType() { 24 | return String.class; 25 | } 26 | 27 | public String getUuid() { 28 | String string = this.uuid; 29 | if (string == null) { 30 | throw new IllegalStateException("string cannot be null!"); 31 | } 32 | return string; 33 | } 34 | 35 | public boolean equals(Object o) { 36 | if (o == this) { 37 | return true; 38 | } 39 | if (!(o instanceof NotifyShownCommand)) { 40 | return false; 41 | } 42 | NotifyShownCommand other = (NotifyShownCommand) o; 43 | String this$uuid = this.getUuid(); 44 | String other$uuid = other.getUuid(); 45 | return !(this$uuid == null ? other$uuid != null : !this$uuid.equals(other$uuid)); 46 | } 47 | 48 | public int hashCode() { 49 | int result = 1; 50 | String $uuid = this.getUuid(); 51 | result = result * 59 + ($uuid == null ? 43 : $uuid.hashCode()); 52 | return result; 53 | } 54 | 55 | public String toString() { 56 | return "NotifyShownCommand(uuid=" + this.getUuid() + ")"; 57 | } 58 | 59 | public NotifyShownCommand(String uuid) { 60 | if (uuid == null) { 61 | throw new IllegalStateException("uuid cannot be null!"); 62 | } 63 | this.uuid = uuid; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/commands/NotifyAcceptedCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.google.gson.annotations.SerializedName 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.lang.agent.commands; 9 | 10 | import com.github.copilot.lang.agent.rpc.JsonRpcCommand; 11 | import com.google.gson.annotations.SerializedName; 12 | 13 | public final class NotifyAcceptedCommand implements JsonRpcCommand { 14 | @SerializedName(value = "uuid") 15 | private final String uuid; 16 | 17 | @Override 18 | public String getCommandName() { 19 | return "notifyAccepted"; 20 | } 21 | 22 | @Override 23 | public Class getResponseType() { 24 | return String.class; 25 | } 26 | 27 | public String getUuid() { 28 | String string = this.uuid; 29 | if (string == null) { 30 | throw new IllegalStateException("string cannot be null!"); 31 | } 32 | return string; 33 | } 34 | 35 | public boolean equals(Object o) { 36 | if (o == this) { 37 | return true; 38 | } 39 | if (!(o instanceof NotifyAcceptedCommand)) { 40 | return false; 41 | } 42 | NotifyAcceptedCommand other = (NotifyAcceptedCommand) o; 43 | String this$uuid = this.getUuid(); 44 | String other$uuid = other.getUuid(); 45 | return !(this$uuid == null ? other$uuid != null : !this$uuid.equals(other$uuid)); 46 | } 47 | 48 | public int hashCode() { 49 | int result = 1; 50 | String $uuid = this.getUuid(); 51 | result = result * 59 + ($uuid == null ? 43 : $uuid.hashCode()); 52 | return result; 53 | } 54 | 55 | public String toString() { 56 | return "NotifyAcceptedCommand(uuid=" + this.getUuid() + ")"; 57 | } 58 | 59 | public NotifyAcceptedCommand(String uuid) { 60 | if (uuid == null) { 61 | throw new IllegalStateException("uuid cannot be null!"); 62 | } 63 | this.uuid = uuid; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/com/github/copilot/openai/OpenAI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.google.gson.Gson 6 | * com.google.gson.GsonBuilder 7 | * com.intellij.openapi.application.ApplicationManager 8 | */ 9 | package com.github.copilot.openai; 10 | 11 | import com.google.gson.Gson; 12 | import com.google.gson.GsonBuilder; 13 | import com.intellij.openapi.application.ApplicationManager; 14 | import java.time.ZoneId; 15 | import java.time.ZonedDateTime; 16 | 17 | public interface OpenAI { 18 | public static final Gson GSON = new GsonBuilder().create(); 19 | public static final String DEFAULT_ENGINE_PATH = "/v1/engines/copilot-codex"; 20 | public static final String GITHUB_PROXY_HOST = "https://copilot-proxy.githubusercontent.com"; 21 | public static final String GITHUB_API_COPILOT_TOKEN_URL = "https://api.github.com/copilot_internal/token"; 22 | public static final ZonedDateTime LAST_TELEMETRY_TERMS_UPDATE = ZonedDateTime.of(2021, 10, 14, 0, 0, 0, 0, 23 | ZoneId.of("UTC+8")); 24 | public static final int MULTILINE_COMPLETIONS_MAX_DOC_LINES = 8000; 25 | public static final int OPEN_COPILOT_COMPLETIONS = 10; 26 | public static final int ON_DEMAND_COPILOT_COMPLETIONS = 2; 27 | public static final int MAX_PROMPT_LENGTH = 1500; 28 | public static final double AVG_TOKEN_LENGTH = 2.5; 29 | public static final int COMPLETION_MIN_OFFSET = 10; 30 | public static final int HTTP_INCOMPATIBLE_CLIENT = 466; 31 | public static final long CONNECTION_TIMEOUT_MILLIS = 10000L; 32 | public static final long RESPONSE_TIMEOUT_MILLIS = 20000L; 33 | 34 | public static float getTemperatureForSamples(int numShots) { 35 | if (ApplicationManager.getApplication().isUnitTestMode()) { 36 | return 0.0f; 37 | } 38 | if (numShots <= 1) { 39 | return 0.0f; 40 | } 41 | if (numShots < 10) { 42 | return 0.2f; 43 | } 44 | if (numShots < 20) { 45 | return 0.4f; 46 | } 47 | return 0.8f; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/commands/NotifyRejectedCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.google.gson.annotations.SerializedName 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.lang.agent.commands; 9 | 10 | import com.github.copilot.lang.agent.rpc.JsonRpcCommand; 11 | import com.google.gson.annotations.SerializedName; 12 | import java.util.List; 13 | 14 | public final class NotifyRejectedCommand implements JsonRpcCommand { 15 | @SerializedName(value = "uuids") 16 | private final List uuids; 17 | 18 | @Override 19 | public String getCommandName() { 20 | return "notifyRejected"; 21 | } 22 | 23 | @Override 24 | public Class getResponseType() { 25 | return String.class; 26 | } 27 | 28 | public List getUuids() { 29 | List list = this.uuids; 30 | if (list == null) { 31 | throw new IllegalStateException("list cannot be null!"); 32 | } 33 | return list; 34 | } 35 | 36 | public boolean equals(Object o) { 37 | if (o == this) { 38 | return true; 39 | } 40 | if (!(o instanceof NotifyRejectedCommand)) { 41 | return false; 42 | } 43 | NotifyRejectedCommand other = (NotifyRejectedCommand) o; 44 | List this$uuids = this.getUuids(); 45 | List other$uuids = other.getUuids(); 46 | return !(this$uuids == null ? other$uuids != null : !((Object) this$uuids).equals(other$uuids)); 47 | } 48 | 49 | public int hashCode() { 50 | int result = 1; 51 | List $uuids = this.getUuids(); 52 | result = result * 59 + ($uuids == null ? 43 : ((Object) $uuids).hashCode()); 53 | return result; 54 | } 55 | 56 | public String toString() { 57 | return "NotifyRejectedCommand(uuids=" + this.getUuids() + ")"; 58 | } 59 | 60 | public NotifyRejectedCommand(List uuids) { 61 | if (uuids == null) { 62 | throw new IllegalStateException("uuids cannot be null!"); 63 | } 64 | this.uuids = uuids; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/commands/SignInInitiateResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.google.gson.JsonDeserializationContext 6 | * com.google.gson.JsonDeserializer 7 | * com.google.gson.JsonElement 8 | * com.google.gson.JsonObject 9 | * com.google.gson.JsonParseException 10 | * org.jetbrains.annotations.NotNull 11 | */ 12 | package com.github.copilot.lang.agent.commands; 13 | 14 | import com.google.gson.JsonDeserializationContext; 15 | import com.google.gson.JsonDeserializer; 16 | import com.google.gson.JsonElement; 17 | import com.google.gson.JsonObject; 18 | import com.google.gson.JsonParseException; 19 | import java.lang.reflect.Type; 20 | 21 | public interface SignInInitiateResult { 22 | public boolean isAlreadySignedIn(); 23 | 24 | public static final class TypeAdapter implements JsonDeserializer { 25 | public SignInInitiateResult deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) 26 | throws JsonParseException { 27 | String status; 28 | JsonObject o = jsonElement.getAsJsonObject(); 29 | switch (status = o.getAsJsonPrimitive("status").getAsString()) { 30 | case "PromptUserDeviceFlow": { 31 | return this.readAuthRequired(o); 32 | } 33 | case "AlreadySignedIn": { 34 | return new SignInInitiateSignedInResult(); 35 | } 36 | } 37 | throw new IllegalStateException("Unexpected status: " + status); 38 | } 39 | 40 | private SignInInitiateResult readAuthRequired(JsonObject o) { 41 | if (o == null) { 42 | throw new IllegalStateException("o cannot be null!"); 43 | } 44 | String userCode = o.getAsJsonPrimitive("userCode").getAsString(); 45 | String uri = o.getAsJsonPrimitive("verificationUri").getAsString(); 46 | long expiresIn = o.getAsJsonPrimitive("expiresIn").getAsLong(); 47 | long interval = o.getAsJsonPrimitive("interval").getAsLong(); 48 | return new SignInInitiateNotSignedInResult(userCode, uri, expiresIn, interval); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/prompt/PromptLanguageSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.lang.Language 6 | * com.intellij.openapi.extensions.ExtensionPointName 7 | * com.intellij.openapi.util.TextRange 8 | * com.intellij.psi.PsiElement 9 | * com.intellij.psi.PsiFile 10 | * org.jetbrains.annotations.NotNull 11 | * org.jetbrains.annotations.Nullable 12 | */ 13 | package com.github.copilot.lang.prompt; 14 | 15 | import com.github.copilot.openai.CopilotLanguage; 16 | import com.github.copilot.request.BlockMode; 17 | import com.intellij.lang.Language; 18 | import com.intellij.openapi.extensions.ExtensionPointName; 19 | import com.intellij.openapi.util.TextRange; 20 | import com.intellij.psi.PsiElement; 21 | import com.intellij.psi.PsiFile; 22 | 23 | public interface PromptLanguageSupport { 24 | public static final ExtensionPointName EP = new ExtensionPointName( 25 | "com.github.copilot.prompt"); 26 | 27 | public static PromptLanguageSupport find(CopilotLanguage language) { 28 | if (language == null) { 29 | throw new IllegalStateException("language cannot be null!"); 30 | } 31 | return (PromptLanguageSupport) EP.findFirstSafe(e -> e.isAvailable(language)); 32 | } 33 | 34 | public boolean isAvailable(CopilotLanguage var1); 35 | 36 | public String getLanguageMarker(PsiFile var1); 37 | 38 | public String getLanguageId(PsiFile var1); 39 | 40 | public String getPathMarker(Language var1, String var2); 41 | 42 | public PsiElement findParentFunction(PsiFile var1, int var2); 43 | 44 | public TextRange findFunctionRange(PsiElement var1); 45 | 46 | public PsiElement findNextSiblingFunction(PsiElement var1); 47 | 48 | public boolean isSupportingMultilineCompletion(Language var1); 49 | 50 | default public BlockMode getBlockMode() { 51 | BlockMode blockMode = BlockMode.Client; 52 | if (blockMode == null) { 53 | throw new IllegalStateException("blockMode cannot be null!"); 54 | } 55 | return blockMode; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/com/github/copilot/actions/RefreshCopilotToolWindowAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.icons.AllIcons$Actions 6 | * com.intellij.openapi.actionSystem.ActionManager 7 | * com.intellij.openapi.actionSystem.AnAction 8 | * com.intellij.openapi.actionSystem.AnActionEvent 9 | * com.intellij.openapi.editor.Editor 10 | * com.intellij.openapi.fileEditor.FileEditorManager 11 | * com.intellij.openapi.project.Project 12 | * org.jetbrains.annotations.NotNull 13 | */ 14 | package com.github.copilot.actions; 15 | 16 | import com.github.copilot.CopilotBundle; 17 | import com.github.copilot.toolWindow.CopilotSplitEditorManager; 18 | import com.intellij.icons.AllIcons; 19 | import com.intellij.openapi.actionSystem.ActionManager; 20 | import com.intellij.openapi.actionSystem.AnAction; 21 | import com.intellij.openapi.actionSystem.AnActionEvent; 22 | import com.intellij.openapi.editor.Editor; 23 | import com.intellij.openapi.fileEditor.FileEditorManager; 24 | import com.intellij.openapi.project.Project; 25 | 26 | public class RefreshCopilotToolWindowAction extends AnAction { 27 | public RefreshCopilotToolWindowAction() { 28 | super(CopilotBundle.get("openCopilot.refreshAction"), null, AllIcons.Actions.Refresh); 29 | AnAction refreshAction = ActionManager.getInstance().getAction("Refresh"); 30 | if (refreshAction != null) { 31 | this.copyShortcutFrom(refreshAction); 32 | } 33 | } 34 | 35 | public void update(AnActionEvent e) { 36 | if (e == null) { 37 | throw new IllegalStateException("e cannot be null!"); 38 | } 39 | e.getPresentation().setEnabledAndVisible(e.getProject() != null); 40 | } 41 | 42 | public void actionPerformed(AnActionEvent e) { 43 | Project project; 44 | if (e == null) { 45 | throw new IllegalStateException("e cannot be null!"); 46 | } 47 | if ((project = e.getProject()) == null) { 48 | return; 49 | } 50 | Editor editor = FileEditorManager.getInstance((Project) project).getSelectedTextEditor(); 51 | if (editor != null) { 52 | CopilotSplitEditorManager.getInstance().openCopilot(editor, true); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/fallback/VSCodeLanguageMap.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.lang.fallback; 2 | 3 | import java.util.Collections; 4 | import java.util.Map; 5 | import java.util.concurrent.ConcurrentHashMap; 6 | 7 | public final class VSCodeLanguageMap { 8 | public static final Map INTELLIJ_VSCODE_MAP = Collections 9 | .unmodifiableMap(new ConcurrentHashMap() { 10 | private static final long serialVersionUID = -6245267354191843399L; 11 | 12 | { 13 | this.put("CoffeeScript", "coffeescript"); 14 | this.put("ObjectiveC", "c"); 15 | this.put("CSS", "css"); 16 | this.put("go", "go"); 17 | this.put("Groovy", "groovy"); 18 | this.put("Handlebars", "handlebars"); 19 | this.put("HTML", "html"); 20 | this.put("XHTML", "html"); 21 | this.put("JAVA", "java"); 22 | this.put("JavaScript", "javascript"); 23 | this.put("TypeScript JSX", "jsx"); 24 | this.put("LESS", "less"); 25 | this.put("Makefile", "makefile"); 26 | this.put("Markdown", "markdown"); 27 | this.put("PHP", "php"); 28 | this.put("Jade", "pug"); 29 | this.put("Python", "python"); 30 | this.put("R", "r"); 31 | this.put("ruby", "ruby"); 32 | this.put("Rust", "rust"); 33 | this.put("SCSS", "scss"); 34 | this.put("Shell Script", "shellscript"); 35 | this.put("SQL", "sql"); 36 | this.put("SQL92", "sql"); 37 | this.put("Stylus", "stylus"); 38 | this.put("TypeScript", "typescript"); 39 | this.put("Vue", "vue"); 40 | this.put("XML", "xml"); 41 | this.put("yaml", "yaml"); 42 | } 43 | }); 44 | public static final Map SHEBANG_MAP = Collections 45 | .unmodifiableMap(new ConcurrentHashMap() { 46 | private static final long serialVersionUID = -4376366775698776171L; 47 | 48 | { 49 | this.put("shellscript", "#!/bin/sh"); 50 | this.put("python", "#!/usr/bin/env python3"); 51 | this.put("ruby", "#!/usr/bin/env ruby"); 52 | this.put("html", ""); 53 | this.put("yaml", "# YAML data"); 54 | } 55 | }); 56 | 57 | private VSCodeLanguageMap() { 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/com/github/copilot/update/CopilotUpdateStartupActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.application.ApplicationManager 6 | * me.masecla.copilot.extra.Logger 7 | * com.intellij.openapi.project.Project 8 | * com.intellij.openapi.startup.StartupActivity$Background 9 | * com.intellij.util.concurrency.annotations.RequiresBackgroundThread 10 | * org.jetbrains.annotations.NotNull 11 | */ 12 | package com.github.copilot.update; 13 | 14 | import com.github.copilot.settings.CopilotApplicationSettings; 15 | import com.github.copilot.settings.CopilotLocalApplicationSettings; 16 | import com.github.copilot.update.CopilotPluginUpdater; 17 | import com.intellij.openapi.application.ApplicationManager; 18 | import me.masecla.copilot.extra.Logger; 19 | import com.intellij.openapi.project.Project; 20 | import com.intellij.openapi.startup.StartupActivity; 21 | import com.intellij.util.concurrency.annotations.RequiresBackgroundThread; 22 | import java.time.ZonedDateTime; 23 | import java.util.concurrent.atomic.AtomicBoolean; 24 | 25 | public class CopilotUpdateStartupActivity implements StartupActivity.Background { 26 | private static final Logger LOG = Logger.getInstance(CopilotUpdateStartupActivity.class); 27 | private final AtomicBoolean hasRun = new AtomicBoolean(false); 28 | 29 | @RequiresBackgroundThread 30 | public void runActivity(Project project) { 31 | if (project == null) { 32 | throw new IllegalStateException("project cannot be null!"); 33 | } 34 | if (!this.hasRun.compareAndSet(false, true) || ApplicationManager.getApplication().isUnitTestMode()) { 35 | return; 36 | } 37 | if (!CopilotApplicationSettings.settings().checkForUpdate) { 38 | LOG.debug("Update check is disabled"); 39 | return; 40 | } 41 | ZonedDateTime now = ZonedDateTime.now(); 42 | ZonedDateTime lastCheck = CopilotLocalApplicationSettings.settings().lastUpdateCheck; 43 | if (lastCheck != null && lastCheck.plusDays(1L).isAfter(now)) { 44 | return; 45 | } 46 | CopilotLocalApplicationSettings.settings().lastUpdateCheck = now; 47 | new CopilotPluginUpdater.CheckUpdatesTask(project).queue(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/com/github/copilot/telemetry/CopilotActionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.actionSystem.ActionManager 6 | * com.intellij.openapi.actionSystem.AnAction 7 | * com.intellij.openapi.actionSystem.AnActionEvent 8 | * com.intellij.openapi.actionSystem.AnActionResult 9 | * com.intellij.openapi.actionSystem.ex.AnActionListener 10 | * com.intellij.openapi.application.ApplicationManager 11 | * org.jetbrains.annotations.NotNull 12 | */ 13 | package com.github.copilot.telemetry; 14 | 15 | import com.github.copilot.actions.CopilotAction; 16 | import com.github.copilot.telemetry.TelemetryService; 17 | import com.intellij.openapi.actionSystem.ActionManager; 18 | import com.intellij.openapi.actionSystem.AnAction; 19 | import com.intellij.openapi.actionSystem.AnActionEvent; 20 | import com.intellij.openapi.actionSystem.AnActionResult; 21 | import com.intellij.openapi.actionSystem.ex.AnActionListener; 22 | import com.intellij.openapi.application.ApplicationManager; 23 | import java.util.Map; 24 | 25 | public class CopilotActionListener implements AnActionListener { 26 | public void afterActionPerformed(AnAction action, AnActionEvent event, AnActionResult result) { 27 | if (action == null) { 28 | throw new IllegalStateException("action cannot be null!"); 29 | } 30 | if (event == null) { 31 | throw new IllegalStateException("event cannot be null!"); 32 | } 33 | if (result == null) { 34 | throw new IllegalStateException("result cannot be null!"); 35 | } 36 | if (!(action instanceof CopilotAction)) { 37 | return; 38 | } 39 | if (ApplicationManager.getApplication().isUnitTestMode()) { 40 | return; 41 | } 42 | Map metrics = Map.of(); 43 | if (event.getInputEvent() != null) { 44 | metrics = Map.of("runningTimeMs", 45 | System.currentTimeMillis() - (double) event.getInputEvent().getWhen()); 46 | } 47 | String id = ActionManager.getInstance().getId(action); 48 | boolean isError = !result.isPerformed(); 49 | TelemetryService.getInstance().track("command.executed", 50 | Map.of("command", id, "isError", String.valueOf(isError)), metrics); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/CopilotAgentUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.execution.configurations.PathEnvironmentVariableUtil 6 | * com.intellij.openapi.application.ApplicationManager 7 | * me.masecla.copilot.extra.Logger 8 | * org.jetbrains.annotations.Nullable 9 | */ 10 | package com.github.copilot.lang.agent; 11 | 12 | import com.github.copilot.CopilotPlugin; 13 | import com.intellij.execution.configurations.PathEnvironmentVariableUtil; 14 | import com.intellij.openapi.application.ApplicationManager; 15 | import me.masecla.copilot.extra.Logger; 16 | import java.io.File; 17 | import java.nio.file.Files; 18 | import java.nio.file.LinkOption; 19 | import java.nio.file.Path; 20 | import java.nio.file.Paths; 21 | 22 | public class CopilotAgentUtil { 23 | private static final Logger LOG = Logger.getInstance(CopilotAgentUtil.class); 24 | 25 | public static Path getNodeExecutablePath() { 26 | File path = PathEnvironmentVariableUtil.findExecutableInPathOnAnyOS((String) "node"); 27 | if (path == null) { 28 | LOG.warn("node executable not found in $PATH"); 29 | return null; 30 | } 31 | Path nioPath = path.toPath(); 32 | if (!Files.isExecutable(nioPath)) { 33 | LOG.warn("node executable has no execute permissions: " + nioPath); 34 | return null; 35 | } 36 | LOG.debug("Found node executable at " + nioPath); 37 | return nioPath; 38 | } 39 | 40 | public static Path getAgentDirectoryPath() { 41 | String envValue; 42 | if (ApplicationManager.getApplication().isUnitTestMode() 43 | && (envValue = System.getenv("GITHUB_COPILOT_AGENTDIR")) != null) { 44 | Path envPath = Paths.get(envValue, new String[0]); 45 | if (!Files.exists(envPath, new LinkOption[0])) { 46 | LOG.error("GITHUB_COPILOT_AGENTDIR path doesn't exist: " + envPath); 47 | return null; 48 | } 49 | return envPath; 50 | } 51 | Path basePath = CopilotPlugin.getPluginBasePath(); 52 | Path distPath = basePath.resolve("copilot-agent/dist"); 53 | if (Files.exists(distPath, new LinkOption[0])) { 54 | return distPath; 55 | } 56 | LOG.error("Unable to locate the Copilot agent dist path in base path: " + basePath); 57 | return null; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/com/github/copilot/editor/CompletionPopupInhibitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.codeInsight.editorActions.TypedHandlerDelegate 6 | * com.intellij.codeInsight.editorActions.TypedHandlerDelegate$Result 7 | * me.masecla.copilot.extra.Logger 8 | * com.intellij.openapi.editor.Editor 9 | * com.intellij.openapi.project.Project 10 | * com.intellij.psi.PsiFile 11 | * org.jetbrains.annotations.NotNull 12 | */ 13 | package com.github.copilot.editor; 14 | 15 | import com.github.copilot.editor.CopilotEditorManager; 16 | import com.github.copilot.settings.CopilotApplicationSettings; 17 | import com.intellij.codeInsight.editorActions.TypedHandlerDelegate; 18 | import me.masecla.copilot.extra.Logger; 19 | import com.intellij.openapi.editor.Editor; 20 | import com.intellij.openapi.project.Project; 21 | import com.intellij.psi.PsiFile; 22 | 23 | public class CompletionPopupInhibitor extends TypedHandlerDelegate { 24 | private static final Logger LOG = Logger.getInstance(CompletionPopupInhibitor.class); 25 | 26 | public TypedHandlerDelegate.Result checkAutoPopup(char charTyped, Project project, Editor editor, PsiFile file) { 27 | boolean showIdeCompletions; 28 | if (project == null) { 29 | throw new IllegalStateException("project cannot be null!"); 30 | } 31 | if (editor == null) { 32 | throw new IllegalStateException("editor cannot be null!"); 33 | } 34 | if (file == null) { 35 | throw new IllegalStateException("file cannot be null!"); 36 | } 37 | if (!(showIdeCompletions = CopilotApplicationSettings.settings().isShowIdeCompletions()) 38 | && CopilotEditorManager.getInstance().hasTypingAsSuggestedData(editor, charTyped)) { 39 | LOG.debug("inhibiting IDE completion popup because typing-as-suggested is available"); 40 | TypedHandlerDelegate.Result result = TypedHandlerDelegate.Result.STOP; 41 | if (result == null) { 42 | throw new IllegalStateException("result cannot be null!"); 43 | } 44 | return result; 45 | } 46 | TypedHandlerDelegate.Result result = super.checkAutoPopup(charTyped, project, editor, file); 47 | if (result == null) { 48 | throw new IllegalStateException("result cannot be null!"); 49 | } 50 | return result; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/com/github/copilot/settings/LanguageChoice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.lang.Language 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.settings; 9 | 10 | import com.intellij.lang.Language; 11 | 12 | class LanguageChoice { 13 | private final Language language; 14 | private boolean selected; 15 | 16 | public Language getLanguage() { 17 | Language language = this.language; 18 | if (language == null) { 19 | throw new IllegalStateException("language cannot be null!"); 20 | } 21 | return language; 22 | } 23 | 24 | public boolean isSelected() { 25 | return this.selected; 26 | } 27 | 28 | public void setSelected(boolean selected) { 29 | this.selected = selected; 30 | } 31 | 32 | public boolean equals(Object o) { 33 | if (o == this) { 34 | return true; 35 | } 36 | if (!(o instanceof LanguageChoice)) { 37 | return false; 38 | } 39 | LanguageChoice other = (LanguageChoice) o; 40 | if (!other.canEqual(this)) { 41 | return false; 42 | } 43 | if (this.isSelected() != other.isSelected()) { 44 | return false; 45 | } 46 | Language this$language = this.getLanguage(); 47 | Language other$language = other.getLanguage(); 48 | return !(this$language == null ? other$language != null : !this$language.equals(other$language)); 49 | } 50 | 51 | protected boolean canEqual(Object other) { 52 | return other instanceof LanguageChoice; 53 | } 54 | 55 | public int hashCode() { 56 | int PRIME = 59; 57 | int result = 1; 58 | result = result * 59 + (this.isSelected() ? 79 : 97); 59 | Language $language = this.getLanguage(); 60 | result = result * 59 + ($language == null ? 43 : $language.hashCode()); 61 | return result; 62 | } 63 | 64 | public String toString() { 65 | return "LanguageChoice(language=" + this.getLanguage() + ", selected=" + this.isSelected() + ")"; 66 | } 67 | 68 | public LanguageChoice(Language language, boolean selected) { 69 | if (language == null) { 70 | throw new IllegalStateException("language cannot be null!"); 71 | } 72 | if (language == null) { 73 | throw new NullPointerException("language is marked non-null but is null"); 74 | } 75 | this.language = language; 76 | this.selected = selected; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/com/github/copilot/settings/CopilotLocalApplicationSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.application.ApplicationManager 6 | * com.intellij.openapi.components.PersistentStateComponent 7 | * com.intellij.openapi.components.RoamingType 8 | * com.intellij.openapi.components.State 9 | * com.intellij.openapi.components.Storage 10 | * org.jetbrains.annotations.NotNull 11 | * org.jetbrains.annotations.Nullable 12 | */ 13 | package com.github.copilot.settings; 14 | 15 | import com.github.copilot.settings.CopilotLocalApplicationState; 16 | import com.intellij.openapi.application.ApplicationManager; 17 | import com.intellij.openapi.components.PersistentStateComponent; 18 | import com.intellij.openapi.components.RoamingType; 19 | import com.intellij.openapi.components.State; 20 | import com.intellij.openapi.components.Storage; 21 | 22 | @State(name = "github-copilot-local", storages = { 23 | @Storage(value = "github-copilot.local.xml", roamingType = RoamingType.DISABLED) }) 24 | public class CopilotLocalApplicationSettings implements PersistentStateComponent { 25 | private CopilotLocalApplicationState state; 26 | 27 | public static CopilotLocalApplicationState settings() { 28 | CopilotLocalApplicationState state = ((CopilotLocalApplicationSettings) ApplicationManager.getApplication() 29 | .getService(CopilotLocalApplicationSettings.class)).getState(); 30 | assert (state != null); 31 | CopilotLocalApplicationState copilotLocalApplicationState = state; 32 | if (copilotLocalApplicationState == null) { 33 | throw new IllegalStateException("copilotLocalApplicationState cannot be null!"); 34 | } 35 | return copilotLocalApplicationState; 36 | } 37 | 38 | public synchronized CopilotLocalApplicationState getState() { 39 | return this.state; 40 | } 41 | 42 | public synchronized void noStateLoaded() { 43 | CopilotLocalApplicationState state = new CopilotLocalApplicationState(); 44 | state.githubTokenMigration = true; 45 | this.state = state; 46 | } 47 | 48 | public synchronized void loadState(CopilotLocalApplicationState state) { 49 | if (state == null) { 50 | throw new IllegalStateException("state cannot be null!"); 51 | } 52 | this.state = state; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/com/github/copilot/editor/CopilotLookupListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.codeInsight.lookup.Lookup 6 | * com.intellij.codeInsight.lookup.LookupManagerListener 7 | * me.masecla.copilot.extra.Logger 8 | * com.intellij.openapi.editor.Editor 9 | * com.intellij.psi.PsiFile 10 | * org.jetbrains.annotations.Nullable 11 | */ 12 | package com.github.copilot.editor; 13 | 14 | import com.github.copilot.editor.CopilotEditorManager; 15 | import com.github.copilot.editor.CopilotEditorUtil; 16 | import com.github.copilot.editor.InlayDisposeContext; 17 | import com.github.copilot.settings.CopilotApplicationSettings; 18 | import com.intellij.codeInsight.lookup.Lookup; 19 | import com.intellij.codeInsight.lookup.LookupManagerListener; 20 | import me.masecla.copilot.extra.Logger; 21 | import com.intellij.openapi.editor.Editor; 22 | import com.intellij.psi.PsiFile; 23 | 24 | public class CopilotLookupListener implements LookupManagerListener { 25 | private static final Logger LOG = Logger.getInstance(CopilotLookupListener.class); 26 | 27 | public void activeLookupChanged(Lookup oldLookup, Lookup newLookup) { 28 | PsiFile psiFile; 29 | LOG.debug("activeLookupChanged"); 30 | Lookup validLookup = newLookup != null ? newLookup : oldLookup; 31 | PsiFile psiFile2 = psiFile = validLookup != null ? validLookup.getPsiFile() : null; 32 | if (psiFile != null && !CopilotApplicationSettings.isCopilotEnabled(psiFile)) { 33 | return; 34 | } 35 | CopilotEditorManager editorManager = CopilotEditorManager.getInstance(); 36 | if (oldLookup != null && newLookup == null) { 37 | Editor editor; 38 | PsiFile file = oldLookup.getPsiFile(); 39 | if (file != null && CopilotEditorUtil.isSelectedEditor(editor = oldLookup.getEditor()) 40 | && editorManager.isAvailable(editor) && !editor.getDocument().isInBulkUpdate()) { 41 | editorManager.editorModified(editor, editor.getCaretModel().getOffset(), true); 42 | } 43 | } else if (newLookup != null && oldLookup == null 44 | && !CopilotApplicationSettings.settings().isShowIdeCompletions()) { 45 | Editor editor = newLookup.getEditor(); 46 | editorManager.cancelCompletionRequests(editor); 47 | editorManager.disposeInlays(editor, InlayDisposeContext.IdeCompletion); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/com/github/copilot/github/GitHubAuthUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.CommonBundle 6 | * com.intellij.ide.BrowserUtil 7 | * com.intellij.openapi.project.Project 8 | * com.intellij.openapi.ui.Messages 9 | * com.intellij.openapi.util.text.StringUtil 10 | * org.jetbrains.annotations.NotNull 11 | * org.jetbrains.annotations.Nullable 12 | */ 13 | package com.github.copilot.github; 14 | 15 | import com.github.copilot.CopilotBundle; 16 | import com.intellij.CommonBundle; 17 | import com.intellij.ide.BrowserUtil; 18 | import com.intellij.openapi.project.Project; 19 | import com.intellij.openapi.ui.Messages; 20 | import com.intellij.openapi.util.text.StringUtil; 21 | import javax.swing.Icon; 22 | 23 | public final class GitHubAuthUtil { 24 | private static final String COPILOT_URL = "https://copilot.github.com"; 25 | 26 | private GitHubAuthUtil() { 27 | } 28 | 29 | public static void showUnauthorizedMessage(Project project, String url) { 30 | int clickedButton; 31 | if (project == null) { 32 | throw new IllegalStateException("project cannot be null!"); 33 | } 34 | if ((clickedButton = Messages.showDialog((Project) project, 35 | (String) CopilotBundle.get("github.login.copilotUnauthorized.message", 36 | StringUtil.defaultIfEmpty((String) url, (String) COPILOT_URL)), 37 | (String) CopilotBundle.get("github.login.copilotUnauthorized.title"), 38 | (String[]) new String[] { CopilotBundle.get("github.login.copilotUnauthorized.joinButton"), 39 | CommonBundle.getCloseButtonText() }, 40 | (int) 0, (Icon) Messages.getWarningIcon())) == 0) { 41 | BrowserUtil.open((String) StringUtil.defaultIfEmpty((String) url, (String) COPILOT_URL)); 42 | } 43 | } 44 | 45 | public static boolean showTelemetryTermsDialog(Project project) { 46 | if (project == null) { 47 | throw new IllegalStateException("project cannot be null!"); 48 | } 49 | return Messages.showYesNoDialog((Project) project, 50 | (String) CopilotBundle.get("github.login.telemetryConsent.message"), 51 | (String) CopilotBundle.get("github.login.telemetryConsent.title"), 52 | (String) CopilotBundle.get("github.login.telemetryConsent.yes"), 53 | (String) CopilotBundle.get("github.login.telemetryConsent.no"), (Icon) Messages.getWarningIcon()) == 0; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/com/github/copilot/openai/StringDoublePair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.google.gson.TypeAdapter 6 | * com.google.gson.stream.JsonReader 7 | * com.google.gson.stream.JsonWriter 8 | */ 9 | package com.github.copilot.openai; 10 | 11 | import com.google.gson.stream.JsonReader; 12 | import com.google.gson.stream.JsonWriter; 13 | import java.io.IOException; 14 | 15 | final class StringDoublePair { 16 | private final String key; 17 | private final double value; 18 | 19 | public StringDoublePair(String key, double value) { 20 | this.key = key; 21 | this.value = value; 22 | } 23 | 24 | public String getKey() { 25 | return this.key; 26 | } 27 | 28 | public double getValue() { 29 | return this.value; 30 | } 31 | 32 | public boolean equals(Object o) { 33 | if (o == this) { 34 | return true; 35 | } 36 | if (!(o instanceof StringDoublePair)) { 37 | return false; 38 | } 39 | StringDoublePair other = (StringDoublePair) o; 40 | if (Double.compare(this.getValue(), other.getValue()) != 0) { 41 | return false; 42 | } 43 | String this$key = this.getKey(); 44 | String other$key = other.getKey(); 45 | return !(this$key == null ? other$key != null : !this$key.equals(other$key)); 46 | } 47 | 48 | public int hashCode() { 49 | int result = 1; 50 | long $value = Double.doubleToLongBits(this.getValue()); 51 | result = result * 59 + (int) ($value >>> 32 ^ $value); 52 | String $key = this.getKey(); 53 | result = result * 59 + ($key == null ? 43 : $key.hashCode()); 54 | return result; 55 | } 56 | 57 | public String toString() { 58 | return "StringDoublePair(key=" + this.getKey() + ", value=" + this.getValue() + ")"; 59 | } 60 | 61 | static final class TypeAdapter extends com.google.gson.TypeAdapter { 62 | TypeAdapter() { 63 | } 64 | 65 | public void write(JsonWriter jsonWriter, StringDoublePair pair) throws IOException { 66 | jsonWriter.beginObject(); 67 | jsonWriter.name(pair.key); 68 | jsonWriter.value(pair.value); 69 | jsonWriter.endObject(); 70 | } 71 | 72 | public StringDoublePair read(JsonReader jsonReader) throws IOException { 73 | jsonReader.beginObject(); 74 | String key = jsonReader.nextName(); 75 | double value = jsonReader.nextDouble(); 76 | jsonReader.endObject(); 77 | return new StringDoublePair(key, value); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/com/github/copilot/editor/EditorSelectionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.editor.Editor 6 | * com.intellij.openapi.fileEditor.FileEditor 7 | * com.intellij.openapi.fileEditor.FileEditorManagerEvent 8 | * com.intellij.openapi.fileEditor.FileEditorManagerListener 9 | * com.intellij.openapi.fileEditor.TextEditor 10 | * com.intellij.openapi.project.Project 11 | * com.intellij.openapi.vfs.VirtualFile 12 | * com.intellij.psi.PsiFile 13 | * com.intellij.psi.PsiManager 14 | * org.jetbrains.annotations.NotNull 15 | */ 16 | package com.github.copilot.editor; 17 | 18 | import com.github.copilot.editor.CopilotEditorManager; 19 | import com.github.copilot.editor.InlayDisposeContext; 20 | import com.github.copilot.lang.LanguageSupport; 21 | import com.intellij.openapi.editor.Editor; 22 | import com.intellij.openapi.fileEditor.FileEditor; 23 | import com.intellij.openapi.fileEditor.FileEditorManagerEvent; 24 | import com.intellij.openapi.fileEditor.FileEditorManagerListener; 25 | import com.intellij.openapi.fileEditor.TextEditor; 26 | import com.intellij.openapi.project.Project; 27 | import com.intellij.openapi.vfs.VirtualFile; 28 | import com.intellij.psi.PsiFile; 29 | import com.intellij.psi.PsiManager; 30 | 31 | public class EditorSelectionListener implements FileEditorManagerListener { 32 | private final Project project; 33 | 34 | public EditorSelectionListener(Project project) { 35 | if (project == null) { 36 | throw new IllegalStateException("project cannot be null!"); 37 | } 38 | this.project = project; 39 | } 40 | 41 | public void selectionChanged(FileEditorManagerEvent event) { 42 | VirtualFile oldFile; 43 | if (event == null) { 44 | throw new IllegalStateException("event cannot be null!"); 45 | } 46 | if ((oldFile = event.getOldFile()) == null || !oldFile.isValid()) { 47 | return; 48 | } 49 | PsiFile psiFile = PsiManager.getInstance((Project) this.project).findFile(oldFile); 50 | if (psiFile == null || !psiFile.isValid()) { 51 | return; 52 | } 53 | if (LanguageSupport.find(psiFile) == null) { 54 | return; 55 | } 56 | FileEditor oldEditor = event.getOldEditor(); 57 | if (oldEditor instanceof TextEditor) { 58 | Editor editor = ((TextEditor) oldEditor).getEditor(); 59 | CopilotEditorManager.getInstance().disposeInlays(editor, InlayDisposeContext.UserAction); 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/com/github/copilot/CopilotNotifications.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.notification.Notification 6 | * com.intellij.notification.NotificationListener 7 | * com.intellij.notification.NotificationListener$UrlOpeningListener 8 | * com.intellij.notification.NotificationType 9 | * com.intellij.notification.impl.NotificationFullContent 10 | * com.intellij.openapi.util.NlsContexts$NotificationContent 11 | * com.intellij.openapi.util.NlsContexts$NotificationTitle 12 | * org.jetbrains.annotations.NotNull 13 | */ 14 | package com.github.copilot; 15 | 16 | import com.intellij.notification.Notification; 17 | import com.intellij.notification.NotificationListener; 18 | import com.intellij.notification.NotificationType; 19 | import com.intellij.notification.impl.NotificationFullContent; 20 | import com.intellij.openapi.util.NlsContexts; 21 | 22 | public final class CopilotNotifications { 23 | private static final String GROUP_ID = "github.copilot.notifications"; 24 | 25 | private CopilotNotifications() { 26 | } 27 | 28 | public static Notification createFullContentNotification(String title, String content, NotificationType type, 29 | boolean expireOnLinkClick) { 30 | if (title == null) { 31 | throw new IllegalStateException("title cannot be null!"); 32 | } 33 | if (content == null) { 34 | throw new IllegalStateException("content cannot be null!"); 35 | } 36 | if (type == null) { 37 | throw new IllegalStateException("type cannot be null!"); 38 | } 39 | FullContent notification = new FullContent(GROUP_ID, title, content, type); 40 | notification.setListener((NotificationListener) new NotificationListener.UrlOpeningListener(expireOnLinkClick)); 41 | return notification; 42 | } 43 | 44 | private static class FullContent extends Notification implements NotificationFullContent { 45 | public FullContent(String groupId, @NlsContexts.NotificationTitle String title, 46 | @NlsContexts.NotificationContent String content, NotificationType type) { 47 | if (groupId == null) { 48 | throw new IllegalStateException("groupId cannot be null!"); 49 | } 50 | if (title == null) { 51 | throw new IllegalStateException("title cannot be null!"); 52 | } 53 | if (content == null) { 54 | throw new IllegalStateException("content cannot be null!"); 55 | } 56 | if (type == null) { 57 | throw new IllegalStateException("type cannot be null!"); 58 | } 59 | super(groupId, title, content, type); 60 | } 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/LanguageSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.extensions.ExtensionPointName 6 | * com.intellij.openapi.fileTypes.FileType 7 | * com.intellij.openapi.project.Project 8 | * com.intellij.psi.PsiFile 9 | * com.intellij.util.concurrency.annotations.RequiresBackgroundThread 10 | * com.intellij.util.concurrency.annotations.RequiresReadLock 11 | * org.jetbrains.annotations.NotNull 12 | * org.jetbrains.annotations.Nullable 13 | */ 14 | package com.github.copilot.lang; 15 | 16 | import com.github.copilot.openai.CopilotLanguage; 17 | import com.github.copilot.util.Cancellable; 18 | import com.intellij.openapi.extensions.ExtensionPointName; 19 | import com.intellij.openapi.fileTypes.FileType; 20 | import com.intellij.openapi.project.Project; 21 | import com.intellij.psi.PsiFile; 22 | import com.intellij.util.concurrency.annotations.RequiresBackgroundThread; 23 | import com.intellij.util.concurrency.annotations.RequiresReadLock; 24 | 25 | public interface LanguageSupport { 26 | public static final ExtensionPointName EP = new ExtensionPointName("com.github.copilot.language"); 27 | public static final String[] DEFAULT_SINGLE_LINE_STOP = new String[] { "\n" }; 28 | public static final String[] DEFAULT_MULTI_LINE_STOP = new String[] { "\n\n\n" }; 29 | 30 | public static LanguageSupport find(PsiFile file) { 31 | if (file == null) { 32 | throw new IllegalStateException("file cannot be null!"); 33 | } 34 | return (LanguageSupport) EP.findFirstSafe(e -> e.isAvailable(file)); 35 | } 36 | 37 | public boolean isAvailable(PsiFile var1); 38 | 39 | public FileType getFileType(); 40 | 41 | public CopilotLanguage getCopilotLanguage(); 42 | 43 | @RequiresBackgroundThread 44 | @RequiresReadLock 45 | public boolean isEmptyBlockStart(Project var1, PsiFile var2, int var3); 46 | 47 | @RequiresBackgroundThread 48 | public Integer findBlockEnd(Project var1, Cancellable var2, String var3, int var4, String var5, boolean var6); 49 | 50 | default public String[] getMultiLineStops() { 51 | if (DEFAULT_MULTI_LINE_STOP == null) { 52 | throw new IllegalStateException("DEFAULT_MULTI_LINE_STOP cannot be null"); 53 | } 54 | return DEFAULT_MULTI_LINE_STOP; 55 | } 56 | 57 | default public String[] getSingleLineStops() { 58 | if (DEFAULT_SINGLE_LINE_STOP == null) { 59 | throw new IllegalStateException("DEFAULT_SINGLE_LINE_STOP cannot be null"); 60 | } 61 | return DEFAULT_SINGLE_LINE_STOP; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/com/github/copilot/telemetry/TelemetryService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.application.ApplicationManager 6 | * org.jetbrains.annotations.NotNull 7 | * org.jetbrains.annotations.Nullable 8 | */ 9 | package com.github.copilot.telemetry; 10 | 11 | import com.github.copilot.telemetry.TelemetryData; 12 | import com.intellij.openapi.application.ApplicationManager; 13 | import java.util.Collections; 14 | import java.util.Map; 15 | 16 | public interface TelemetryService { 17 | public static TelemetryService getInstance() { 18 | TelemetryService telemetryService = (TelemetryService) ApplicationManager.getApplication() 19 | .getService(TelemetryService.class); 20 | if (telemetryService == null) { 21 | throw new IllegalStateException("telemetryService cannot be null!"); 22 | } 23 | return telemetryService; 24 | } 25 | 26 | public void setTrackingId(String var1); 27 | 28 | public void trackException(Throwable var1, Map var2); 29 | 30 | public void track(String var1, TelemetryData var2); 31 | 32 | default public void track(String name) { 33 | if (name == null) { 34 | throw new IllegalStateException("name cannot be null!"); 35 | } 36 | this.track(name, Collections.emptyMap(), Collections.emptyMap()); 37 | } 38 | 39 | default public void track(String name, Map properties) { 40 | if (name == null) { 41 | throw new IllegalStateException("name cannot be null!"); 42 | } 43 | if (properties == null) { 44 | throw new IllegalStateException("properties cannot be null!"); 45 | } 46 | this.track(name, properties, Collections.emptyMap()); 47 | } 48 | 49 | public void track(String var1, Map var2, Map var3); 50 | 51 | public void trackSecure(String var1, TelemetryData var2); 52 | 53 | default public void trackSecure(String name) { 54 | if (name == null) { 55 | throw new IllegalStateException("name cannot be null!"); 56 | } 57 | this.trackSecure(name, Collections.emptyMap(), Collections.emptyMap()); 58 | } 59 | 60 | public void trackSecure(String var1, Map var2, Map var3); 61 | 62 | default public void trackSecure(String name, Map properties) { 63 | if (name == null) { 64 | throw new IllegalStateException("name cannot be null!"); 65 | } 66 | if (properties == null) { 67 | throw new IllegalStateException("properties cannot be null!"); 68 | } 69 | this.trackSecure(name, properties, Collections.emptyMap()); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/AgentCompletion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.util.text.StringUtil 6 | * org.jetbrains.annotations.NotNull 7 | * org.jetbrains.annotations.Nullable 8 | */ 9 | package com.github.copilot.lang.agent; 10 | 11 | import com.github.copilot.completions.CompletionUtil; 12 | import com.github.copilot.completions.CopilotCompletion; 13 | import com.github.copilot.lang.agent.commands.GetCompletionsResult; 14 | import com.intellij.openapi.util.text.StringUtil; 15 | import java.util.List; 16 | 17 | class AgentCompletion implements CopilotCompletion { 18 | private final GetCompletionsResult.Completion agentData; 19 | private final List completion; 20 | private volatile boolean isCached = false; 21 | 22 | AgentCompletion(GetCompletionsResult.Completion agentData) { 23 | this.agentData = agentData; 24 | this.completion = StringUtil.split((String) agentData.getDisplayText(), (String) "\n", (boolean) true, 25 | (boolean) false); 26 | } 27 | 28 | @Override 29 | public CopilotCompletion asCached() { 30 | AgentCompletion agentCompletion = this.withCached(true); 31 | if (agentCompletion == null) { 32 | throw new IllegalStateException("agentCompletion cannot be null!"); 33 | } 34 | return agentCompletion; 35 | } 36 | 37 | @Override 38 | public CopilotCompletion withoutPrefix(String prefix) { 39 | if (prefix == null) { 40 | throw new IllegalStateException("prefix cannot be null!"); 41 | } 42 | return CompletionUtil.apiChoiceWithoutPrefix(this, prefix); 43 | } 44 | 45 | public AgentCompletion(GetCompletionsResult.Completion agentData, List completion, boolean isCached) { 46 | this.agentData = agentData; 47 | this.completion = completion; 48 | this.isCached = isCached; 49 | } 50 | 51 | public AgentCompletion(GetCompletionsResult.Completion agentData, List completion) { 52 | this.agentData = agentData; 53 | this.completion = completion; 54 | } 55 | 56 | public GetCompletionsResult.Completion getAgentData() { 57 | return this.agentData; 58 | } 59 | 60 | @Override 61 | public List getCompletion() { 62 | return this.completion; 63 | } 64 | 65 | @Override 66 | public AgentCompletion withCompletion(List completion) { 67 | return this.completion == completion ? this : new AgentCompletion(this.agentData, completion, this.isCached); 68 | } 69 | 70 | public AgentCompletion withCached(boolean isCached) { 71 | return this.isCached == isCached ? this : new AgentCompletion(this.agentData, this.completion, isCached); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/com/github/copilot/settings/CopilotLocalApplicationState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.util.xmlb.annotations.OptionTag 6 | * javax.annotation.Nullable 7 | */ 8 | package com.github.copilot.settings; 9 | 10 | import com.github.copilot.settings.ZonedDateTimeConverter; 11 | import com.intellij.util.xmlb.annotations.OptionTag; 12 | import java.time.ZonedDateTime; 13 | import javax.annotation.Nullable; 14 | 15 | public class CopilotLocalApplicationState { 16 | @OptionTag(value = "lastUpdateCheck", converter = ZonedDateTimeConverter.class) 17 | public ZonedDateTime lastUpdateCheck = null; 18 | @OptionTag(value = "checkEarlyBirdChannel") 19 | public boolean checkEarlyBirdChannel = true; 20 | @OptionTag(value = "githubToken") 21 | public volatile String githubToken; 22 | @OptionTag(value = "githubTokenMigration") 23 | public volatile boolean githubTokenMigration; 24 | 25 | public boolean equals(Object o) { 26 | if (o == this) { 27 | return true; 28 | } 29 | if (!(o instanceof CopilotLocalApplicationState)) { 30 | return false; 31 | } 32 | CopilotLocalApplicationState other = (CopilotLocalApplicationState) o; 33 | if (!other.canEqual(this)) { 34 | return false; 35 | } 36 | if (this.checkEarlyBirdChannel != other.checkEarlyBirdChannel) { 37 | return false; 38 | } 39 | if (this.githubTokenMigration != other.githubTokenMigration) { 40 | return false; 41 | } 42 | ZonedDateTime this$lastUpdateCheck = this.lastUpdateCheck; 43 | ZonedDateTime other$lastUpdateCheck = other.lastUpdateCheck; 44 | if (this$lastUpdateCheck == null ? other$lastUpdateCheck != null 45 | : !((Object) this$lastUpdateCheck).equals(other$lastUpdateCheck)) { 46 | return false; 47 | } 48 | String this$githubToken = this.githubToken; 49 | String other$githubToken = other.githubToken; 50 | return !(this$githubToken == null ? other$githubToken != null : !this$githubToken.equals(other$githubToken)); 51 | } 52 | 53 | protected boolean canEqual(Object other) { 54 | return other instanceof CopilotLocalApplicationState; 55 | } 56 | 57 | public int hashCode() { 58 | int PRIME = 59; 59 | int result = 1; 60 | result = result * 59 + (this.checkEarlyBirdChannel ? 79 : 97); 61 | result = result * 59 + (this.githubTokenMigration ? 79 : 97); 62 | ZonedDateTime $lastUpdateCheck = this.lastUpdateCheck; 63 | result = result * 59 + ($lastUpdateCheck == null ? 43 : ((Object) $lastUpdateCheck).hashCode()); 64 | String $githubToken = this.githubToken; 65 | result = result * 59 + ($githubToken == null ? 43 : $githubToken.hashCode()); 66 | return result; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/com/github/copilot/editor/CopilotDisposeInlaysEditorHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.codeInsight.lookup.LookupManager 6 | * com.intellij.openapi.actionSystem.DataContext 7 | * com.intellij.openapi.editor.Caret 8 | * com.intellij.openapi.editor.Editor 9 | * com.intellij.openapi.editor.actionSystem.EditorActionHandler 10 | * org.jetbrains.annotations.NotNull 11 | * org.jetbrains.annotations.Nullable 12 | */ 13 | package com.github.copilot.editor; 14 | 15 | import com.github.copilot.editor.CopilotEditorManager; 16 | import com.github.copilot.editor.InlayDisposeContext; 17 | import com.intellij.codeInsight.lookup.LookupManager; 18 | import com.intellij.openapi.actionSystem.DataContext; 19 | import com.intellij.openapi.editor.Caret; 20 | import com.intellij.openapi.editor.Editor; 21 | import com.intellij.openapi.editor.actionSystem.EditorActionHandler; 22 | 23 | public class CopilotDisposeInlaysEditorHandler extends EditorActionHandler { 24 | private final EditorActionHandler baseHandler; 25 | 26 | public CopilotDisposeInlaysEditorHandler(EditorActionHandler baseHandler) { 27 | this.baseHandler = baseHandler; 28 | } 29 | 30 | protected boolean isEnabledForCaret(Editor editor, Caret caret, DataContext dataContext) { 31 | CopilotEditorManager manager; 32 | if (editor == null) { 33 | throw new IllegalStateException("editor cannot be null!"); 34 | } 35 | if (caret == null) { 36 | throw new IllegalStateException("caret cannot be null!"); 37 | } 38 | return (manager = CopilotEditorManager.getInstance()).isAvailable(editor) && manager.hasCompletionInlays(editor) 39 | && LookupManager.getActiveLookup((Editor) editor) == null 40 | || this.baseHandler != null && this.baseHandler.isEnabled(editor, caret, dataContext); 41 | } 42 | 43 | public boolean executeInCommand(Editor editor, DataContext dataContext) { 44 | if (editor == null) { 45 | throw new IllegalStateException("editor cannot be null!"); 46 | } 47 | return this.baseHandler != null && this.baseHandler.executeInCommand(editor, dataContext); 48 | } 49 | 50 | protected void doExecute(Editor editor, Caret caret, DataContext dataContext) { 51 | if (editor == null) { 52 | throw new IllegalStateException("editor cannot be null!"); 53 | } 54 | if (LookupManager.getActiveLookup((Editor) editor) == null) { 55 | CopilotEditorManager.getInstance().disposeInlays(editor, InlayDisposeContext.CaretChange); 56 | } 57 | if (this.baseHandler != null && this.baseHandler.isEnabled(editor, caret, dataContext)) { 58 | this.baseHandler.execute(editor, caret, dataContext); 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/vscodeRpc/VSCodeJsonRpcCommandSender.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.lang.agent.vscodeRpc; 2 | 3 | import com.github.copilot.lang.agent.rpc.JsonRPC; 4 | import com.github.copilot.lang.agent.rpc.JsonRpcCommand; 5 | import com.github.copilot.lang.agent.rpc.JsonRpcCommandSender; 6 | import com.github.copilot.lang.agent.rpc.JsonRpcNotification; 7 | import me.masecla.copilot.extra.Logger; 8 | import java.io.IOException; 9 | import java.io.OutputStream; 10 | import java.nio.charset.StandardCharsets; 11 | 12 | public class VSCodeJsonRpcCommandSender implements JsonRpcCommandSender { 13 | private static final Logger LOG = Logger.getInstance(VSCodeJsonRpcCommandSender.class); 14 | private final OutputStream target; 15 | 16 | @Override 17 | public void sendCommand(int id, JsonRpcCommand command) throws IOException { 18 | if (command == null) { 19 | throw new IllegalStateException("command cannot be null!"); 20 | } 21 | String name = command.getCommandName(); 22 | String commandJSON = JsonRPC.serializeCommand(id, name, command); 23 | if (LOG.isTraceEnabled()) { 24 | LOG.trace(String.format("[%d] sending command to agent: %s\n%s", id, name, commandJSON)); 25 | } else if (LOG.isDebugEnabled()) { 26 | LOG.debug(String.format("[%d] sending command to agent: %s", id, name)); 27 | } 28 | this.sendBytes(commandJSON); 29 | } 30 | 31 | @Override 32 | public void sendNotification(JsonRpcNotification notification) throws IOException { 33 | if (notification == null) { 34 | throw new IllegalStateException("notification cannot be null!"); 35 | } 36 | String name = notification.getCommandName(); 37 | String commandJSON = JsonRPC.serializeNotification(name, notification); 38 | if (LOG.isTraceEnabled()) { 39 | LOG.trace(String.format("sending notification to agent: %s\n%s", name, commandJSON)); 40 | } else if (LOG.isDebugEnabled()) { 41 | LOG.debug(String.format("sending command to agent: %s", name)); 42 | } 43 | this.sendBytes(commandJSON); 44 | } 45 | 46 | private void sendBytes(String commandJSON) throws IOException { 47 | byte[] commandBytes = commandJSON.getBytes(StandardCharsets.UTF_8); 48 | String message = "Content-Length: " + commandBytes.length + "\r\n\r\n"; 49 | if (LOG.isTraceEnabled()) { 50 | LOG.trace("Sending JSON-RPC message:\n" + message + commandJSON); 51 | } 52 | this.target.write(message.getBytes(StandardCharsets.UTF_8)); 53 | this.target.write(commandBytes); 54 | this.target.flush(); 55 | } 56 | 57 | public VSCodeJsonRpcCommandSender(OutputStream target) { 58 | if (target == null) { 59 | throw new IllegalStateException("target cannot be null!"); 60 | } 61 | this.target = target; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/vscodeRpc/VSCodeJsonRpcParser.java: -------------------------------------------------------------------------------- 1 | package com.github.copilot.lang.agent.vscodeRpc; 2 | 3 | import java.nio.charset.StandardCharsets; 4 | 5 | import com.github.copilot.lang.agent.rpc.JsonRpcMessageHandler; 6 | import com.github.copilot.lang.agent.rpc.JsonRpcMessageParser; 7 | 8 | import me.masecla.copilot.extra.Logger; 9 | 10 | public class VSCodeJsonRpcParser implements JsonRpcMessageParser { 11 | private static final Logger LOG = Logger.getInstance(VSCodeJsonRpcParser.class); 12 | private static final byte[] CONTENT_LENGTH = "Content-Length: ".getBytes(StandardCharsets.UTF_8); 13 | public static final byte[] SEPARATOR = "\r\n\r\n".getBytes(StandardCharsets.UTF_8); 14 | private final JsonRpcMessageHandler messageHandler; 15 | private int pendingContentLength = 0; 16 | private final ByteArray pendingContent = new ByteArray(); 17 | 18 | public String getPendingContent() { 19 | String string = this.pendingContent.toString(StandardCharsets.UTF_8); 20 | if (string == null) { 21 | throw new IllegalStateException("string cannot be null!"); 22 | } 23 | return string; 24 | } 25 | 26 | @Override 27 | public void append(String content) { 28 | if (content == null) { 29 | throw new IllegalStateException("content cannot be null!"); 30 | } 31 | this.pendingContent.add(content.getBytes(StandardCharsets.UTF_8)); 32 | if (this.pendingContent.indexOf(CONTENT_LENGTH) == 0) { 33 | this.handleContentLengthMessage(); 34 | } 35 | if (this.pendingContentLength > 0) { 36 | this.processPendingContent(); 37 | } 38 | } 39 | 40 | @Override 41 | public void close() { 42 | } 43 | 44 | private void handleContentLengthMessage() { 45 | assert (this.pendingContentLength == 0); 46 | int lineEnd = this.pendingContent.indexOf(SEPARATOR); 47 | if (lineEnd > 0) { 48 | String line = new String(this.pendingContent.getBytes(CONTENT_LENGTH.length, lineEnd), 49 | StandardCharsets.UTF_8); 50 | this.pendingContent.deleteFirst(lineEnd + SEPARATOR.length); 51 | int length = Integer.parseInt(line, 0, line.length(), 10); 52 | LOG.debug("Found content-length: " + line); 53 | this.pendingContentLength += length; 54 | } 55 | } 56 | 57 | private void processPendingContent() { 58 | if (this.pendingContent.size() < this.pendingContentLength) { 59 | return; 60 | } 61 | String message = this.pendingContent.toString(0, this.pendingContentLength, StandardCharsets.UTF_8); 62 | this.pendingContent.deleteFirst(this.pendingContentLength); 63 | this.pendingContentLength = 0; 64 | this.messageHandler.handleJsonMessage(message); 65 | } 66 | 67 | public VSCodeJsonRpcParser(JsonRpcMessageHandler messageHandler) { 68 | this.messageHandler = messageHandler; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/commands/Range.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.google.gson.annotations.SerializedName 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.lang.agent.commands; 9 | 10 | import com.google.gson.annotations.SerializedName; 11 | 12 | public class Range { 13 | @SerializedName(value = "start") 14 | Position start; 15 | @SerializedName(value = "end") 16 | Position end; 17 | 18 | public Range(Position start, Position end) { 19 | if (start == null) { 20 | throw new IllegalStateException("start cannot be null!"); 21 | } 22 | if (end == null) { 23 | throw new IllegalStateException("end cannot be null!"); 24 | } 25 | this.start = start; 26 | this.end = end; 27 | } 28 | 29 | public Position getStart() { 30 | Position position = this.start; 31 | if (position == null) { 32 | throw new IllegalStateException("position cannot be null!"); 33 | } 34 | return position; 35 | } 36 | 37 | public Position getEnd() { 38 | Position position = this.end; 39 | if (position == null) { 40 | throw new IllegalStateException("position cannot be null!"); 41 | } 42 | return position; 43 | } 44 | 45 | public void setStart(Position start) { 46 | if (start == null) { 47 | throw new IllegalStateException("start cannot be null!"); 48 | } 49 | this.start = start; 50 | } 51 | 52 | public void setEnd(Position end) { 53 | if (end == null) { 54 | throw new IllegalStateException("end cannot be null!"); 55 | } 56 | this.end = end; 57 | } 58 | 59 | public boolean equals(Object o) { 60 | if (o == this) { 61 | return true; 62 | } 63 | if (!(o instanceof Range)) { 64 | return false; 65 | } 66 | Range other = (Range) o; 67 | if (!other.canEqual(this)) { 68 | return false; 69 | } 70 | Position this$start = this.getStart(); 71 | Position other$start = other.getStart(); 72 | if (this$start == null ? other$start != null : !((Object) this$start).equals(other$start)) { 73 | return false; 74 | } 75 | Position this$end = this.getEnd(); 76 | Position other$end = other.getEnd(); 77 | return !(this$end == null ? other$end != null : !((Object) this$end).equals(other$end)); 78 | } 79 | 80 | protected boolean canEqual(Object other) { 81 | return other instanceof Range; 82 | } 83 | 84 | public int hashCode() { 85 | int result = 1; 86 | Position $start = this.getStart(); 87 | result = result * 59 + ($start == null ? 43 : ((Object) $start).hashCode()); 88 | Position $end = this.getEnd(); 89 | result = result * 59 + ($end == null ? 43 : ((Object) $end).hashCode()); 90 | return result; 91 | } 92 | 93 | public String toString() { 94 | return "Range(start=" + this.getStart() + ", end=" + this.getEnd() + ")"; 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/commands/Position.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.google.gson.annotations.SerializedName 6 | * com.intellij.openapi.util.text.StringUtil 7 | * org.jetbrains.annotations.NotNull 8 | */ 9 | package com.github.copilot.lang.agent.commands; 10 | 11 | import com.github.copilot.request.LineInfo; 12 | import com.google.gson.annotations.SerializedName; 13 | 14 | public class Position { 15 | @SerializedName(value = "line") 16 | int line; 17 | @SerializedName(value = "character") 18 | int character; 19 | 20 | public Position(LineInfo lineInfo) { 21 | this(lineInfo.getLineNumber(), lineInfo.getColumnOffset()); 22 | } 23 | 24 | public int toOffset(String text) { 25 | if (text == null) { 26 | throw new IllegalStateException("text cannot be null!"); 27 | } 28 | return lineColToOffset(text, this.line, this.character); 29 | } 30 | 31 | public int getLine() { 32 | return this.line; 33 | } 34 | 35 | public int getCharacter() { 36 | return this.character; 37 | } 38 | 39 | public void setLine(int line) { 40 | this.line = line; 41 | } 42 | 43 | public void setCharacter(int character) { 44 | this.character = character; 45 | } 46 | 47 | public boolean equals(Object o) { 48 | if (o == this) { 49 | return true; 50 | } 51 | if (!(o instanceof Position)) { 52 | return false; 53 | } 54 | Position other = (Position) o; 55 | if (!other.canEqual(this)) { 56 | return false; 57 | } 58 | if (this.getLine() != other.getLine()) { 59 | return false; 60 | } 61 | return this.getCharacter() == other.getCharacter(); 62 | } 63 | 64 | protected boolean canEqual(Object other) { 65 | return other instanceof Position; 66 | } 67 | 68 | private int lineColToOffset(CharSequence text, int line, int col) { 69 | int curLine = 0; 70 | int offset = 0; 71 | while (line != curLine) { 72 | if (offset == text.length()) 73 | return -1; 74 | char c = text.charAt(offset); 75 | if (c == '\n') { 76 | curLine++; 77 | } else if (c == '\r') { 78 | curLine++; 79 | if (offset < text.length() - 1 && text.charAt(offset + 1) == '\n') { 80 | offset++; 81 | } 82 | } 83 | offset++; 84 | } 85 | return offset + col; 86 | } 87 | 88 | public int hashCode() { 89 | int result = 1; 90 | result = result * 59 + this.getLine(); 91 | result = result * 59 + this.getCharacter(); 92 | return result; 93 | } 94 | 95 | public String toString() { 96 | return "Position(line=" + this.getLine() + ", character=" + this.getCharacter() + ")"; 97 | } 98 | 99 | public Position(int line, int character) { 100 | this.line = line; 101 | this.character = character; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/commands/GetCompletionsCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.google.gson.annotations.SerializedName 6 | * org.jetbrains.annotations.NotNull 7 | * org.jetbrains.annotations.Nullable 8 | */ 9 | package com.github.copilot.lang.agent.commands; 10 | 11 | import com.github.copilot.lang.agent.rpc.JsonRpcCommand; 12 | import com.google.gson.annotations.SerializedName; 13 | import java.util.Map; 14 | 15 | public class GetCompletionsCommand implements JsonRpcCommand { 16 | @SerializedName(value = "doc") 17 | private final Document doc; 18 | @SerializedName(value = "options") 19 | private final Map options; 20 | 21 | @Override 22 | public String getCommandName() { 23 | return "getCompletions"; 24 | } 25 | 26 | @Override 27 | public Class getResponseType() { 28 | return GetCompletionsResult.class; 29 | } 30 | 31 | public GetCompletionsCommand(Document doc, Map options) { 32 | if (doc == null) { 33 | throw new IllegalStateException("doc cannot be null!"); 34 | } 35 | this.doc = doc; 36 | this.options = options; 37 | } 38 | 39 | public Document getDoc() { 40 | Document document = this.doc; 41 | if (document == null) { 42 | throw new IllegalStateException("document cannot be null!"); 43 | } 44 | return document; 45 | } 46 | 47 | public Map getOptions() { 48 | return this.options; 49 | } 50 | 51 | public boolean equals(Object o) { 52 | if (o == this) { 53 | return true; 54 | } 55 | if (!(o instanceof GetCompletionsCommand)) { 56 | return false; 57 | } 58 | GetCompletionsCommand other = (GetCompletionsCommand) o; 59 | if (!other.canEqual(this)) { 60 | return false; 61 | } 62 | Document this$doc = this.getDoc(); 63 | Document other$doc = other.getDoc(); 64 | if (this$doc == null ? other$doc != null : !((Object) this$doc).equals(other$doc)) { 65 | return false; 66 | } 67 | Map this$options = this.getOptions(); 68 | Map other$options = other.getOptions(); 69 | return !(this$options == null ? other$options != null : !((Object) this$options).equals(other$options)); 70 | } 71 | 72 | protected boolean canEqual(Object other) { 73 | return other instanceof GetCompletionsCommand; 74 | } 75 | 76 | public int hashCode() { 77 | int result = 1; 78 | Document $doc = this.getDoc(); 79 | result = result * 59 + ($doc == null ? 43 : ((Object) $doc).hashCode()); 80 | Map $options = this.getOptions(); 81 | result = result * 59 + ($options == null ? 43 : ((Object) $options).hashCode()); 82 | return result; 83 | } 84 | 85 | public String toString() { 86 | return "GetCompletionsCommand(doc=" + this.getDoc() + ", options=" + this.getOptions() + ")"; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/com/github/copilot/CopilotPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.ide.plugins.IdeaPluginDescriptor 6 | * com.intellij.ide.plugins.PluginManagerCore 7 | * com.intellij.openapi.Disposable 8 | * com.intellij.openapi.application.ApplicationInfo 9 | * com.intellij.openapi.application.ApplicationManager 10 | * com.intellij.openapi.extensions.PluginId 11 | * com.intellij.openapi.util.BuildNumber 12 | * org.jetbrains.annotations.NotNull 13 | * org.jetbrains.annotations.Nullable 14 | */ 15 | package com.github.copilot; 16 | 17 | import com.github.copilot.CopilotLifecycleService; 18 | import com.intellij.ide.plugins.IdeaPluginDescriptor; 19 | import com.intellij.ide.plugins.PluginManagerCore; 20 | import com.intellij.openapi.Disposable; 21 | import com.intellij.openapi.application.ApplicationInfo; 22 | import com.intellij.openapi.application.ApplicationManager; 23 | import com.intellij.openapi.extensions.PluginId; 24 | import com.intellij.openapi.util.BuildNumber; 25 | import java.nio.file.Path; 26 | 27 | public final class CopilotPlugin { 28 | public static final PluginId COPILOT_ID = PluginId.getId((String) "com.github.copilot"); 29 | 30 | private CopilotPlugin() { 31 | } 32 | 33 | public static String getVersion() { 34 | IdeaPluginDescriptor plugin = PluginManagerCore.getPlugin((PluginId) COPILOT_ID); 35 | String string = plugin == null ? "unknown" : plugin.getVersion(); 36 | if (string == null) { 37 | throw new IllegalStateException("string cannot be null!"); 38 | } 39 | return string; 40 | } 41 | 42 | public static Path getPluginBasePath() { 43 | IdeaPluginDescriptor plugin = PluginManagerCore.getPlugin((PluginId) COPILOT_ID); 44 | assert (plugin != null); 45 | Path path = plugin.getPluginPath(); 46 | if (path == null) { 47 | throw new IllegalStateException("path cannot be null!"); 48 | } 49 | return path; 50 | } 51 | 52 | public static Disposable getLifecycleDisposable() { 53 | return (Disposable) ApplicationManager.getApplication().getService(CopilotLifecycleService.class); 54 | } 55 | 56 | public static String editorVersionString() { 57 | String string; 58 | try { 59 | BuildNumber build = ApplicationInfo.getInstance().getBuild(); 60 | string = "JetBrains-" + build.getProductCode() + "/" + build.asStringWithoutProductCode(); 61 | } catch (Exception e) { 62 | return "JetBrains-??/ERROR"; 63 | } 64 | if (string == null) { 65 | throw new IllegalStateException("string cannot be null!"); 66 | } 67 | return string; 68 | } 69 | 70 | public static String pluginVersionString() { 71 | String string; 72 | try { 73 | string = "copilot-intellij/" + CopilotPlugin.getVersion(); 74 | } catch (Exception e) { 75 | return "copilot-intellij/ERROR"; 76 | } 77 | if (string == null) { 78 | throw new IllegalStateException("string cannot be null!"); 79 | } 80 | return string; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/com/github/copilot/completions/CopilotCompletionService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.application.ApplicationManager 6 | * com.intellij.openapi.editor.Editor 7 | * com.intellij.util.concurrency.annotations.RequiresBackgroundThread 8 | * com.intellij.util.concurrency.annotations.RequiresEdt 9 | * org.jetbrains.annotations.NotNull 10 | * org.jetbrains.annotations.Nullable 11 | */ 12 | package com.github.copilot.completions; 13 | 14 | import com.github.copilot.completions.CopilotCompletion; 15 | import com.github.copilot.completions.CopilotInlayList; 16 | import com.github.copilot.github.GitHubCopilotToken; 17 | import com.github.copilot.request.CompletionType; 18 | import com.github.copilot.request.EditorRequest; 19 | import com.github.copilot.settings.CopilotApplicationSettings; 20 | import com.intellij.openapi.application.ApplicationManager; 21 | import com.intellij.openapi.editor.Editor; 22 | import com.intellij.util.concurrency.annotations.RequiresBackgroundThread; 23 | import com.intellij.util.concurrency.annotations.RequiresEdt; 24 | import java.util.List; 25 | import java.util.concurrent.Flow; 26 | 27 | public interface CopilotCompletionService { 28 | public static CopilotCompletionService getInstance() { 29 | return (CopilotCompletionService) ApplicationManager.getApplication() 30 | .getService(CopilotCompletionService.class); 31 | } 32 | 33 | public boolean isAvailable(Editor var1); 34 | 35 | public EditorRequest createRequest(Editor var1, int var2, CompletionType var3); 36 | 37 | @RequiresBackgroundThread 38 | public boolean fetchCompletions(EditorRequest var1, GitHubCopilotToken var2, Integer var3, boolean var4, 39 | boolean var5, Flow.Subscriber> var6); 40 | 41 | @RequiresBackgroundThread 42 | default public boolean fetchCompletions(EditorRequest request, GitHubCopilotToken proxyToken, 43 | Integer maxCompletions, Flow.Subscriber> subscriber) { 44 | if (request == null) { 45 | throw new IllegalStateException("request cannot be null!"); 46 | } 47 | if (subscriber == null) { 48 | throw new IllegalStateException("subscriber cannot be null!"); 49 | } 50 | boolean enableCaching = !CopilotApplicationSettings.settings().internalDisableHttpCache; 51 | return this.fetchCompletions(request, proxyToken, maxCompletions, enableCaching, false, subscriber); 52 | } 53 | 54 | @RequiresEdt 55 | public List fetchCachedCompletions(EditorRequest var1); 56 | 57 | public void reset(); 58 | 59 | @RequiresEdt 60 | public boolean isSupportingOnDemandCycling(Editor var1); 61 | 62 | public boolean isCyclingReplacingCompletions(); 63 | 64 | public void sendShownTelemetry(CopilotCompletion var1); 65 | 66 | public void sendAcceptedTelemetry(CopilotCompletion var1, CompletionType var2); 67 | 68 | public void sendRejectedTelemetry(List var1); 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/com/github/copilot/actions/CopilotDisposeInlaysAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.codeInsight.lookup.LookupManager 6 | * com.intellij.openapi.actionSystem.DataContext 7 | * com.intellij.openapi.editor.Caret 8 | * com.intellij.openapi.editor.Editor 9 | * com.intellij.openapi.editor.actionSystem.EditorAction 10 | * com.intellij.openapi.editor.actionSystem.EditorActionHandler 11 | * com.intellij.openapi.project.DumbAware 12 | * org.jetbrains.annotations.NotNull 13 | * org.jetbrains.annotations.Nullable 14 | */ 15 | package com.github.copilot.actions; 16 | 17 | import com.github.copilot.actions.CopilotAction; 18 | import com.github.copilot.editor.CopilotEditorManager; 19 | import com.github.copilot.editor.InlayDisposeContext; 20 | import com.intellij.codeInsight.lookup.LookupManager; 21 | import com.intellij.openapi.actionSystem.DataContext; 22 | import com.intellij.openapi.editor.Caret; 23 | import com.intellij.openapi.editor.Editor; 24 | import com.intellij.openapi.editor.actionSystem.EditorAction; 25 | import com.intellij.openapi.editor.actionSystem.EditorActionHandler; 26 | import com.intellij.openapi.project.DumbAware; 27 | 28 | public class CopilotDisposeInlaysAction extends EditorAction implements DumbAware, CopilotAction { 29 | public CopilotDisposeInlaysAction() { 30 | super((EditorActionHandler) new DisposeInlaysHandler()); 31 | this.setInjectedContext(true); 32 | } 33 | 34 | static boolean isSupported(Editor editor) { 35 | CopilotEditorManager manager; 36 | if (editor == null) { 37 | throw new IllegalStateException("editor cannot be null!"); 38 | } 39 | return (manager = CopilotEditorManager.getInstance()).isAvailable(editor) && manager.hasCompletionInlays(editor) 40 | && LookupManager.getActiveLookup((Editor) editor) == null; 41 | } 42 | 43 | private static class DisposeInlaysHandler extends EditorActionHandler { 44 | private DisposeInlaysHandler() { 45 | } 46 | 47 | protected boolean isEnabledForCaret(Editor editor, Caret caret, DataContext dataContext) { 48 | if (editor == null) { 49 | throw new IllegalStateException("editor cannot be null!"); 50 | } 51 | if (caret == null) { 52 | throw new IllegalStateException("caret cannot be null!"); 53 | } 54 | return CopilotDisposeInlaysAction.isSupported(editor); 55 | } 56 | 57 | public boolean executeInCommand(Editor editor, DataContext dataContext) { 58 | if (editor == null) { 59 | throw new IllegalStateException("editor cannot be null!"); 60 | } 61 | return false; 62 | } 63 | 64 | protected void doExecute(Editor editor, Caret caret, DataContext dataContext) { 65 | if (editor == null) { 66 | throw new IllegalStateException("editor cannot be null!"); 67 | } 68 | if (LookupManager.getActiveLookup((Editor) editor) == null) { 69 | CopilotEditorManager.getInstance().disposeInlays(editor, InlayDisposeContext.UserAction); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/com/github/copilot/intentions/OpenCopilotIntention.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.codeInsight.intention.PriorityAction 6 | * com.intellij.codeInsight.intention.PriorityAction$Priority 7 | * com.intellij.codeInsight.intention.impl.BaseIntentionAction 8 | * com.intellij.codeInspection.util.IntentionFamilyName 9 | * com.intellij.openapi.editor.Editor 10 | * com.intellij.openapi.project.DumbAware 11 | * com.intellij.openapi.project.Project 12 | * com.intellij.psi.PsiFile 13 | * com.intellij.util.IncorrectOperationException 14 | * org.jetbrains.annotations.NotNull 15 | */ 16 | package com.github.copilot.intentions; 17 | 18 | import com.github.copilot.CopilotBundle; 19 | import com.github.copilot.editor.CopilotEditorManager; 20 | import com.github.copilot.editor.CopilotEditorUtil; 21 | import com.github.copilot.telemetry.TelemetryService; 22 | import com.github.copilot.toolWindow.CopilotSplitEditorManager; 23 | import com.intellij.codeInsight.intention.PriorityAction; 24 | import com.intellij.codeInsight.intention.impl.BaseIntentionAction; 25 | import com.intellij.codeInspection.util.IntentionFamilyName; 26 | import com.intellij.openapi.editor.Editor; 27 | import com.intellij.openapi.project.DumbAware; 28 | import com.intellij.openapi.project.Project; 29 | import com.intellij.psi.PsiFile; 30 | import com.intellij.util.IncorrectOperationException; 31 | import java.util.Map; 32 | 33 | public class OpenCopilotIntention extends BaseIntentionAction implements DumbAware, PriorityAction { 34 | public OpenCopilotIntention() { 35 | this.setText(CopilotBundle.get("intention.openCopilot.text")); 36 | } 37 | 38 | @IntentionFamilyName 39 | public String getFamilyName() { 40 | String string = CopilotBundle.get("intention.openCopilot.familyName"); 41 | if (string == null) { 42 | throw new IllegalStateException("string cannot be null!"); 43 | } 44 | return string; 45 | } 46 | 47 | public boolean isAvailable(Project project, Editor editor, PsiFile file) { 48 | if (project == null) { 49 | throw new IllegalStateException("project cannot be null!"); 50 | } 51 | if (!CopilotEditorUtil.isSelectedEditor(editor)) { 52 | return false; 53 | } 54 | return CopilotEditorManager.getInstance().isAvailable(editor); 55 | } 56 | 57 | public boolean startInWriteAction() { 58 | return false; 59 | } 60 | 61 | public PriorityAction.Priority getPriority() { 62 | PriorityAction.Priority priority = PriorityAction.Priority.LOW; 63 | if (priority == null) { 64 | throw new IllegalStateException("priority cannot be null!"); 65 | } 66 | return priority; 67 | } 68 | 69 | public void invoke(Project project, Editor editor, PsiFile file) throws IncorrectOperationException { 70 | if (project == null) { 71 | throw new IllegalStateException("project cannot be null!"); 72 | } 73 | CopilotSplitEditorManager.getInstance().openCopilot(editor, true); 74 | TelemetryService.getInstance().track("command.executed", Map.of("command", "intention.openCopilot")); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/com/github/copilot/status/CopilotStatusService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.Disposable 6 | * com.intellij.openapi.application.Application 7 | * com.intellij.openapi.application.ApplicationManager 8 | * com.intellij.openapi.project.Project 9 | * com.intellij.openapi.project.ProjectManager 10 | * javax.annotation.concurrent.GuardedBy 11 | * org.jetbrains.annotations.NotNull 12 | */ 13 | package com.github.copilot.status; 14 | 15 | import com.github.copilot.status.CopilotStatus; 16 | import com.github.copilot.status.CopilotStatusListener; 17 | import com.github.copilot.statusBar.CopilotStatusBarWidget; 18 | import com.intellij.openapi.Disposable; 19 | import com.intellij.openapi.application.Application; 20 | import com.intellij.openapi.application.ApplicationManager; 21 | import com.intellij.openapi.project.Project; 22 | import com.intellij.openapi.project.ProjectManager; 23 | import javax.annotation.concurrent.GuardedBy; 24 | 25 | public class CopilotStatusService implements CopilotStatusListener, Disposable { 26 | private final Object lock = new Object(); 27 | @GuardedBy(value = "lock") 28 | private CopilotStatus status = CopilotStatus.Ready; 29 | 30 | public static CopilotStatus getCurrentStatus() { 31 | CopilotStatus copilotStatus = ((CopilotStatusService) ApplicationManager.getApplication() 32 | .getService(CopilotStatusService.class)).status; 33 | if (copilotStatus == null) { 34 | throw new IllegalStateException("copilotStatus cannot be null!"); 35 | } 36 | return copilotStatus; 37 | } 38 | 39 | public CopilotStatusService() { 40 | ApplicationManager.getApplication().getMessageBus().connect((Disposable) this) 41 | .subscribe(CopilotStatusListener.TOPIC, (Object) this); 42 | } 43 | 44 | public static void notifyApplication(CopilotStatus status) { 45 | if (status == null) { 46 | throw new IllegalStateException("status cannot be null!"); 47 | } 48 | ((CopilotStatusListener) ApplicationManager.getApplication().getMessageBus() 49 | .syncPublisher(CopilotStatusListener.TOPIC)).onCopilotStatus(status); 50 | } 51 | 52 | /* 53 | * WARNING - Removed try catching itself - possible behaviour change. 54 | */ 55 | @Override 56 | public void onCopilotStatus(CopilotStatus status) { 57 | if (status == null) { 58 | throw new IllegalStateException("status cannot be null!"); 59 | } 60 | boolean notify = false; 61 | Object object = this.lock; 62 | synchronized (object) { 63 | notify = this.status != status; 64 | this.status = status; 65 | } 66 | if (notify) { 67 | Runnable action = () -> { 68 | for (Project project : ProjectManager.getInstance().getOpenProjects()) { 69 | CopilotStatusBarWidget.update(project); 70 | } 71 | }; 72 | Application application = ApplicationManager.getApplication(); 73 | if (application.isDispatchThread()) { 74 | action.run(); 75 | } else { 76 | application.invokeLater(action); 77 | } 78 | } 79 | } 80 | 81 | public void dispose() { 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/com/github/copilot/telemetry/CopilotContextInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.application.ApplicationInfo 6 | * com.intellij.openapi.application.PermanentInstallationID 7 | * com.intellij.openapi.util.SystemInfoRt 8 | * com.microsoft.applicationinsights.extensibility.ContextInitializer 9 | * com.microsoft.applicationinsights.telemetry.TelemetryContext 10 | * org.jetbrains.annotations.NotNull 11 | */ 12 | package com.github.copilot.telemetry; 13 | 14 | import com.github.copilot.CopilotPlugin; 15 | import com.github.copilot.CopilotSessionId; 16 | import com.github.copilot.telemetry.AzureInsightsTelemetryService; 17 | import com.github.copilot.util.Maps; 18 | import com.intellij.openapi.application.ApplicationInfo; 19 | import com.intellij.openapi.application.PermanentInstallationID; 20 | import com.intellij.openapi.util.SystemInfoRt; 21 | import com.microsoft.applicationinsights.extensibility.ContextInitializer; 22 | import com.microsoft.applicationinsights.telemetry.TelemetryContext; 23 | import java.util.Map; 24 | 25 | class CopilotContextInitializer implements ContextInitializer { 26 | static final CopilotContextInitializer INSTANCE = new CopilotContextInitializer(); 27 | private final Map staticProperties = Maps.of("common_vscodemachineid", 28 | PermanentInstallationID.get(), "common_vscodesessionid", CopilotSessionId.SESSION_ID, 29 | "common_platformversion", SystemInfoRt.OS_VERSION, "common_intellijversion", 30 | ApplicationInfo.getInstance().getFullVersion(), "common_intellijbuild", 31 | ApplicationInfo.getInstance().getBuild().asString(), "common_extname", "copilot-intellij", 32 | "common_extversion", CopilotPlugin.getVersion(), "common_uikind", "desktop", "common_os", 33 | CopilotContextInitializer.vscodeOSName(), "copilot_build", AzureInsightsTelemetryService.build(), 34 | "copilot_buildType", String.valueOf(AzureInsightsTelemetryService.isDeveloperMode())); 35 | private final Map commonProperties = Map.of("editor_plugin_version", 36 | CopilotPlugin.pluginVersionString(), "editor_version", CopilotPlugin.editorVersionString(), 37 | "client_machineid", PermanentInstallationID.get(), "client_sessionid", CopilotSessionId.SESSION_ID); 38 | 39 | CopilotContextInitializer() { 40 | } 41 | 42 | public void initialize(TelemetryContext context) { 43 | context.getProperties().putAll(this.staticProperties); 44 | context.getProperties().putAll(this.commonProperties); 45 | context.getSession().setId(CopilotSessionId.SESSION_ID); 46 | context.getDevice().setId(""); 47 | context.getCloud().setRoleInstance(""); 48 | } 49 | 50 | private static String vscodeOSName() { 51 | if (SystemInfoRt.isWindows) { 52 | return "win32"; 53 | } 54 | if (SystemInfoRt.isLinux) { 55 | return "linux"; 56 | } 57 | if (SystemInfoRt.isMac) { 58 | return "darwin"; 59 | } 60 | String string = SystemInfoRt.OS_NAME; 61 | if (string == null) { 62 | throw new IllegalStateException("string cannot be null!"); 63 | } 64 | return string; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/vscodeRpc/ByteArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * org.jetbrains.annotations.NotNull 6 | */ 7 | package com.github.copilot.lang.agent.vscodeRpc; 8 | 9 | import java.nio.charset.Charset; 10 | import java.nio.charset.StandardCharsets; 11 | 12 | public class ByteArray { 13 | static final byte[] EMPTY_ARRAY = new byte[0]; 14 | private int size = 0; 15 | private byte[] data = EMPTY_ARRAY; 16 | 17 | public void add(byte[] newData) { 18 | int oldSize = this.size; 19 | byte[] oldData = this.data; 20 | this.size += newData.length; 21 | this.data = new byte[this.size]; 22 | System.arraycopy(oldData, 0, this.data, 0, oldSize); 23 | System.arraycopy(newData, 0, this.data, oldSize, newData.length); 24 | } 25 | 26 | public byte[] getBytes() { 27 | return this.getBytes(0, this.size); 28 | } 29 | 30 | public byte[] getBytes(int startOffset, int endOffset) { 31 | assert (startOffset >= 0); 32 | assert (startOffset <= endOffset); 33 | assert (endOffset <= this.size); 34 | int length = endOffset - startOffset; 35 | if (length == 0) { 36 | return EMPTY_ARRAY; 37 | } 38 | byte[] copy = new byte[length]; 39 | System.arraycopy(this.data, startOffset, copy, 0, length); 40 | return copy; 41 | } 42 | 43 | public void deleteFirst(int length) { 44 | if (length == this.size) { 45 | this.data = EMPTY_ARRAY; 46 | this.size = 0; 47 | return; 48 | } 49 | byte[] newData = this.getBytes(length, this.size); 50 | this.data = newData; 51 | this.size = newData.length; 52 | } 53 | 54 | public int size() { 55 | return this.size; 56 | } 57 | 58 | public String toString(int startOffset, int endOffset, Charset charset) { 59 | if (charset == null) { 60 | throw new IllegalStateException("charset cannot be null!"); 61 | } 62 | assert (startOffset >= 0); 63 | assert (startOffset <= endOffset); 64 | assert (endOffset <= this.size); 65 | return new String(this.data, startOffset, endOffset - startOffset, charset); 66 | } 67 | 68 | public String toString(Charset charset) { 69 | if (charset == null) { 70 | throw new IllegalStateException("charset cannot be null!"); 71 | } 72 | String string = this.toString(0, this.size, charset); 73 | if (string == null) { 74 | throw new IllegalStateException("string cannot be null!"); 75 | } 76 | return string; 77 | } 78 | 79 | public String toString() { 80 | String string = this.toString(StandardCharsets.UTF_8); 81 | if (string == null) { 82 | throw new IllegalStateException("string cannot be null!"); 83 | } 84 | return string; 85 | } 86 | 87 | public int indexOf(byte[] query) { 88 | if (query.length == 0 || query.length > this.size) { 89 | return -1; 90 | } 91 | block0: for (int i = 0; i < this.size - query.length + 1; ++i) { 92 | for (int j = 0; j < query.length; ++j) { 93 | if (this.data[i + j] != query[j]) 94 | continue block0; 95 | } 96 | return i; 97 | } 98 | return -1; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/com/github/copilot/github/GitHubService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.notification.NotificationAction 6 | * com.intellij.notification.NotificationType 7 | * com.intellij.openapi.actionSystem.AnAction 8 | * com.intellij.openapi.application.ApplicationManager 9 | * com.intellij.openapi.project.Project 10 | * com.intellij.util.concurrency.annotations.RequiresBackgroundThread 11 | * com.intellij.util.concurrency.annotations.RequiresEdt 12 | * org.jetbrains.annotations.NotNull 13 | * org.jetbrains.annotations.Nullable 14 | */ 15 | package com.github.copilot.github; 16 | 17 | import com.github.copilot.CopilotBundle; 18 | import com.github.copilot.CopilotNotifications; 19 | import com.github.copilot.github.GitHubCopilotToken; 20 | import com.github.copilot.github.GitHubSession; 21 | import com.github.copilot.github.UnauthorizedTokenCallback; 22 | import com.github.copilot.settings.CopilotApplicationSettings; 23 | import com.intellij.notification.NotificationAction; 24 | import com.intellij.notification.NotificationType; 25 | import com.intellij.openapi.actionSystem.AnAction; 26 | import com.intellij.openapi.application.ApplicationManager; 27 | import com.intellij.openapi.project.Project; 28 | import com.intellij.util.concurrency.annotations.RequiresBackgroundThread; 29 | import com.intellij.util.concurrency.annotations.RequiresEdt; 30 | import java.util.concurrent.TimeUnit; 31 | import java.util.function.Consumer; 32 | 33 | public interface GitHubService { 34 | public static GitHubService getInstance() { 35 | return (GitHubService) ApplicationManager.getApplication().getService(GitHubService.class); 36 | } 37 | 38 | @RequiresBackgroundThread 39 | public void refreshStatus(); 40 | 41 | public boolean isSignedIn(); 42 | 43 | @RequiresEdt 44 | public void loginInteractive(Project var1); 45 | 46 | public GitHubCopilotToken fetchCopilotTokenInteractive(Project var1, GitHubSession var2, boolean var3, 47 | UnauthorizedTokenCallback var4, Consumer var5); 48 | 49 | public void logout(); 50 | 51 | public GitHubCopilotToken getCopilotToken(boolean var1, long var2, TimeUnit var4); 52 | 53 | default public GitHubCopilotToken getCopilotToken() { 54 | return this.getCopilotToken(false, 0L, TimeUnit.MILLISECONDS); 55 | } 56 | 57 | @RequiresEdt 58 | default public void showLoginNotification(Project project, boolean force) { 59 | if (project == null) { 60 | throw new IllegalStateException("project cannot be null!"); 61 | } 62 | boolean shown = CopilotApplicationSettings.settings().signinNotificationShown; 63 | if (force || !shown) { 64 | if (!force) { 65 | CopilotApplicationSettings.settings().signinNotificationShown = true; 66 | } 67 | CopilotNotifications 68 | .createFullContentNotification(CopilotBundle.get("github.loginNotification.title"), 69 | CopilotBundle.get("github.loginNotification.text"), NotificationType.WARNING, true) 70 | .addAction((AnAction) NotificationAction.createExpiring( 71 | (String) CopilotBundle.get("github.loginNotification.loginAction"), 72 | (e, notification) -> GitHubService.getInstance().loginInteractive(project))) 73 | .notify(project); 74 | } 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/com/github/copilot/editor/CopilotEditorTestManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.application.ApplicationManager 6 | * com.intellij.openapi.editor.Document 7 | * com.intellij.openapi.editor.Editor 8 | * com.intellij.util.ThrowableRunnable 9 | * com.intellij.util.concurrency.annotations.RequiresEdt 10 | * org.jetbrains.annotations.NotNull 11 | * org.jetbrains.annotations.TestOnly 12 | */ 13 | package com.github.copilot.editor; 14 | 15 | import com.github.copilot.editor.CopilotEditorManager; 16 | import com.github.copilot.editor.CopilotEditorManagerImpl; 17 | import com.github.copilot.editor.CopilotInlayRenderer; 18 | import com.intellij.openapi.application.ApplicationManager; 19 | import com.intellij.openapi.editor.Document; 20 | import com.intellij.openapi.editor.Editor; 21 | import com.intellij.util.ThrowableRunnable; 22 | import com.intellij.util.concurrency.annotations.RequiresEdt; 23 | import java.util.List; 24 | import org.jetbrains.annotations.TestOnly; 25 | 26 | @TestOnly 27 | public class CopilotEditorTestManager extends CopilotEditorManagerImpl { 28 | private volatile boolean disabled; 29 | 30 | public static CopilotEditorTestManager getInstance() { 31 | CopilotEditorTestManager copilotEditorTestManager = (CopilotEditorTestManager) ApplicationManager 32 | .getApplication().getService(CopilotEditorManager.class); 33 | if (copilotEditorTestManager == null) { 34 | throw new IllegalStateException("copilotEditorTestManager cannot be null!"); 35 | } 36 | return copilotEditorTestManager; 37 | } 38 | 39 | @RequiresEdt 40 | public List collectInlays(Editor editor) { 41 | if (editor == null) { 42 | throw new IllegalStateException("editor cannot be null!"); 43 | } 44 | Document document = editor.getDocument(); 45 | List list = this.collectInlays(editor, 0, document.getTextLength()); 46 | if (list == null) { 47 | throw new IllegalStateException("list cannot be null!"); 48 | } 49 | return list; 50 | } 51 | 52 | @RequiresEdt 53 | public List collectCurrentLineInlays(Editor editor) { 54 | if (editor == null) { 55 | throw new IllegalStateException("editor cannot be null!"); 56 | } 57 | Document document = editor.getDocument(); 58 | int line = document.getLineNumber(editor.getCaretModel().getOffset()); 59 | int lineStart = document.getLineStartOffset(line); 60 | int lineEnd = document.getLineEndOffset(line); 61 | List list = this.collectInlays(editor, lineStart, lineEnd); 62 | if (list == null) { 63 | throw new IllegalStateException("list cannot be null!"); 64 | } 65 | return list; 66 | } 67 | 68 | public void withDisabled(ThrowableRunnable action) throws Exception { 69 | if (action == null) { 70 | throw new IllegalStateException("action cannot be null!"); 71 | } 72 | try { 73 | this.disabled = true; 74 | action.run(); 75 | } finally { 76 | this.disabled = false; 77 | } 78 | } 79 | 80 | @Override 81 | public boolean isAvailable(Editor editor) { 82 | if (editor == null) { 83 | throw new IllegalStateException("editor cannot be null!"); 84 | } 85 | return !this.disabled && super.isAvailable(editor); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/com/github/copilot/actions/CopilotActionPromoter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.actionSystem.ActionPromoter 6 | * com.intellij.openapi.actionSystem.ActionWithDelegate 7 | * com.intellij.openapi.actionSystem.AnAction 8 | * com.intellij.openapi.actionSystem.CommonDataKeys 9 | * com.intellij.openapi.actionSystem.DataContext 10 | * com.intellij.openapi.editor.Editor 11 | * com.intellij.openapi.editor.actionSystem.EditorAction 12 | * org.jetbrains.annotations.NotNull 13 | */ 14 | package com.github.copilot.actions; 15 | 16 | import com.github.copilot.actions.CopilotAction; 17 | import com.github.copilot.actions.CopilotApplyInlaysAction; 18 | import com.github.copilot.actions.CopilotDisposeInlaysAction; 19 | import com.intellij.openapi.actionSystem.ActionPromoter; 20 | import com.intellij.openapi.actionSystem.ActionWithDelegate; 21 | import com.intellij.openapi.actionSystem.AnAction; 22 | import com.intellij.openapi.actionSystem.CommonDataKeys; 23 | import com.intellij.openapi.actionSystem.DataContext; 24 | import com.intellij.openapi.editor.Editor; 25 | import com.intellij.openapi.editor.actionSystem.EditorAction; 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | public class CopilotActionPromoter implements ActionPromoter { 30 | public List promote(List actions, DataContext context) { 31 | Editor editor; 32 | if (actions == null) { 33 | throw new IllegalStateException("actions cannot be null!"); 34 | } 35 | if (context == null) { 36 | throw new IllegalStateException("context cannot be null!"); 37 | } 38 | if ((editor = (Editor) CommonDataKeys.EDITOR.getData(context)) == null 39 | || !CopilotApplyInlaysAction.isSupported(editor) && !CopilotDisposeInlaysAction.isSupported(editor)) { 40 | return null; 41 | } 42 | if (actions.stream().noneMatch(action -> action instanceof CopilotAction && action instanceof EditorAction)) { 43 | return null; 44 | } 45 | ArrayList result = new ArrayList(actions); 46 | result.sort((a, b) -> { 47 | boolean bIsCopilot; 48 | boolean aIsCopilot = a instanceof CopilotAction && a instanceof EditorAction; 49 | boolean bl = bIsCopilot = b instanceof CopilotAction && b instanceof EditorAction; 50 | if (aIsCopilot && bIsCopilot) { 51 | if (a instanceof CopilotApplyInlaysAction) { 52 | return -1; 53 | } 54 | if (b instanceof CopilotApplyInlaysAction) { 55 | return -1; 56 | } 57 | } 58 | if (CopilotActionPromoter.isIdeaVimAction(a) || CopilotActionPromoter.isIdeaVimAction(b)) { 59 | return 0; 60 | } 61 | if (aIsCopilot) { 62 | return -1; 63 | } 64 | if (bIsCopilot) { 65 | return 1; 66 | } 67 | return 0; 68 | }); 69 | return result; 70 | } 71 | 72 | private static boolean isIdeaVimAction(AnAction action) { 73 | if (action == null) { 74 | throw new IllegalStateException("action cannot be null!"); 75 | } 76 | String packagePrefix = "com.maddyhome.idea.vim"; 77 | if (action.getClass().getName().startsWith(packagePrefix)) { 78 | return true; 79 | } 80 | if (action instanceof ActionWithDelegate) { 81 | Object delegate = ((ActionWithDelegate) action).getDelegate(); 82 | return delegate.getClass().getName().startsWith(packagePrefix); 83 | } 84 | return false; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/com/github/copilot/openai/OpenAITestService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.application.ApplicationManager 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.openai; 9 | 10 | import com.github.copilot.lang.LanguageSupport; 11 | import com.github.copilot.openai.APIChoice; 12 | import com.github.copilot.openai.OpenAIService; 13 | import com.github.copilot.openai.OpenAIServiceImpl; 14 | import com.github.copilot.request.BlockMode; 15 | import com.github.copilot.request.LanguageEditorRequest; 16 | import com.github.copilot.telemetry.TelemetryData; 17 | import com.intellij.openapi.application.ApplicationManager; 18 | import java.util.concurrent.Flow; 19 | import java.util.concurrent.atomic.AtomicInteger; 20 | 21 | public class OpenAITestService extends OpenAIServiceImpl { 22 | private final AtomicInteger completionRequestCount = new AtomicInteger(); 23 | public volatile String TEST_COMPLETION_URL; 24 | 25 | public static OpenAITestService getInstance() { 26 | OpenAITestService openAITestService = (OpenAITestService) ApplicationManager.getApplication() 27 | .getService(OpenAIService.class); 28 | if (openAITestService == null) { 29 | throw new IllegalStateException("openAITestService cannot be null!"); 30 | } 31 | return openAITestService; 32 | } 33 | 34 | /* 35 | * WARNING - void declaration 36 | */ 37 | @Override 38 | public void fetchCompletions(String apiToken, LanguageEditorRequest request, String prompt, int completionCount, 39 | double temperature, int maxTokens, int topP, BlockMode blockMode, boolean multilineCompletions, 40 | TelemetryData telemetryBaseData, Flow.Subscriber subscriber) { 41 | void subscriber2; 42 | if (apiToken == null) { 43 | throw new IllegalStateException("apiToken cannot be null!"); 44 | } 45 | if (request == null) { 46 | throw new IllegalStateException("request cannot be null!"); 47 | } 48 | if (prompt == null) { 49 | throw new IllegalStateException("prompt cannot be null!"); 50 | } 51 | if (blockMode == null) { 52 | throw new IllegalStateException("blockMode cannot be null!"); 53 | } 54 | if (telemetryBaseData == null) { 55 | throw new IllegalStateException("telemetryBaseData cannot be null!"); 56 | } 57 | if (subscriber == null) { 58 | throw new IllegalStateException("subscriber cannot be null!"); 59 | } 60 | this.completionRequestCount.incrementAndGet(); 61 | super.fetchCompletions(apiToken, request, prompt, completionCount, temperature, maxTokens, topP, blockMode, 62 | multilineCompletions, telemetryBaseData, (Flow.Subscriber) subscriber2); 63 | } 64 | 65 | @Override 66 | protected String getCompletionURL(LanguageSupport lang) { 67 | String override; 68 | if (lang == null) { 69 | throw new IllegalStateException("lang cannot be null!"); 70 | } 71 | if ((override = this.TEST_COMPLETION_URL) != null) { 72 | String string = override; 73 | return string; 74 | } 75 | String string = super.getCompletionURL(lang); 76 | if (string == null) { 77 | throw new IllegalStateException("string cannot be null!"); 78 | } 79 | return string; 80 | } 81 | 82 | public int getCompletionRequestCount() { 83 | return this.completionRequestCount.get(); 84 | } 85 | 86 | public void reset() { 87 | this.completionRequestCount.set(0); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/com/github/copilot/actions/EnableCopilotCompletionsAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.openapi.actionSystem.AnAction 6 | * com.intellij.openapi.actionSystem.AnActionEvent 7 | * com.intellij.openapi.actionSystem.CommonDataKeys 8 | * com.intellij.openapi.project.Project 9 | * com.intellij.openapi.wm.StatusBar 10 | * com.intellij.openapi.wm.WindowManager 11 | * com.intellij.psi.PsiFile 12 | * org.jetbrains.annotations.NotNull 13 | */ 14 | package com.github.copilot.actions; 15 | 16 | import com.github.copilot.CopilotBundle; 17 | import com.github.copilot.actions.CopilotAction; 18 | import com.github.copilot.lang.fallback.VSCodeLanguageMap; 19 | import com.github.copilot.settings.CopilotApplicationSettings; 20 | import com.github.copilot.settings.CopilotApplicationState; 21 | import com.github.copilot.statusBar.CopilotStatusBarWidget; 22 | import com.github.copilot.telemetry.TelemetryData; 23 | import com.github.copilot.telemetry.TelemetryService; 24 | import com.intellij.openapi.actionSystem.AnAction; 25 | import com.intellij.openapi.actionSystem.AnActionEvent; 26 | import com.intellij.openapi.actionSystem.CommonDataKeys; 27 | import com.intellij.openapi.project.Project; 28 | import com.intellij.openapi.wm.StatusBar; 29 | import com.intellij.openapi.wm.WindowManager; 30 | import com.intellij.psi.PsiFile; 31 | import java.util.Map; 32 | 33 | public class EnableCopilotCompletionsAction extends AnAction implements CopilotAction { 34 | public void update(AnActionEvent e) { 35 | Project project; 36 | if (e == null) { 37 | throw new IllegalStateException("e cannot be null!"); 38 | } 39 | if ((project = e.getProject()) == null) { 40 | e.getPresentation().setEnabledAndVisible(false); 41 | return; 42 | } 43 | PsiFile file = (PsiFile) e.getData(CommonDataKeys.PSI_FILE); 44 | boolean currentlyDisabled = !CopilotApplicationSettings.settings().enableCompletions 45 | || file != null && !CopilotApplicationSettings.isCopilotEnabled(file); 46 | e.getPresentation().setEnabledAndVisible(currentlyDisabled); 47 | } 48 | 49 | public void actionPerformed(AnActionEvent e) { 50 | StatusBar bar; 51 | Project project; 52 | if (e == null) { 53 | throw new IllegalStateException("e cannot be null!"); 54 | } 55 | if ((project = e.getProject()) == null || project.isDisposed()) { 56 | return; 57 | } 58 | CopilotApplicationState settings = CopilotApplicationSettings.settings(); 59 | boolean global = !settings.enableCompletions; 60 | settings.enableCompletions = true; 61 | PsiFile file = (PsiFile) e.getData(CommonDataKeys.PSI_FILE); 62 | if (file != null) { 63 | settings.enableLanguage(file.getLanguage()); 64 | } 65 | if ((bar = WindowManager.getInstance().getStatusBar(project)) != null) { 66 | bar.setInfo(CopilotBundle.get("action.copilot.enableCopilot.statusEnabled")); 67 | } 68 | CopilotStatusBarWidget.update(project); 69 | String languageId = file == null ? "*" 70 | : VSCodeLanguageMap.INTELLIJ_VSCODE_MAP.getOrDefault(file.getLanguage().getID(), 71 | file.getLanguage().getID()); 72 | TelemetryData telemetryData = TelemetryData.createIssued(Map.of("languageId", languageId)); 73 | TelemetryService.getInstance().track("statusBar" + (global ? ".globalOn" : ".languageOn"), telemetryData); 74 | } 75 | 76 | public boolean isDumbAware() { 77 | return true; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/com/github/copilot/update/CopilotEarlyBirdChannelStartupActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.notification.Notification 6 | * com.intellij.notification.NotificationAction 7 | * com.intellij.notification.NotificationType 8 | * com.intellij.openapi.actionSystem.AnAction 9 | * com.intellij.openapi.application.ApplicationManager 10 | * me.masecla.copilot.extra.Logger 11 | * com.intellij.openapi.project.Project 12 | * com.intellij.openapi.startup.StartupActivity 13 | * com.intellij.openapi.updateSettings.impl.UpdateSettings 14 | * org.jetbrains.annotations.NotNull 15 | */ 16 | package com.github.copilot.update; 17 | 18 | import com.github.copilot.CopilotBundle; 19 | import com.github.copilot.CopilotNotifications; 20 | import com.github.copilot.settings.CopilotLocalApplicationSettings; 21 | import com.intellij.notification.Notification; 22 | import com.intellij.notification.NotificationAction; 23 | import com.intellij.notification.NotificationType; 24 | import com.intellij.openapi.actionSystem.AnAction; 25 | import com.intellij.openapi.application.ApplicationManager; 26 | import me.masecla.copilot.extra.Logger; 27 | import com.intellij.openapi.project.Project; 28 | import com.intellij.openapi.startup.StartupActivity; 29 | import com.intellij.openapi.updateSettings.impl.UpdateSettings; 30 | import java.util.List; 31 | import java.util.concurrent.atomic.AtomicBoolean; 32 | 33 | public class CopilotEarlyBirdChannelStartupActivity implements StartupActivity { 34 | private static final Logger LOG = Logger.getInstance(CopilotEarlyBirdChannelStartupActivity.class); 35 | private static final String EARLY_BIRD_CHANNEL = "https://plugins.jetbrains.com/plugins/super-early-bird/list"; 36 | private final AtomicBoolean hasRun = new AtomicBoolean(false); 37 | 38 | public void runActivity(Project project) { 39 | if (project == null) { 40 | throw new IllegalStateException("project cannot be null!"); 41 | } 42 | if (!this.hasRun.compareAndSet(false, true) || ApplicationManager.getApplication().isUnitTestMode()) { 43 | return; 44 | } 45 | if (!CopilotLocalApplicationSettings.settings().checkEarlyBirdChannel) { 46 | return; 47 | } 48 | List hostListCopy = UpdateSettings.getInstance().getPluginHosts(); 49 | if (!hostListCopy.contains(EARLY_BIRD_CHANNEL)) { 50 | return; 51 | } 52 | Notification notification = CopilotNotifications.createFullContentNotification( 53 | CopilotBundle.get("earlyBirdNotification.title"), CopilotBundle.get("earlyBirdNotification.message"), 54 | NotificationType.WARNING, true); 55 | notification.addAction((AnAction) NotificationAction 56 | .createSimpleExpiring((String) CopilotBundle.get("earlyBirdNotification.removeChannelButton"), () -> { 57 | CopilotLocalApplicationSettings.settings().checkEarlyBirdChannel = false; 58 | boolean ok = UpdateSettings.getInstance().getStoredPluginHosts() 59 | .removeIf(EARLY_BIRD_CHANNEL::equals); 60 | if (!ok) { 61 | LOG.warn("Failed to remove the early bird channel: " + hostListCopy); 62 | } 63 | })); 64 | notification.addAction((AnAction) NotificationAction 65 | .createSimpleExpiring((String) CopilotBundle.get("earlyBirdNotification.hideButton"), () -> { 66 | CopilotLocalApplicationSettings.settings().checkEarlyBirdChannel = false; 67 | })); 68 | notification.notify(project); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/com/github/copilot/lang/agent/rpc/JsonRPC.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.google.gson.Gson 6 | * com.google.gson.GsonBuilder 7 | * com.google.gson.JsonElement 8 | * com.google.gson.JsonObject 9 | * com.google.gson.JsonParseException 10 | * com.google.gson.JsonSyntaxException 11 | * org.jetbrains.annotations.NotNull 12 | */ 13 | package com.github.copilot.lang.agent.rpc; 14 | 15 | import com.github.copilot.lang.agent.commands.AuthStatusResult; 16 | import com.github.copilot.lang.agent.commands.SignInInitiateResult; 17 | import com.google.gson.Gson; 18 | import com.google.gson.GsonBuilder; 19 | import com.google.gson.JsonElement; 20 | import com.google.gson.JsonObject; 21 | import com.google.gson.JsonParseException; 22 | import com.google.gson.JsonSyntaxException; 23 | 24 | public final class JsonRPC { 25 | private static final Gson GSON = new GsonBuilder() 26 | .registerTypeAdapter(AuthStatusResult.class, new AuthStatusResult.TypeAdapter()) 27 | .registerTypeAdapter(SignInInitiateResult.class, new SignInInitiateResult.TypeAdapter()).create(); 28 | 29 | private JsonRPC() { 30 | } 31 | 32 | public static String serializeCommand(int requestId, String name, Object command) { 33 | if (name == null) { 34 | throw new IllegalStateException("name cannot be null!"); 35 | } 36 | if (command == null) { 37 | throw new IllegalStateException("command cannot be null!"); 38 | } 39 | JsonObject json = new JsonObject(); 40 | json.addProperty("jsonrpc", "2.0"); 41 | json.addProperty("id", requestId); 42 | json.addProperty("method", name); 43 | json.add("params", GSON.toJsonTree(command)); 44 | return GSON.toJson(json); 45 | } 46 | 47 | public static String serializeNotification(String name, Object command) { 48 | if (name == null) { 49 | throw new IllegalStateException("name cannot be null!"); 50 | } 51 | if (command == null) { 52 | throw new IllegalStateException("command cannot be null!"); 53 | } 54 | JsonObject json = new JsonObject(); 55 | json.addProperty("jsonrpc", "2.0"); 56 | json.addProperty("method", name); 57 | json.add("params", GSON.toJsonTree(command)); 58 | return GSON.toJson(json); 59 | } 60 | 61 | public static JsonRpcResponse parseResponse(String responseContent) 62 | throws JsonRpcErrorException, JsonParseException { 63 | JsonObject response; 64 | if (responseContent == null) { 65 | throw new IllegalStateException("responseContent cannot be null!"); 66 | } 67 | if ((response = GSON.fromJson(responseContent, JsonObject.class)).has("error")) { 68 | int id = response.getAsJsonPrimitive("id").getAsInt(); 69 | JsonObject error = (JsonObject) response.get("error"); 70 | String message = error.getAsJsonPrimitive("message").getAsString(); 71 | throw new JsonRpcErrorException(id, message); 72 | } 73 | int id = response.getAsJsonPrimitive("id").getAsInt(); 74 | JsonElement resultJSON = response.get("result"); 75 | return new JsonRpcResponse(id, resultJSON); 76 | } 77 | 78 | public static T parseResponse(JsonElement json, Class responseType) throws JsonSyntaxException { 79 | if (json == null) { 80 | throw new IllegalStateException("json cannot be null!"); 81 | } 82 | T object = GSON.fromJson(json, responseType); 83 | if (object == null) { 84 | throw new IllegalStateException("object cannot be null!"); 85 | } 86 | return object; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/com/github/copilot/github/DeviceLoginDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.intellij.ide.BrowserUtil 6 | * com.intellij.ide.ClipboardSynchronizer 7 | * com.intellij.openapi.project.Project 8 | * com.intellij.openapi.ui.DialogWrapper 9 | * com.intellij.openapi.ui.DialogWrapper$DialogWrapperAction 10 | * com.intellij.openapi.ui.DialogWrapper$IdeModalityType 11 | * com.intellij.util.concurrency.annotations.RequiresEdt 12 | * org.jetbrains.annotations.NotNull 13 | * org.jetbrains.annotations.Nullable 14 | */ 15 | package com.github.copilot.github; 16 | 17 | import com.github.copilot.CopilotBundle; 18 | import com.github.copilot.github.DeviceCodeResponse; 19 | import com.github.copilot.github.DeviceLoginForm; 20 | import com.intellij.ide.BrowserUtil; 21 | import com.intellij.ide.ClipboardSynchronizer; 22 | import com.intellij.openapi.project.Project; 23 | import com.intellij.openapi.ui.DialogWrapper; 24 | import com.intellij.util.concurrency.annotations.RequiresEdt; 25 | import java.awt.datatransfer.ClipboardOwner; 26 | import java.awt.datatransfer.StringSelection; 27 | import java.awt.datatransfer.Transferable; 28 | import java.awt.event.ActionEvent; 29 | import javax.swing.Action; 30 | import javax.swing.JComponent; 31 | 32 | public class DeviceLoginDialog extends DialogWrapper { 33 | private final DeviceCodeResponse codeResponse; 34 | 35 | @RequiresEdt 36 | public static boolean showDeviceLogin(Project project, DeviceCodeResponse codeResponse) { 37 | if (project == null) { 38 | throw new IllegalStateException("project cannot be null!"); 39 | } 40 | if (codeResponse == null) { 41 | throw new IllegalStateException("codeResponse cannot be null!"); 42 | } 43 | DeviceLoginDialog dialog = new DeviceLoginDialog(project, codeResponse); 44 | dialog.init(); 45 | return dialog.showAndGet(); 46 | } 47 | 48 | public DeviceLoginDialog(Project project, DeviceCodeResponse codeResponse) { 49 | if (codeResponse == null) { 50 | throw new IllegalStateException("codeResponse cannot be null!"); 51 | } 52 | super(project, false, DialogWrapper.IdeModalityType.PROJECT); 53 | this.codeResponse = codeResponse; 54 | this.setTitle(CopilotBundle.get("deviceAuth.dialog.title")); 55 | } 56 | 57 | protected void doOKAction() { 58 | StringSelection content = new StringSelection(this.codeResponse.getUserCode()); 59 | ClipboardSynchronizer.getInstance().setContent((Transferable) content, (ClipboardOwner) content); 60 | BrowserUtil.browse((String) this.codeResponse.getVerificationUri()); 61 | super.doOKAction(); 62 | } 63 | 64 | protected Action[] createActions() { 65 | DialogWrapper.DialogWrapperAction proceedButton = new DialogWrapper.DialogWrapperAction( 66 | CopilotBundle.get("deviceAuth.okButton")) { 67 | 68 | protected void doAction(ActionEvent e) { 69 | DeviceLoginDialog.super.doOKAction(); 70 | } 71 | }; 72 | this.getOKAction().putValue("Name", CopilotBundle.get("deviceAuth.copyOpenButton")); 73 | Action[] actionArray = new Action[] { this.getOKAction(), proceedButton, this.getCancelAction() }; 74 | if (actionArray == null) { 75 | throw new IllegalStateException("actionArray cannot be null!"); 76 | } 77 | return actionArray; 78 | } 79 | 80 | protected JComponent createCenterPanel() { 81 | DeviceLoginForm form = new DeviceLoginForm(); 82 | form.update(this.codeResponse); 83 | return form.getMainPanel(); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/com/github/copilot/github/GitHubCopilotToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.google.gson.annotations.SerializedName 6 | * com.intellij.openapi.util.text.StringUtil 7 | * org.jetbrains.annotations.Nullable 8 | */ 9 | package com.github.copilot.github; 10 | 11 | import com.google.gson.annotations.SerializedName; 12 | import com.intellij.openapi.util.text.StringUtil; 13 | import java.util.concurrent.TimeUnit; 14 | 15 | public class GitHubCopilotToken { 16 | @SerializedName(value = "token") 17 | private String token; 18 | @SerializedName(value = "expires_at") 19 | private long expiresAtSeconds; 20 | public static final GitHubCopilotToken ACCESS_DENIED_TOKEN = new GitHubCopilotToken(null); 21 | 22 | GitHubCopilotToken(String token) { 23 | this.token = token; 24 | this.expiresAtSeconds = 0L; 25 | } 26 | 27 | public boolean isValid() { 28 | return !this.isExpired() && StringUtil.isNotEmpty((String) this.token); 29 | } 30 | 31 | public boolean isUnauthorized() { 32 | return StringUtil.isEmpty((String) this.token); 33 | } 34 | 35 | public boolean isExpired() { 36 | return System.currentTimeMillis() / 1000L >= this.expiresAtSeconds; 37 | } 38 | 39 | public boolean isExpiringSoon(long timeDelta, TimeUnit timeUnit) { 40 | return timeUnit.toSeconds(timeDelta) + System.currentTimeMillis() / 1000L >= this.expiresAtSeconds; 41 | } 42 | 43 | public String getTrackingId() { 44 | String token = this.token; 45 | if (token == null) { 46 | return null; 47 | } 48 | int index = token.indexOf(58); 49 | return index == -1 ? null : token.substring(0, index); 50 | } 51 | 52 | public String getToken() { 53 | return this.token; 54 | } 55 | 56 | public long getExpiresAtSeconds() { 57 | return this.expiresAtSeconds; 58 | } 59 | 60 | public void setToken(String token) { 61 | this.token = token; 62 | } 63 | 64 | public void setExpiresAtSeconds(long expiresAtSeconds) { 65 | this.expiresAtSeconds = expiresAtSeconds; 66 | } 67 | 68 | public boolean equals(Object o) { 69 | if (o == this) { 70 | return true; 71 | } 72 | if (!(o instanceof GitHubCopilotToken)) { 73 | return false; 74 | } 75 | GitHubCopilotToken other = (GitHubCopilotToken) o; 76 | if (!other.canEqual(this)) { 77 | return false; 78 | } 79 | if (this.getExpiresAtSeconds() != other.getExpiresAtSeconds()) { 80 | return false; 81 | } 82 | String this$token = this.getToken(); 83 | String other$token = other.getToken(); 84 | return !(this$token == null ? other$token != null : !this$token.equals(other$token)); 85 | } 86 | 87 | protected boolean canEqual(Object other) { 88 | return other instanceof GitHubCopilotToken; 89 | } 90 | 91 | public int hashCode() { 92 | int result = 1; 93 | long $expiresAtSeconds = this.getExpiresAtSeconds(); 94 | result = result * 59 + (int) ($expiresAtSeconds >>> 32 ^ $expiresAtSeconds); 95 | String $token = this.getToken(); 96 | result = result * 59 + ($token == null ? 43 : $token.hashCode()); 97 | return result; 98 | } 99 | 100 | public String toString() { 101 | return "GitHubCopilotToken(token=" + this.getToken() + ", expiresAtSeconds=" + this.getExpiresAtSeconds() + ")"; 102 | } 103 | 104 | public GitHubCopilotToken(String token, long expiresAtSeconds) { 105 | this.token = token; 106 | this.expiresAtSeconds = expiresAtSeconds; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/com/github/copilot/util/String2DoubleMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * com.google.gson.TypeAdapter 6 | * com.google.gson.stream.JsonReader 7 | * com.google.gson.stream.JsonWriter 8 | * it.unimi.dsi.fastutil.objects.Object2DoubleMap 9 | * it.unimi.dsi.fastutil.objects.Object2DoubleMap$Entry 10 | * it.unimi.dsi.fastutil.objects.Object2DoubleMaps 11 | * it.unimi.dsi.fastutil.objects.Object2DoubleMaps$EmptyMap 12 | * it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap 13 | */ 14 | package com.github.copilot.util; 15 | 16 | import com.google.gson.stream.JsonReader; 17 | import com.google.gson.stream.JsonWriter; 18 | import it.unimi.dsi.fastutil.objects.Object2DoubleMap; 19 | import it.unimi.dsi.fastutil.objects.Object2DoubleMaps; 20 | import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap; 21 | import java.io.IOException; 22 | 23 | public final class String2DoubleMap extends Object2DoubleOpenHashMap { 24 | private static final long serialVersionUID = -4680414524405617139L; 25 | public static final Object2DoubleMap EMPTY = new Object2DoubleMaps.EmptyMap() { 26 | private static final long serialVersionUID = 4680414524405687139L; 27 | }; 28 | 29 | public static Object2DoubleMap of() { 30 | return EMPTY; 31 | } 32 | 33 | public static Object2DoubleMap of(String key, double value) { 34 | return Object2DoubleMaps.singleton(key, value); 35 | } 36 | 37 | public static Object2DoubleMap of(String k1, double v1, String k2, double v2) { 38 | String2DoubleMap map = new String2DoubleMap(); 39 | map.put(k1, v1); 40 | map.put(k2, v2); 41 | return map; 42 | } 43 | 44 | public static Object2DoubleMap of(String k1, double v1, String k2, double v2, String k3, double v3) { 45 | String2DoubleMap map = new String2DoubleMap(); 46 | map.put(k1, v1); 47 | map.put(k2, v2); 48 | map.put(k3, v3); 49 | return map; 50 | } 51 | 52 | public static Object2DoubleMap of(String k1, double v1, String k2, double v2, String k3, double v3, 53 | String k4, double v4) { 54 | String2DoubleMap map = new String2DoubleMap(); 55 | map.put(k1, v1); 56 | map.put(k2, v2); 57 | map.put(k3, v3); 58 | map.put(k4, v4); 59 | return map; 60 | } 61 | 62 | public static Object2DoubleMap of(String k1, double v1, String k2, double v2, String k3, double v3, 63 | String k4, double v4, String k5, double v5) { 64 | String2DoubleMap map = new String2DoubleMap(); 65 | map.put(k1, v1); 66 | map.put(k2, v2); 67 | map.put(k3, v3); 68 | map.put(k4, v4); 69 | map.put(k5, v5); 70 | return map; 71 | } 72 | 73 | public static final class TypeAdapter extends com.google.gson.TypeAdapter { 74 | public void write(JsonWriter jsonWriter, String2DoubleMap string2DoubleMap) throws IOException { 75 | jsonWriter.beginObject(); 76 | for (Object2DoubleMap.Entry entry : string2DoubleMap.object2DoubleEntrySet()) { 77 | jsonWriter.name(entry.getKey()); 78 | jsonWriter.value(entry.getDoubleValue()); 79 | } 80 | jsonWriter.endObject(); 81 | } 82 | 83 | public String2DoubleMap read(JsonReader jsonReader) throws IOException { 84 | String2DoubleMap map = new String2DoubleMap(); 85 | jsonReader.beginObject(); 86 | while (jsonReader.hasNext()) { 87 | String key = jsonReader.nextName(); 88 | double value = jsonReader.nextDouble(); 89 | map.put(key, value); 90 | } 91 | jsonReader.endObject(); 92 | return map; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/com/github/copilot/completions/DefaultCopilotEditorInlay.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Decompiled with CFR 0.152. 3 | * 4 | * Could not load the following classes: 5 | * javax.annotation.concurrent.Immutable 6 | * org.jetbrains.annotations.NotNull 7 | */ 8 | package com.github.copilot.completions; 9 | 10 | import com.github.copilot.completions.CopilotCompletionType; 11 | import com.github.copilot.completions.CopilotEditorInlay; 12 | import java.util.List; 13 | import javax.annotation.concurrent.Immutable; 14 | 15 | @Immutable 16 | final class DefaultCopilotEditorInlay implements CopilotEditorInlay { 17 | private final CopilotCompletionType type; 18 | private final int editorOffset; 19 | private final List completionLines; 20 | 21 | public DefaultCopilotEditorInlay(CopilotCompletionType type, int editorOffset, List completionLines) { 22 | if (type == null) { 23 | throw new IllegalStateException("type cannot be null!"); 24 | } 25 | if (completionLines == null) { 26 | throw new IllegalStateException("completionLines cannot be null!"); 27 | } 28 | this.type = type; 29 | this.editorOffset = editorOffset; 30 | this.completionLines = completionLines; 31 | } 32 | 33 | @Override 34 | public CopilotCompletionType getType() { 35 | CopilotCompletionType copilotCompletionType = this.type; 36 | if (copilotCompletionType == null) { 37 | throw new IllegalStateException("copilotCompletionType cannot be null!"); 38 | } 39 | return copilotCompletionType; 40 | } 41 | 42 | @Override 43 | public List getLines() { 44 | List list = this.completionLines; 45 | if (list == null) { 46 | throw new IllegalStateException("list cannot be null!"); 47 | } 48 | return list; 49 | } 50 | 51 | @Override 52 | public int getEditorOffset() { 53 | return this.editorOffset; 54 | } 55 | 56 | public List getCompletionLines() { 57 | List list = this.completionLines; 58 | if (list == null) { 59 | throw new IllegalStateException("list cannot be null!"); 60 | } 61 | return list; 62 | } 63 | 64 | public boolean equals(Object o) { 65 | if (o == this) { 66 | return true; 67 | } 68 | if (!(o instanceof DefaultCopilotEditorInlay)) { 69 | return false; 70 | } 71 | DefaultCopilotEditorInlay other = (DefaultCopilotEditorInlay) o; 72 | if (this.getEditorOffset() != other.getEditorOffset()) { 73 | return false; 74 | } 75 | CopilotCompletionType this$type = this.getType(); 76 | CopilotCompletionType other$type = other.getType(); 77 | if (this$type == null ? other$type != null : !(this$type).equals(other$type)) { 78 | return false; 79 | } 80 | List this$completionLines = this.getCompletionLines(); 81 | List other$completionLines = other.getCompletionLines(); 82 | return !(this$completionLines == null ? other$completionLines != null 83 | : !((Object) this$completionLines).equals(other$completionLines)); 84 | } 85 | 86 | public int hashCode() { 87 | int PRIME = 59; 88 | int result = 1; 89 | result = result * 59 + this.getEditorOffset(); 90 | CopilotCompletionType $type = this.getType(); 91 | result = result * 59 + ($type == null ? 43 : ($type).hashCode()); 92 | List $completionLines = this.getCompletionLines(); 93 | result = result * 59 + ($completionLines == null ? 43 : ((Object) $completionLines).hashCode()); 94 | return result; 95 | } 96 | 97 | public String toString() { 98 | return "DefaultCopilotEditorInlay(type=" + this.getType() + ", editorOffset=" + this.getEditorOffset() 99 | + ", completionLines=" + this.getCompletionLines() + ")"; 100 | } 101 | 102 | } 103 | --------------------------------------------------------------------------------