Skip to content

Commit bc723c8

Browse files
committed
Dirty impl of sync vew
1 parent 4da2f23 commit bc723c8

File tree

1 file changed

+100
-34
lines changed

1 file changed

+100
-34
lines changed

editors/code/src/test_explorer.ts

+100-34
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as vscode from 'vscode';
22
import * as path from 'path';
33
import { func } from 'vscode-languageclient/lib/utils/is';
4+
import { strict } from 'assert';
5+
import { Func } from 'mocha';
46

57

68
const iconsRootPath = path.join(path.dirname(__dirname), '..', 'resources', 'icons');
@@ -10,17 +12,20 @@ function getIconUri(iconName: string, theme: string): vscode.Uri {
1012
}
1113

1214
interface Workspace {
15+
id: string,
1316
crates: Crate[],
1417
location: string,
1518
}
1619

1720
interface Crate {
21+
id: string,
1822
name: string,
1923
modules: Module[],
2024
location: string,
2125
}
2226

2327
interface Module {
28+
id: string,
2429
name: string,
2530
modules?: Module[],
2631
targets?: Function[],
@@ -33,17 +38,13 @@ enum TestKind {
3338
}
3439

3540
interface Function {
41+
id: string,
3642
name: string,
3743
location: string,
3844
kind: TestKind,
3945
}
4046

41-
class Workspace extends vscode.TreeItem {
42-
get tooltip(): string {
43-
// @ts-ignore
44-
return super.label;
45-
}
46-
47+
class Workspace extends vscode.TreeItem {
4748
get description(): string {
4849
return this.location;
4950
}
@@ -60,15 +61,14 @@ class Workspace extends vscode.TreeItem {
6061

6162
class Crate extends vscode.TreeItem {
6263
constructor(
64+
id: string,
6365
name: string,
6466
modules: Module[],
67+
location: string,
6568
) {
6669
super(name, vscode.TreeItemCollapsibleState.Collapsed);
67-
}
68-
69-
get tooltip(): string {
70-
// @ts-ignore
71-
return super.label;
70+
this.location = location;
71+
this.id = id;
7272
}
7373

7474
get description(): string {
@@ -87,20 +87,17 @@ class Crate extends vscode.TreeItem {
8787

8888
class Module extends vscode.TreeItem {
8989
constructor(
90+
id: string,
9091
name: string,
9192
location: string,
9293
modules?: Module[],
9394
targets?: Function[],
9495
) {
9596
super(name, vscode.TreeItemCollapsibleState.Collapsed);
9697
this.location = location;
98+
this.id = id;
9799
}
98100

99-
get tooltip(): string {
100-
// @ts-ignore
101-
return super.label;
102-
}
103-
104101
get description(): string {
105102
return this.location;
106103
}
@@ -124,12 +121,14 @@ class Module extends vscode.TreeItem {
124121

125122
class Function extends vscode.TreeItem {
126123
constructor(
124+
id: string,
127125
name: string,
128126
location: string,
129127
kind: TestKind,
130128
) {
131129
super(name, vscode.TreeItemCollapsibleState.None);
132130
this.location = location;
131+
this.id = id;
133132

134133
switch(kind) {
135134
case TestKind.Bench: {
@@ -148,12 +147,7 @@ class Function extends vscode.TreeItem {
148147
}
149148
}
150149
}
151-
152-
get tooltip(): string {
153-
// @ts-ignore
154-
return super.label;
155-
}
156-
150+
157151
get description(): string {
158152
return this.location;
159153
}
@@ -163,35 +157,107 @@ class Function extends vscode.TreeItem {
163157
}
164158
}
165159

166-
type Executable = Workspace | Crate | Module | Function;
160+
type Node = Workspace | Crate | Module | Function;
161+
162+
function bfs(root: Node, process: (node: Node) => void) {
163+
let queue: Array<Node> = [root];
164+
while(queue.length != 0) {
165+
let current = queue.pop();
166+
//@ts-ignore
167+
process(current);
168+
//@ts-ignore
169+
current.getChildren();
170+
}
171+
}
167172

168-
export class RunnableProvider implements vscode.TreeDataProvider<Executable> {
169-
// private changesEmitter: vscode.EventEmitter<Executable | undefined> = new vscode.EventEmitter<Executable | undefined>();
170-
// readonly onDidChangeTreeData: vscode.Event<Executable | undefined> = this.changesEmitter.event;
173+
export class RunnableDataProvider implements vscode.TreeDataProvider<Node> {
174+
private _onDidChangeTreeData: vscode.EventEmitter<Node | undefined> = new vscode.EventEmitter<Node | undefined>()
175+
readonly onDidChangeTreeData: vscode.Event<Node | undefined> = this._onDidChangeTreeData.event;
171176

172-
getChildren(element?: Executable): vscode.ProviderResult<Executable[]> {
177+
getChildren(element?: Node): vscode.ProviderResult<Node[]> {
173178
if(element == undefined) {
174179
return Promise.resolve([]);
175180
}
176181

177182
return element.getChildren();
178183
}
179184

180-
getTreeItem(element: Executable): Executable {
185+
getTreeItem(element: Node): Node {
181186
return element;
182187
}
183188
}
184189

185-
function runExecutable() {
186-
190+
export class RunnableView {
191+
private dataProvider: RunnableDataProvider;
192+
private data: Node;
193+
194+
constructor(context: vscode.ExtensionContext) {
195+
this.dataProvider = new RunnableDataProvider()
196+
}
197+
198+
public applyUpdate(deltaUpdate: Patch[]) {
199+
deltaUpdate.map((patch) => {
200+
switch(patch.kind) {
201+
case PatchKind.Create:
202+
find(patch.targetId);
203+
break;
204+
case PatchKind.Delete:
205+
find();
206+
break;
207+
case PatchKind.Update:
208+
find();
209+
break;
210+
}
211+
});
212+
}
187213
}
188214

189-
function goToDefinition() {
190-
vscode.workspace.openTextDocument().then((document)=>{
191-
vscode.window.activeTextEditor?.revealRange();
192-
});
215+
/// The view synchronized with RA data by delta updates. The update is an array
216+
/// of elementary actions called a `Patch`. After applying an update to the tree
217+
/// it will become synchronized.
218+
219+
type Patch = Delete | Update | Create;
220+
221+
enum PatchKind {
222+
Delete = "DELETE",
223+
Update = "UPDATE",
224+
Create = "CREATE"
225+
}
226+
227+
interface Delete {
228+
kind: PatchKind.Delete,
229+
id: string,
193230
}
194231

232+
interface Update {
233+
kind: PatchKind.Update,
234+
payload: {
235+
name?: string,
236+
location?: string,
237+
kind?: TestKind,
238+
},
239+
}
240+
241+
interface Create {
242+
kind: PatchKind.Create,
243+
targetId: string,
244+
payload: Node,
245+
}
246+
247+
// function runExecutable() {
248+
// // TODO: implement
249+
// }
250+
251+
// function goToDefinition() {
252+
// vscode.workspace.openTextDocument().then((document)=>{
253+
// vscode.window.activeTextEditor?.revealRange();
254+
// });
255+
// }
256+
// Для Workspace и Crate show in explorer
257+
258+
// TODO: возможность создавать run lists
259+
// TODO: Run History
260+
195261

196262

197263

0 commit comments

Comments
 (0)