@@ -19,6 +19,7 @@ export class GhostServiceManager {
1919 private documentStore : GhostDocumentStore
2020 private model : GhostModel
2121 private cline : ClineProvider
22+ private context : vscode . ExtensionContext
2223 private providerSettingsManager : ProviderSettingsManager
2324 private settings : GhostServiceSettings | null = null
2425 private ghostContext : GhostContext
@@ -35,10 +36,12 @@ export class GhostServiceManager {
3536 // VSCode Providers
3637 public codeActionProvider : GhostCodeActionProvider
3738 public inlineCompletionProvider : GhostInlineCompletionProvider
39+ private inlineCompletionProviderDisposable : vscode . Disposable | null = null
3840
3941 private ignoreController ?: Promise < RooIgnoreController >
4042
4143 private constructor ( context : vscode . ExtensionContext , cline : ClineProvider ) {
44+ this . context = context
4245 this . cline = cline
4346
4447 // Register Internal Components
@@ -112,9 +115,30 @@ export class GhostServiceManager {
112115 this . cursorAnimation . updateSettings ( this . settings || undefined )
113116 await this . updateGlobalContext ( )
114117 this . updateStatusBar ( )
118+ await this . updateInlineCompletionProviderRegistration ( )
115119 await this . saveSettings ( )
116120 }
117121
122+ /**
123+ * Register or unregister the inline completion provider based on enableAutoTrigger setting
124+ */
125+ private async updateInlineCompletionProviderRegistration ( ) {
126+ const shouldBeRegistered = this . settings ?. enableAutoTrigger ?? false
127+
128+ if ( shouldBeRegistered && ! this . inlineCompletionProviderDisposable ) {
129+ // Register the provider
130+ this . inlineCompletionProviderDisposable = vscode . languages . registerInlineCompletionItemProvider (
131+ "*" ,
132+ this . inlineCompletionProvider ,
133+ )
134+ this . context . subscriptions . push ( this . inlineCompletionProviderDisposable )
135+ } else if ( ! shouldBeRegistered && this . inlineCompletionProviderDisposable ) {
136+ // Unregister the provider
137+ this . inlineCompletionProviderDisposable . dispose ( )
138+ this . inlineCompletionProviderDisposable = null
139+ }
140+ }
141+
118142 public async disable ( ) {
119143 this . settings = {
120144 ...this . settings ,
@@ -348,6 +372,12 @@ export class GhostServiceManager {
348372 this . statusBar ?. dispose ( )
349373 this . cursorAnimation . dispose ( )
350374
375+ // Dispose inline completion provider registration
376+ if ( this . inlineCompletionProviderDisposable ) {
377+ this . inlineCompletionProviderDisposable . dispose ( )
378+ this . inlineCompletionProviderDisposable = null
379+ }
380+
351381 this . disposeIgnoreController ( )
352382
353383 GhostServiceManager . instance = null // Reset singleton
0 commit comments