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

Access active source control provider #51734

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 13 additions & 0 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,19 @@ declare module 'vscode' {

//#endregion

//#region scm
export namespace scm {
/**
* The currently active [source control](#SourceControl).
*/
export let activeSourceControl: SourceControl | undefined;
/**
* An [event](#Event) which fires when the active [source control](#SourceControl) has changed.
*/
export const onDidChangeActiveSourceControl: Event<SourceControl>;
}
//#endregion

//#region Comments
/**
* Comments provider related APIs are still in early stages, they may be changed significantly during our API experiments.
Expand Down
22 changes: 22 additions & 0 deletions src/vs/workbench/api/electron-browser/mainThreadSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ export class MainThreadSCM implements MainThreadSCMShape {
private _proxy: ExtHostSCMShape;
private _repositories: { [handle: number]: ISCMRepository; } = Object.create(null);
private _inputDisposables: { [handle: number]: IDisposable; } = Object.create(null);
private _focusDisposables: { [handle: number]: IDisposable; } = Object.create(null);
private _focusedRepository: ISCMRepository | undefined;
private _disposables: IDisposable[] = [];

constructor(
Expand All @@ -281,6 +283,10 @@ export class MainThreadSCM implements MainThreadSCMShape {
.forEach(id => this._inputDisposables[id].dispose());
this._inputDisposables = Object.create(null);

Object.keys(this._focusDisposables)
.forEach(id => this._focusDisposables[id].dispose());
this._focusDisposables = Object.create(null);

this._disposables = dispose(this._disposables);
}

Expand All @@ -289,8 +295,21 @@ export class MainThreadSCM implements MainThreadSCMShape {
const repository = this.scmService.registerSCMProvider(provider);
this._repositories[handle] = repository;

if (!this._focusedRepository) {
this._focusedRepository = repository;
this._proxy.$acceptActiveSourceControlChange(handle);
}

const inputDisposable = repository.input.onDidChange(value => this._proxy.$onInputBoxValueChange(handle, value));
this._inputDisposables[handle] = inputDisposable;

const focusDisposable = repository.onDidFocus(_ => this.onDidFocus(handle, repository));
this._focusDisposables[handle] = focusDisposable;
}

onDidFocus(handle: number, repository: ISCMRepository) {
this._focusedRepository = repository;
this._proxy.$acceptActiveSourceControlChange(handle);
}

$updateSourceControl(handle: number, features: SCMProviderFeatures): void {
Expand All @@ -314,6 +333,9 @@ export class MainThreadSCM implements MainThreadSCMShape {
this._inputDisposables[handle].dispose();
delete this._inputDisposables[handle];

this._focusDisposables[handle].dispose();
delete this._focusDisposables[handle];

repository.dispose();
delete this._repositories[handle];
}
Expand Down
6 changes: 6 additions & 0 deletions src/vs/workbench/api/node/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,12 @@ export function createApiFactory(
get inputBox() {
return extHostSCM.getLastInputBox(extension);
},
get activeSourceControl() {
return extHostSCM.activeSourceControl;
},
get onDidChangeActiveSourceControl() {
return extHostSCM.onDidChangeActiveSourceControl;
},
createSourceControl(id: string, label: string, rootUri?: vscode.Uri) {
return extHostSCM.createSourceControl(extension, id, label, rootUri);
}
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ export interface ExtHostTerminalServiceShape {
export interface ExtHostSCMShape {
$provideOriginalResource(sourceControlHandle: number, uri: UriComponents): TPromise<UriComponents>;
$onInputBoxValueChange(sourceControlHandle: number, value: string): TPromise<void>;
$acceptActiveSourceControlChange(sourceControlHandle: number): TPromise<void>;
$executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number): TPromise<void>;
$validateInput(sourceControlHandle: number, value: string, cursorPosition: number): TPromise<[string, number] | undefined>;
}
Expand Down
25 changes: 22 additions & 3 deletions src/vs/workbench/api/node/extHostSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,12 @@ export class ExtHostSCM implements ExtHostSCMShape {
private _proxy: MainThreadSCMShape;
private _sourceControls: Map<ProviderHandle, ExtHostSourceControl> = new Map<ProviderHandle, ExtHostSourceControl>();
private _sourceControlsByExtension: Map<string, ExtHostSourceControl[]> = new Map<string, ExtHostSourceControl[]>();

private _onDidChangeActiveProvider = new Emitter<vscode.SourceControl>();
get onDidChangeActiveProvider(): Event<vscode.SourceControl> { return this._onDidChangeActiveProvider.event; }
private _activeSourceControl: vscode.SourceControl | undefined;
get activeSourceControl(): vscode.SourceControl | undefined {
return this._activeSourceControl;
}
private _onDidChangeActiveSourceControl = new Emitter<vscode.SourceControl>();
get onDidChangeActiveSourceControl(): Event<vscode.SourceControl> { return this._onDidChangeActiveSourceControl.event; }

constructor(
mainContext: IMainContext,
Expand Down Expand Up @@ -568,6 +571,22 @@ export class ExtHostSCM implements ExtHostSCMShape {
return TPromise.as(null);
}

$acceptActiveSourceControlChange(sourceControlHandle: number): TPromise<void> {
this.logService.trace('ExtHostSCM#$acceptActiveSourceControlChange', sourceControlHandle);
const sourceControl = this._sourceControls.get(sourceControlHandle);

if (!sourceControl) {
return TPromise.as(null);
}

if (this._activeSourceControl !== sourceControl) {
this._activeSourceControl = sourceControl;
this._onDidChangeActiveSourceControl.fire(this.activeSourceControl);
}

return TPromise.as(null);
}

async $executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number): TPromise<void> {
this.logService.trace('ExtHostSCM#$executeResourceCommand', sourceControlHandle, groupHandle, handle);

Expand Down