Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcd0259a

Browse files
authored
Merge pull requestmicrosoft#222305 from microsoft/tyriar/222302
Cache global pwsh completions across terminals and reloads
2 parents53b4f07 +41d73f9 commitcd0259a

File tree

4 files changed

+65
-14
lines changed

4 files changed

+65
-14
lines changed

‎src/vs/workbench/contrib/terminal/browser/media/shellIntegration.ps1

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,16 @@ function Set-MappedKeyHandlers {
186186
Send-Completions
187187
}
188188

189-
# TODO: When does this invalidate? Installing a new module could add new commands. We could expose a command to update? Track `(Get-Module).Count`?
190-
# Get commands, convert to string array to reduce the payload size and send as JSON
191-
$commands= [System.Management.Automation.CompletionCompleters]::CompleteCommand('')
192-
$mappedCommands=Compress-Completions($commands)
193-
$result="$([char]0x1b)]633;CompletionsPwshCommands;commands;"
194-
$result+=$mappedCommands|ConvertTo-Json-Compress
195-
$result+="`a"
196-
Write-Host-NoNewLine$result
189+
# VS Code send global completions request
190+
Set-PSReadLineKeyHandler-Chord'F12,f'-ScriptBlock {
191+
# Get commands, convert to string array to reduce the payload size and send as JSON
192+
$commands= [System.Management.Automation.CompletionCompleters]::CompleteCommand('')
193+
$mappedCommands=Compress-Completions($commands)
194+
$result="$([char]0x1b)]633;CompletionsPwshCommands;commands;"
195+
$result+=$mappedCommands|ConvertTo-Json-Compress
196+
$result+="`a"
197+
Write-Host-NoNewLine$result
198+
}
197199
}
198200
}
199201

‎src/vs/workbench/contrib/terminalContrib/suggest/browser/terminal.suggest.contribution.ts

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
1313
import{ContextKeyExpr,IContextKey,IContextKeyService,IReadableSet}from'vs/platform/contextkey/common/contextkey';
1414
import{IInstantiationService}from'vs/platform/instantiation/common/instantiation';
1515
import{KeybindingWeight}from'vs/platform/keybinding/common/keybindingsRegistry';
16+
import{IStorageService,StorageScope,StorageTarget}from'vs/platform/storage/common/storage';
1617
import{TerminalSettingId}from'vs/platform/terminal/common/terminal';
1718
import{ShellIntegrationOscPs}from'vs/platform/terminal/common/xterm/shellIntegrationAddon';
1819
import{ITerminalContribution,ITerminalInstance,IXtermTerminal}from'vs/workbench/contrib/terminal/browser/terminal';
@@ -23,9 +24,13 @@ import { ITerminalProcessManager, TERMINAL_CONFIG_SECTION, type ITerminalConfigu
2324
import{TerminalContextKeys}from'vs/workbench/contrib/terminal/common/terminalContextKey';
2425
import{parseCompletionsFromShell,SuggestAddon,VSCodeSuggestOscPt,typeCompressedPwshCompletion,typePwshCompletion}from'vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon';
2526
import{TerminalSuggestCommandId}from'vs/workbench/contrib/terminalContrib/suggest/common/terminal.suggest';
26-
import{terminalSuggestConfigSection,typeITerminalSuggestConfiguration}from'vs/workbench/contrib/terminalContrib/suggest/common/terminalSuggestConfiguration';
27+
import{terminalSuggestConfigSection,TerminalSuggestSettingId,typeITerminalSuggestConfiguration}from'vs/workbench/contrib/terminalContrib/suggest/common/terminalSuggestConfiguration';
2728
import{SimpleCompletionItem}from'vs/workbench/services/suggest/browser/simpleCompletionItem';
2829

30+
constenumConstants{
31+
CachedPwshCommandsStorageKey='terminal.suggest.pwshCommands'
32+
}
33+
2934
// #region Terminal Contributions
3035

3136
classTerminalSuggestContributionextendsDisposableStoreimplementsITerminalContribution{
@@ -42,17 +47,37 @@ class TerminalSuggestContribution extends DisposableStore implements ITerminalCo
4247

4348
getaddon():SuggestAddon|undefined{returnthis._addon.value;}
4449

50+
privatestaticreadonly_cachedPwshCommands:Set<SimpleCompletionItem>=newSet();
51+
4552
constructor(
4653
privatereadonly_instance:ITerminalInstance,
4754
processManager:ITerminalProcessManager,
4855
widgetManager:TerminalWidgetManager,
4956
@IContextKeyServiceprivatereadonly_contextKeyService:IContextKeyService,
5057
@IConfigurationServiceprivatereadonly_configurationService:IConfigurationService,
51-
@IInstantiationServiceprivatereadonly_instantiationService:IInstantiationService
58+
@IInstantiationServiceprivatereadonly_instantiationService:IInstantiationService,
59+
@IStorageServiceprivatereadonly_storageService:IStorageService,
5260
){
5361
super();
5462
this.add(toDisposable(()=>this._addon?.dispose()));
5563
this._terminalSuggestWidgetVisibleContextKey=TerminalContextKeys.suggestWidgetVisible.bindTo(this._contextKeyService);
64+
65+
// Attempt to load cached pwsh commands if not already loaded
66+
if(TerminalSuggestContribution._cachedPwshCommands.size===0){
67+
constconfig=this._storageService.get(Constants.CachedPwshCommandsStorageKey,StorageScope.APPLICATION,undefined);
68+
if(config!==undefined){
69+
constcompletions=JSON.parse(config);
70+
for(constcofcompletions){
71+
TerminalSuggestContribution._cachedPwshCommands.add(c);
72+
}
73+
}
74+
}
75+
76+
this.add(this._configurationService.onDidChangeConfiguration(e=>{
77+
if(e.affectsConfiguration(TerminalSuggestSettingId.Enabled)){
78+
this.clearSuggestCache();
79+
}
80+
}));
5681
}
5782

5883
xtermReady(xterm:IXtermTerminal&{raw:RawXtermTerminal}):void{
@@ -83,22 +108,27 @@ class TerminalSuggestContribution extends DisposableStore implements ITerminalCo
83108
returnfalse;
84109
}
85110

86-
// TODO: These aren't persisted across reloads
87-
private_cachedPwshCommands:Set<SimpleCompletionItem>=newSet();
88111
privateasync_handleCompletionsPwshCommandsSequence(terminal:RawXtermTerminal,data:string,command:string,args:string[]):Promise<boolean>{
89112
consttype=args[0];
90113
constrawCompletions:PwshCompletion|PwshCompletion[]|CompressedPwshCompletion[]|CompressedPwshCompletion=JSON.parse(data.slice(command.length+type.length+2/*semi-colons*/));
91114
constcompletions=parseCompletionsFromShell(rawCompletions);
92115

93-
constset=this._cachedPwshCommands;
116+
constset=TerminalSuggestContribution._cachedPwshCommands;
94117
set.clear();
95118
for(constcofcompletions){
96119
set.add(c);
97120
}
98121

122+
this._storageService.store(Constants.CachedPwshCommandsStorageKey,JSON.stringify(Array.from(set.values())),StorageScope.APPLICATION,StorageTarget.MACHINE);
123+
99124
returntrue;
100125
}
101126

127+
clearSuggestCache():void{
128+
TerminalSuggestContribution._cachedPwshCommands.clear();
129+
this._storageService.remove(Constants.CachedPwshCommandsStorageKey,StorageScope.APPLICATION);
130+
}
131+
102132
xtermOpen(xterm:IXtermTerminal&{raw:RawXtermTerminal}):void{
103133
constconfig=this._configurationService.getValue<ITerminalSuggestConfiguration>(terminalSuggestConfigSection);
104134
constenabled=config.enabled;
@@ -127,7 +157,7 @@ class TerminalSuggestContribution extends DisposableStore implements ITerminalCo
127157
return;
128158
}
129159
if(this._terminalSuggestWidgetVisibleContextKey){
130-
this._addon.value=this._instantiationService.createInstance(SuggestAddon,this._cachedPwshCommands,this._instance.capabilities,this._terminalSuggestWidgetVisibleContextKey);
160+
this._addon.value=this._instantiationService.createInstance(SuggestAddon,TerminalSuggestContribution._cachedPwshCommands,this._instance.capabilities,this._terminalSuggestWidgetVisibleContextKey);
131161
xterm.loadAddon(this._addon.value);
132162
this._addon.value.setPanel(dom.findParentWithClass(xterm.element!,'panel')!);
133163
this._addon.value.setScreen(xterm.element!.querySelector('.xterm-screen')!);
@@ -238,4 +268,11 @@ registerActiveInstanceAction({
238268
run:(activeInstance)=>TerminalSuggestContribution.get(activeInstance)?.addon?.hideSuggestWidget()
239269
});
240270

271+
registerActiveInstanceAction({
272+
id:TerminalSuggestCommandId.ClearSuggestCache,
273+
title:localize2('workbench.action.terminal.clearSuggestCache','Clear Suggest Cache'),
274+
f1:true,
275+
run:(activeInstance)=>TerminalSuggestContribution.get(activeInstance)?.clearSuggestCache()
276+
});
277+
241278
// #endregion

‎src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
122122
private_lastUserData?:string;
123123

124124
staticrequestCompletionsSequence='\x1b[24~e';// F12,e
125+
staticrequestGlobalCompletionsSequence='\x1b[24~f';// F12,f
125126

126127
privatereadonly_onBell=this._register(newEmitter<void>());
127128
readonlyonBell=this._onBell.event;
@@ -178,13 +179,22 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
178179
}
179180

180181
private_requestCompletions():void{
182+
// Request global completions if there are none cached
183+
if(this._cachedPwshCommands.size===0){
184+
this._requestGlobalCompletions();
185+
}
186+
181187
// Ensure that a key has been pressed since the last accepted completion in order to prevent
182188
// completions being requested again right after accepting a completion
183189
if(this._lastUserDataTimestamp>this._lastAcceptedCompletionTimestamp){
184190
this._onAcceptedCompletion.fire(SuggestAddon.requestCompletionsSequence);
185191
}
186192
}
187193

194+
private_requestGlobalCompletions():void{
195+
this._onAcceptedCompletion.fire(SuggestAddon.requestGlobalCompletionsSequence);
196+
}
197+
188198
private_sync(promptInputState:IPromptInputModelState):void{
189199
constconfig=this._configurationService.getValue<ITerminalSuggestConfiguration>(terminalSuggestConfigSection);
190200

‎src/vs/workbench/contrib/terminalContrib/suggest/common/terminal.suggest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const enum TerminalSuggestCommandId {
1111
AcceptSelectedSuggestion='workbench.action.terminal.acceptSelectedSuggestion',
1212
AcceptSelectedSuggestionEnter='workbench.action.terminal.acceptSelectedSuggestionEnter',
1313
HideSuggestWidget='workbench.action.terminal.hideSuggestWidget',
14+
ClearSuggestCache='workbench.action.terminal.clearSuggestCache',
1415
}
1516

1617
exportconstdefaultTerminalSuggestCommandsToSkipShell=[
@@ -21,4 +22,5 @@ export const defaultTerminalSuggestCommandsToSkipShell = [
2122
TerminalSuggestCommandId.AcceptSelectedSuggestion,
2223
TerminalSuggestCommandId.AcceptSelectedSuggestionEnter,
2324
TerminalSuggestCommandId.HideSuggestWidget,
25+
TerminalSuggestCommandId.ClearSuggestCache,
2426
];

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp