From 7c4c04600f016dcdf283e03482a8fd0b19e3161c Mon Sep 17 00:00:00 2001 From: CismonX Date: Thu, 22 Apr 2021 17:07:55 +0800 Subject: [PATCH] Support definition of Texinfo variables in config. --- package.json | 57 +++++++++++++++++--------------- src/options.ts | 8 +++++ src/providers/completion_item.ts | 1 + src/utils/converter.ts | 8 ++++- 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 2c6bc8e..cecf813 100644 --- a/package.json +++ b/package.json @@ -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." } } }, diff --git a/src/options.ts b/src/options.ts index 7047ed7..5c54c87 100644 --- a/src/options.ts +++ b/src/options.ts @@ -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, []); + } + private getBoolean(section: string) { return this.configuration.get(section, false); } diff --git a/src/providers/completion_item.ts b/src/providers/completion_item.ts index 0241e94..680d33b 100644 --- a/src/providers/completion_item.ts +++ b/src/providers/completion_item.ts @@ -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'), diff --git a/src/utils/converter.ts b/src/utils/converter.ts index d5d7a9b..813015d 100644 --- a/src/utils/converter.ts +++ b/src/utils/converter.ts @@ -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) {