diff --git a/development_extensions/oni-dev-extension/package.json b/development_extensions/oni-dev-extension/package.json index 8c0596af6a..db0f698122 100644 --- a/development_extensions/oni-dev-extension/package.json +++ b/development_extensions/oni-dev-extension/package.json @@ -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" diff --git a/src/Exthost/Extension/Exthost_Extension.rei b/src/Exthost/Extension/Exthost_Extension.rei index cc2623582d..25c4469699 100644 --- a/src/Exthost/Extension/Exthost_Extension.rei +++ b/src/Exthost/Extension/Exthost_Extension.rei @@ -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), @@ -131,7 +131,6 @@ module Manifest: { extensionDependencies: list(string), extensionPack: list(string), extensionKind: kind, - // TODO: Bring back contributes: Contributions.t, enableProposedApi: bool, } @@ -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: { diff --git a/src/Exthost/Extension/InitData.re b/src/Exthost/Extension/InitData.re index c6c1e4b3bf..ef3f99f5cd 100644 --- a/src/Exthost/Extension/InitData.re +++ b/src/Exthost/Extension/InitData.re @@ -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, diff --git a/src/Exthost/Extension/Manifest.re b/src/Exthost/Extension/Manifest.re index c934e8f482..876788f1dc 100644 --- a/src/Exthost/Extension/Manifest.re +++ b/src/Exthost/Extension/Manifest.re @@ -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), @@ -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; @@ -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)), diff --git a/src/Exthost/Extension/Scanner.re b/src/Exthost/Extension/Scanner.re index 01a01b6cf9..daa6e94adc 100644 --- a/src/Exthost/Extension/Scanner.re +++ b/src/Exthost/Extension/Scanner.re @@ -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"); @@ -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}); @@ -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); }; diff --git a/src/Store/StoreThread.re b/src/Store/StoreThread.re index deb537b8b8..9fe63aa219 100644 --- a/src/Store/StoreThread.re +++ b/src/Store/StoreThread.re @@ -27,7 +27,6 @@ let discoverExtensions = Scanner.scan( // The extension host assumes bundled extensions start with 'vscode.' ~category=Bundled, - ~prefix=Some("vscode"), setup.bundledExtensionsPath, ); diff --git a/test/Exthost/ExtensionsTest.re b/test/Exthost/ExtensionsTest.re new file mode 100644 index 0000000000..541ebbd3e6 --- /dev/null +++ b/test/Exthost/ExtensionsTest.re @@ -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 + }) +}); diff --git a/test/Exthost/Test.re b/test/Exthost/Test.re index 2f39a2f0b6..f67a630057 100644 --- a/test/Exthost/Test.re +++ b/test/Exthost/Test.re @@ -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) diff --git a/test/collateral/extensions/oni-activation-events/package.json b/test/collateral/extensions/oni-activation-events/package.json index a6056699da..7b3c072078 100644 --- a/test/collateral/extensions/oni-activation-events/package.json +++ b/test/collateral/extensions/oni-activation-events/package.json @@ -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" diff --git a/test/collateral/extensions/oni-always-activate/package.json b/test/collateral/extensions/oni-always-activate/package.json index 07f1bbc9dd..628c63546a 100644 --- a/test/collateral/extensions/oni-always-activate/package.json +++ b/test/collateral/extensions/oni-always-activate/package.json @@ -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" diff --git a/test/collateral/extensions/oni-basic-events/package.json b/test/collateral/extensions/oni-basic-events/package.json index 8fe3bbb5cc..38a3ca3423 100644 --- a/test/collateral/extensions/oni-basic-events/package.json +++ b/test/collateral/extensions/oni-basic-events/package.json @@ -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" diff --git a/test/collateral/extensions/oni-configuration/package.json b/test/collateral/extensions/oni-configuration/package.json index a1062bc146..80e801044b 100644 --- a/test/collateral/extensions/oni-configuration/package.json +++ b/test/collateral/extensions/oni-configuration/package.json @@ -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" diff --git a/test/collateral/extensions/oni-diagnostics/package.json b/test/collateral/extensions/oni-diagnostics/package.json index 0f84debd86..5d35933dc2 100644 --- a/test/collateral/extensions/oni-diagnostics/package.json +++ b/test/collateral/extensions/oni-diagnostics/package.json @@ -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" diff --git a/test/collateral/extensions/oni-document-sync/package.json b/test/collateral/extensions/oni-document-sync/package.json index 92faf96d34..6a1525a2f9 100644 --- a/test/collateral/extensions/oni-document-sync/package.json +++ b/test/collateral/extensions/oni-document-sync/package.json @@ -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" diff --git a/test/collateral/extensions/oni-extensions/extension.js b/test/collateral/extensions/oni-extensions/extension.js new file mode 100644 index 0000000000..b79e28f3d6 --- /dev/null +++ b/test/collateral/extensions/oni-extensions/extension.js @@ -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 +} diff --git a/test/collateral/extensions/oni-extensions/package.json b/test/collateral/extensions/oni-extensions/package.json new file mode 100644 index 0000000000..8e22ce6ef2 --- /dev/null +++ b/test/collateral/extensions/oni-extensions/package.json @@ -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" + } +} diff --git a/test/collateral/extensions/oni-language-features/package.json b/test/collateral/extensions/oni-language-features/package.json index 020dca0376..c6442aea26 100644 --- a/test/collateral/extensions/oni-language-features/package.json +++ b/test/collateral/extensions/oni-language-features/package.json @@ -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" diff --git a/test/collateral/extensions/oni-scm/package.json b/test/collateral/extensions/oni-scm/package.json index aa074c0cb6..a5748fe6c1 100644 --- a/test/collateral/extensions/oni-scm/package.json +++ b/test/collateral/extensions/oni-scm/package.json @@ -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" diff --git a/test/collateral/extensions/oni-uri/package.json b/test/collateral/extensions/oni-uri/package.json index 8e2ac075eb..eb7acc756f 100644 --- a/test/collateral/extensions/oni-uri/package.json +++ b/test/collateral/extensions/oni-uri/package.json @@ -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" diff --git a/test/collateral/extensions/oni-virtual-document/package.json b/test/collateral/extensions/oni-virtual-document/package.json index c1cfaddbdc..fe0e3d0d2f 100644 --- a/test/collateral/extensions/oni-virtual-document/package.json +++ b/test/collateral/extensions/oni-virtual-document/package.json @@ -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" diff --git a/test/collateral/extensions/oni-workspace/package.json b/test/collateral/extensions/oni-workspace/package.json index 11100141a5..0baf2bd607 100644 --- a/test/collateral/extensions/oni-workspace/package.json +++ b/test/collateral/extensions/oni-workspace/package.json @@ -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"