diff --git a/.gitignore b/.gitignore index a2025c0..4e7d666 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .vscode/ -node_modules -out -.vscode-test/ +out/ +node_modules/ *.vsix diff --git a/.travis.yml b/.travis.yml index 24b185f..cc06602 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,3 @@ -os: - - linux dist: bionic language: node_js diff --git a/.vscodeignore b/.vscodeignore index 3902712..f65da5d 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -1,9 +1,8 @@ .vscode/** -.vscode-test/** -out/test/** src/** +scripts/** .gitignore -.yarnrc +.gitattributes .travis.yml **/tsconfig.json **/*.map diff --git a/language-config.json b/language-config.json index 7e34c3b..5fb8b1a 100644 --- a/language-config.json +++ b/language-config.json @@ -5,8 +5,7 @@ "brackets": [ ["{", "}"], ["[", "]"], - ["(", ")"], - ["``", "''"] + ["(", ")"] ], "autoClosingPairs": [ ["{", "}"], diff --git a/package-lock.json b/package-lock.json index 201e094..27617ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -74,9 +74,9 @@ "dev": true }, "@types/node": { - "version": "14.11.8", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.11.8.tgz", - "integrity": "sha512-KPcKqKm5UKDkaYPTuXSx8wEP7vE9GnuaXIZKijwRYcePpZFDVuy2a57LarFKiORbHOuTOOwYzxVxcUzsh2P2Pw==", + "version": "14.11.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.11.10.tgz", + "integrity": "sha512-yV1nWZPlMFpoXyoknm4S56y2nlTAuFYaJuQtYRAOU7xA/FJ9RY0Xm7QOkaYMMmr8ESdHIuUb6oQgR/0+2NqlyA==", "dev": true }, "@types/vscode": { diff --git a/package.json b/package.json index 3e8a791..77ab7a0 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ }, "icon": "assets/texinfo.png", "devDependencies": { - "@types/node": "^14.11.8", + "@types/node": "^14.11.10", "@types/vscode": "^1.50.0", "@typescript-eslint/eslint-plugin": "^3.8.0", "@typescript-eslint/parser": "^3.8.0", @@ -110,42 +110,45 @@ "texinfo.makeinfo": { "type": "string", "default": "makeinfo", - "markdownDescription": "Path to the `makeinfo` command." + "markdownDescription": "Path to the `makeinfo` (or `texi2any`) command. If not located in `$PATH`, an absolute path should be specified.\n\nThe value should not contain any command-line arguments, just the filename." }, "texinfo.preview.noHeaders": { "type": "boolean", "default": false, - "markdownDescription": "Suppress node separators in preview. See `makeinfo --help` for details." + "markdownDescription": "Suppress node separators in preview.\n\nThis corresponds to the `--no-headers` option of `makeinfo`." }, "texinfo.preview.maxSize": { "type": "integer", "default": "2", + "minimum": 1, + "maximum": 16, "markdownDescription": "Max allowed size (in MiB) for the preview document." }, "texinfo.preview.errorLimit": { "type": "integer", "default": 100, - "markdownDescription": "Max tolerated number of errors when trying to display preview." + "minimum": 0, + "markdownDescription": "Max tolerated number of errors when trying to display preview.\n\nThis corresponds to the `--error-limit=NUM` option of `makeinfo`." }, "texinfo.preview.force": { "type": "boolean", "default": false, - "markdownDescription": "Preserve preview even if errors." + "markdownDescription": "Preserve preview even if errors.\n\nThis corresponds to the `--force` option of `makeinfo`." }, - "texinfo.preview.noValidate": { + "texinfo.preview.noValidation": { "type": "boolean", "default": false, - "markdownDescription": "Supress node cross-reference validation." + "markdownDescription": "Supress node cross-reference validation.\n\nThis corresponds to the `--no-validate` option of `makeinfo`." }, - "texinfo.preview.noWarn": { + "texinfo.preview.noWarnings": { "type": "boolean", "default": false, - "markdownDescription": "Suppress warnings." + "markdownDescription": "Suppress warnings.\n\nThis corresponds to the `--no-warn` option of `makeinfo`." }, "texinfo.preview.displayImage": { "type": "boolean", "default": false, - "markdownDescription": "Whether to display images in in the preview." + "markdownDescription": "Whether to display images in in the preview.\n\nIf image display is not needed, turn off this option to improve preview performance." } } }, diff --git a/scripts/prepare.sh b/scripts/prepare.sh index 4c3c2aa..485cede 100755 --- a/scripts/prepare.sh +++ b/scripts/prepare.sh @@ -1,8 +1,8 @@ #!/usr/bin/env sh -mkdir -p ./out/grammars - -# Convert TextMate grammar from CSON to JSON (VSCode cannot recognize CSON ones). -TMGRAMMAR_CSON=./node_modules/language-texinfo/grammars/texinfo.cson -TMGRAMMAR_JSON=./out/grammars/texinfo.json -cson2json $TMGRAMMAR_CSON > $TMGRAMMAR_JSON +SRC_PATH=./node_modules/language-texinfo +DEST_PATH=./out/grammars +mkdir -p $DEST_PATH +cp $SRC_PATH/LICENSE.md $DEST_PATH +# Convert TextMate grammar from CSON to JSON, as VSCode cannot recognize CSON ones. +cson2json $SRC_PATH/grammars/texinfo.cson > $DEST_PATH/texinfo.json diff --git a/src/converter.ts b/src/converter.ts index 95e170e..53745e7 100644 --- a/src/converter.ts +++ b/src/converter.ts @@ -31,8 +31,8 @@ export default class Converter { private constructor() { Options.noHeaders && this.options.push('--no-headers'); Options.force && this.options.push('--force'); - Options.noValidate && this.options.push('--no-validate'); - Options.noWarn && this.options.push('--no-warn'); + Options.noValidation && this.options.push('--no-validate'); + Options.noWarnings && this.options.push('--no-warn'); this.options.push(`--error-limit=${Options.errorLimit}`); } diff --git a/src/extension.ts b/src/extension.ts index 76cc645..f9cc017 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,5 +1,5 @@ /** - * extension.ts - Texinfo extension entry + * extension.ts - extension entry * * @author CismonX * @license MIT @@ -27,7 +27,7 @@ export function activate(context: vscode.ExtensionContext) { } export function deactivate() { - Preview.destroyAll(); + Preview.clear(); Options.clear(); FoldingRangeContext.clear(); } diff --git a/src/folding.ts b/src/folding.ts index 0a5af57..3ef0024 100644 --- a/src/folding.ts +++ b/src/folding.ts @@ -13,7 +13,7 @@ import * as vscode from 'vscode'; export class FoldingRangeProvider implements vscode.FoldingRangeProvider { provideFoldingRanges(document: vscode.TextDocument) { - return FoldingRangeContext.get(document).foldingRanges; + return FoldingRangeContext.get(document).values; } } @@ -30,9 +30,7 @@ export class FoldingRangeContext { * @param document */ static open(document: vscode.TextDocument) { - if (document.languageId === 'texinfo') { - FoldingRangeContext.get(document); - } + document.languageId === 'texinfo' && FoldingRangeContext.get(document); } /** @@ -50,10 +48,9 @@ export class FoldingRangeContext { * @param event Change event of a document. */ static update(event: vscode.TextDocumentChangeEvent) { - if (event.document.languageId !== 'texinfo') { - return; + if (event.document.languageId === 'texinfo') { + FoldingRangeContext.get(event.document).update(event.contentChanges); } - FoldingRangeContext.get(event.document).update(event.contentChanges); } /** @@ -75,14 +72,11 @@ export class FoldingRangeContext { /** * Get VSCode folding ranges from the context. */ - get foldingRanges() { - if (this.bufferedFoldingRanges === undefined) { - this.calculateFoldingRanges(); - } - return this.bufferedFoldingRanges; + get values() { + return this.foldingRanges ?? (this.foldingRanges = this.calculateFoldingRanges()); } - private bufferedFoldingRanges?: vscode.FoldingRange[]; + private foldingRanges?: vscode.FoldingRange[]; private commentRange?: { start: number, end: number }; @@ -128,6 +122,7 @@ export class FoldingRangeContext { this.insertRange(this.commentRange.start, this.commentRange.end, vscode.FoldingRangeKind.Comment); } this.commentRange = undefined; + return this.foldingRanges; } private processComment(lineText: string, lineNum: number) { @@ -159,10 +154,7 @@ export class FoldingRangeContext { } private insertRange(start: number, end: number, kind?: vscode.FoldingRangeKind) { - if (this.bufferedFoldingRanges === undefined) { - this.bufferedFoldingRanges = []; - } - this.bufferedFoldingRanges.push(new vscode.FoldingRange(start, end, kind)); + (this.foldingRanges ?? (this.foldingRanges = [])).push(new vscode.FoldingRange(start, end, kind)); } /** @@ -171,12 +163,14 @@ export class FoldingRangeContext { * @param events Events describing the changes in the document. */ private update(events: readonly vscode.TextDocumentContentChangeEvent[]) { + if (this.foldingRanges === undefined) { + return; + } for (const event of events) { - const range = event.range; const updatedLines = event.text.split(this.document.eol === vscode.EndOfLine.LF ? '\n' : '\r\n').length; - // Clear range buffer when line number changes. - if (updatedLines !== 1 || range.start.line !== range.end.line) { - this.bufferedFoldingRanges = undefined; + // Clear folding range buffer when line count changes. + if (updatedLines !== 1 || event.range.start.line !== event.range.end.line) { + this.foldingRanges = undefined; } } } diff --git a/src/options.ts b/src/options.ts index 8a0e6ec..ba3770d 100644 --- a/src/options.ts +++ b/src/options.ts @@ -44,12 +44,12 @@ export default class Options { return Options.instance.getBoolean('preview.force'); } - static get noValidate() { - return Options.instance.getBoolean('preview.noValidate'); + static get noValidation() { + return Options.instance.getBoolean('preview.noValidation'); } - static get noWarn() { - return Options.instance.getBoolean('preview.noWarn'); + static get noWarnings() { + return Options.instance.getBoolean('preview.noWarnings'); } static get displayImage() { @@ -62,15 +62,15 @@ export default class Options { this.configuration = vscode.workspace.getConfiguration(section); } - private getString(section: string) { - return this.configuration.get(section) ?? ''; + private getString(section: string): string { + return this.configuration.get(section) ?? ''; } - private getBoolean(section: string) { - return this.configuration.get(section) ?? false; + private getBoolean(section: string): boolean { + return this.configuration.get(section) ?? false; } - private getNumber(section: string) { - return this.configuration.get(section) ?? 0; + private getNumber(section: string): number { + return this.configuration.get(section) ?? 0; } } diff --git a/src/preview.ts b/src/preview.ts index 7287cd5..1759abc 100644 --- a/src/preview.ts +++ b/src/preview.ts @@ -54,7 +54,7 @@ export default class Preview { Preview.getByDocument(document)?.destroy(); } - static destroyAll() { + static clear() { Preview.map.forEach((preview) => preview.destroy()); } diff --git a/src/utils.ts b/src/utils.ts index 9f55942..a67d10b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,5 @@ /** - * utils.ts - Helper functions + * utils.ts * * @author CismonX * @license MIT