vscode-texinfo/src/options.ts

81 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-10-03 18:04:18 +00:00
/**
* options.ts
*
* @author CismonX <admin@cismon.net>
* @license MIT
*/
import * as vscode from 'vscode';
/**
2020-10-05 22:31:40 +00:00
* Fetch extension option values.
2020-10-03 18:04:18 +00:00
*
* See `contributes.configuration` of package.json for details.
*/
2020-10-24 21:45:32 +00:00
export default class Options implements vscode.Disposable {
2020-10-03 18:04:18 +00:00
2020-10-15 20:16:13 +00:00
private static singleton?: Options;
2020-10-24 21:45:32 +00:00
static get instance() {
2020-10-20 20:07:44 +00:00
return Options.singleton ??= new Options('texinfo');
2020-10-03 18:04:18 +00:00
}
static get makeinfo() {
return Options.instance.getString('makeinfo');
}
static get noHeaders() {
return Options.instance.getBoolean('preview.noHeaders');
}
static get maxSize() {
2020-10-24 21:45:32 +00:00
return Options.instance.getNumber('preview.maxSize') * 1024 * 1024;
2020-10-03 18:04:18 +00:00
}
static get errorLimit() {
return Options.instance.getNumber('preview.errorLimit');
}
static get force() {
return Options.instance.getBoolean('preview.force');
}
2020-10-17 13:41:03 +00:00
static get noValidation() {
return Options.instance.getBoolean('preview.noValidation');
2020-10-03 18:04:18 +00:00
}
2020-10-17 13:41:03 +00:00
static get noWarnings() {
return Options.instance.getBoolean('preview.noWarnings');
2020-10-03 18:04:18 +00:00
}
static get displayImage() {
return Options.instance.getBoolean('preview.displayImage');
}
2020-10-24 21:45:32 +00:00
static clear() {
Options.singleton = undefined;
}
2020-10-03 18:04:18 +00:00
private readonly configuration: vscode.WorkspaceConfiguration;
private constructor(section: string) {
this.configuration = vscode.workspace.getConfiguration(section);
}
2020-10-22 22:40:41 +00:00
private getString(section: string) {
return this.configuration.get(section, '');
2020-10-03 18:04:18 +00:00
}
2020-10-22 22:40:41 +00:00
private getBoolean(section: string) {
return this.configuration.get(section, false);
2020-10-03 18:04:18 +00:00
}
2020-10-22 22:40:41 +00:00
private getNumber(section: string) {
return this.configuration.get(section, 0);
2020-10-03 18:04:18 +00:00
}
2020-10-24 21:45:32 +00:00
dispose() {
Options.singleton = undefined;
}
2020-10-03 18:04:18 +00:00
}