@@ -3,6 +3,18 @@ import delay from "delay"
33
44import { ClineProvider } from "../core/webview/ClineProvider"
55
6+ /**
7+ * Helper to get the visible ClineProvider instance or log if not found.
8+ */
9+ export function getVisibleProviderOrLog ( outputChannel : vscode . OutputChannel ) : ClineProvider | undefined {
10+ const visibleProvider = ClineProvider . getVisibleInstance ( )
11+ if ( ! visibleProvider ) {
12+ outputChannel . appendLine ( "Cannot find any visible Cline instances." )
13+ return undefined
14+ }
15+ return visibleProvider
16+ }
17+
618import { registerHumanRelayCallback , unregisterHumanRelayCallback , handleHumanRelayResponse } from "./humanRelay"
719import { handleNewTask } from "./handleTask"
820
@@ -52,47 +64,32 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
5264 return {
5365 "roo-cline.activationCompleted" : ( ) => { } ,
5466 "roo-cline.plusButtonClicked" : async ( ) => {
55- const visibleProvider = ClineProvider . getVisibleInstance ( )
56- if ( ! visibleProvider ) {
57- outputChannel . appendLine ( "Cannot find any visible Cline instances." )
58- return
59- }
67+ const visibleProvider = getVisibleProviderOrLog ( outputChannel )
68+ if ( ! visibleProvider ) return
6069 await visibleProvider . removeClineFromStack ( )
6170 await visibleProvider . postStateToWebview ( )
6271 await visibleProvider . postMessageToWebview ( { type : "action" , action : "chatButtonClicked" } )
6372 } ,
6473 "roo-cline.mcpButtonClicked" : ( ) => {
65- const visibleProvider = ClineProvider . getVisibleInstance ( )
66- if ( ! visibleProvider ) {
67- outputChannel . appendLine ( "Cannot find any visible Cline instances." )
68- return
69- }
74+ const visibleProvider = getVisibleProviderOrLog ( outputChannel )
75+ if ( ! visibleProvider ) return
7076 visibleProvider . postMessageToWebview ( { type : "action" , action : "mcpButtonClicked" } )
7177 } ,
7278 "roo-cline.promptsButtonClicked" : ( ) => {
73- const visibleProvider = ClineProvider . getVisibleInstance ( )
74- if ( ! visibleProvider ) {
75- outputChannel . appendLine ( "Cannot find any visible Cline instances." )
76- return
77- }
79+ const visibleProvider = getVisibleProviderOrLog ( outputChannel )
80+ if ( ! visibleProvider ) return
7881 visibleProvider . postMessageToWebview ( { type : "action" , action : "promptsButtonClicked" } )
7982 } ,
8083 "roo-cline.popoutButtonClicked" : ( ) => openClineInNewTab ( { context, outputChannel } ) ,
8184 "roo-cline.openInNewTab" : ( ) => openClineInNewTab ( { context, outputChannel } ) ,
8285 "roo-cline.settingsButtonClicked" : ( ) => {
83- const visibleProvider = ClineProvider . getVisibleInstance ( )
84- if ( ! visibleProvider ) {
85- outputChannel . appendLine ( "Cannot find any visible Cline instances." )
86- return
87- }
86+ const visibleProvider = getVisibleProviderOrLog ( outputChannel )
87+ if ( ! visibleProvider ) return
8888 visibleProvider . postMessageToWebview ( { type : "action" , action : "settingsButtonClicked" } )
8989 } ,
9090 "roo-cline.historyButtonClicked" : ( ) => {
91- const visibleProvider = ClineProvider . getVisibleInstance ( )
92- if ( ! visibleProvider ) {
93- outputChannel . appendLine ( "Cannot find any visible Cline instances." )
94- return
95- }
91+ const visibleProvider = getVisibleProviderOrLog ( outputChannel )
92+ if ( ! visibleProvider ) return
9693 visibleProvider . postMessageToWebview ( { type : "action" , action : "historyButtonClicked" } )
9794 } ,
9895 "roo-cline.helpButtonClicked" : ( ) => {
0 commit comments