@@ -26,7 +26,6 @@ export class GhostServiceManager {
2626 private ghostContext : GhostContext
2727 private cursorAnimation : GhostGutterAnimation
2828
29- private enabled : boolean = true
3029 private taskId : string | null = null
3130 private isProcessing : boolean = false
3231
@@ -60,6 +59,7 @@ export class GhostServiceManager {
6059 this . updateCostTracking . bind ( this ) ,
6160 this . ghostContext ,
6261 this . cursorAnimation ,
62+ ( ) => this . settings ,
6363 )
6464
6565 // Register document event handlers
@@ -94,7 +94,7 @@ export class GhostServiceManager {
9494
9595 // Settings Management
9696 private loadSettings ( ) {
97- const state = ContextProxy . instance ? .getValues ?. ( )
97+ const state = ContextProxy . instance . getValues ( )
9898 return state . ghostServiceSettings
9999 }
100100
@@ -107,7 +107,7 @@ export class GhostServiceManager {
107107 provider : this . getCurrentProviderName ( ) ,
108108 model : this . getCurrentModelName ( ) ,
109109 }
110- await ContextProxy . instance ? .setValues ?. ( { ghostServiceSettings : settingsWithModelInfo } )
110+ await ContextProxy . instance . setValues ( { ghostServiceSettings : settingsWithModelInfo } )
111111 await this . cline . postStateToWebview ( )
112112 }
113113
@@ -121,22 +121,21 @@ export class GhostServiceManager {
121121 await this . saveSettings ( )
122122 }
123123
124- /**
125- * Update the inline completion provider with current settings
126- */
127124 private async updateInlineCompletionProviderRegistration ( ) {
128- // Always keep the provider registered so manual triggers (cmd-L) work
129- // The provider will check enableAutoTrigger internally to decide whether to auto-trigger
130- if ( ! this . inlineCompletionProviderDisposable ) {
125+ const shouldBeRegistered = this . settings ?. enableAutoTrigger ?? false
126+
127+ if ( shouldBeRegistered && ! this . inlineCompletionProviderDisposable ) {
128+ // Register the provider
131129 this . inlineCompletionProviderDisposable = vscode . languages . registerInlineCompletionItemProvider (
132130 "*" ,
133131 this . inlineCompletionProvider ,
134132 )
135133 this . context . subscriptions . push ( this . inlineCompletionProviderDisposable )
134+ } else if ( ! shouldBeRegistered && this . inlineCompletionProviderDisposable ) {
135+ // Deregister the provider
136+ this . inlineCompletionProviderDisposable . dispose ( )
137+ this . inlineCompletionProviderDisposable = null
136138 }
137-
138- // Update the provider's settings
139- this . inlineCompletionProvider . updateSettings ( this . settings )
140139 }
141140
142141 public async disable ( ) {
@@ -165,7 +164,7 @@ export class GhostServiceManager {
165164
166165 // VsCode Event Handlers
167166 private onDidCloseTextDocument ( document : vscode . TextDocument ) : void {
168- if ( ! this . enabled || document . uri . scheme !== "file" ) {
167+ if ( document . uri . scheme !== "file" ) {
169168 return
170169 }
171170 this . documentStore . removeDocument ( document . uri )
@@ -195,7 +194,7 @@ export class GhostServiceManager {
195194 }
196195
197196 private async onDidOpenTextDocument ( document : vscode . TextDocument ) : Promise < void > {
198- if ( ! this . enabled || document . uri . scheme !== "file" ) {
197+ if ( document . uri . scheme !== "file" ) {
199198 return
200199 }
201200 await this . documentStore . storeDocument ( {
@@ -204,7 +203,7 @@ export class GhostServiceManager {
204203 }
205204
206205 private async onDidChangeTextDocument ( event : vscode . TextDocumentChangeEvent ) : Promise < void > {
207- if ( ! this . enabled || event . document . uri . scheme !== "file" ) {
206+ if ( event . document . uri . scheme !== "file" ) {
208207 return
209208 }
210209
@@ -242,14 +241,11 @@ export class GhostServiceManager {
242241 }
243242
244243 private async onDidChangeTextEditorSelection ( event : vscode . TextEditorSelectionChangeEvent ) : Promise < void > {
245- if ( ! this . enabled ) {
246- return
247- }
248244 this . cursorAnimation . update ( )
249245 }
250246
251247 private async onDidChangeActiveTextEditor ( editor : vscode . TextEditor | undefined ) {
252- if ( ! this . enabled || ! editor ) {
248+ if ( ! editor ) {
253249 return
254250 }
255251 // Update global context when switching editors
@@ -261,9 +257,6 @@ export class GhostServiceManager {
261257 }
262258
263259 public async codeSuggestion ( ) {
264- if ( ! this . enabled ) {
265- return
266- }
267260 const editor = vscode . window . activeTextEditor
268261 if ( ! editor ) {
269262 return
@@ -284,8 +277,41 @@ export class GhostServiceManager {
284277 await this . load ( )
285278 }
286279
287- // Trigger the inline completion provider
288- await vscode . commands . executeCommand ( "editor.action.inlineSuggest.trigger" )
280+ // Call the inline completion provider directly with manual trigger context
281+ const position = editor . selection . active
282+ const context : vscode . InlineCompletionContext = {
283+ triggerKind : vscode . InlineCompletionTriggerKind . Invoke ,
284+ selectedCompletionInfo : undefined ,
285+ }
286+ const tokenSource = new vscode . CancellationTokenSource ( )
287+
288+ try {
289+ const completions = await this . inlineCompletionProvider . provideInlineCompletionItems_Internal (
290+ document ,
291+ position ,
292+ context ,
293+ tokenSource . token ,
294+ )
295+
296+ // If we got completions, directly insert the first one
297+ if ( completions && ( Array . isArray ( completions ) ? completions . length > 0 : completions . items . length > 0 ) ) {
298+ const items = Array . isArray ( completions ) ? completions : completions . items
299+ const firstCompletion = items [ 0 ]
300+
301+ if ( firstCompletion && firstCompletion . insertText ) {
302+ const insertText =
303+ typeof firstCompletion . insertText === "string"
304+ ? firstCompletion . insertText
305+ : firstCompletion . insertText . value
306+
307+ await editor . edit ( ( editBuilder ) => {
308+ editBuilder . insert ( position , insertText )
309+ } )
310+ }
311+ }
312+ } finally {
313+ tokenSource . dispose ( )
314+ }
289315 }
290316
291317 private async updateGlobalContext ( ) {
@@ -303,9 +329,6 @@ export class GhostServiceManager {
303329 }
304330
305331 private initializeStatusBar ( ) {
306- if ( ! this . enabled ) {
307- return
308- }
309332 this . statusBar = new GhostStatusBar ( {
310333 enabled : false ,
311334 model : "loading..." ,
0 commit comments