aboutsummaryrefslogtreecommitdiff
path: root/editors/vscode/src/config.ts
blob: 1950b2ca7699f3b676593aa183e03915d0a8a66d (plain)
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
54
import * as vscode from 'vscode';
import { log } from "./util";

export class Config {

	readonly extensionId = "danielgavin.ols";
	readonly rootSection = "ols";

	readonly globalStorageUri: vscode.Uri;

	readonly package: {
		version: string;
		releaseTag: string | null;
		enableProposedApi: boolean | undefined;
	} = vscode.extensions.getExtension(this.extensionId)!.packageJSON;

	constructor(ctx: vscode.ExtensionContext) {
		this.globalStorageUri = ctx.globalStorageUri;
	}

	private get cfg(): vscode.WorkspaceConfiguration {
		return vscode.workspace.getConfiguration(this.rootSection);
	}

	get serverPath() {
		return this.get<null | string>("server.path") ?? this.get<null | string>("serverPath");
	}

	get httpProxy() {
		const httpProxy = vscode
			.workspace
			.getConfiguration('http')
			.get<null | string>("proxy")!;

		return httpProxy || process.env["https_proxy"] || process.env["HTTPS_PROXY"];
	}

	private get<T>(path: string): T {
		return this.cfg.get<T>(path)!;
	}

	get askBeforeDownload() { return this.get<boolean>("updates.askBeforeDownload"); }

	get debugEngine() { return this.get<string>("debug.engine"); }

    get askCreateOLS() {  return this.get<boolean>("prompt.AskCreateOLS"); }

	public updateAskCreateOLS(ask: boolean) {
		this.cfg.update("prompt.AskCreateOLS", ask, vscode.ConfigurationTarget.Global);
	}

	collections: any[] = [];
	odinCommand: string = null;
}