This commit is contained in:
CismonX 2020-10-04 20:40:54 +08:00
parent 68f4ef2954
commit 06248c86d2
Signed by: cismonx
GPG Key ID: 3094873E29A482FB
5 changed files with 25 additions and 35 deletions

View File

@ -1,19 +1,14 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
"@typescript-eslint/explicit-module-boundary-types": "off"
}
}

View File

@ -1,7 +1,7 @@
# vscode-texinfo
[![Build Status](https://travis-ci.com/texinfo-lang/vscode-texinfo.svg)](https://travis-ci.com/github/texinfo-lang/vscode-texinfo)
[![MIT License](https://img.shields.io/badge/licence-MIT-blue.svg)](LICENSE)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
Texinfo language support for Visual Studio Code.

View File

@ -11,7 +11,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/CismonX/vscode-texinfo"
"url": "https://github.com/texinfo-lang/vscode-texinfo"
},
"engines": {
"vscode": "^1.49.0"
@ -30,7 +30,7 @@
"commands": [
{
"command": "texinfo.showPreview",
"title": "Show preview (Texinfo)",
"title": "Show preview (as HTML)",
"icon": "$(open-preview)"
}
],
@ -111,7 +111,7 @@
"compile": "tsc -p ./",
"prepare": "sh ./scripts/prepare.sh",
"build": "npm run prepare && npm run compile",
"lint": "eslint src --ext ts",
"lint": "eslint --ext ts --fix src",
"watch": "tsc -watch -p ./"
},
"devDependencies": {

View File

@ -14,9 +14,10 @@ import { exec } from './utils';
export class Converter {
/**
* Convert a texinfo document to HTML.
* Convert a Texinfo document to HTML.
*
* @param path Path to the Texinfo document to be converted.
* @param path Path to the Texinfo document.
* @yields HTML code, or `undefined` if conversion fails.
*/
static async convert(path: string) {
const converter = new Converter(path);
@ -29,18 +30,10 @@ export class Converter {
private readonly options = ['-o', '-', '--no-split', '--html'];
private constructor(path: string) {
if (Options.noHeaders) {
this.options.push('--no-headers');
}
if (Options.force) {
this.options.push('--force');
}
if (Options.noValidate) {
this.options.push('--no-validate');
}
if (Options.noWarn) {
this.options.push('--no-warn');
}
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');
this.options.push(`--error-limit=${Options.errorLimit}`);
this.options.push(path);
}

View File

@ -68,7 +68,7 @@ export class Preview {
private readonly panel: vscode.WebviewPanel;
private readonly disposables = new Array<vscode.Disposable>();
private readonly disposables = <vscode.Disposable[]>[];
/**
* Whether the preview is updating.
@ -83,14 +83,14 @@ export class Preview {
private constructor(private readonly document: vscode.TextDocument) {
this.panel = vscode.window.createWebviewPanel('texinfo.preview', '', vscode.ViewColumn.Beside);
this.disposables.push(this.panel.onDidDispose(() => this.destroy()));
Preview.map.set(this.document, this);
Preview.map.set(document, this);
this.updateWebview();
}
private get title() {
private updateTitle() {
const updating = this.updating ? '(Updating) ' : '';
const fileName = path.basename(this.document.fileName);
return `${updating}Preview ${fileName}`;
this.panel.title = `${updating}Preview ${fileName}`;
}
private destroy() {
@ -106,15 +106,17 @@ export class Preview {
}
this.updating = true;
this.pendingUpdate = false;
this.panel.title = this.title;
this.updateTitle();
const htmlCode = await Converter.convert(this.document.fileName);
if (htmlCode === undefined) {
vscode.window.showErrorMessage(`Failed to show preview for file ${this.document.fileName}.`);
vscode.window.showErrorMessage(`Failed to show preview for ${this.document.fileName}.`);
} else {
this.panel.webview.html = htmlCode;
}
this.updating = false;
this.panel.title = this.title;
this.updateTitle();
if (this.pendingUpdate) {
this.updateWebview();
}