@@ -19,13 +19,40 @@ import { t } from "../i18n"
1919
2020/**
2121 * Helper to get the visible ClineProvider instance or log if not found.
22+ * Shows user-friendly error message when provider is not available.
2223 */
23- export function getVisibleProviderOrLog ( outputChannel : vscode . OutputChannel ) : ClineProvider | undefined {
24- const visibleProvider = ClineProvider . getVisibleInstance ( )
24+ export async function getVisibleProviderOrLog ( outputChannel : vscode . OutputChannel ) : Promise < ClineProvider | undefined > {
25+ let visibleProvider = ClineProvider . getVisibleInstance ( )
26+
27+ // If no visible provider, try to activate the sidebar view first
28+ if ( ! visibleProvider ) {
29+ outputChannel . appendLine ( "No visible Roo Code instance found, attempting to activate sidebar view..." )
30+
31+ try {
32+ // Try to focus the sidebar view which should trigger provider creation
33+ await vscode . commands . executeCommand ( `${ Package . name } .SidebarProvider.focus` )
34+
35+ // Wait a bit for the view to initialize
36+ await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) )
37+
38+ // Try to get the provider again
39+ visibleProvider = ClineProvider . getVisibleInstance ( )
40+ } catch ( error ) {
41+ outputChannel . appendLine ( `Failed to activate sidebar view: ${ error } ` )
42+ }
43+ }
44+
2545 if ( ! visibleProvider ) {
26- outputChannel . appendLine ( "Cannot find any visible Roo Code instances." )
46+ outputChannel . appendLine ( "Cannot find any visible Roo Code instances after activation attempt." )
47+ // Show user-friendly error message only if not in test environment
48+ if ( typeof vscode . window . showErrorMessage === "function" ) {
49+ vscode . window . showErrorMessage (
50+ "Roo Code is still initializing. Please wait a moment and try again, or restart VS Code if the issue persists." ,
51+ )
52+ }
2753 return undefined
2854 }
55+
2956 return visibleProvider
3057}
3158
@@ -74,8 +101,8 @@ export const registerCommands = (options: RegisterCommandOptions) => {
74101
75102const getCommandsMap = ( { context, outputChannel, provider } : RegisterCommandOptions ) : Record < CommandId , any > => ( {
76103 activationCompleted : ( ) => { } ,
77- accountButtonClicked : ( ) => {
78- const visibleProvider = getVisibleProviderOrLog ( outputChannel )
104+ accountButtonClicked : async ( ) => {
105+ const visibleProvider = await getVisibleProviderOrLog ( outputChannel )
79106
80107 if ( ! visibleProvider ) {
81108 return
@@ -86,7 +113,7 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
86113 visibleProvider . postMessageToWebview ( { type : "action" , action : "accountButtonClicked" } )
87114 } ,
88115 plusButtonClicked : async ( ) => {
89- const visibleProvider = getVisibleProviderOrLog ( outputChannel )
116+ const visibleProvider = await getVisibleProviderOrLog ( outputChannel )
90117
91118 if ( ! visibleProvider ) {
92119 return
@@ -101,8 +128,8 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
101128 // This ensures the focus happens after the view has switched
102129 await visibleProvider . postMessageToWebview ( { type : "action" , action : "focusInput" } )
103130 } ,
104- mcpButtonClicked : ( ) => {
105- const visibleProvider = getVisibleProviderOrLog ( outputChannel )
131+ mcpButtonClicked : async ( ) => {
132+ const visibleProvider = await getVisibleProviderOrLog ( outputChannel )
106133
107134 if ( ! visibleProvider ) {
108135 return
@@ -112,8 +139,8 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
112139
113140 visibleProvider . postMessageToWebview ( { type : "action" , action : "mcpButtonClicked" } )
114141 } ,
115- promptsButtonClicked : ( ) => {
116- const visibleProvider = getVisibleProviderOrLog ( outputChannel )
142+ promptsButtonClicked : async ( ) => {
143+ const visibleProvider = await getVisibleProviderOrLog ( outputChannel )
117144
118145 if ( ! visibleProvider ) {
119146 return
@@ -129,8 +156,8 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
129156 return openClineInNewTab ( { context, outputChannel } )
130157 } ,
131158 openInNewTab : ( ) => openClineInNewTab ( { context, outputChannel } ) ,
132- settingsButtonClicked : ( ) => {
133- const visibleProvider = getVisibleProviderOrLog ( outputChannel )
159+ settingsButtonClicked : async ( ) => {
160+ const visibleProvider = await getVisibleProviderOrLog ( outputChannel )
134161
135162 if ( ! visibleProvider ) {
136163 return
@@ -142,8 +169,8 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
142169 // Also explicitly post the visibility message to trigger scroll reliably
143170 visibleProvider . postMessageToWebview ( { type : "action" , action : "didBecomeVisible" } )
144171 } ,
145- historyButtonClicked : ( ) => {
146- const visibleProvider = getVisibleProviderOrLog ( outputChannel )
172+ historyButtonClicked : async ( ) => {
173+ const visibleProvider = await getVisibleProviderOrLog ( outputChannel )
147174
148175 if ( ! visibleProvider ) {
149176 return
@@ -153,8 +180,8 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
153180
154181 visibleProvider . postMessageToWebview ( { type : "action" , action : "historyButtonClicked" } )
155182 } ,
156- marketplaceButtonClicked : ( ) => {
157- const visibleProvider = getVisibleProviderOrLog ( outputChannel )
183+ marketplaceButtonClicked : async ( ) => {
184+ const visibleProvider = await getVisibleProviderOrLog ( outputChannel )
158185 if ( ! visibleProvider ) return
159186 visibleProvider . postMessageToWebview ( { type : "action" , action : "marketplaceButtonClicked" } )
160187 } ,
@@ -178,7 +205,7 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
178205 await promptForCustomStoragePath ( )
179206 } ,
180207 importSettings : async ( filePath ?: string ) => {
181- const visibleProvider = getVisibleProviderOrLog ( outputChannel )
208+ const visibleProvider = await getVisibleProviderOrLog ( outputChannel )
182209 if ( ! visibleProvider ) {
183210 return
184211 }
@@ -212,8 +239,8 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
212239 outputChannel . appendLine ( `Error focusing panel: ${ error } ` )
213240 }
214241 } ,
215- acceptInput : ( ) => {
216- const visibleProvider = getVisibleProviderOrLog ( outputChannel )
242+ acceptInput : async ( ) => {
243+ const visibleProvider = await getVisibleProviderOrLog ( outputChannel )
217244
218245 if ( ! visibleProvider ) {
219246 return
0 commit comments