@@ -12,14 +12,13 @@ import { DisposableStore, MutableDisposable, toDisposable } from '../../../../..
12
12
import { isWindows } from '../../../../../base/common/platform.js' ;
13
13
import { localize2 } from '../../../../../nls.js' ;
14
14
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js' ;
15
- import { ContextKeyExpr , IContextKey , IContextKeyService , IReadableSet } from '../../../../../platform/contextkey/common/contextkey.js' ;
15
+ import { ContextKeyExpr , IContextKey , IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js' ;
16
16
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js' ;
17
17
import { KeybindingWeight } from '../../../../../platform/keybinding/common/keybindingsRegistry.js' ;
18
- import { GeneralShellType , TerminalLocation , TerminalSettingId } from '../../../../../platform/terminal/common/terminal.js' ;
18
+ import { GeneralShellType , TerminalLocation } from '../../../../../platform/terminal/common/terminal.js' ;
19
19
import { ITerminalContribution , ITerminalInstance , IXtermTerminal } from '../../../terminal/browser/terminal.js' ;
20
20
import { registerActiveInstanceAction } from '../../../terminal/browser/terminalActions.js' ;
21
21
import { registerTerminalContribution , type ITerminalContributionContext } from '../../../terminal/browser/terminalExtensions.js' ;
22
- import { TERMINAL_CONFIG_SECTION , type ITerminalConfiguration } from '../../../terminal/common/terminal.js' ;
23
22
import { TerminalContextKeys } from '../../../terminal/common/terminalContextKey.js' ;
24
23
import { TerminalSuggestCommandId } from '../common/terminal.suggest.js' ;
25
24
import { terminalSuggestConfigSection , TerminalSuggestSettingId , type ITerminalSuggestConfiguration } from '../common/terminalSuggestConfiguration.js' ;
@@ -42,8 +41,7 @@ class TerminalSuggestContribution extends DisposableStore implements ITerminalCo
42
41
43
42
private readonly _addon : MutableDisposable < SuggestAddon > = new MutableDisposable ( ) ;
44
43
private readonly _pwshAddon : MutableDisposable < PwshCompletionProviderAddon > = new MutableDisposable ( ) ;
45
- private _terminalSuggestWidgetContextKeys : IReadableSet < string > = new Set ( TerminalContextKeys . suggestWidgetVisible . key ) ;
46
- private _terminalSuggestWidgetVisibleContextKey : IContextKey < boolean > ;
44
+ private readonly _terminalSuggestWidgetVisibleContextKey : IContextKey < boolean > ;
47
45
48
46
get addon ( ) : SuggestAddon | undefined { return this . _addon . value ; }
49
47
get pwshAddon ( ) : PwshCompletionProviderAddon | undefined { return this . _pwshAddon . value ; }
@@ -87,23 +85,15 @@ class TerminalSuggestContribution extends DisposableStore implements ITerminalCo
87
85
if ( ! enabled ) {
88
86
return ;
89
87
}
88
+ this . _loadAddons ( xterm . raw ) ;
90
89
this . add ( Event . runAndSubscribe ( this . _ctx . instance . onDidChangeShellType , async ( ) => {
91
- this . _loadAddons ( xterm . raw ) ;
92
- } ) ) ;
93
- this . add ( this . _contextKeyService . onDidChangeContext ( e => {
94
- if ( e . affectsSome ( this . _terminalSuggestWidgetContextKeys ) ) {
95
- this . _loadAddons ( xterm . raw ) ;
96
- }
97
- } ) ) ;
98
- this . add ( this . _configurationService . onDidChangeConfiguration ( e => {
99
- if ( e . affectsConfiguration ( TerminalSettingId . SendKeybindingsToShell ) ) {
100
- this . _loadAddons ( xterm . raw ) ;
101
- }
90
+ this . _refreshAddons ( ) ;
102
91
} ) ) ;
103
92
}
104
93
105
94
private _loadPwshCompletionAddon ( xterm : RawXtermTerminal ) : void {
106
95
if ( this . _ctx . instance . shellType !== GeneralShellType . PowerShell ) {
96
+ this . _pwshAddon . clear ( ) ;
107
97
return ;
108
98
}
109
99
const pwshCompletionProviderAddon = this . _pwshAddon . value = this . _instantiationService . createInstance ( PwshCompletionProviderAddon , undefined , this . _ctx . instance . capabilities ) ;
@@ -139,42 +129,47 @@ class TerminalSuggestContribution extends DisposableStore implements ITerminalCo
139
129
}
140
130
141
131
private _loadAddons ( xterm : RawXtermTerminal ) : void {
142
- const sendingKeybindingsToShell = this . _configurationService . getValue < ITerminalConfiguration > ( TERMINAL_CONFIG_SECTION ) . sendKeybindingsToShell ;
143
- if ( sendingKeybindingsToShell || ! this . _ctx . instance . shellType ) {
144
- this . _addon . clear ( ) ;
145
- this . _pwshAddon . clear ( ) ;
132
+ // Don't re-create the addon
133
+ if ( this . _addon . value ) {
146
134
return ;
147
135
}
148
- if ( this . _terminalSuggestWidgetVisibleContextKey ) {
149
- const addon = this . _addon . value = this . _instantiationService . createInstance ( SuggestAddon , this . _ctx . instance . shellType , this . _ctx . instance . capabilities , this . _terminalSuggestWidgetVisibleContextKey ) ;
150
- xterm . loadAddon ( addon ) ;
151
- this . _loadPwshCompletionAddon ( xterm ) ;
152
- if ( this . _ctx . instance . target === TerminalLocation . Editor ) {
153
- addon . setContainerWithOverflow ( xterm . element ! ) ;
154
- } else {
155
- addon . setContainerWithOverflow ( dom . findParentWithClass ( xterm . element ! , 'panel' ) ! ) ;
156
- }
157
- addon . setScreen ( xterm . element ! . querySelector ( '.xterm-screen' ) ! ) ;
158
- this . add ( this . _ctx . instance . onDidBlur ( ( ) => addon . hideSuggestWidget ( ) ) ) ;
159
- this . add ( addon . onAcceptedCompletion ( async text => {
160
- this . _ctx . instance . focus ( ) ;
161
- this . _ctx . instance . sendText ( text , false ) ;
162
- } ) ) ;
163
- const clipboardContrib = TerminalClipboardContribution . get ( this . _ctx . instance ) ! ;
164
- this . add ( clipboardContrib . onWillPaste ( ( ) => addon . isPasting = true ) ) ;
165
- this . add ( clipboardContrib . onDidPaste ( ( ) => {
166
- // Delay this slightly as synchronizing the prompt input is debounced
167
- setTimeout ( ( ) => addon . isPasting = false , 100 ) ;
136
+
137
+ const addon = this . _addon . value = this . _instantiationService . createInstance ( SuggestAddon , this . _ctx . instance . shellType , this . _ctx . instance . capabilities , this . _terminalSuggestWidgetVisibleContextKey ) ;
138
+ xterm . loadAddon ( addon ) ;
139
+ this . _loadPwshCompletionAddon ( xterm ) ;
140
+ if ( this . _ctx . instance . target === TerminalLocation . Editor ) {
141
+ addon . setContainerWithOverflow ( xterm . element ! ) ;
142
+ } else {
143
+ addon . setContainerWithOverflow ( dom . findParentWithClass ( xterm . element ! , 'panel' ) ! ) ;
144
+ }
145
+ addon . setScreen ( xterm . element ! . querySelector ( '.xterm-screen' ) ! ) ;
146
+ this . add ( this . _ctx . instance . onDidBlur ( ( ) => addon . hideSuggestWidget ( ) ) ) ;
147
+ this . add ( addon . onAcceptedCompletion ( async text => {
148
+ this . _ctx . instance . focus ( ) ;
149
+ this . _ctx . instance . sendText ( text , false ) ;
150
+ } ) ) ;
151
+ const clipboardContrib = TerminalClipboardContribution . get ( this . _ctx . instance ) ! ;
152
+ this . add ( clipboardContrib . onWillPaste ( ( ) => addon . isPasting = true ) ) ;
153
+ this . add ( clipboardContrib . onDidPaste ( ( ) => {
154
+ // Delay this slightly as synchronizing the prompt input is debounced
155
+ setTimeout ( ( ) => addon . isPasting = false , 100 ) ;
156
+ } ) ) ;
157
+ if ( ! isWindows ) {
158
+ let barrier : AutoOpenBarrier | undefined ;
159
+ this . add ( addon . onDidReceiveCompletions ( ( ) => {
160
+ barrier ?. open ( ) ;
161
+ barrier = undefined ;
168
162
} ) ) ;
169
- if ( ! isWindows ) {
170
- let barrier : AutoOpenBarrier | undefined ;
171
- this . add ( addon . onDidReceiveCompletions ( ( ) => {
172
- barrier ?. open ( ) ;
173
- barrier = undefined ;
174
- } ) ) ;
175
- }
176
163
}
177
164
}
165
+
166
+ private _refreshAddons ( ) : void {
167
+ const addon = this . _addon . value ;
168
+ if ( ! addon ) {
169
+ return ;
170
+ }
171
+ addon . shellType = this . _ctx . instance . shellType ;
172
+ }
178
173
}
179
174
180
175
registerTerminalContribution ( TerminalSuggestContribution . ID , TerminalSuggestContribution ) ;
@@ -190,7 +185,7 @@ registerActiveInstanceAction({
190
185
primary : KeyMod . CtrlCmd | KeyCode . Space ,
191
186
mac : { primary : KeyMod . WinCtrl | KeyCode . Space } ,
192
187
weight : KeybindingWeight . WorkbenchContrib + 1 ,
193
- when : ContextKeyExpr . and ( TerminalContextKeys . focus , TerminalContextKeys . terminalShellIntegrationEnabled , ContextKeyExpr . equals ( `config.${ TerminalSuggestSettingId . Enabled } ` , true ) )
188
+ when : ContextKeyExpr . and ( TerminalContextKeys . focus , ContextKeyExpr . equals ( `config.${ TerminalSuggestSettingId . Enabled } ` , true ) )
194
189
} ,
195
190
run : ( activeInstance ) => TerminalSuggestContribution . get ( activeInstance ) ?. addon ?. requestCompletions ( true )
196
191
} ) ;
0 commit comments