Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(extension/#2676): Implement workspace storage #3030

Merged
merged 8 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES_CURRENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- #3029 - Editor: Fix rubber-banding while scrolling with high key-repeat set
- #3021 - Configuration: Fix zoom being reset when saving configuration (fixes #2294)
- #3051 - Editor: Make horizontal / vertical scrollbars on editor surface configurable (fixes #3036)
- #3030 - Extensions: Implement workspace storage (related #2676)

### Performance

Expand Down
3 changes: 3 additions & 0 deletions development_extensions/oni-dev-extension/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ function activate(context) {
cleanup(
vscode.commands.registerCommand("developer.oni.showWorkspaceRootPath", () => {
vscode.window.showInformationMessage("Workspace rootPath: " + vscode.workspace.rootPath)
vscode.window.showInformationMessage("Workspace storagePath: " + context.storagePath)
}),
)

Expand Down Expand Up @@ -339,6 +340,8 @@ function activate(context) {
)
disposable.dispose()

console.log("Storage path available: " + context.storagePath);

// Configuration

const rlsLocation = vscode.workspace.getConfiguration().get("reason_language_server.location")
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Filesystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ let getGlobalStorageFolder = () =>
|> Result.map(dir => Fp.append(dir, "global"))
|> ResultEx.flatMap(mkdirp);

let getWorkspaceStorageFolder = () =>
getUserDataDirectory()
|> ResultEx.flatMap(getOniDirectory)
|> Result.map(dir => Fp.append(dir, "workspace"))
|> ResultEx.flatMap(mkdirp);

let rec getOrCreateConfigFile = (~overridePath=?, filename) => {
switch (overridePath) {
| Some(path) =>
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Filesystem.rei
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ let getStoreFolder: unit => result(Fp.t(Fp.absolute), string);

let getGlobalStorageFolder: unit => result(Fp.t(Fp.absolute), string);

let getWorkspaceStorageFolder: unit => result(Fp.t(Fp.absolute), string);

let getOrCreateConfigFolder:
Fp.t(Fp.absolute) => result(Fp.t(Fp.absolute), string);

Expand Down
13 changes: 13 additions & 0 deletions src/Exthost/Extension/Exthost_Extension.rei
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ module InitData: {
let fromString: string => t;
};

module StaticWorkspaceData: {
[@deriving (show, yojson({strict: false}))]
type t = {
id: string,
name: string,
};

let global: t;
};

module Extension: {
[@deriving (show, yojson({strict: false}))]
type t;
Expand All @@ -224,6 +234,7 @@ module InitData: {
appLanguage: string,
appRoot: Oni_Core.Uri.t,
globalStorageHome: option(Oni_Core.Uri.t),
workspaceStorageHome: option(Oni_Core.Uri.t),
userHome: option(Oni_Core.Uri.t),
// TODO
/*
Expand Down Expand Up @@ -277,6 +288,7 @@ module InitData: {
autoStart: bool,
remote: Remote.t,
telemetryInfo: TelemetryInfo.t,
workspace: StaticWorkspaceData.t,
};

let create:
Expand All @@ -290,6 +302,7 @@ module InitData: {
~autoStart: bool=?,
~remote: Remote.t=?,
~telemetryInfo: TelemetryInfo.t=?,
~workspace: StaticWorkspaceData.t=?,
list(Extension.t)
) =>
t;
Expand Down
20 changes: 20 additions & 0 deletions src/Exthost/Extension/InitData.re
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ module Extension = {
};
};

module StaticWorkspaceData = {
[@deriving (show, yojson({strict: false}))]
type t = {
id: string,
name: string,
};

let global = {id: "global", name: "global"};
};

module Environment = {
[@deriving (show, yojson({strict: false}))]
type t = {
Expand All @@ -106,6 +116,7 @@ module Environment = {
appLanguage: string,
appRoot: Uri.t,
globalStorageHome: option(Uri.t),
workspaceStorageHome: option(Uri.t),
userHome: option(Uri.t),
// TODO
/*
Expand All @@ -123,6 +134,11 @@ module Environment = {
// TODO - INTL: Get proper user language
appLanguage: "en-US",
appRoot: Revery.Environment.getExecutingDirectory() |> Uri.fromPath,
// TODO: Set up correctly
workspaceStorageHome:
Oni_Core.Filesystem.getWorkspaceStorageFolder()
|> Result.to_option
|> Option.map(Uri.fromFilePath),
globalStorageHome:
Oni_Core.Filesystem.getGlobalStorageFolder()
|> Result.to_option
Expand Down Expand Up @@ -178,6 +194,7 @@ type t = {
autoStart: bool,
remote: Remote.t,
telemetryInfo: TelemetryInfo.t,
workspace: StaticWorkspaceData.t,
};

let create =
Expand All @@ -191,13 +208,15 @@ let create =
~autoStart=true,
~remote=Remote.default,
~telemetryInfo=TelemetryInfo.default,
~workspace=StaticWorkspaceData.global,
extensions,
) => {
let environment =
switch (environment) {
| None => Environment.default()
| Some(env) => env
};

{
version,
parentPid,
Expand All @@ -211,5 +230,6 @@ let create =
autoStart,
remote,
telemetryInfo,
workspace,
};
};
2 changes: 1 addition & 1 deletion src/Exthost/Exthost.rei
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ module WorkspaceData: {
isUntitled: bool,
};

let fromUri: (~name: string, ~id: string, Uri.t) => t;
let fromUri: (~name: string, Uri.t) => t;
let fromPath: string => t;

let encode: Json.encoder(t);
Expand Down
13 changes: 10 additions & 3 deletions src/Exthost/WorkspaceData.re
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,23 @@ let encode = workspace =>
])
);

let fromUri = (~name, ~id, uri) => {
id,
module Internal = {
let hash =
fun
| "global" => "global"
| value => value |> Hashtbl.hash |> Printf.sprintf("%x");
};

let fromUri = (~name, uri) => {
id: Internal.hash(Uri.toString(uri)),
name,
folders: [{uri, name, index: 0}],
isUntitled: false,
configuration: None,
};

let fromPath = path => {
id: path,
id: Internal.hash(path),
name: path,
configuration: None,
isUntitled: false,
Expand Down
10 changes: 10 additions & 0 deletions src/Store/ExtensionClient.re
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,22 @@ let create =
|> Option.value(~default=originalVersion);
};

let staticWorkspace =
initialWorkspace
|> Option.map(({id, name, _}: Exthost.WorkspaceData.t) => {
Exthost.Extension.InitData.StaticWorkspaceData.{id, name}
})
|> Option.value(
~default=Exthost.Extension.InitData.StaticWorkspaceData.global,
);

let initData =
InitData.create(
~version=extHostVersion,
~parentPid,
~logsLocation,
~logFile,
~workspace=staticWorkspace,
extensionInfo,
);

Expand Down
6 changes: 5 additions & 1 deletion test/Exthost/WorkspaceTest.re
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module TestWorkspaceEvent = {
type t = {
eventType: string,
workspacePath: option(string),
storagePath: option(string),
added: int,
removed: int,
};
Expand All @@ -38,6 +39,7 @@ module TestWorkspaceEvent = {
{
eventType: field.required("type", string),
workspacePath: field.optional("workspacePath", string),
storagePath: field.optional("storagePath", string),
added: field.required("added", int),
removed: field.required("removed", int),
}
Expand Down Expand Up @@ -78,7 +80,9 @@ describe("WorkspaceTest", ({test, _}) => {
),
)
|> waitForWorkspaceEvent(~name="Workspace showActive", evt => {
evt.eventType == "workspace.show" && evt.workspacePath != None
evt.eventType == "workspace.show"
&& evt.workspacePath != None
&& evt.storagePath != None
})
|> Test.withClient(
Request.Workspace.acceptWorkspaceData(~workspace=Some(workspace1)),
Expand Down
1 change: 1 addition & 0 deletions test/collateral/extensions/oni-workspace/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function activate(context) {
showData({
type: "workspace.show",
workspacePath: vscode.workspace.rootPath,
storagePath: context.storagePath,
added: 0,
removed: 0,
});
Expand Down