Skip to content

Commit

Permalink
GH-3397: Stub for the interactive Git prompt.
Browse files Browse the repository at this point in the history
Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
Akos Kitta committed Nov 7, 2018
1 parent 7f9ee3e commit 58c229e
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/git/src/browser/git-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { GitRepositoryTracker } from './git-repository-tracker';
import { GitCommitMessageValidator } from './git-commit-message-validator';
import { GitSyncService } from './git-sync-service';
import { GitErrorHandler } from './git-error-handler';
import { GitPrompt, GitPromptServer, GitPromptServerProxy, ReconnectingGitPromptServer } from '../common/git-prompt';

import '../../src/browser/style/index.css';

Expand Down Expand Up @@ -72,4 +73,8 @@ export default new ContainerModule(bind => {

bind(GitSyncService).toSelf().inSingletonScope();
bind(GitErrorHandler).toSelf().inSingletonScope();

bind(GitPrompt).toSelf();
bind(GitPromptServerProxy).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, GitPrompt.WS_PATH)).inSingletonScope();
bind(GitPromptServer).to(ReconnectingGitPromptServer).inSingletonScope();
});
2 changes: 2 additions & 0 deletions packages/git/src/browser/git-view-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { GitWidget } from './git-widget';
import { GitRepositoryTracker } from './git-repository-tracker';
import { GitQuickOpenService } from './git-quick-open-service';
import { GitSyncService } from './git-sync-service';
import { GitPrompt } from '../common/git-prompt';

export const GIT_WIDGET_FACTORY_ID = 'git';

Expand Down Expand Up @@ -95,6 +96,7 @@ export class GitViewContribution extends AbstractViewContribution<GitWidget> imp
@inject(GitQuickOpenService) protected readonly quickOpenService: GitQuickOpenService;
@inject(GitRepositoryTracker) protected readonly repositoryTracker: GitRepositoryTracker;
@inject(GitSyncService) protected readonly syncService: GitSyncService;
@inject(GitPrompt) protected readonly prompt: GitPrompt;

constructor() {
super({
Expand Down
100 changes: 100 additions & 0 deletions packages/git/src/common/git-prompt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/********************************************************************************
* Copyright (C) 2018 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { inject, injectable, postConstruct } from 'inversify';
// import { Event, Emitter } from '@theia/core/lib/common/event';
import { JsonRpcServer } from '@theia/core/lib/common/messaging/proxy-factory';
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
import { JsonRpcProxy } from '@theia/core';

export const GitPromptServer = Symbol('GitPromptServer');
export interface GitPromptServer extends JsonRpcServer<GitPromptClient> {
}

export const GitPromptServerProxy = Symbol('GitPromptServerProxy');
export interface GitPromptServerProxy extends JsonRpcProxy<GitPromptServer> {
}

@injectable()
export class GitPrompt implements GitPromptClient, Disposable {

@inject(GitPromptServer)
protected readonly server: GitPromptServer;

protected readonly toDispose = new DisposableCollection();

@postConstruct()
protected init(): void {
this.server.setClient(this);
}

dispose(): void {
this.toDispose.dispose();
}

// TODO password?
async ask(question: string): Promise<string | undefined> {
console.log('ask', question);
return undefined;
}

async confirm(question: string): Promise<boolean | undefined> {
console.log('confirm', question);
return undefined;
}

}

export namespace GitPrompt {

/**
* Unique WS endpoint path for the Git prompt service.
*/
export const WS_PATH = 'services/git-prompt';

}

export const GitPromptClient = Symbol('GitPromptClient');
export interface GitPromptClient {

ask(question: string): Promise<string | undefined>;

confirm(question: string): Promise<boolean | undefined>;

// XXX support for `select`?

}

@injectable()
export class ReconnectingGitPromptServer implements GitPromptServer {

@inject(GitPromptServerProxy)
protected readonly proxy: GitPromptServerProxy;

@postConstruct()
protected init(): void {
// this.proxy.onDidCloseConnection(() => this.rec)
}

setClient(client: GitPromptClient): void {
this.proxy.setClient(client);
}

dispose(): void {
this.proxy.dispose();
}

}
2 changes: 2 additions & 0 deletions packages/git/src/electron-node/askpass/askpass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export interface AskpassEnvironment {
readonly THEIA_GIT_ASKPASS_HANDLE?: string;
}

// TODO !!! no console.error/log !!!

@injectable()
export class Askpass implements Disposable {

Expand Down
47 changes: 47 additions & 0 deletions packages/git/src/node/dugite-git-prompt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/********************************************************************************
* Copyright (C) 2018 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable } from 'inversify';
import { GitPromptServer, GitPromptClient } from '../common/git-prompt';

@injectable()
export class DugiteGitPromptServer implements GitPromptServer, GitPromptClient {

protected client: GitPromptClient | undefined;

dispose(): void {
}

setClient(client: GitPromptClient | undefined): void {
this.client = client;
}

async ask(question: string): Promise<string | undefined> {
if (this.client) {
return this.client.ask(question);
}
return undefined;
}

async confirm(question: string): Promise<boolean | undefined> {
if (this.client) {
return this.client.confirm(question);
}
return undefined;

}

}
5 changes: 5 additions & 0 deletions packages/git/src/node/dugite-git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { GitRepositoryManager } from './git-repository-manager';
import { GitLocator } from './git-locator/git-locator-protocol';
import { GitExecProvider } from './git-exec-provider';
import { GitEnvProvider } from './env/git-env-provider';
import { DugiteGitPromptServer } from './dugite-git-prompt';

/**
* Parsing and converting raw Git output into Git model instances.
Expand Down Expand Up @@ -318,6 +319,9 @@ export class DugiteGit implements Git {
@inject(GitEnvProvider)
protected readonly envProvider: GitEnvProvider;

@inject(DugiteGitPromptServer)
protected readonly promptServer: DugiteGitPromptServer;

protected gitEnv: Deferred<Object> = new Deferred();

@postConstruct()
Expand Down Expand Up @@ -363,6 +367,7 @@ export class DugiteGit implements Git {
}

async status(repository: Repository): Promise<WorkingDirectoryStatus> {
this.promptServer.ask('does this work?');
const repositoryPath = this.getFsPath(repository);
const [exec, env] = await Promise.all([this.execProvider.exec(), this.gitEnv.promise]);
const dugiteStatus = await getStatus(repositoryPath, true, this.limit, { exec, env });
Expand Down
17 changes: 17 additions & 0 deletions packages/git/src/node/git-backend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { GitLocator } from './git-locator/git-locator-protocol';
import { GitLocatorClient } from './git-locator/git-locator-client';
import { GitLocatorImpl } from './git-locator/git-locator-impl';
import { GitExecProvider } from './git-exec-provider';
import { GitPromptServer, GitPromptClient, GitPrompt } from '../common/git-prompt';
import { DugiteGitPromptServer } from './dugite-git-prompt';

export interface GitBindingOptions {
readonly bindManager: (binding: interfaces.BindingToSyntax<{}>) => interfaces.BindingWhenOnSyntax<{}>;
Expand Down Expand Up @@ -74,6 +76,11 @@ export function bindRepositoryWatcher(bind: interfaces.Bind): void {
bind(GitWatcherServer).toDynamicValue(context => context.container.get(DugiteGitWatcherServer));
}

export function bindPrompt(bind: interfaces.Bind): void {
bind(DugiteGitPromptServer).toSelf().inSingletonScope(); // TODO is this really singleton, probably not.
bind(GitPromptServer).toDynamicValue(context => context.container.get(DugiteGitPromptServer));
}

export default new ContainerModule(bind => {
bindGit(bind);
bind(ConnectionHandler).toDynamicValue(context =>
Expand All @@ -93,4 +100,14 @@ export default new ContainerModule(bind => {
return server;
})
).inSingletonScope();

bindPrompt(bind);
bind(ConnectionHandler).toDynamicValue(context =>
new JsonRpcConnectionHandler<GitPromptClient>(GitPrompt.WS_PATH, client => {
const server = context.container.get<GitPromptServer>(GitPromptServer);
server.setClient(client);
client.onDidCloseConnection(() => server.dispose());
return server;
})
).inSingletonScope();
});

0 comments on commit 58c229e

Please sign in to comment.