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

Commita9a09dc

Browse files
authored
Only serialize tasks that require it (microsoft#2553)
* Remove serialization in the queuing except for cases that actually need it
1 parente0e7944 commita9a09dc

File tree

1 file changed

+63
-30
lines changed

1 file changed

+63
-30
lines changed

‎Extension/src/LanguageServer/client.ts‎

Lines changed: 63 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,34 @@ const InactiveRegionNotification: NotificationType<InactiveRegionParams, void>
145145
constCompileCommandsPathsNotification:NotificationType<CompileCommandsPaths,void>=newNotificationType<CompileCommandsPaths,void>('cpptools/compileCommandsPaths');
146146
constUpdateClangFormatPathNotification:NotificationType<string,void>=newNotificationType<string,void>('cpptools/updateClangFormatPath');
147147

148+
classBlockingTask<T>{
149+
privatedependency:BlockingTask<any>;
150+
privatedone:boolean=false;
151+
privatepromise:Promise<T>;
152+
153+
constructor(task:()=>T,dependency?:BlockingTask<any>){
154+
this.promise=newPromise<T>(async(resolve,reject)=>{
155+
try{
156+
letresult:T=awaittask();
157+
resolve(result);
158+
this.done=true;
159+
}catch(err){
160+
reject(err);
161+
this.done=true;
162+
}
163+
});
164+
this.dependency=dependency;
165+
}
166+
167+
publicgetDone():boolean{
168+
returnthis.done&&(!this.dependency||this.dependency.Done);
169+
}
170+
171+
publicthen(onSucceeded:(value:T)=>any,onRejected:(err)=>any):Promise<any>{
172+
returnthis.promise.then(onSucceeded,onRejected);
173+
}
174+
}
175+
148176
letfailureMessageShown:boolean=false;
149177

150178
interfaceClientModel{
@@ -174,7 +202,6 @@ export interface Client {
174202
getCurrentConfigName():Thenable<string>;
175203
takeOwnership(document:vscode.TextDocument):void;
176204
queueTask<T>(task:()=>Thenable<T>):Thenable<T>;
177-
queueTaskWithTimeout(thenable:()=>Thenable<any>,ms:number,tokenSource?:CancellationTokenSource):Thenable<any>;
178205
requestWhenReady(request:()=>Thenable<any>):Thenable<any>;
179206
notifyWhenReady(notify:()=>void):void;
180207
requestGoToDeclaration():Thenable<void>;
@@ -183,8 +210,6 @@ export interface Client {
183210
activeDocumentChanged(document:vscode.TextDocument):void;
184211
activate():void;
185212
selectionChanged(selection:Range):void;
186-
sendCustomConfigurations(configs:any):void;
187-
sendCustomBrowseConfiguration(config:any):Thenable<void>;
188213
resetDatabase():void;
189214
deactivate():void;
190215
pauseParsing():void;
@@ -267,8 +292,7 @@ class DefaultClient implements Client {
267292
*@see notifyWhenReady(notify)
268293
*/
269294

270-
privatependingTask:Thenable<any>;
271-
privatependingRequests:number=0;
295+
privatependingTask:BlockingTask<void>;
272296

273297
constructor(allClients:ClientCollection,workspaceFolder?:vscode.WorkspaceFolder){
274298
try{
@@ -281,7 +305,7 @@ class DefaultClient implements Client {
281305
ui.bind(this);
282306

283307
// requests/notifications are deferred until this.languageClient is set.
284-
this.queueTask(()=>languageClient.onReady().then(
308+
this.queueBlockingTask(()=>languageClient.onReady().then(
285309
()=>{
286310
this.configuration=newconfigs.CppProperties(this.RootUri);
287311
this.configuration.ConfigurationsChanged((e)=>this.onConfigurationsChanged(e));
@@ -522,10 +546,10 @@ class DefaultClient implements Client {
522546

523547
publicupdateCustomBrowseConfiguration(requestingProvider?:CustomConfigurationProvider1):Thenable<void>{
524548
returnthis.notifyWhenReady(()=>{
525-
console.log("updateCustomBrowseConfiguration");
526549
if(!this.configurationProvider){
527550
return;
528551
}
552+
console.log("updateCustomBrowseConfiguration");
529553
letcurrentProvider:CustomConfigurationProvider1=getCustomConfigProviders().get(this.configurationProvider);
530554
if(!currentProvider||(requestingProvider&&requestingProvider.extensionId!==currentProvider.extensionId)){
531555
return;
@@ -553,10 +577,10 @@ class DefaultClient implements Client {
553577
publicasyncprovideCustomConfiguration(document:vscode.TextDocument):Promise<void>{
554578
lettokenSource:CancellationTokenSource=newCancellationTokenSource();
555579
letproviders:CustomConfigurationProviderCollection=getCustomConfigProviders();
556-
console.log("provideCustomConfiguration");
557580
if(providers.size===0){
558581
returnPromise.resolve();
559582
}
583+
console.log("provideCustomConfiguration");
560584
letproviderId:string|undefined=awaitthis.getCustomConfigurationProviderId();
561585
if(!providerId){
562586
returnPromise.resolve();
@@ -588,7 +612,7 @@ class DefaultClient implements Client {
588612
returnthis.queueTaskWithTimeout(provideConfigurationAsync,configProviderTimeout,tokenSource).then(
589613
(configs:SourceFileConfigurationItem[])=>{
590614
if(configs&&configs.length>0){
591-
this.sendCustomConfigurations(configs);
615+
this.sendCustomConfigurations(configs,true);
592616
}
593617
},
594618
(err)=>{
@@ -657,32 +681,39 @@ class DefaultClient implements Client {
657681
if(this.isSupported){
658682
letnextTask:()=>Thenable<any>=async()=>{
659683
try{
660-
letresult:any=awaittask();
661-
this.pendingRequests--;
662-
returnresult;
684+
returnawaittask();
663685
}catch(err){
664686
console.error(err);
665-
this.pendingRequests--;
666687
throwerr;
667688
}
668689
};
669690

670-
console.assert(this.pendingRequests>=0);
671-
if(this.pendingRequests===0){
672-
this.pendingRequests++;
673-
this.pendingTask=nextTask();
674-
returnthis.pendingTask;
675-
}else{
691+
if(this.pendingTask&&!this.pendingTask.Done){
676692
// We don't want the queue to stall because of a rejected promise.
677-
this.pendingRequests++;
678693
returnthis.pendingTask.then(nextTask,nextTask);
694+
}else{
695+
this.pendingTask=undefined;
696+
returnnextTask();
679697
}
680698
}else{
681699
returnPromise.reject("Unsupported client");
682700
}
683701
}
684702

685-
publicqueueTaskWithTimeout(task:()=>Thenable<any>,ms:number,cancelToken?:CancellationTokenSource):Thenable<any>{
703+
/**
704+
* Queue a task that blocks all future tasks until it completes. This is currently only intended to be used
705+
* during language client startup and for custom configuration providers.
706+
*@param task The task that blocks all future tasks
707+
*/
708+
privatequeueBlockingTask(task:()=>Thenable<void>):Thenable<void>{
709+
if(this.isSupported){
710+
this.pendingTask=newBlockingTask<void>(task,this.pendingTask);
711+
}else{
712+
returnPromise.reject("Unsupported client");
713+
}
714+
}
715+
716+
privatequeueTaskWithTimeout(task:()=>Thenable<any>,ms:number,cancelToken?:CancellationTokenSource):Thenable<any>{
686717
lettimer:NodeJS.Timer;
687718
// Create a promise that rejects in <ms> milliseconds
688719
lettimeout:()=>Promise<any>=()=>newPromise((resolve,reject)=>{
@@ -713,11 +744,16 @@ class DefaultClient implements Client {
713744
returnthis.queueTask(request);
714745
}
715746

716-
publicnotifyWhenReady(notify:()=>void):Thenable<void>{
717-
returnthis.queueTask(()=>newPromise(resolve=>{
747+
publicnotifyWhenReady(notify:()=>void,blockingTask?:boolean):Thenable<void>{
748+
lettask:()=>Thenable<void>=()=>newPromise(resolve=>{
718749
notify();
719750
resolve();
720-
}));
751+
});
752+
if(blockingTask){
753+
returnthis.queueBlockingTask(task);
754+
}else{
755+
returnthis.queueTask(task);
756+
}
721757
}
722758

723759
/**
@@ -1117,7 +1153,7 @@ class DefaultClient implements Client {
11171153
util.isOptionalArrayOfString(input.configuration.forcedInclude));
11181154
}
11191155

1120-
publicsendCustomConfigurations(configs:any):void{
1156+
privatesendCustomConfigurations(configs:any,blockingTask?:boolean):void{
11211157
// configs is marked as 'any' because it is untrusted data coming from a 3rd-party. We need to sanitize it before sending it to the language server.
11221158
if(!configs||!(configsinstanceofArray)){
11231159
console.warn("discarding invalid SourceFileConfigurationItems[]: "+configs);
@@ -1155,10 +1191,10 @@ class DefaultClient implements Client {
11551191
letparams:CustomConfigurationParams={
11561192
configurationItems:sanitized
11571193
};
1158-
this.notifyWhenReady(()=>this.languageClient.sendNotification(CustomConfigurationNotification,params));
1194+
this.notifyWhenReady(()=>this.languageClient.sendNotification(CustomConfigurationNotification,params),blockingTask);
11591195
}
11601196

1161-
publicsendCustomBrowseConfiguration(config:any):Thenable<void>{
1197+
privatesendCustomBrowseConfiguration(config:any):Thenable<void>{
11621198
// config is marked as 'any' because it is untrusted data coming from a 3rd-party. We need to sanitize it before sending it to the language server.
11631199
if(!config||configinstanceofArray){
11641200
console.warn("discarding invalid WorkspaceBrowseConfiguration: "+config);
@@ -1307,11 +1343,8 @@ class NullClient implements Client {
13071343
getCurrentConfigName():Thenable<string>{returnPromise.resolve("");}
13081344
takeOwnership(document:vscode.TextDocument):void{}
13091345
queueTask<T>(task:()=>Thenable<T>):Thenable<T>{returntask();}
1310-
queueTaskWithTimeout(task:()=>Thenable<any>,ms:number,tokenSource?:CancellationTokenSource):Thenable<any>{returntask();}
13111346
requestWhenReady(request:()=>Thenable<any>):Thenable<any>{return;}
13121347
notifyWhenReady(notify:()=>void):void{}
1313-
sendCustomConfigurations(configs:any):void{}
1314-
sendCustomBrowseConfiguration(config:any):Thenable<void>{returnPromise.resolve();}
13151348
requestGoToDeclaration():Thenable<void>{returnPromise.resolve();}
13161349
requestSwitchHeaderSource(rootPath:string,fileName:string):Thenable<string>{returnPromise.resolve("");}
13171350
requestNavigationList(document:vscode.TextDocument):Thenable<string>{returnPromise.resolve("");}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp