mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-02 14:31:31 +01:00
Rename types in the markdown extension (#152905)
Renames in the markdown extension This renames some types and splits up some files as part of an exploration towards a proper LSP. Changes: - `SkinnyTextDocument` -> `ITextDocument` - Moved `ITextDocument` to own file - `MdWorkspaceContents` -> `IMdWorkspace`
This commit is contained in:
@@ -5,13 +5,13 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { TextDocument } from 'vscode-languageserver-textdocument';
|
||||
import { SkinnyTextDocument, SkinnyTextLine } from '../workspaceContents';
|
||||
import { ITextDocument, ITextLine } from '../types/textDocument';
|
||||
|
||||
export class InMemoryDocument implements SkinnyTextDocument {
|
||||
export class InMemoryDocument implements ITextDocument {
|
||||
|
||||
private readonly _doc: TextDocument;
|
||||
|
||||
private lines: SkinnyTextLine[] | undefined;
|
||||
private lines: ITextLine[] | undefined;
|
||||
|
||||
constructor(
|
||||
public readonly uri: vscode.Uri, contents: string,
|
||||
@@ -25,7 +25,7 @@ export class InMemoryDocument implements SkinnyTextDocument {
|
||||
return this._doc.lineCount;
|
||||
}
|
||||
|
||||
lineAt(index: any): SkinnyTextLine {
|
||||
lineAt(index: any): ITextLine {
|
||||
if (!this.lines) {
|
||||
this.lines = this._doc.getText().split(/\r?\n/).map(text => ({
|
||||
text,
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { MdTableOfContentsProvider, TableOfContents } from '../tableOfContents';
|
||||
import { MdWorkspaceContents, SkinnyTextDocument } from '../workspaceContents';
|
||||
import { ITextDocument } from '../types/textDocument';
|
||||
import { IMdWorkspace } from '../workspace';
|
||||
import { equals } from './arrays';
|
||||
import { Delayer } from './async';
|
||||
import { Disposable } from './dispose';
|
||||
@@ -36,7 +37,7 @@ export class MdTableOfContentsWatcher extends Disposable {
|
||||
private readonly delayer: Delayer<void>;
|
||||
|
||||
public constructor(
|
||||
private readonly workspaceContents: MdWorkspaceContents,
|
||||
private readonly workspace: IMdWorkspace,
|
||||
private readonly tocProvider: MdTableOfContentsProvider,
|
||||
private readonly delay: number,
|
||||
) {
|
||||
@@ -44,17 +45,17 @@ export class MdTableOfContentsWatcher extends Disposable {
|
||||
|
||||
this.delayer = this._register(new Delayer<void>(delay));
|
||||
|
||||
this._register(this.workspaceContents.onDidChangeMarkdownDocument(this.onDidChangeDocument, this));
|
||||
this._register(this.workspaceContents.onDidCreateMarkdownDocument(this.onDidCreateDocument, this));
|
||||
this._register(this.workspaceContents.onDidDeleteMarkdownDocument(this.onDidDeleteDocument, this));
|
||||
this._register(this.workspace.onDidChangeMarkdownDocument(this.onDidChangeDocument, this));
|
||||
this._register(this.workspace.onDidCreateMarkdownDocument(this.onDidCreateDocument, this));
|
||||
this._register(this.workspace.onDidDeleteMarkdownDocument(this.onDidDeleteDocument, this));
|
||||
}
|
||||
|
||||
private async onDidCreateDocument(document: SkinnyTextDocument) {
|
||||
private async onDidCreateDocument(document: ITextDocument) {
|
||||
const toc = await this.tocProvider.getForDocument(document);
|
||||
this._files.set(document.uri, { toc });
|
||||
}
|
||||
|
||||
private async onDidChangeDocument(document: SkinnyTextDocument) {
|
||||
private async onDidChangeDocument(document: ITextDocument) {
|
||||
if (this.delay > 0) {
|
||||
this._pending.set(document.uri);
|
||||
this.delayer.trigger(() => this.flushPending());
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { ITextDocument } from '../types/textDocument';
|
||||
import { IMdWorkspace } from '../workspace';
|
||||
import { Disposable } from './dispose';
|
||||
import { Lazy, lazy } from './lazy';
|
||||
import { ResourceMap } from './resourceMap';
|
||||
import { MdWorkspaceContents, SkinnyTextDocument } from '../workspaceContents';
|
||||
|
||||
class LazyResourceMap<T> {
|
||||
private readonly _map = new ResourceMap<Lazy<Promise<T>>>();
|
||||
@@ -43,16 +44,16 @@ class LazyResourceMap<T> {
|
||||
export class MdDocumentInfoCache<T> extends Disposable {
|
||||
|
||||
private readonly _cache = new LazyResourceMap<T>();
|
||||
private readonly _loadingDocuments = new ResourceMap<Promise<SkinnyTextDocument | undefined>>();
|
||||
private readonly _loadingDocuments = new ResourceMap<Promise<ITextDocument | undefined>>();
|
||||
|
||||
public constructor(
|
||||
private readonly workspaceContents: MdWorkspaceContents,
|
||||
private readonly getValue: (document: SkinnyTextDocument) => Promise<T>,
|
||||
private readonly workspace: IMdWorkspace,
|
||||
private readonly getValue: (document: ITextDocument) => Promise<T>,
|
||||
) {
|
||||
super();
|
||||
|
||||
this._register(this.workspaceContents.onDidChangeMarkdownDocument(doc => this.invalidate(doc)));
|
||||
this._register(this.workspaceContents.onDidDeleteMarkdownDocument(this.onDidDeleteDocument, this));
|
||||
this._register(this.workspace.onDidChangeMarkdownDocument(doc => this.invalidate(doc)));
|
||||
this._register(this.workspace.onDidDeleteMarkdownDocument(this.onDidDeleteDocument, this));
|
||||
}
|
||||
|
||||
public async get(resource: vscode.Uri): Promise<T | undefined> {
|
||||
@@ -75,7 +76,7 @@ export class MdDocumentInfoCache<T> extends Disposable {
|
||||
return this.resetEntry(doc)?.value;
|
||||
}
|
||||
|
||||
public async getForDocument(document: SkinnyTextDocument): Promise<T> {
|
||||
public async getForDocument(document: ITextDocument): Promise<T> {
|
||||
const existing = this._cache.get(document.uri);
|
||||
if (existing) {
|
||||
return existing;
|
||||
@@ -83,13 +84,13 @@ export class MdDocumentInfoCache<T> extends Disposable {
|
||||
return this.resetEntry(document).value;
|
||||
}
|
||||
|
||||
private loadDocument(resource: vscode.Uri): Promise<SkinnyTextDocument | undefined> {
|
||||
private loadDocument(resource: vscode.Uri): Promise<ITextDocument | undefined> {
|
||||
const existing = this._loadingDocuments.get(resource);
|
||||
if (existing) {
|
||||
return existing;
|
||||
}
|
||||
|
||||
const p = this.workspaceContents.getOrLoadMarkdownDocument(resource);
|
||||
const p = this.workspace.getOrLoadMarkdownDocument(resource);
|
||||
this._loadingDocuments.set(resource, p);
|
||||
p.finally(() => {
|
||||
this._loadingDocuments.delete(resource);
|
||||
@@ -97,13 +98,13 @@ export class MdDocumentInfoCache<T> extends Disposable {
|
||||
return p;
|
||||
}
|
||||
|
||||
private resetEntry(document: SkinnyTextDocument): Lazy<Promise<T>> {
|
||||
private resetEntry(document: ITextDocument): Lazy<Promise<T>> {
|
||||
const value = lazy(() => this.getValue(document));
|
||||
this._cache.set(document.uri, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
private invalidate(document: SkinnyTextDocument): void {
|
||||
private invalidate(document: ITextDocument): void {
|
||||
if (this._cache.has(document.uri)) {
|
||||
this.resetEntry(document);
|
||||
}
|
||||
@@ -126,8 +127,8 @@ export class MdWorkspaceInfoCache<T> extends Disposable {
|
||||
private _init?: Promise<void>;
|
||||
|
||||
public constructor(
|
||||
private readonly workspaceContents: MdWorkspaceContents,
|
||||
private readonly getValue: (document: SkinnyTextDocument) => Promise<T>,
|
||||
private readonly workspace: IMdWorkspace,
|
||||
private readonly getValue: (document: ITextDocument) => Promise<T>,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@@ -146,25 +147,25 @@ export class MdWorkspaceInfoCache<T> extends Disposable {
|
||||
if (!this._init) {
|
||||
this._init = this.populateCache();
|
||||
|
||||
this._register(this.workspaceContents.onDidChangeMarkdownDocument(this.onDidChangeDocument, this));
|
||||
this._register(this.workspaceContents.onDidCreateMarkdownDocument(this.onDidChangeDocument, this));
|
||||
this._register(this.workspaceContents.onDidDeleteMarkdownDocument(this.onDidDeleteDocument, this));
|
||||
this._register(this.workspace.onDidChangeMarkdownDocument(this.onDidChangeDocument, this));
|
||||
this._register(this.workspace.onDidCreateMarkdownDocument(this.onDidChangeDocument, this));
|
||||
this._register(this.workspace.onDidDeleteMarkdownDocument(this.onDidDeleteDocument, this));
|
||||
}
|
||||
await this._init;
|
||||
}
|
||||
|
||||
private async populateCache(): Promise<void> {
|
||||
const markdownDocumentUris = await this.workspaceContents.getAllMarkdownDocuments();
|
||||
const markdownDocumentUris = await this.workspace.getAllMarkdownDocuments();
|
||||
for (const document of markdownDocumentUris) {
|
||||
this.update(document);
|
||||
}
|
||||
}
|
||||
|
||||
private update(document: SkinnyTextDocument): void {
|
||||
private update(document: ITextDocument): void {
|
||||
this._cache.set(document.uri, lazy(() => this.getValue(document)));
|
||||
}
|
||||
|
||||
private onDidChangeDocument(document: SkinnyTextDocument) {
|
||||
private onDidChangeDocument(document: ITextDocument) {
|
||||
this.update(document);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user