/
config.ts
34 lines (28 loc) · 901 Bytes
/
config.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
import path from 'path'
import { workspace } from 'vscode'
import { EXT_NAMESPACE } from './meta'
import { getCTX } from './ctx'
export type SupportTargetLanguage = 'py' | 'js'
export class Config {
static get executablePath () {
return this.getConfig<string>('executablePath') || path.join(getCTX().extensionPath, 'vendor', 'wenyan.js')
}
static get targetLanguage (): SupportTargetLanguage {
if (this.getConfig<string>('targetLanguage') === 'python')
return 'py'
else
return 'js'
}
private static getConfig<T = any> (key: string): T | undefined {
const config = workspace
.getConfiguration(EXT_NAMESPACE)
.get<T>(key)
return config
}
// @ts-ignore
private static async setConfig (key: string, value: any, isGlobal = false) {
return await workspace
.getConfiguration(EXT_NAMESPACE)
.update(key, value, isGlobal)
}
}