@@ -24,11 +24,11 @@ export interface CopilotTrait {
2424 promptTextOverride ?: string ;
2525}
2626
27- export interface CopilotChatApi {
27+ export interface CopilotContextProviderAPI {
2828 getContextProviderAPI ( version : string ) : Promise < ContextProviderApiV1 | undefined > ;
2929}
3030
31- export interface CopilotApi extends CopilotChatApi {
31+ export interface CopilotApi extends CopilotContextProviderAPI {
3232 registerRelatedFilesProvider (
3333 providerId : { extensionId : string ; languageId : string } ,
3434 callback : (
@@ -40,7 +40,7 @@ export interface CopilotApi extends CopilotChatApi {
4040}
4141
4242export async function registerRelatedFilesProvider ( ) : Promise < void > {
43- const api = await getCopilotApi ( ) ;
43+ const api = await getCopilotClientApi ( ) ;
4444 if ( util . extensionContext && api ) {
4545 try {
4646 for ( const languageId of [ 'c' , 'cpp' , 'cuda-cpp' ] ) {
@@ -132,7 +132,7 @@ async function getIncludes(uri: vscode.Uri, maxDepth: number): Promise<GetInclud
132132 return includes ;
133133}
134134
135- export async function getCopilotApi ( ) : Promise < CopilotApi | undefined > {
135+ export async function getCopilotClientApi ( ) : Promise < CopilotApi | undefined > {
136136 const copilotExtension = vscode . extensions . getExtension < CopilotApi > ( 'github.copilot' ) ;
137137 if ( ! copilotExtension ) {
138138 return undefined ;
@@ -149,19 +149,30 @@ export async function getCopilotApi(): Promise<CopilotApi | undefined> {
149149 }
150150}
151151
152- export async function getCopilotChatApi ( ) : Promise < CopilotChatApi | undefined > {
152+ export async function getCopilotChatApi ( ) : Promise < CopilotContextProviderAPI | undefined > {
153+ type CopilotChatApi = { getAPI ?( version : number ) : CopilotContextProviderAPI | undefined } ;
153154 const copilotExtension = vscode . extensions . getExtension < CopilotChatApi > ( 'github.copilot-chat' ) ;
154155 if ( ! copilotExtension ) {
155156 return undefined ;
156157 }
157158
159+ let exports : CopilotChatApi | undefined ;
158160 if ( ! copilotExtension . isActive ) {
159161 try {
160- return await copilotExtension . activate ( ) ;
162+ exports = await copilotExtension . activate ( ) ;
161163 } catch {
162164 return undefined ;
163165 }
164166 } else {
165- return copilotExtension . exports ;
167+ exports = copilotExtension . exports ;
168+ }
169+ if ( ! exports || typeof exports . getAPI !== 'function' ) {
170+ return undefined ;
166171 }
172+ const result = exports . getAPI ( 1 ) ;
173+ return result ;
174+ }
175+
176+ interface Disposable {
177+ dispose ( ) : void ;
167178}
0 commit comments