Clean up structure of markdown extension (#161148)

- Move things related to the client under `client`
- Remove extra abstractions that are no longer used
- Add MdLanguageClient type
This commit is contained in:
Matt Bierner
2022-09-18 22:16:45 -07:00
committed by GitHub
parent f4bf1f30a2
commit d03f015931
17 changed files with 183 additions and 226 deletions

View File

@@ -1,34 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { ITextDocument } from '../types/textDocument';
export class InMemoryDocument implements ITextDocument {
private readonly _doc: TextDocument;
constructor(
public readonly uri: vscode.Uri, contents: string,
public readonly version = 0,
) {
this._doc = TextDocument.create(uri.toString(), 'markdown', version, contents);
}
get lineCount(): number {
return this._doc.lineCount;
}
positionAt(offset: number): vscode.Position {
const pos = this._doc.positionAt(offset);
return new vscode.Position(pos.line, pos.character);
}
getText(range?: vscode.Range): string {
return this._doc.getText(range);
}
}

View File

@@ -1,39 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export interface Lazy<T> {
readonly value: T;
readonly hasValue: boolean;
map<R>(f: (x: T) => R): Lazy<R>;
}
class LazyValue<T> implements Lazy<T> {
private _hasValue: boolean = false;
private _value?: T;
constructor(
private readonly _getValue: () => T
) { }
get value(): T {
if (!this._hasValue) {
this._hasValue = true;
this._value = this._getValue();
}
return this._value!;
}
get hasValue(): boolean {
return this._hasValue;
}
public map<R>(f: (x: T) => R): Lazy<R> {
return new LazyValue(() => f(this.value));
}
}
export function lazy<T>(getValue: () => T): Lazy<T> {
return new LazyValue<T>(getValue);
}

View File

@@ -4,8 +4,8 @@
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { BaseLanguageClient } from 'vscode-languageclient';
import * as proto from '../protocol';
import { MdLanguageClient } from '../client/client';
import * as proto from '../client/protocol';
enum OpenMarkdownLinks {
beside = 'beside',
@@ -15,15 +15,15 @@ enum OpenMarkdownLinks {
export class MdLinkOpener {
constructor(
private readonly client: BaseLanguageClient,
private readonly client: MdLanguageClient,
) { }
public async resolveDocumentLink(linkText: string, fromResource: vscode.Uri): Promise<proto.ResolvedDocumentLinkTarget> {
return this.client.sendRequest(proto.resolveLinkTarget, { linkText, uri: fromResource.toString() });
return this.client.resolveLinkTarget(linkText, fromResource);
}
public async openDocumentLink(linkText: string, fromResource: vscode.Uri, viewColumn?: vscode.ViewColumn): Promise<void> {
const resolved = await this.client.sendRequest(proto.resolveLinkTarget, { linkText, uri: fromResource.toString() });
const resolved = await this.client.resolveLinkTarget(linkText, fromResource);
if (!resolved) {
return;
}