diff --git a/README.md b/README.md index 2dda15b..3e68418 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ See `File -> Preferences -> Settings -> Extensions -> Texinfo` for details. The * If syntax highlighting is not satisfactory, try another color theme where keyword/operator colors are distinct (e.g. Solarized Light/Dark, Monokai). * Preview content is updated on document save rather than document change. -* For macOS users: Version of preinstalled GNU Texinfo is very old, use a latest one instead. This can be easily done by `brew install texinfo` and change extension setting `texinfo.makeinfo` value. +* For macOS users: Preinstalled GNU Texinfo distribution is very old. Use a latest one instead. This can be easily done by `brew install texinfo` and change extension setting `texinfo.makeinfo` value. ## Future Plans diff --git a/language-config.json b/language-config.json new file mode 100644 index 0000000..7e34c3b --- /dev/null +++ b/language-config.json @@ -0,0 +1,22 @@ +{ + "comments": { + "lineComment": "@c" + }, + "brackets": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["``", "''"] + ], + "autoClosingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"] + ], + "surroundingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["`", "'"] + ] +} diff --git a/language-configuration.json b/language-configuration.json deleted file mode 100644 index 568b405..0000000 --- a/language-configuration.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "comments": { - "lineComment": "@c" - }, - "brackets": [ - ["{", "}"] - ], - "autoClosingPairs": [ - ["{", "}"] - ], - "surroundingPairs": [ - ["{", "}"] - ] -} diff --git a/package.json b/package.json index 7cdd430..3e8a791 100644 --- a/package.json +++ b/package.json @@ -160,15 +160,14 @@ ".texinfo", ".txi" ], - "configuration": "./language-configuration.json" + "configuration": "./language-config.json" } ], "grammars": [ { "language": "texinfo", "scopeName": "text.texinfo", - "path": "./out/texinfo.tmGrammar.json", - "configuration": "./language-configuration.json" + "path": "./out/grammars/texinfo.json" } ] } diff --git a/scripts/prepare.sh b/scripts/prepare.sh index 58f8f2f..4c3c2aa 100755 --- a/scripts/prepare.sh +++ b/scripts/prepare.sh @@ -1,8 +1,8 @@ #!/usr/bin/env sh -mkdir -p ./out +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/texinfo.tmGrammar.json +TMGRAMMAR_JSON=./out/grammars/texinfo.json cson2json $TMGRAMMAR_CSON > $TMGRAMMAR_JSON diff --git a/src/folding.ts b/src/folding.ts index 981b7a5..0a5af57 100644 --- a/src/folding.ts +++ b/src/folding.ts @@ -84,7 +84,7 @@ export class FoldingRangeContext { private bufferedFoldingRanges?: vscode.FoldingRange[]; - private commentRange?: [number, number]; + private commentRange?: { start: number, end: number }; private headerStart?: number; @@ -99,7 +99,6 @@ export class FoldingRangeContext { * @param end Ending line number. */ private calculateFoldingRanges() { - this.commentRange = undefined; this.headerStart = undefined; const closingBlocks = <{ name: string, line: number }[]>[]; for (let idx = this.document.lineCount - 1; idx >= 0; --idx) { @@ -116,7 +115,7 @@ export class FoldingRangeContext { } else { const closingBlock = closingBlocks.pop(); if (closingBlock === undefined) { - return; + continue; } if (line.substring(1, closingBlock.name.length + 2).trim() === closingBlock.name) { this.insertRange(idx, closingBlock.line); @@ -126,9 +125,9 @@ export class FoldingRangeContext { } } if (this.commentRange !== undefined) { - this.insertRange(this.commentRange[0], this.commentRange[1], vscode.FoldingRangeKind.Comment); + this.insertRange(this.commentRange.start, this.commentRange.end, vscode.FoldingRangeKind.Comment); } - return this.bufferedFoldingRanges; + this.commentRange = undefined; } private processComment(lineText: string, lineNum: number) { @@ -147,12 +146,12 @@ export class FoldingRangeContext { return true; } if (this.commentRange === undefined) { - this.commentRange = [lineNum, lineNum]; - } else if (this.commentRange[0] - 1 === lineNum) { - this.commentRange[0] = lineNum; + this.commentRange = { start: lineNum, end: lineNum }; + } else if (this.commentRange.start - 1 === lineNum) { + this.commentRange.start = lineNum; } else { - this.insertRange(this.commentRange[0], this.commentRange[1], vscode.FoldingRangeKind.Comment); - this.commentRange = [lineNum, lineNum]; + this.insertRange(this.commentRange.start, this.commentRange.end, vscode.FoldingRangeKind.Comment); + this.commentRange = { start: lineNum, end: lineNum }; } return true; } diff --git a/src/options.ts b/src/options.ts index 8bb93e2..8a0e6ec 100644 --- a/src/options.ts +++ b/src/options.ts @@ -7,8 +7,6 @@ import * as vscode from 'vscode'; -let options: Options | undefined; - /** * Fetch extension option values. * @@ -16,12 +14,14 @@ let options: Options | undefined; */ export default class Options { + private static singleton?: Options; + private static get instance() { - return options ?? (options = new Options('texinfo')); + return Options.singleton ?? (Options.singleton = new Options('texinfo')); } static clear() { - options = undefined; + Options.singleton = undefined; } static get makeinfo() { diff --git a/src/preview.ts b/src/preview.ts index c2ef413..7287cd5 100644 --- a/src/preview.ts +++ b/src/preview.ts @@ -126,8 +126,6 @@ export default class Preview { this.updating = false; this.updateTitle(); - if (this.pendingUpdate) { - this.updateWebview(); - } + this.pendingUpdate && this.updateWebview(); } }