@@ -76,17 +76,8 @@ export function registerCopilotContextProviders(
7676 return ;
7777 }
7878
79- devkit . activate ( ) . then ( async ( ) => {
79+ devkit . activate ( ) . then ( ( ) => {
8080 try {
81- const copilotClientApi = await getCopilotClientApi ( ) ;
82- const copilotChatApi = await getCopilotChatApi ( ) ;
83- if ( ! copilotClientApi && ! copilotChatApi ) {
84- channel . debug (
85- 'Failed to find compatible version of GitHub Copilot extension installed. Skip registration of Copilot context provider.'
86- ) ;
87- return ;
88- }
89-
9081 const provider : ContextProvider < SupportedContextItem > = {
9182 id : CSharpExtensionId , // use extension id as provider id for now
9283 selector : [ { language : 'csharp' } ] ,
@@ -106,30 +97,50 @@ export function registerCopilotContextProviders(
10697 } ,
10798 } ,
10899 } ;
109-
110- let installCount = 0 ;
111- if ( copilotClientApi ) {
112- const disposable = await installContextProvider ( copilotClientApi , provider ) ;
113- if ( disposable ) {
114- context . subscriptions . push ( disposable ) ;
115- installCount ++ ;
116- }
117- }
118- if ( copilotChatApi ) {
119- const disposable = await installContextProvider ( copilotChatApi , provider ) ;
120- if ( disposable ) {
121- context . subscriptions . push ( disposable ) ;
122- installCount ++ ;
123- }
124- }
125-
126- if ( installCount === 0 ) {
127- channel . debug (
128- 'Incompatible GitHub Copilot extension installed. Skip registration of C# context providers.'
129- ) ;
130- return ;
131- }
132- channel . debug ( 'Registration of C# context provider for GitHub Copilot extension succeeded.' ) ;
100+ getCopilotClientApi ( )
101+ . then ( async ( api ) => {
102+ if ( ! api ) {
103+ channel . debug (
104+ 'Failed to find compatible version of GitHub Copilot extension installed. Skip registration of Copilot context provider.'
105+ ) ;
106+ return ;
107+ }
108+ const disposable = await installContextProvider ( api , provider ) ;
109+ if ( disposable ) {
110+ context . subscriptions . push ( disposable ) ;
111+ channel . debug ( 'Registration of C# context provider for GitHub Copilot extension succeeded.' ) ;
112+ } else {
113+ channel . debug (
114+ 'Incompatible GitHub Copilot extension installed. Skip registration of C# context providers.'
115+ ) ;
116+ }
117+ } )
118+ . catch ( ( error ) => {
119+ channel . error ( 'Failed to register Copilot context providers' , error ) ;
120+ } ) ;
121+ getCopilotChatApi ( )
122+ . then ( async ( api ) => {
123+ if ( ! api ) {
124+ channel . debug (
125+ 'Failed to find compatible version of GitHub Copilot Chat extension installed. Skip registration of Copilot context provider.'
126+ ) ;
127+ return ;
128+ }
129+ const disposable = await installContextProvider ( api , provider ) ;
130+ if ( disposable ) {
131+ context . subscriptions . push ( disposable ) ;
132+ channel . debug (
133+ 'Registration of C# context provider for GitHub Copilot Chat extension succeeded.'
134+ ) ;
135+ } else {
136+ channel . debug (
137+ 'Incompatible GitHub Copilot Chat extension installed. Skip registration of C# context providers.'
138+ ) ;
139+ }
140+ } )
141+ . catch ( ( error ) => {
142+ channel . error ( 'Failed to register Copilot Chat context providers' , error ) ;
143+ } ) ;
133144 } catch ( error ) {
134145 channel . error ( 'Failed to register Copilot context providers' , error ) ;
135146 }
@@ -157,14 +168,7 @@ async function getCopilotChatApi(): Promise<CopilotApi | undefined> {
157168
158169 let exports : CopilotChatApi | undefined ;
159170 try {
160- exports = await Promise . race ( [
161- extension . activate ( ) ,
162- new Promise < undefined > ( ( resolve ) => {
163- setTimeout ( ( ) => {
164- resolve ( undefined ) ;
165- } , 3000 ) ;
166- } ) ,
167- ] ) ;
171+ exports = await extension . activate ( ) ;
168172 } catch {
169173 return undefined ;
170174 }
0 commit comments