Skip to content

Commit 3aab211

Browse files
committed
Some changes
1 parent 3c0d500 commit 3aab211

File tree

2 files changed

+192
-59
lines changed

2 files changed

+192
-59
lines changed

crates/rust-analyzer/src/lsp_ext.rs

+40
Original file line numberDiff line numberDiff line change
@@ -506,3 +506,43 @@ pub struct CompletionResolveData {
506506
pub full_import_path: String,
507507
pub imported_name: String,
508508
}
509+
// Request for derive selected data and do subscribes to their changes
510+
pub enum SubscriptionRequest {}
511+
512+
impl Request for SubscriptionRequest {
513+
type Params = SubscriptionRequestParams;
514+
type Result = String;
515+
const METHOD: &'static str = "rust-analyzer/subscription";
516+
}
517+
518+
#[derive(Deserialize, Serialize, Debug)]
519+
#[serde(rename_all = "camelCase")]
520+
pub struct SubscriptionRequestParams {
521+
pub data_objects: Vec<String>
522+
}
523+
524+
#[derive(Debug)]
525+
pub enum DataUpdate{}
526+
527+
impl Notification for DataUpdate {
528+
type Params = DataUpdateParams;
529+
const METHOD: &'static str = "data/update";
530+
}
531+
532+
#[derive(Deserialize, Serialize, Debug)]
533+
pub struct DataUpdateParams {
534+
pub patch: Patch,
535+
}
536+
537+
#[derive(Deserialize, Serialize, Debug)]
538+
pub struct Patch {
539+
pub delete: Vec<usize>,
540+
pub append: Vec<Append>,
541+
}
542+
543+
#[derive(Deserialize, Serialize, Debug)]
544+
#[serde(rename_all = "camelCase")]
545+
pub struct Append {
546+
pub target_id: usize,
547+
//TODO: ...
548+
}

editors/code/src/test_explorer.ts

+152-59
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
22
import * as path from 'path';
3-
import { func } from 'vscode-languageclient/lib/utils/is';
3+
import { array, func } from 'vscode-languageclient/lib/utils/is';
44
import { strict } from 'assert';
55
import { Func } from 'mocha';
66

@@ -11,20 +11,36 @@ function getIconUri(iconName: string, theme: string): vscode.Uri {
1111
return vscode.Uri.file(path.join(iconsRootPath, theme, `${iconName}.svg`));
1212
}
1313

14+
/// Runnable.
15+
16+
type Node = Workspace | Crate | Module | Function;
17+
18+
enum NodeKind {
19+
Workspace,
20+
Crate,
21+
Module,
22+
Function,
23+
}
24+
25+
type Session = Iterable<Workspace>;
26+
1427
interface Workspace {
28+
kind: NodeKind.Workspace,
1529
id: string,
1630
crates: Crate[],
1731
location: string,
1832
}
1933

2034
interface Crate {
35+
kind: NodeKind.Crate,
2136
id: string,
2237
name: string,
2338
modules: Module[],
2439
location: string,
2540
}
2641

2742
interface Module {
43+
kind: NodeKind.Module,
2844
id: string,
2945
name: string,
3046
modules?: Module[],
@@ -38,16 +54,50 @@ enum TestKind {
3854
}
3955

4056
interface Function {
57+
kind: NodeKind.Function,
4158
id: string,
4259
name: string,
4360
location: string,
44-
kind: TestKind,
61+
testKind: TestKind,
62+
}
63+
64+
/// The view synchronized with RA data by `DeltaUpdate`'s. The update is an array
65+
/// of elementary actions called a `Patch`. After applying an update to the tree
66+
/// it will become synchronized.
67+
68+
type DeltaUpdate = Iterable<Patch>;
69+
70+
type Patch = Delete | Update | Create;
71+
72+
enum PatchKind {
73+
Delete = "DELETE",
74+
Update = "UPDATE",
75+
Create = "CREATE"
76+
}
77+
78+
interface Delete {
79+
kind: PatchKind.Delete,
80+
targetId: string,
81+
}
82+
83+
interface Update {
84+
kind: PatchKind.Update,
85+
targetId: string,
86+
payload: {
87+
name?: string,
88+
location?: string,
89+
testKind?: TestKind,
90+
},
91+
}
92+
93+
interface Create {
94+
kind: PatchKind.Create,
95+
targetId: string,
96+
payload: Node,
4597
}
4698

4799
class Workspace extends vscode.TreeItem {
48-
get description(): string {
49-
return this.location;
50-
}
100+
description = this.location;
51101

52102
iconPath = {
53103
light: getIconUri('squares', 'dark'),
@@ -69,11 +119,10 @@ class Crate extends vscode.TreeItem {
69119
super(name, vscode.TreeItemCollapsibleState.Collapsed);
70120
this.location = location;
71121
this.id = id;
122+
this.modules = modules;
72123
}
73124

74-
get description(): string {
75-
return this.location;
76-
}
125+
description = this.location;
77126

78127
iconPath = {
79128
light: getIconUri('squares', 'dark'),
@@ -98,9 +147,7 @@ class Module extends vscode.TreeItem {
98147
this.id = id;
99148
}
100149

101-
get description(): string {
102-
return this.location;
103-
}
150+
description = this.location;
104151

105152
iconPath = {
106153
light: getIconUri('squares', 'dark'),
@@ -148,18 +195,14 @@ class Function extends vscode.TreeItem {
148195
}
149196
}
150197

151-
get description(): string {
152-
return this.location;
153-
}
198+
description = this.location;
154199

155200
getChildren(): null {
156201
return null;
157202
}
158203
}
159204

160-
type Node = Workspace | Crate | Module | Function;
161-
162-
function bfs(root: Node, process: (node: Node) => void) {
205+
function bfs(root: Node, process: (parentField: Node[], node: Node) => void) {
163206
let queue: Array<Node> = [root];
164207
while(queue.length != 0) {
165208
let current = queue.pop();
@@ -189,59 +232,109 @@ export class RunnableDataProvider implements vscode.TreeDataProvider<Node> {
189232

190233
export class RunnableView {
191234
private dataProvider: RunnableDataProvider;
192-
private data: Node;
235+
private tree: Node;
193236

194237
constructor(context: vscode.ExtensionContext) {
195238
this.dataProvider = new RunnableDataProvider()
196239
}
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;
240+
241+
handleCreate(node: Node, patch: Create) {
242+
switch(node.kind) {
243+
case NodeKind.Workspace: {
244+
if (patch.payload.kind != NodeKind.Crate) {
245+
throw Error(`${patch.payload.kind} cant't be payload for ${NodeKind.Workspace} target`);
246+
}
247+
node.crates.push(patch.payload);
248+
}
249+
break;
250+
case NodeKind.Crate: {
251+
if (patch.payload.kind != NodeKind.Module) {
252+
throw Error(`${patch.payload.kind} cant't be payload for ${NodeKind.Crate} target`);
253+
}
254+
node.modules.push(patch.payload);
210255
}
211-
});
256+
break;
257+
case NodeKind.Module: {
258+
if (patch.payload.kind == NodeKind.Module) {
259+
if(node.modules == undefined) {
260+
node.modules = [];
261+
}
262+
node.modules!.push(patch.payload);
263+
} else if (patch.payload.kind == NodeKind.Function) {
264+
if(node.modules == undefined) {
265+
node.modules = [];
266+
}
267+
node.targets!.push(patch.payload);
268+
} else {
269+
throw Error(`${patch.payload.kind} cant't be payload for ${NodeKind.Module} target`);
270+
}
271+
}
272+
break;
273+
case NodeKind.Function: {
274+
throw Error("Function can't be a target for Create's patch");
275+
}
276+
}
212277
}
213-
}
214-
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;
220278

221-
enum PatchKind {
222-
Delete = "DELETE",
223-
Update = "UPDATE",
224-
Create = "CREATE"
225-
}
279+
handleDelete(node: Node, parentField: Array<Node>) {
280+
const index = parentField.indexOf(node);
281+
parentField.splice(index, 1);
282+
}
226283

227-
interface Delete {
228-
kind: PatchKind.Delete,
229-
id: string,
230-
}
284+
handleUpdate(node: Node, patch: Update) {
285+
switch(node.kind) {
286+
case NodeKind.Workspace: {
287+
node.location = patch.payload.location!;
288+
}
289+
break;
290+
case NodeKind.Crate: {
291+
node.location = patch.payload.location!;
292+
node.name = patch.payload.name!;
293+
}
294+
break;
295+
case NodeKind.Module: {
296+
node.name = patch.payload.name!;
297+
node.location = patch.payload.location!;
298+
}
299+
break;
300+
case NodeKind.Function: {
301+
node.name = patch.payload.name!;
302+
node.location = patch.payload.location!;
303+
node.testKind = patch.payload.testKind!;
304+
}
305+
break;
306+
}
307+
}
231308

232-
interface Update {
233-
kind: PatchKind.Update,
234-
payload: {
235-
name?: string,
236-
location?: string,
237-
kind?: TestKind,
238-
},
309+
public applyUpdate(update: DeltaUpdate) {
310+
for (let patch of update) {
311+
bfs(this.tree, (parentField, node) => {
312+
if(node.id == patch.targetId) {
313+
switch(patch.kind) {
314+
case PatchKind.Create: {
315+
this.handleCreate(node, patch);
316+
}
317+
break;
318+
case PatchKind.Delete: {
319+
this.handleDelete(node, parentField)
320+
}
321+
break;
322+
case PatchKind.Update: {
323+
this.handleUpdate(node, patch)
324+
}
325+
break;
326+
}
327+
}
328+
})
329+
}
330+
}
239331
}
240332

241-
interface Create {
242-
kind: PatchKind.Create,
243-
targetId: string,
244-
payload: Node,
333+
export class TestView {
334+
335+
constructor() {
336+
let controller = vscode.tests.createTestController();
337+
}
245338
}
246339

247340
// function runExecutable() {

0 commit comments

Comments
 (0)