-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #261 from Xanewok/window-progress
Add proposed window/progress extension
- Loading branch information
Showing
6 changed files
with
237 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
'use strict'; | ||
|
||
import { window, Progress, ProgressLocation } from 'vscode'; | ||
|
||
import { BaseLanguageClient, StaticFeature } from './client'; | ||
import { ClientCapabilities, Proposed } from 'vscode-languageserver-protocol'; | ||
|
||
export class WindowProgressFeature implements StaticFeature { | ||
private _progresses: Map<string, WindowProgress> = new Map<string, WindowProgress>(); | ||
|
||
constructor(private _client: BaseLanguageClient) {} | ||
|
||
public fillClientCapabilities(capabilities: ClientCapabilities): void { | ||
let windowProgressCapabilities = capabilities as Proposed.WindowProgressClientCapabilities; | ||
|
||
windowProgressCapabilities.window = windowProgressCapabilities.window || {}; | ||
windowProgressCapabilities.window.progress = true; | ||
} | ||
|
||
public initialize(): void { | ||
let client = this._client; | ||
let progresses = this._progresses; | ||
|
||
let handler = function (params: Proposed.ProgressParams) { | ||
let progress = progresses.get(params.id); | ||
if (progress !== undefined) { | ||
progress.updateProgress(params); | ||
} else { | ||
window.withProgress({ location: ProgressLocation.Window }, p => { | ||
progress = new WindowProgress(p); | ||
progresses.set(params.id, progress); | ||
|
||
progress.updateProgress(params); | ||
return progress.promise; | ||
}); | ||
} | ||
// In both cases progress shouldn't be undefined, but make the compiler happy. | ||
if (params.done && progress !== undefined) { | ||
progress.finish(); | ||
progresses.delete(params.id); | ||
} | ||
}; | ||
|
||
client.onNotification(Proposed.WindowProgressNotification.type, handler); | ||
} | ||
} | ||
|
||
class WindowProgress { | ||
public promise: Promise<{}>; | ||
private resolve: (value?: {} | PromiseLike<{}> | undefined) => void; | ||
private reject: (reason?: any) => void; | ||
|
||
private progress: Progress<{ message?: string; }>; | ||
|
||
private title: string; | ||
private message: string | undefined; | ||
|
||
constructor(progress: Progress<{ message?: string; }>) { | ||
this.progress = progress; | ||
|
||
this.promise = new Promise((resolve, reject) => { | ||
this.resolve = resolve; | ||
this.reject = reject; | ||
}); | ||
} | ||
|
||
public updateProgress(params: Proposed.ProgressParams) { | ||
this.title = params.title; | ||
this.message = params.message || this.message; | ||
|
||
const details = this.message ? ` (${this.message})` : ''; | ||
this.progress.report({message: `${this.title}${details}`}); | ||
} | ||
|
||
public finish() { | ||
this.resolve(); | ||
} | ||
|
||
public cancel() { | ||
this.reject(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#### Reporting server task progress | ||
|
||
Many tools are capable of performing some background task processing or data streaming. From a UX point of view, it's good to report both the fact that the tool is performing some background work, but also report the progress being made for it. To realize that and to provide a simple proposal based on which the feature can be later improved, the following additions are proposed: | ||
|
||
_Client Capabilities_: | ||
|
||
The client sets the following capability if it is supporting notifying task progress. | ||
|
||
```ts | ||
/** | ||
* Experimental client capabilities. | ||
*/ | ||
experimental: { | ||
/** | ||
* The client has support for reporting progress. | ||
*/ | ||
progress?: boolean; | ||
} | ||
``` | ||
|
||
##### Window Progress Notification | ||
_Notification_: | ||
|
||
The `window/progress` notification is sent from the server to the client to ask the client to indicate progress. | ||
|
||
* method: 'window/progress' | ||
* params: `ProgressParams` defined as follows: | ||
```ts | ||
export interface ProgressParams { | ||
/** | ||
* A unique identifier to associate multiple progress notifications with | ||
* the same progress. | ||
*/ | ||
id: string; | ||
|
||
/** | ||
* Mandatory title of the progress operation. Used to briefly inform about | ||
* the kind of operation being performed. | ||
* Examples: "Indexing" or "Linking dependencies". | ||
*/ | ||
title: string; | ||
|
||
/** | ||
* Optional, more detailed associated progress message. Contains | ||
* complementary information to the `title`. | ||
* Examples: "3/25 files", "project/src/module2", "node_modules/some_dep". | ||
* If unset, the previous progress message (if any) is still valid. | ||
*/ | ||
message?: string; | ||
|
||
/** | ||
* Optional progress percentage to display (value 100 is considered 100%). | ||
* If unset, the previous progress percentage (if any) is still valid. | ||
*/ | ||
percentage?: number; | ||
|
||
/** | ||
* Set to true on the final progress update. | ||
* No more progress notifications with the same ID should be sent. | ||
*/ | ||
done?: boolean; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
'use strict'; | ||
|
||
import { NotificationType, NotificationHandler } from 'vscode-jsonrpc'; | ||
|
||
export interface WindowProgressClientCapabilities { | ||
/** | ||
* Window specific client capabilities. | ||
*/ | ||
window?: { | ||
/** | ||
* Whether client supports handling progress notifications. | ||
*/ | ||
progress?: boolean; | ||
} | ||
} | ||
|
||
export interface ProgressParams { | ||
/** | ||
* A unique identifier to associate multiple progress notifications with the same progress. | ||
*/ | ||
id: string; | ||
|
||
/** | ||
* Mandatory title of the progress operation. Used to briefly inform about | ||
* the kind of operation being performed. | ||
* Examples: "Indexing" or "Linking dependencies". | ||
*/ | ||
title: string; | ||
|
||
/** | ||
* Optional, more detailed associated progress message. Contains | ||
* complementary information to the `title`. | ||
* Examples: "3/25 files", "project/src/module2", "node_modules/some_dep". | ||
* If unset, the previous progress message (if any) is still valid. | ||
*/ | ||
message?: string; | ||
|
||
/** | ||
* Optional progress percentage to display (value 100 is considered 100%). | ||
* If unset, the previous progress percentage (if any) is still valid. | ||
*/ | ||
percentage?: number; | ||
|
||
/** | ||
* Set to true on the final progress update. | ||
* No more progress notifications with the same ID should be sent. | ||
*/ | ||
done?: boolean; | ||
} | ||
|
||
/** | ||
* The `window/progress` notification is sent from the server to the client | ||
* to inform the client about ongoing progress. | ||
*/ | ||
export namespace WindowProgressNotification { | ||
export const type = new NotificationType<ProgressParams, void>('window/progress'); | ||
export type HandlerSignature = NotificationHandler<ProgressParams>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters