Refactors commands to use typed args objects

This commit is contained in:
Eric Amodio
2017-05-14 01:48:07 -04:00
parent ee29596d45
commit 1acc183621
43 changed files with 2366 additions and 1761 deletions

View File

@@ -1,33 +1,35 @@
'use strict';
import { TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, Commands, openEditor } from './common';
import { TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, Commands, getCommandUri, openEditor } from './common';
import { GitService } from '../gitService';
import { Logger } from '../logger';
export interface OpenChangedFilesCommandArgs {
uris?: Uri[];
}
export class OpenChangedFilesCommand extends ActiveEditorCommand {
constructor(private git: GitService) {
super(Commands.OpenChangedFiles);
}
async execute(editor: TextEditor, uri?: Uri, uris?: Uri[]) {
if (!(uri instanceof Uri)) {
uri = editor && editor.document && editor.document.uri;
}
async execute(editor: TextEditor, uri?: Uri, args: OpenChangedFilesCommandArgs = {}) {
uri = getCommandUri(uri, editor);
try {
if (!uris) {
if (args.uris === undefined) {
const repoPath = await this.git.getRepoPathFromUri(uri);
if (!repoPath) return window.showWarningMessage(`Unable to open changed files`);
if (repoPath === undefined) return window.showWarningMessage(`Unable to open changed files`);
const status = await this.git.getStatusForRepo(repoPath);
if (!status) return window.showWarningMessage(`Unable to open changed files`);
if (status === undefined) return window.showWarningMessage(`Unable to open changed files`);
uris = status.files.filter(_ => _.status !== 'D').map(_ => _.Uri);
args.uris = status.files.filter(_ => _.status !== 'D').map(_ => _.Uri);
}
for (const uri of uris) {
await openEditor(uri, true);
for (const uri of args.uris) {
await openEditor(uri, { preserveFocus: true, preview: false } as TextDocumentShowOptions);
}
return undefined;