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,
"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": {
"type": "boolean",
"default": true,
"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": {
"type": "integer",
"default": 100,
"minimum": 0,
"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": {
"type": "integer",
"default": 2,
@ -177,11 +187,6 @@
"maximum": 16,
"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": {
"type": "boolean",
"default": false,
@ -197,10 +202,10 @@
"default": false,
"description": "Suppress warnings."
},
"texinfo.vars": {
"texinfo.preview.variables": {
"type": "array",
"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');
}
get includePaths() {
return this.getArray('preview.includePaths');
}
get maxSize() {
return this.getNumber('preview.maxSize') * 1024 * 1024;
}
@ -68,14 +72,14 @@ export default class Options {
return this.getBoolean('preview.noWarnings');
}
get vars() {
return this.getArray('vars');
get variables() {
return this.getArray('preview.variables');
}
private readonly configuration = vscode.workspace.getConfiguration('texinfo');
private getArray(section: string) {
return this.configuration.get(section, <readonly string[]>[]);
private getArray(section: string): readonly string[] {
return this.configuration.get(section, []);
}
private getBoolean(section: string) {

View File

@ -19,7 +19,7 @@
* 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 Logger from '../logger';
import Options from '../options';
@ -41,8 +41,9 @@ export default class Converter {
if (insertScript !== undefined) {
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.addVars(this.options.vars, options);
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 addVars(vars: readonly string[], options: string[]) {
vars.forEach(varName => options.push('-D', varName));
private addIncludePaths(paths: readonly string[], options: string[]) {
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[]) {