mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-16 17:25:40 -05:00
Refactors commands to use typed args objects
This commit is contained in:
@@ -1,31 +1,33 @@
|
||||
'use strict';
|
||||
import { TextEditor, Uri, window } from 'vscode';
|
||||
import { ActiveEditorTracker } from '../activeEditorTracker';
|
||||
import { ActiveEditorCommand, Commands } from './common';
|
||||
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
|
||||
import { TextEditorComparer, UriComparer } from '../comparers';
|
||||
import { GitService } from '../gitService';
|
||||
import { Logger } from '../logger';
|
||||
|
||||
export interface CloseUnchangedFilesCommandArgs {
|
||||
uris?: Uri[];
|
||||
}
|
||||
|
||||
export class CloseUnchangedFilesCommand extends ActiveEditorCommand {
|
||||
|
||||
constructor(private git: GitService) {
|
||||
super(Commands.CloseUnchangedFiles);
|
||||
}
|
||||
|
||||
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: CloseUnchangedFilesCommandArgs = {}) {
|
||||
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 close unchanged files`);
|
||||
if (repoPath === undefined) return window.showWarningMessage(`Unable to close unchanged files`);
|
||||
|
||||
const status = await this.git.getStatusForRepo(repoPath);
|
||||
if (!status) return window.showWarningMessage(`Unable to close unchanged files`);
|
||||
if (status === undefined) return window.showWarningMessage(`Unable to close unchanged files`);
|
||||
|
||||
uris = status.files.map(_ => _.Uri);
|
||||
args.uris = status.files.map(_ => _.Uri);
|
||||
}
|
||||
|
||||
const editorTracker = new ActiveEditorTracker();
|
||||
@@ -35,7 +37,7 @@ export class CloseUnchangedFilesCommand extends ActiveEditorCommand {
|
||||
do {
|
||||
if (editor !== undefined) {
|
||||
if ((editor.document !== undefined && editor.document.isDirty) ||
|
||||
uris.some(_ => UriComparer.equals(_, editor!.document && editor!.document.uri))) {
|
||||
args.uris.some(_ => UriComparer.equals(_, editor!.document && editor!.document.uri))) {
|
||||
// If we didn't start with a valid editor, set one once we find it
|
||||
if (active === undefined) {
|
||||
active = editor;
|
||||
|
||||
Reference in New Issue
Block a user