forked from onivim/oni2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkspaceData.re
78 lines (71 loc) · 1.64 KB
/
WorkspaceData.re
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
open Oni_Core;
module Folder = {
type t = {
uri: Uri.t,
name: string,
index: int,
};
let decode = {
Json.Decode.(
obj(({field, _}) =>
{
uri: field.required("uri", Uri.decode),
name: field.required("name", string),
index: field.required("index", int),
}
)
);
};
let encode = folder =>
Json.Encode.(
obj([
("uri", folder.uri |> Uri.encode),
("name", folder.name |> string),
("index", folder.index |> int),
])
);
};
type t = {
folders: list(Folder.t),
id: string,
name: string,
configuration: option(Uri.t),
isUntitled: bool,
};
let decode = {
Json.Decode.(
obj(({field, _}) =>
{
folders: field.withDefault("folders", [], list(Folder.decode)),
id: field.required("id", string),
name: field.required("name", string),
configuration: field.optional("configuration", Uri.decode),
isUntitled: field.withDefault("isUntitled", false, bool),
}
)
);
};
let encode = workspace =>
Json.Encode.(
obj([
("folders", workspace.folders |> list(Folder.encode)),
("id", workspace.id |> string),
("name", workspace.name |> string),
("configuration", workspace.configuration |> nullable(Uri.encode)),
("isUntitled", workspace.isUntitled |> bool),
])
);
let fromUri = (~name, ~id, uri) => {
id,
name,
folders: [{uri, name, index: 0}],
isUntitled: false,
configuration: None,
};
let fromPath = path => {
id: path,
name: path,
configuration: None,
isUntitled: false,
folders: [{uri: Uri.fromPath(path), name: path, index: 0}],
};