Misc update

This commit is contained in:
CismonX 2020-10-17 21:41:03 +08:00
parent 0a42421055
commit a1ac8eb8b9
Signed by: cismonx
GPG Key ID: 3094873E29A482FB
13 changed files with 58 additions and 66 deletions

5
.gitignore vendored
View File

@ -1,5 +1,4 @@
.vscode/
node_modules
out
.vscode-test/
out/
node_modules/
*.vsix

View File

@ -1,5 +1,3 @@
os:
- linux
dist: bionic
language: node_js

View File

@ -1,9 +1,8 @@
.vscode/**
.vscode-test/**
out/test/**
src/**
scripts/**
.gitignore
.yarnrc
.gitattributes
.travis.yml
**/tsconfig.json
**/*.map

View File

@ -5,8 +5,7 @@
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"],
["``", "''"]
["(", ")"]
],
"autoClosingPairs": [
["{", "}"],

6
package-lock.json generated
View File

@ -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": {

View File

@ -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."
}
}
},

View File

@ -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

View File

@ -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}`);
}

View File

@ -1,5 +1,5 @@
/**
* extension.ts - Texinfo extension entry
* extension.ts - extension entry
*
* @author CismonX <admin@cismon.net>
* @license MIT
@ -27,7 +27,7 @@ export function activate(context: vscode.ExtensionContext) {
}
export function deactivate() {
Preview.destroyAll();
Preview.clear();
Options.clear();
FoldingRangeContext.clear();
}

View File

@ -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;
}
}
}

View File

@ -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<string>(section) ?? '';
private getString(section: string): string {
return this.configuration.get(section) ?? '';
}
private getBoolean(section: string) {
return this.configuration.get<boolean>(section) ?? false;
private getBoolean(section: string): boolean {
return this.configuration.get(section) ?? false;
}
private getNumber(section: string) {
return this.configuration.get<number>(section) ?? 0;
private getNumber(section: string): number {
return this.configuration.get(section) ?? 0;
}
}

View File

@ -54,7 +54,7 @@ export default class Preview {
Preview.getByDocument(document)?.destroy();
}
static destroyAll() {
static clear() {
Preview.map.forEach((preview) => preview.destroy());
}

View File

@ -1,5 +1,5 @@
/**
* utils.ts - Helper functions
* utils.ts
*
* @author CismonX <admin@cismon.net>
* @license MIT