@@ -275,8 +275,9 @@ public final class SuggestionWidgetController: NSObject {
275275
276276public extension SuggestionWidgetController {
277277 func suggestCode( fileURL: URL ) {
278- widgetViewModel. isProcessing = false
279278 Task {
279+ markAsProcessing ( true )
280+ defer { markAsProcessing ( false ) }
280281 if let suggestion = await dataSource? . suggestionForFile ( at: fileURL) {
281282 suggestionPanelViewModel. content = . suggestion( suggestion)
282283 suggestionPanelViewModel. isPanelDisplayed = true
@@ -285,25 +286,28 @@ public extension SuggestionWidgetController {
285286 }
286287
287288 func discardSuggestion( fileURL: URL ) {
288- widgetViewModel. isProcessing = false
289289 Task {
290290 await updateContentForActiveEditor ( fileURL: fileURL)
291291 }
292292 }
293293
294294 func markAsProcessing( _ isProcessing: Bool ) {
295- widgetViewModel. isProcessing = isProcessing
295+ if isProcessing {
296+ widgetViewModel. markIsProcessing ( )
297+ } else {
298+ widgetViewModel. endIsProcessing ( )
299+ }
296300 }
297301
298302 func presentError( _ errorDescription: String ) {
299303 suggestionPanelViewModel. content = . error( errorDescription)
300304 suggestionPanelViewModel. isPanelDisplayed = true
301- widgetViewModel. isProcessing = false
302305 }
303306
304307 func presentChatRoom( fileURL: URL ) {
305- widgetViewModel. isProcessing = false
306308 Task {
309+ markAsProcessing ( true )
310+ defer { markAsProcessing ( false ) }
307311 if let chat = await dataSource? . chatForFile ( at: fileURL) {
308312 chatWindowViewModel. chat = chat
309313 chatWindowViewModel. isPanelDisplayed = true
@@ -343,15 +347,15 @@ public extension SuggestionWidgetController {
343347 }
344348
345349 func closeChatRoom( fileURL: URL ) {
346- widgetViewModel. isProcessing = false
347350 Task {
348351 await updateContentForActiveEditor ( fileURL: fileURL)
349352 }
350353 }
351354
352355 func presentPromptToCode( fileURL: URL ) {
353- widgetViewModel. isProcessing = false
354356 Task {
357+ markAsProcessing ( true )
358+ defer { markAsProcessing ( false ) }
355359 if let provider = await dataSource? . promptToCodeForFile ( at: fileURL) {
356360 suggestionPanelViewModel. content = . promptToCode( provider)
357361 suggestionPanelViewModel. isPanelDisplayed = true
@@ -367,7 +371,6 @@ public extension SuggestionWidgetController {
367371 }
368372
369373 func discardPromptToCode( fileURL: URL ) {
370- widgetViewModel. isProcessing = false
371374 Task {
372375 await updateContentForActiveEditor ( fileURL: fileURL)
373376 }
0 commit comments