Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/markdown-language-features/src/client/inMemoryDocument.ts
3292 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { TextDocument } from 'vscode-languageserver-textdocument';
7
import * as vscode from 'vscode';
8
import { ITextDocument } from '../types/textDocument';
9
10
export class InMemoryDocument implements ITextDocument {
11
12
private readonly _doc: TextDocument;
13
14
public readonly uri: vscode.Uri;
15
public readonly version: number;
16
17
constructor(
18
uri: vscode.Uri,
19
contents: string,
20
version: number = 0,
21
) {
22
this.uri = uri;
23
this.version = version;
24
this._doc = TextDocument.create(this.uri.toString(), 'markdown', 0, contents);
25
}
26
27
getText(range?: vscode.Range): string {
28
return this._doc.getText(range);
29
}
30
31
positionAt(offset: number): vscode.Position {
32
const pos = this._doc.positionAt(offset);
33
return new vscode.Position(pos.line, pos.character);
34
}
35
}
36
37