-
-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathVscodeTextDocument.ts
More file actions
74 lines (62 loc) · 1.72 KB
/
Copy pathVscodeTextDocument.ts
File metadata and controls
74 lines (62 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import * as path from "node:path";
import type * as vscode from "vscode";
import type { URI } from "vscode-uri";
import type {
EndOfLine,
Position,
TextDocument,
TextLine,
} from "@cursorless/lib-common";
import { Range } from "@cursorless/lib-common";
import {
fromVscodeEndOfLine,
fromVscodePosition,
toVscodePosition,
toVscodeRange,
} from "@cursorless/lib-vscode-common";
import { VscodeTextLine } from "./VscodeTextLine";
export class VscodeTextDocument implements TextDocument {
get uri(): URI {
return this.document.uri;
}
get filename(): string {
return path.basename(this.document.uri.path);
}
get languageId(): string {
return this.document.languageId;
}
get version(): number {
return this.document.version;
}
get lineCount(): number {
return this.document.lineCount;
}
get range(): Range {
const { end } = this.document.lineAt(this.document.lineCount - 1).range;
return new Range(0, 0, end.line, end.character);
}
get eol(): EndOfLine {
return fromVscodeEndOfLine(this.document.eol);
}
constructor(private document: vscode.TextDocument) {}
public lineAt(lineOrPosition: number | Position): TextLine {
return new VscodeTextLine(
this.document.lineAt(
typeof lineOrPosition === "number"
? lineOrPosition
: lineOrPosition.line,
),
);
}
public offsetAt(position: Position): number {
return this.document.offsetAt(toVscodePosition(position));
}
public positionAt(offset: number): Position {
return fromVscodePosition(this.document.positionAt(offset));
}
public getText(range?: Range): string {
return this.document.getText(
range != null ? toVscodeRange(range) : undefined,
);
}
}