Skip to content

Commit

Permalink
include priority in requestItem and add to request queue accordingly (#…
Browse files Browse the repository at this point in the history
…60582)

* include priority in requestItem and add to queue accordingly

* add boolean lowPriority flag to requestItem and add to queue based on that

* set lowPriority flag to optional

* send lowPriority flag from CodeLensProvider

* revert priorityFlag for provider
  • Loading branch information
ParkourKarthik authored and mjbvz committed Oct 17, 2018
1 parent 4b8f928 commit f891d5a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
19 changes: 17 additions & 2 deletions extensions/typescript-language-features/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ interface RequestItem {
readonly request: Proto.Request;
readonly expectsResponse: boolean;
readonly isAsync: boolean;
readonly lowPriority?: boolean;
}

class RequestQueue {
Expand All @@ -83,6 +84,19 @@ class RequestQueue {
}

public push(item: RequestItem): void {
// insert before existing lowPriority requestItems in the queue.
if (!item.lowPriority && this.length) {
for (let i = this.length - 1; i > -1; i--) {
if (!this.queue[i].lowPriority) {
this.queue.splice(i + 1, 0, item);
return;
}
}
//if all of the items are lowPriority insert at top
this.queue.unshift(item);
return;
}
//if none is low priority just push to end
this.queue.push(item);
}

Expand Down Expand Up @@ -381,12 +395,13 @@ export class TypeScriptServer extends Disposable {
}
}

public executeImpl(command: string, args: any, executeInfo: { isAsync: boolean, token?: vscode.CancellationToken, expectsResult: boolean }): Promise<any> {
public executeImpl(command: string, args: any, executeInfo: { isAsync: boolean, token?: vscode.CancellationToken, expectsResult: boolean, lowPriority?: boolean }): Promise<any> {
const request = this._requestQueue.createRequest(command, args);
const requestInfo: RequestItem = {
request: request,
expectsResponse: executeInfo.expectsResult,
isAsync: executeInfo.isAsync
isAsync: executeInfo.isAsync,
lowPriority: executeInfo.lowPriority
};
let result: Promise<any>;
if (executeInfo.expectsResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export interface ITypeScriptServiceClient {
execute<K extends keyof TypeScriptRequestTypes>(
command: K,
args: TypeScriptRequestTypes[K][0],
token: vscode.CancellationToken
token: vscode.CancellationToken,
lowPriority?: boolean
): Promise<ServerResponse<TypeScriptRequestTypes[K][1]>>;

executeWithoutWaitingForResponse(command: 'open', args: Proto.OpenRequestArgs): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,12 @@ export default class TypeScriptServiceClient extends Disposable implements IType
return undefined;
}

public execute(command: string, args: any, token: vscode.CancellationToken): Promise<any> {
public execute(command: string, args: any, token: vscode.CancellationToken, lowPriority?: boolean): Promise<any> {
return this.executeImpl(command, args, {
isAsync: false,
token,
expectsResult: true
expectsResult: true,
lowPriority
});
}

Expand All @@ -584,7 +585,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
});
}

private executeImpl(command: string, args: any, executeInfo: { isAsync: boolean, token?: vscode.CancellationToken, expectsResult: boolean }): Promise<any> {
private executeImpl(command: string, args: any, executeInfo: { isAsync: boolean, token?: vscode.CancellationToken, expectsResult: boolean, lowPriority?: boolean }): Promise<any> {
const server = this.service();
if (!server) {
return Promise.reject(new Error('Could not load TS Server'));
Expand Down

0 comments on commit f891d5a

Please sign in to comment.