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(exthost): Fix error when trying to read package metadata #1788

Merged
merged 7 commits into from
May 20, 2020
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: 0 additions & 1 deletion development_extensions/oni-dev-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "oni-dev-extension",
"description": "Development Extension for Oni",
"version": "0.0.1",
"publisher": "Outrun Labs, LLC",
"repository": "https://github.com/onivim/oni2",
"engines": {
"vscode": "^1.25.0"
Expand Down
11 changes: 3 additions & 8 deletions src/Exthost/Extension/Exthost_Extension.rei
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ module Manifest: {
author: string,
displayName: option(LocalizedToken.t),
description: option(string),
// publisher: option(string),
publisher: option(string),
main: option(string),
icon: option(string),
categories: list(string),
Expand All @@ -131,7 +131,6 @@ module Manifest: {
extensionDependencies: list(string),
extensionPack: list(string),
extensionKind: kind,
// TODO: Bring back
contributes: Contributions.t,
enableProposedApi: bool,
}
Expand Down Expand Up @@ -162,12 +161,8 @@ module Scanner: {
};
};

let load:
(~prefix: option(string)=?, ~category: category, string) =>
option(ScanResult.t);
let scan:
(~prefix: option(string)=?, ~category: category, string) =>
list(ScanResult.t);
let load: (~category: category, string) => option(ScanResult.t);
let scan: (~category: category, string) => list(ScanResult.t);
};

module InitData: {
Expand Down
3 changes: 1 addition & 2 deletions src/Exthost/Extension/InitData.re
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ module Extension = {
};

let ofManifestAndPath = (manifest: Manifest.t, path: string) => {
// TODO: Is identifier right?
identifier: manifest.name,
identifier: Manifest.identifier(manifest),
extensionLocation: path |> Uri.fromPath,
name: manifest.name,
main: manifest.main,
Expand Down
10 changes: 9 additions & 1 deletion src/Exthost/Extension/Manifest.re
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type t = {
author: string,
displayName: option(LocalizedToken.t),
description: option(string),
// publisher: option(string),
publisher: option(string),
main: option(string),
icon: option(string),
categories: list(string),
Expand All @@ -32,6 +32,13 @@ and kind =
| Ui
| Workspace;

let identifier = manifest => {
switch (manifest.publisher) {
| Some(publisher) => publisher ++ "." ++ manifest.name
| None => manifest.name
};
};

module Decode = {
open Json.Decode;

Expand Down Expand Up @@ -65,6 +72,7 @@ module Decode = {
),
displayName: field.optional("displayName", LocalizedToken.decode),
description: field.optional("description", string),
publisher: field.optional("publisher", string),
main: field.optional("main", string),
icon: field.optional("icon", string),
categories: field.withDefault("categories", [], list(string)),
Expand Down
16 changes: 4 additions & 12 deletions src/Exthost/Extension/Scanner.re
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let _getLocalizations = path =>
LocalizationDictionary.initial;
};

let load = (~prefix=None, ~category, packageFile) => {
let load = (~category, packageFile) => {
let json = Yojson.Safe.from_file(packageFile);
let directory = Filename.dirname(packageFile);
let nlsPath = Path.join(directory, "package.nls.json");
Expand All @@ -52,15 +52,7 @@ let load = (~prefix=None, ~category, packageFile) => {

switch (Json.Decode.decode_value(Manifest.decode, json)) {
| Ok(parsedManifest) =>
let manifest =
parsedManifest
|> remapManifest(directory)
|> Manifest.updateName(name =>
prefix
|> Option.map(prefix => prefix ++ "." ++ name)
|> Option.value(~default=name)
)
|> localize;
let manifest = parsedManifest |> remapManifest(directory) |> localize;

Some(ScanResult.{category, manifest, path: directory});

Expand All @@ -76,13 +68,13 @@ let load = (~prefix=None, ~category, packageFile) => {
};
};

let scan = (~prefix=None, ~category, directory: string) => {
let scan = (~category, directory: string) => {
Sys.readdir(directory)
|> Array.to_list
|> List.map(Path.join(directory))
|> List.filter(Sys.is_directory)
|> List.map(dir => Path.join(dir, "package.json"))
|> List.filter(Sys.file_exists)
|> List.map(load(~category, ~prefix))
|> List.map(load(~category))
|> List.filter_map(Fun.id);
};
1 change: 0 additions & 1 deletion src/Store/StoreThread.re
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ let discoverExtensions =
Scanner.scan(
// The extension host assumes bundled extensions start with 'vscode.'
~category=Bundled,
~prefix=Some("vscode"),
setup.bundledExtensionsPath,
);

Expand Down
51 changes: 51 additions & 0 deletions test/Exthost/ExtensionsTest.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
open TestFramework;

open Oni_Core;
open Exthost;

module TestExtensionsEvent = {
type t = {name: string};

let decode = {
Json.Decode.(
obj(({field, _}) => {name: field.required("name", string)})
);
};
};

let waitForExtensionsEvent = (~name, f, context) => {
context
|> Test.waitForMessage(
~name,
fun
| Msg.MessageService(ShowMessage({message, _})) => {
message
|> Yojson.Safe.from_string
|> Json.Decode.decode_value(TestExtensionsEvent.decode)
|> Result.map(f)
|> Result.value(~default=false);
}
| _ => false,
);
};

// Test cases for the vscode extesnsions API:
// https://code.visualstudio.com/api/references/vscode-api#extensions
describe("ExtensionsTest", ({test, _}) => {
test("change workspaces", ({expect, _}) => {
Test.startWithExtensions(["oni-extensions"])
|> Test.waitForExtensionActivation("outrunlabs.oni-extensions")
|> Test.withClient(
Request.Commands.executeContributedCommand(
~arguments=[`String("outrunlabs.oni-extensions")],
~command="testExtensions.getPackageJSON",
),
)
|> waitForExtensionsEvent(~name="Extensions PackageJSON", json => {
expect.string(json.name).toEqual("oni-extensions");
true;
})
|> Test.terminate
|> Test.waitForProcessClosed
})
});
2 changes: 1 addition & 1 deletion test/Exthost/Test.re
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ let startWithExtensions =
extensions
|> List.map(Rench.Path.join(rootPath))
|> List.map(p => Rench.Path.join(p, "package.json"))
|> List.map(Scanner.load(~prefix=None, ~category=Scanner.Bundled))
|> List.map(Scanner.load(~category=Scanner.Bundled))
|> List.filter_map(v => v)
|> List.map((Extension.Scanner.ScanResult.{manifest, path, _}) => {
InitData.Extension.ofManifestAndPath(manifest, path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "oni-activation-events",
"description": "Minimal HelloWorld example for VS Code",
"version": "0.0.1",
"publisher": "vscode-samples",
"repository": "https://github.com/Microsoft/vscode-extension-samples/helloworld-minimal-sample",
"engines": {
"vscode": "^1.25.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "oni-always-activate",
"description": "Minimal HelloWorld example for VS Code",
"version": "0.0.1",
"publisher": "vscode-samples",
"repository": "https://github.com/Microsoft/vscode-extension-samples/helloworld-minimal-sample",
"engines": {
"vscode": "^1.25.0"
Expand Down
1 change: 0 additions & 1 deletion test/collateral/extensions/oni-basic-events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "oni-basic-events",
"description": "Minimal HelloWorld example for VS Code",
"version": "0.0.1",
"publisher": "vscode-samples",
"repository": "https://github.com/Microsoft/vscode-extension-samples/helloworld-minimal-sample",
"engines": {
"vscode": "^1.25.0"
Expand Down
1 change: 0 additions & 1 deletion test/collateral/extensions/oni-configuration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "oni-configuration",
"description": "Configuration API test",
"version": "0.0.1",
"publisher": "vscode-samples",
"repository": "https://github.com/Microsoft/vscode-extension-samples/helloworld-minimal-sample",
"engines": {
"vscode": "^1.25.0"
Expand Down
1 change: 0 additions & 1 deletion test/collateral/extensions/oni-diagnostics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "oni-diagnostics",
"description": "Minimal HelloWorld example for VS Code",
"version": "0.0.1",
"publisher": "vscode-samples",
"repository": "https://github.com/Microsoft/vscode-extension-samples/helloworld-minimal-sample",
"engines": {
"vscode": "^1.25.0"
Expand Down
1 change: 0 additions & 1 deletion test/collateral/extensions/oni-document-sync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "oni-document-sync",
"description": "Minimal HelloWorld example for VS Code",
"version": "0.0.1",
"publisher": "vscode-samples",
"repository": "https://github.com/Microsoft/vscode-extension-samples/helloworld-minimal-sample",
"engines": {
"vscode": "^1.25.0"
Expand Down
31 changes: 31 additions & 0 deletions test/collateral/extensions/oni-extensions/extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const vscode = require('vscode');

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed

/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
const showData = (val) => {
vscode.window.showInformationMessage(JSON.stringify(val));
};

const disposable0 = vscode.commands.registerCommand("testExtensions.getPackageJSON", (args) => {

const extension = vscode.extensions.getExtension(args);
showData(extension.packageJSON);
});

context.subscriptions.push(disposable0);
}

// this method is called when your extension is deactivated
function deactivate() {}

module.exports = {
activate,
deactivate
}
18 changes: 18 additions & 0 deletions test/collateral/extensions/oni-extensions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "oni-extensions",
"description": "Test extension to exercise the vscode.extensions API",
"version": "0.0.1",
"publisher": "outrunlabs",
"repository": "https://github.com/Microsoft/vscode-extension-samples/helloworld-minimal-sample",
"engines": {
"vscode": "^1.25.0"
},
"activationEvents": ["*"],
"main": "./extension.js",
"scripts": {
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"vscode": "^1.1.22"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "oni-language-features",
"description": "Minimal HelloWorld example for VS Code",
"version": "0.0.1",
"publisher": "vscode-samples",
"repository": "https://github.com/Microsoft/vscode-extension-samples/helloworld-minimal-sample",
"engines": {
"vscode": "^1.25.0"
Expand Down
1 change: 0 additions & 1 deletion test/collateral/extensions/oni-scm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "oni-scm",
"description": "SCM extension for Onivim tests",
"version": "0.0.1",
"publisher": "vscode-samples",
"repository": "https://github.com/Microsoft/vscode-extension-samples/helloworld-minimal-sample",
"engines": {
"vscode": "^1.25.0"
Expand Down
1 change: 0 additions & 1 deletion test/collateral/extensions/oni-uri/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "oni-uri",
"description": "Minimal HelloWorld example for VS Code",
"version": "0.0.1",
"publisher": "vscode-samples",
"repository": "https://github.com/Microsoft/vscode-extension-samples/helloworld-minimal-sample",
"engines": {
"vscode": "^1.25.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "oni-virtual-document",
"description": "Minimal HelloWorld example for VS Code",
"version": "0.0.1",
"publisher": "vscode-samples",
"repository": "https://github.com/Microsoft/vscode-extension-samples/helloworld-minimal-sample",
"engines": {
"vscode": "^1.25.0"
Expand Down
1 change: 0 additions & 1 deletion test/collateral/extensions/oni-workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "oni-workspace",
"description": "Minimal HelloWorld example for VS Code",
"version": "0.0.1",
"publisher": "vscode-samples",
"repository": "https://github.com/Microsoft/vscode-extension-samples/helloworld-minimal-sample",
"engines": {
"vscode": "^1.25.0"
Expand Down