Misc updates
This commit is contained in:
parent
b67b37343b
commit
d66287c8e5
|
@ -18,7 +18,7 @@ Texinfo language support for Visual Studio Code.
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Block Folding</summary>
|
<summary>Folding</summary>
|
||||||
(Screenshots here...)
|
(Screenshots here...)
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,11 @@
|
||||||
"strip-json-comments": "^3.1.1"
|
"strip-json-comments": "^3.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@flatten-js/interval-tree": {
|
||||||
|
"version": "1.0.12",
|
||||||
|
"resolved": "https://registry.npmjs.org/@flatten-js/interval-tree/-/interval-tree-1.0.12.tgz",
|
||||||
|
"integrity": "sha512-j2o14WdFPII5cI57j0XNSWQm80gM4G6RT5+NLaH8q7KmQKejR/qZiGiViMjRgMtPiiwaX6hv3hlXeyRL3yzi7g=="
|
||||||
|
},
|
||||||
"@types/eslint-visitor-keys": {
|
"@types/eslint-visitor-keys": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz",
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.0.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@flatten-js/interval-tree": "^1.0.12",
|
||||||
"node-html-parser": "^1.3.1"
|
"node-html-parser": "^1.3.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Texinfo language completion item provider.
|
* Provide code completion info for Texinfo source code.
|
||||||
*/
|
*/
|
||||||
export class CompletionItemProvider implements vscode.CompletionItemProvider {
|
export class CompletionItemProvider implements vscode.CompletionItemProvider {
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Options } from './options';
|
import Options from './options';
|
||||||
import * as utils from './utils';
|
import * as utils from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Texinfo to HTML converter.
|
* Texinfo to HTML converter.
|
||||||
*/
|
*/
|
||||||
export class Converter {
|
export default class Converter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a Texinfo document to HTML.
|
* Convert a Texinfo document to HTML.
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { Options } from './options';
|
import Options from './options';
|
||||||
import { Preview } from './preview';
|
import Preview from './preview';
|
||||||
import { CompletionItemProvider } from './completion';
|
import { CompletionItemProvider } from './completion';
|
||||||
import { FoldingRangeProvider, FoldingRangeContext } from './folding';
|
import { FoldingRangeProvider, FoldingRangeContext } from './folding';
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import IntervalTree from '@flatten-js/interval-tree';
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +36,7 @@ export class FoldingRangeContext {
|
||||||
if (event.document.languageId !== 'texinfo') {
|
if (event.document.languageId !== 'texinfo') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FoldingRangeContext.get(event.document)?.update(event.contentChanges);
|
FoldingRangeContext.get(event.document).update(event.contentChanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
static close(document: vscode.TextDocument) {
|
static close(document: vscode.TextDocument) {
|
||||||
|
@ -46,9 +47,15 @@ export class FoldingRangeContext {
|
||||||
FoldingRangeContext.map.clear();
|
FoldingRangeContext.map.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
foldingRanges = <vscode.FoldingRange[]>[];
|
get foldingRanges(): vscode.FoldingRange[] {
|
||||||
|
return this.tempFoldingRanges ?? (this.tempFoldingRanges = this.intervalTree.values);
|
||||||
|
}
|
||||||
|
|
||||||
private commentRange?: vscode.FoldingRange;
|
private intervalTree = new IntervalTree();
|
||||||
|
|
||||||
|
private tempFoldingRanges?: vscode.FoldingRange[];
|
||||||
|
|
||||||
|
private commentRange?: [number, number];
|
||||||
|
|
||||||
private headerStart?: number;
|
private headerStart?: number;
|
||||||
|
|
||||||
|
@ -56,7 +63,9 @@ export class FoldingRangeContext {
|
||||||
|
|
||||||
private constructor(private readonly document: vscode.TextDocument) {
|
private constructor(private readonly document: vscode.TextDocument) {
|
||||||
FoldingRangeContext.map.set(document, this);
|
FoldingRangeContext.map.set(document, this);
|
||||||
|
console.log(Date.now());
|
||||||
this.calculateFoldingRanges();
|
this.calculateFoldingRanges();
|
||||||
|
console.log(Date.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
private calculateFoldingRanges() {
|
private calculateFoldingRanges() {
|
||||||
|
@ -73,8 +82,8 @@ export class FoldingRangeContext {
|
||||||
this.processBlock(lineText, lineNum);
|
this.processBlock(lineText, lineNum);
|
||||||
}
|
}
|
||||||
if (this.commentRange !== undefined) {
|
if (this.commentRange !== undefined) {
|
||||||
if (this.commentRange.end - this.commentRange.start > 1) {
|
if (this.commentRange[1] - this.commentRange[0] > 1) {
|
||||||
this.foldingRanges.push(this.commentRange);
|
this.insertRange(this.commentRange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,17 +98,17 @@ export class FoldingRangeContext {
|
||||||
if (this.headerStart === undefined) {
|
if (this.headerStart === undefined) {
|
||||||
this.headerStart = lineNum;
|
this.headerStart = lineNum;
|
||||||
} else {
|
} else {
|
||||||
this.foldingRanges.push(new vscode.FoldingRange(lineNum, this.headerStart));
|
this.insertRange([lineNum, this.headerStart]);
|
||||||
this.headerStart = undefined;
|
this.headerStart = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.commentRange === undefined) {
|
if (this.commentRange === undefined) {
|
||||||
this.commentRange = new vscode.FoldingRange(lineNum, lineNum, vscode.FoldingRangeKind.Comment);
|
this.commentRange = [lineNum, lineNum];
|
||||||
} else if (this.commentRange.start - 1 === lineNum) {
|
} else if (this.commentRange[0] - 1 === lineNum) {
|
||||||
this.commentRange.start = lineNum;
|
this.commentRange[0] = lineNum;
|
||||||
} else {
|
} else {
|
||||||
this.foldingRanges.push(this.commentRange);
|
this.insertRange(this.commentRange, vscode.FoldingRangeKind.Comment);
|
||||||
this.commentRange = new vscode.FoldingRange(lineNum, lineNum, vscode.FoldingRangeKind.Comment);
|
this.commentRange = [lineNum, lineNum];
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -115,15 +124,28 @@ export class FoldingRangeContext {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (lineText.substring(1, closingBlock.name.length + 2).trim() === closingBlock.name) {
|
if (lineText.substring(1, closingBlock.name.length + 2).trim() === closingBlock.name) {
|
||||||
this.foldingRanges.push(new vscode.FoldingRange(lineNum, closingBlock.line));
|
this.insertRange([lineNum, closingBlock.line]);
|
||||||
} else {
|
} else {
|
||||||
this.closingBlocks.push(closingBlock);
|
this.closingBlocks.push(closingBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private insertRange(range: [start: number, end: number], kind?: vscode.FoldingRangeKind) {
|
||||||
|
const foldingRange = new vscode.FoldingRange(range[0], range[1], kind);
|
||||||
|
this.intervalTree.insert(range, foldingRange);
|
||||||
|
}
|
||||||
|
|
||||||
private update(events: readonly vscode.TextDocumentContentChangeEvent[]) {
|
private update(events: readonly vscode.TextDocumentContentChangeEvent[]) {
|
||||||
// console.log(events);
|
console.log(events);
|
||||||
|
}
|
||||||
|
|
||||||
|
private clear() {
|
||||||
|
this.intervalTree = new IntervalTree();
|
||||||
|
this.tempFoldingRanges = undefined;
|
||||||
|
this.commentRange = undefined;
|
||||||
|
this.headerStart = undefined;
|
||||||
|
this.closingBlocks = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ let options: Options | undefined;
|
||||||
*
|
*
|
||||||
* See `contributes.configuration` of package.json for details.
|
* See `contributes.configuration` of package.json for details.
|
||||||
*/
|
*/
|
||||||
export class Options {
|
export default class Options {
|
||||||
|
|
||||||
private static get instance() {
|
private static get instance() {
|
||||||
return options ?? (options = new Options('texinfo'));
|
return options ?? (options = new Options('texinfo'));
|
||||||
|
|
|
@ -7,14 +7,14 @@
|
||||||
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { Converter } from './converter';
|
import Converter from './converter';
|
||||||
import { Options } from './options';
|
import Options from './options';
|
||||||
import * as utils from './utils';
|
import * as utils from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Texinfo document preview.
|
* Texinfo document preview.
|
||||||
*/
|
*/
|
||||||
export class Preview {
|
export default class Preview {
|
||||||
|
|
||||||
private static readonly map = new Map<vscode.TextDocument, Preview>();
|
private static readonly map = new Map<vscode.TextDocument, Preview>();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue