/
workspaceFolders.ts
45 lines (40 loc) · 1.99 KB
/
workspaceFolders.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* --------------------------------------------------------------------------------------------
* 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 {
Event, Emitter, Disposable, ClientCapabilities, WorkspaceFolder, WorkspaceFoldersChangeEvent, DidChangeWorkspaceFoldersNotification, WorkspaceFoldersRequest
} from 'vscode-languageserver-protocol';
import { Feature, _RemoteWorkspace } from './main';
export interface WorkspaceFolders {
getWorkspaceFolders(): Promise<WorkspaceFolder[] | null>;
onDidChangeWorkspaceFolders: Event<WorkspaceFoldersChangeEvent>;
}
export const WorkspaceFoldersFeature: Feature<_RemoteWorkspace, WorkspaceFolders> = (Base) => {
return class extends Base {
private _onDidChangeWorkspaceFolders: Emitter<WorkspaceFoldersChangeEvent>;
private _unregistration: Promise<Disposable>;
public initialize(capabilities: ClientCapabilities): void {
let workspaceCapabilities = capabilities.workspace;
if (workspaceCapabilities && workspaceCapabilities.workspaceFolders) {
this._onDidChangeWorkspaceFolders = new Emitter<WorkspaceFoldersChangeEvent>();
this.connection.onNotification(DidChangeWorkspaceFoldersNotification.type, (params) => {
this._onDidChangeWorkspaceFolders.fire(params.event);
});
}
}
getWorkspaceFolders(): Promise<WorkspaceFolder[] | null> {
return this.connection.sendRequest(WorkspaceFoldersRequest.type);
}
get onDidChangeWorkspaceFolders(): Event<WorkspaceFoldersChangeEvent> {
if (!this._onDidChangeWorkspaceFolders) {
throw new Error('Client doesn\'t support sending workspace folder change events.');
}
if (!this._unregistration) {
this._unregistration = this.connection.client.register(DidChangeWorkspaceFoldersNotification.type);
}
return this._onDidChangeWorkspaceFolders.event;
}
};
};