Support extra include paths for preview.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
CismonX 2021-04-25 20:44:56 +08:00
parent 6006881fb9
commit ba9e6a6b2a
Signed by: cismonx
GPG Key ID: 3094873E29A482FB
3 changed files with 35 additions and 20 deletions

View File

@ -154,22 +154,32 @@
"default": true, "default": true,
"description": "When snippet is enabled, hide the snippets' corresponding commands from completion items." "description": "When snippet is enabled, hide the snippets' corresponding commands from completion items."
}, },
"texinfo.preview.customCSS": {
"type": "string",
"default": "",
"description": "URI of custom CSS for preview."
},
"texinfo.enableCodeLens": { "texinfo.enableCodeLens": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
"description": "Enable code lens on node identifiers which jumps to the corresponding nodes in preview." "description": "Enable code lens on node identifiers which jumps to the corresponding nodes in preview."
}, },
"texinfo.makeinfo": {
"type": "string",
"default": "makeinfo",
"description": "Path to the makeinfo (or texi2any) command."
},
"texinfo.preview.customCSS": {
"type": "string",
"default": "",
"description": "URI of custom CSS for preview."
},
"texinfo.preview.errorLimit": { "texinfo.preview.errorLimit": {
"type": "integer", "type": "integer",
"default": 100, "default": 100,
"minimum": 0, "minimum": 0,
"description": "Max number of errors before quit when trying to display preview." "description": "Max number of errors before quit when trying to display preview."
}, },
"texinfo.preview.includePaths": {
"type": "array",
"default": [],
"description": "Extra paths to search for @include files."
},
"texinfo.preview.maxSize": { "texinfo.preview.maxSize": {
"type": "integer", "type": "integer",
"default": 2, "default": 2,
@ -177,11 +187,6 @@
"maximum": 16, "maximum": 16,
"description": "Max allowed size (in MiB) for the preview document." "description": "Max allowed size (in MiB) for the preview document."
}, },
"texinfo.makeinfo": {
"type": "string",
"default": "makeinfo",
"description": "Path to the `makeinfo` (or `texi2any`) command."
},
"texinfo.preview.noHeaders": { "texinfo.preview.noHeaders": {
"type": "boolean", "type": "boolean",
"default": false, "default": false,
@ -197,10 +202,10 @@
"default": false, "default": false,
"description": "Suppress warnings." "description": "Suppress warnings."
}, },
"texinfo.vars": { "texinfo.preview.variables": {
"type": "array", "type": "array",
"default": [], "default": [],
"description": "Define variables." "description": "Define variables (as with @set)."
} }
} }
}, },

View File

@ -52,6 +52,10 @@ export default class Options {
return this.getNumber('preview.errorLimit'); return this.getNumber('preview.errorLimit');
} }
get includePaths() {
return this.getArray('preview.includePaths');
}
get maxSize() { get maxSize() {
return this.getNumber('preview.maxSize') * 1024 * 1024; return this.getNumber('preview.maxSize') * 1024 * 1024;
} }
@ -68,14 +72,14 @@ export default class Options {
return this.getBoolean('preview.noWarnings'); return this.getBoolean('preview.noWarnings');
} }
get vars() { get variables() {
return this.getArray('vars'); return this.getArray('preview.variables');
} }
private readonly configuration = vscode.workspace.getConfiguration('texinfo'); private readonly configuration = vscode.workspace.getConfiguration('texinfo');
private getArray(section: string) { private getArray(section: string): readonly string[] {
return this.configuration.get(section, <readonly string[]>[]); return this.configuration.get(section, []);
} }
private getBoolean(section: string) { private getBoolean(section: string) {

View File

@ -19,7 +19,7 @@
* vscode-texinfo. If not, see <https://www.gnu.org/licenses/>. * vscode-texinfo. If not, see <https://www.gnu.org/licenses/>.
*/ */
import * as path from 'path'; import * as path from 'path';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import Logger from '../logger'; import Logger from '../logger';
import Options from '../options'; import Options from '../options';
@ -41,8 +41,9 @@ export default class Converter {
if (insertScript !== undefined) { if (insertScript !== undefined) {
options.push('--set-customization-variable', `EXTRA_HEAD <script>${insertScript}</script>`); options.push('--set-customization-variable', `EXTRA_HEAD <script>${insertScript}</script>`);
} }
this.addIncludePaths(this.options.includePaths, options);
this.defineVariables(this.options.variables, options);
this.includeCustomCSS(this.options.customCSS, options); this.includeCustomCSS(this.options.customCSS, options);
this.addVars(this.options.vars, options);
return await exec(this.options.makeinfo, options.concat(this.path), this.options.maxSize); return await exec(this.options.makeinfo, options.concat(this.path), this.options.maxSize);
} }
@ -53,8 +54,13 @@ export default class Converter {
private readonly logger: Logger, private readonly logger: Logger,
) {} ) {}
private addVars(vars: readonly string[], options: string[]) { private addIncludePaths(paths: readonly string[], options: string[]) {
vars.forEach(varName => options.push('-D', varName)); const separator = process.platform === 'win32' ? ';' : ':';
options.push('-I', paths.join(separator));
}
private defineVariables(variables: readonly string[], options: string[]) {
variables.forEach(varName => options.push('-D', varName));
} }
private includeCustomCSS(cssFileURI: string, options: string[]) { private includeCustomCSS(cssFileURI: string, options: string[]) {