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
134 lines (111 loc) · 3.91 KB
/
mockTextEditor.ts
File metadata and controls
134 lines (111 loc) · 3.91 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* eslint-disable max-classes-per-file */
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import {
DecorationOptions,
EndOfLine,
Position,
Range,
Selection,
SnippetString,
TextDocument,
TextEditorDecorationType,
TextEditorEdit,
TextEditorOptions,
TextEditorRevealType,
ViewColumn,
} from 'vscode';
import { noop } from '../../client/common/utils/misc';
import { MockDocument } from './mockDocument';
import { IMockDocumentManager, IMockTextEditor } from './mockTypes';
class MockEditorEdit implements TextEditorEdit {
constructor(private _documentManager: IMockDocumentManager, 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,
},
]);
}
// eslint-disable-next-line class-methods-use-this
public delete(_location: Selection | Range): void {
throw new Error('Method not implemented.');
}
// eslint-disable-next-line class-methods-use-this
public setEndOfLine(_endOfLine: EndOfLine): void {
throw new Error('Method not implemented.');
}
}
export class MockEditor implements IMockTextEditor {
public selection: Selection;
public selections: Selection[] = [];
private _revealCallback: () => void;
constructor(private _documentManager: IMockDocumentManager, private _document: MockDocument) {
this.selection = new Selection(0, 0, 0, 0);
this._revealCallback = noop;
}
public get document(): TextDocument {
return this._document;
}
// eslint-disable-next-line class-methods-use-this
public get visibleRanges(): Range[] {
return [];
}
// eslint-disable-next-line class-methods-use-this
public get options(): TextEditorOptions {
return {};
}
// eslint-disable-next-line class-methods-use-this
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);
});
}
// eslint-disable-next-line class-methods-use-this
public insertSnippet(
_snippet: SnippetString,
_location?: Range | Position | Range[] | Position[] | undefined,
_options?: { undoStopBefore: boolean; undoStopAfter: boolean } | undefined,
): Thenable<boolean> {
throw new Error('Method not implemented.');
}
// eslint-disable-next-line class-methods-use-this
public setDecorations(
_decorationType: TextEditorDecorationType,
_rangesOrOptions: Range[] | DecorationOptions[],
): void {
throw new Error('Method not implemented.');
}
public revealRange(_range: Range, _revealType?: TextEditorRevealType | undefined): void {
this._revealCallback();
}
// eslint-disable-next-line class-methods-use-this
public show(_column?: ViewColumn | undefined): void {
throw new Error('Method not implemented.');
}
// eslint-disable-next-line class-methods-use-this
public hide(): void {
throw new Error('Method not implemented.');
}
public setRevealCallback(callback: () => void): void {
this._revealCallback = callback;
}
}