forked from karrtikr/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmockWorkspaceConfig.ts
More file actions
53 lines (43 loc) · 1.55 KB
/
mockWorkspaceConfig.ts
File metadata and controls
53 lines (43 loc) · 1.55 KB
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
46
47
48
49
50
51
52
53
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { ConfigurationTarget, WorkspaceConfiguration } from 'vscode';
type SectionType<T> = {
key: string;
defaultValue?: T | undefined;
globalValue?: T | undefined;
globalLanguageValue?: T | undefined;
workspaceValue?: T | undefined;
workspaceLanguageValue?: T | undefined;
workspaceFolderValue?: T | undefined;
workspaceFolderLanguageValue?: T | undefined;
};
export class MockWorkspaceConfiguration implements WorkspaceConfiguration {
private values = new Map<string, unknown>();
constructor(defaultSettings?: { [key: string]: unknown }) {
if (defaultSettings) {
const keys = [...Object.keys(defaultSettings)];
keys.forEach((k) => this.values.set(k, defaultSettings[k]));
}
}
public get<T>(key: string, defaultValue?: T): T | undefined {
if (this.values.has(key)) {
return this.values.get(key) as T;
}
return arguments.length > 1 ? defaultValue : undefined;
}
public has(section: string): boolean {
return this.values.has(section);
}
public inspect<T>(section: string): SectionType<T> | undefined {
return this.values.get(section) as SectionType<T>;
}
public update(
section: string,
value: unknown,
_configurationTarget?: boolean | ConfigurationTarget | undefined,
): Promise<void> {
this.values.set(section, value);
return Promise.resolve();
}
}