Skip to content

Commit

Permalink
SCM: Add basic handling of source control providers (onivim#1258)
Browse files Browse the repository at this point in the history
* add SCM capabilities to dev extension for testing

* model

* handle basic source control provider messages

* typo
  • Loading branch information
glennsl authored Jan 25, 2020
1 parent b5c1ae3 commit 5a693c2
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 5 deletions.
31 changes: 30 additions & 1 deletion development_extensions/oni-dev-extension/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,36 @@ function activate(context) {
// This helps us create a test case to validate buffer manipulations
cleanup(vscode.commands.registerCommand('developer.oni.getBufferText', () => {
vscode.window.showInformationMessage("fulltext:" + latestText);
}));
}));

function createResourceUri(relativePath) {
const absolutePath = path.join(vscode.workspace.rootPath, relativePath);
return vscode.Uri.file(absolutePath);
}

const testSCM = vscode.scm.createSourceControl('test', 'Test');

const index = testSCM.createResourceGroup('index', 'Index');
index.resourceStates = [
{ resourceUri: createResourceUri('README.md') },
{ resourceUri: createResourceUri('src/test/api.ts') }
];

const workingTree = testSCM.createResourceGroup('workingTree', 'Changes');
workingTree.resourceStates = [
{ resourceUri: createResourceUri('.travis.yml') },
{ resourceUri: createResourceUri('README.md') }
];

testSCM.count = 13;

testSCM.quickDiffProvider = {
provideOriginalResource: (uri, _token) => {
return vscode.Uri.file("README.md.old");
}
};

testSCM.dispose();
}

// this method is called when your extension is deactivated
Expand Down
67 changes: 63 additions & 4 deletions src/Extensions/ExtHostClient.re
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ module Log = (val Log.withNamespace("Oni2.Extensions.ExtHostClient"));

type t = ExtHostTransport.t;

type msg =
| RegisterSourceControl({
handle: int,
id: string,
label: string,
rootUri: option(Uri.t),
})
| UnregisterSourceControl({handle: int})
| UpdateSourceControl({
handle: int,
hasQuickDiffProvider: option(bool),
count: option(int),
commitTemplate: option(string),
});
// acceptInputCommand: option(_),
// statusBarCommands: option(_),

type unitCallback = unit => unit;
let noop = () => ();
let noop1 = _ => ();
Expand All @@ -45,6 +62,7 @@ let start =
~onRegisterSuggestProvider=noop2,
~onShowMessage=noop1,
~onStatusBarSetEntry,
~dispatch,
setup: Setup.t,
) => {
// Hold onto a reference of the client, so that we can pass it along with
Expand All @@ -62,6 +80,7 @@ let start =
client^,
);
Ok(None);

| ("MainThreadLanguageFeatures", "$registerDefinitionSupport", args) =>
Option.iter(
client => {
Expand All @@ -71,6 +90,7 @@ let start =
client^,
);
Ok(None);

| ("MainThreadLanguageFeatures", "$registerReferenceSupport", args) =>
Option.iter(
client => {
Expand All @@ -80,6 +100,7 @@ let start =
client^,
);
Ok(None);

| (
"MainThreadLanguageFeatures",
"$registerDocumentHighlightProvider",
Expand All @@ -93,6 +114,7 @@ let start =
client^,
);
Ok(None);

| ("MainThreadLanguageFeatures", "$registerSuggestSupport", args) =>
Option.iter(
client => {
Expand All @@ -102,30 +124,37 @@ let start =
client^,
);
Ok(None);

| ("MainThreadOutputService", "$append", [_, `String(msg)]) =>
onOutput(msg);
Ok(None);

| ("MainThreadDiagnostics", "$changeMany", args) =>
In.Diagnostics.parseChangeMany(args)
|> Option.iter(onDiagnosticsChangeMany);
Ok(None);

| ("MainThreadDiagnostics", "$clear", args) =>
In.Diagnostics.parseClear(args) |> Option.iter(onDiagnosticsClear);
Ok(None);

| ("MainThreadTelemetry", "$publicLog", [`String(eventName), json]) =>
onTelemetry(eventName ++ ":" ++ Yojson.Safe.to_string(json));
Ok(None);

| (
"MainThreadMessageService",
"$showMessage",
[_level, `String(s), _extInfo, ..._],
) =>
onShowMessage(s);
Ok(None);

| ("MainThreadExtensionService", "$onDidActivateExtension", [v, ..._]) =>
let id = Protocol.PackedString.parse(v);
onDidActivateExtension(id);
Ok(None);

| (
"MainThreadExtensionService",
"$onExtensionActivationFailed",
Expand All @@ -134,12 +163,45 @@ let start =
let id = Protocol.PackedString.parse(v);
onExtensionActivationFailed(id);
Ok(None);

| ("MainThreadCommands", "$registerCommand", [`String(v), ..._]) =>
onRegisterCommand(v);
Ok(None);

| ("MainThreadStatusBar", "$setEntry", args) =>
In.StatusBar.parseSetEntry(args) |> Option.iter(onStatusBarSetEntry);
Ok(None);

| ("MainThreadSCM", "$registerSourceControl", args) =>
switch (args) {
| [`Int(handle), `String(id), `String(label), rootUri] =>
let rootUri = Core.Uri.of_yojson(rootUri) |> Utility.Result.to_option;
dispatch(RegisterSourceControl({handle, id, label, rootUri}));
| _ =>
Log.error(
"Unexpected arguments for MainThreadSCM.$registerSourceControl",
)
};
Ok(None);

| ("MainThreadSCM", "$unregisterSourceControl", [`Int(handle)]) =>
dispatch(UnregisterSourceControl({handle: handle}));
Ok(None);

| ("MainThreadSCM", "$updateSourceControl", [`Int(handle), features]) =>
open Yojson.Safe.Util;
dispatch(
UpdateSourceControl({
handle,
hasQuickDiffProvider:
features |> member("hasQuickDiffProvider") |> to_bool_option,
count: features |> member("count") |> to_int_option,
commitTemplate:
features |> member("commitTemplate") |> to_string_option,
}),
);
Ok(None);

| (scope, method, argsAsJson) =>
Log.warnf(m =>
m(
Expand Down Expand Up @@ -293,9 +355,6 @@ let provideReferences = (id, uri, position, client) => {
promise;
};

let send = (client, msg) => {
let _ = ExtHostTransport.send(client, msg);
();
};
let send = (client, msg) => ExtHostTransport.send(client, msg);

let close = client => ExtHostTransport.close(client);
18 changes: 18 additions & 0 deletions src/Extensions/ExtHostClient.rei
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ module Core = Oni_Core;

type t;

type msg =
| RegisterSourceControl({
handle: int,
id: string,
label: string,
rootUri: option(Core.Uri.t),
})
| UnregisterSourceControl({handle: int})
| UpdateSourceControl({
handle: int,
hasQuickDiffProvider: option(bool),
count: option(int),
commitTemplate: option(string),
});
// acceptInputCommand: option(_),
// statusBarCommands: option(_),

type unitCallback = unit => unit;

let start:
Expand Down Expand Up @@ -33,6 +50,7 @@ let start:
~onRegisterSuggestProvider: (t, Protocol.SuggestProvider.t) => unit=?,
~onShowMessage: string => unit=?,
~onStatusBarSetEntry: ((int, string, int, int)) => unit,
~dispatch: msg => unit,
Core.Setup.t
) =>
t;
Expand Down
1 change: 1 addition & 0 deletions src/Model/Actions.re
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ type t =
| EnableZenMode
| DisableZenMode
| CopyActiveFilepathToClipboard
| SCM(SCM.msg)
| SearchStart
| SearchHotkey
| Search(Feature_Search.msg)
Expand Down
1 change: 1 addition & 0 deletions src/Model/Oni_Model.re
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module Notification = Notification;
module Notifications = Notifications;
module Pane = Pane;
module References = References;
module SCM = SCM;
module Selection = Selection;
module Selectors = Selectors;
module SideBar = SideBar;
Expand Down
52 changes: 52 additions & 0 deletions src/Model/SCM.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
open Oni_Core;

module Group = {
[@deriving show({with_path: false})]
type t = {
handle: int,
id: string,
label: string,
hideWhenEmpty: bool,
};
};

module Provider = {
[@deriving show({with_path: false})]
type t = {
handle: int,
id: string,
label: string,
rootUri: option(Uri.t),
groups: list(Group.t),
hasQuickDiffProvider: bool,
count: int,
commitTemplate: string,
};
};

[@deriving show({with_path: false})]
type t = {providers: list(Provider.t)};

let initial = {providers: []};

[@deriving show({with_path: false})]
type msg =
| NewProvider({
handle: int,
id: string,
label: string,
rootUri: option(Uri.t),
})
| LostProvider({handle: int})
| CountChanged({
handle: int,
count: int,
})
| QuickDiffProviderChanged({
handle: int,
available: bool,
})
| CommitTemplateChanged({
handle: int,
template: string,
});
2 changes: 2 additions & 0 deletions src/Model/State.re
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type t = {
lifecycle: Lifecycle.t,
notifications: Notifications.t,
references: References.t,
scm: SCM.t,
sneak: Sneak.t,
statusBar: StatusBarModel.t,
windowManager: WindowManager.t,
Expand Down Expand Up @@ -95,6 +96,7 @@ let create: unit => t =
languageInfo: Ext.LanguageInfo.initial,
notifications: Notifications.initial,
references: References.initial,
scm: SCM.initial,
sneak: Sneak.initial,
statusBar: StatusBarModel.create(),
windowManager: WindowManager.create(),
Expand Down
Loading

0 comments on commit 5a693c2

Please sign in to comment.