forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmockTextEditor.ts
More file actions
111 lines (102 loc) · 3.37 KB
/
mockTextEditor.ts
File metadata and controls
111 lines (102 loc) · 3.37 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import {
DecorationOptions,
EndOfLine,
Position,
Range,
Selection,
SnippetString,
TextDocument,
TextEditor,
TextEditorDecorationType,
TextEditorEdit,
TextEditorOptions,
TextEditorRevealType,
ViewColumn,
} from 'vscode';
import { noop } from '../../client/common/utils/misc';
import { MockDocument } from './mockDocument';
import { MockDocumentManager } from './mockDocumentManager';
class MockEditorEdit implements TextEditorEdit {
constructor(private _documentManager: MockDocumentManager, private _document: MockDocument) {}
public replace(location: Selection | Range | Position, value: string): void {
this._documentManager.changeDocument(this._document.fileName, [
{
range: location as Range,
newText: value,
},
]);
}
public insert(location: Position, value: string): void {
this._documentManager.changeDocument(this._document.fileName, [
{
range: new Range(location, location),
newText: value,
},
]);
}
public delete(_location: Selection | Range): void {
throw new Error('Method not implemented.');
}
public setEndOfLine(_endOfLine: EndOfLine): void {
throw new Error('Method not implemented.');
}
}
export class MockEditor implements TextEditor {
public selection: Selection;
public selections: Selection[] = [];
private _revealCallback: () => void;
constructor(private _documentManager: MockDocumentManager, private _document: MockDocument) {
this.selection = new Selection(0, 0, 0, 0);
this._revealCallback = noop;
}
public get document(): TextDocument {
return this._document;
}
public get visibleRanges(): Range[] {
return [];
}
public get options(): TextEditorOptions {
return {};
}
public get viewColumn(): ViewColumn | undefined {
return undefined;
}
public edit(
callback: (editBuilder: TextEditorEdit) => void,
_options?: { undoStopBefore: boolean; undoStopAfter: boolean } | undefined,
): Thenable<boolean> {
return new Promise((r) => {
const editor = new MockEditorEdit(this._documentManager, this._document);
callback(editor);
r(true);
});
}
public insertSnippet(
_snippet: SnippetString,
_location?: Range | Position | Range[] | Position[] | undefined,
_options?: { undoStopBefore: boolean; undoStopAfter: boolean } | undefined,
): Thenable<boolean> {
throw new Error('Method not implemented.');
}
public setDecorations(
_decorationType: TextEditorDecorationType,
_rangesOrOptions: Range[] | DecorationOptions[],
): void {
throw new Error('Method not implemented.');
}
public revealRange(_range: Range, _revealType?: TextEditorRevealType | undefined): void {
this._revealCallback();
}
public show(_column?: ViewColumn | undefined): void {
throw new Error('Method not implemented.');
}
public hide(): void {
throw new Error('Method not implemented.');
}
public setRevealCallback(callback: () => void) {
this._revealCallback = callback;
}
}