Support definition of Texinfo variables in config.

This commit is contained in:
CismonX 2021-04-22 17:07:55 +08:00
parent d5b84cdd7b
commit 7c4c04600f
Signed by: cismonx
GPG Key ID: 3094873E29A482FB
4 changed files with 47 additions and 27 deletions

View File

@ -145,16 +145,6 @@
"configuration": {
"title": "Texinfo",
"properties": {
"texinfo.makeinfo": {
"type": "string",
"default": "makeinfo",
"description": "Path to the `makeinfo` (or `texi2any`) command."
},
"texinfo.enableCodeLens": {
"type": "boolean",
"default": true,
"description": "Enable code lens on node identifiers which jumps to the corresponding nodes in preview."
},
"texinfo.completion.enableSnippets": {
"type": "boolean",
"default": true,
@ -165,10 +155,26 @@
"default": true,
"description": "When snippet is enabled, hide the snippets' corresponding commands from completion items."
},
"texinfo.preview.noHeaders": {
"texinfo.preview.customCSS": {
"type": "string",
"default": "",
"description": "URI of custom CSS for preview."
},
"texinfo.enableCodeLens": {
"type": "boolean",
"default": true,
"description": "Enable code lens on node identifiers which jumps to the corresponding nodes in preview."
},
"texinfo.preview.errorLimit": {
"type": "integer",
"default": 100,
"minimum": 0,
"description": "Max number of errors before quit when trying to display preview."
},
"texinfo.preview.localImage": {
"type": "boolean",
"default": false,
"description": "Suppress node separators in preview."
"description": "Display local images in in preview."
},
"texinfo.preview.maxSize": {
"type": "integer",
@ -177,11 +183,15 @@
"maximum": 16,
"description": "Max allowed size (in MiB) for the preview document."
},
"texinfo.preview.errorLimit": {
"type": "integer",
"default": 100,
"minimum": 0,
"description": "Max number of errors before quit when trying to display preview."
"texinfo.makeinfo": {
"type": "string",
"default": "makeinfo",
"description": "Path to the `makeinfo` (or `texi2any`) command."
},
"texinfo.preview.noHeaders": {
"type": "boolean",
"default": false,
"description": "Suppress node separators in preview."
},
"texinfo.preview.noValidation": {
"type": "boolean",
@ -193,15 +203,10 @@
"default": false,
"description": "Suppress warnings."
},
"texinfo.preview.localImage": {
"type": "boolean",
"default": false,
"description": "Display local images in in preview."
},
"texinfo.preview.customCSS": {
"type": "string",
"default": "",
"description": "URI of custom CSS for preview."
"texinfo.vars": {
"type": "array",
"default": [],
"description": "Define variables."
}
}
},

View File

@ -72,8 +72,16 @@ export default class Options {
return this.getBoolean('preview.noWarnings');
}
get vars() {
return this.getArray('vars');
}
private readonly configuration = vscode.workspace.getConfiguration('texinfo');
private getArray(section: string) {
return this.configuration.get(section, <readonly string[]>[]);
}
private getBoolean(section: string) {
return this.configuration.get(section, false);
}

View File

@ -196,6 +196,7 @@ export default class CompletionItemProvider implements vscode.CompletionItemProv
...blockCommand('ifhtml', 'Begin text that will appear only in HTML format'),
...blockCommand('ifinfo', 'Begin text that will appear only in Info format'),
...blockCommand('ifplaintext', 'Begin text that will appear only in plain text format'),
...blockCommand('ifset', 'If the Texinfo variable is set, format the following text', 'txivar'),
...blockCommand('iftex', 'Begin text that will appear only in TeX format'),
...blockCommand('ifxml', 'Begin text that will appear only in XML format'),
...blockCommand('ifnotdocbook', 'Begin text to be ignored in DocBook format'),

View File

@ -36,7 +36,8 @@ export default class Converter {
this.options.noHeaders && options.push('--no-headers');
this.options.noValidation && options.push('--no-validate');
this.options.noWarnings && options.push('--no-warn');
this.options.customCSS && this.includeCustomCSS(this.options.customCSS, options);
this.includeCustomCSS(this.options.customCSS, options);
this.addVars(this.options.vars, options);
const result = await exec(this.options.makeinfo, options.concat(this.path), this.options.maxSize);
if (result.data !== undefined) {
// No worry about performance here, as the DOM is lazily initialized.
@ -50,7 +51,12 @@ export default class Converter {
constructor(private readonly path: string, private readonly options: Options, private readonly logger: Logger) {}
private addVars(vars: readonly string[], options: string[]) {
vars.forEach(varName => options.push('-D', varName));
}
private includeCustomCSS(cssFileURI: string, options: string[]) {
if (!cssFileURI) return;
try {
const uri = vscode.Uri.parse(cssFileURI, true);
switch (uri.scheme) {