Skip to content

Commit f8a5d5a

Browse files
committed
Consolidates vscode.diff calls into a helper
1 parent f0a0408 commit f8a5d5a

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/commands/diffWith.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import { isCommit } from '../git/models/commit';
77
import { deletedOrMissing } from '../git/models/constants';
88
import { isShaLike, isUncommitted, shortenRevision } from '../git/models/reference';
99
import { showGenericErrorMessage } from '../messages';
10-
import { command, executeCoreCommand } from '../system/command';
10+
import { command } from '../system/command';
1111
import { Logger } from '../system/logger';
1212
import { basename } from '../system/path';
13+
import { openDiffEditor } from '../system/utils';
1314
import { Command } from './base';
1415

1516
export interface DiffWithCommandArgsRevision {
@@ -179,13 +180,12 @@ export class DiffWithCommand extends Command {
179180
args.showOptions.selection = new Range(args.line, 0, args.line, 0);
180181
}
181182

182-
void (await executeCoreCommand(
183-
'vscode.diff',
183+
await openDiffEditor(
184184
lhs ?? this.container.git.getRevisionUri(deletedOrMissing, args.lhs.uri.fsPath, args.repoPath),
185185
rhs ?? this.container.git.getRevisionUri(deletedOrMissing, args.rhs.uri.fsPath, args.repoPath),
186186
title,
187187
args.showOptions,
188-
));
188+
);
189189
} catch (ex) {
190190
Logger.error(ex, 'DiffWithCommand', 'getVersionedFile');
191191
void showGenericErrorMessage('Unable to open compare');

src/commands/openFileFromRemote.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class OpenFileFromRemoteCommand extends Command {
5454
}
5555

5656
try {
57-
await openEditor(local.uri, { selection: selection, rethrow: true });
57+
await openEditor(local.uri, { selection: selection, throwOnError: true });
5858
} catch {
5959
const uris = await window.showOpenDialog({
6060
title: 'Open local file',

src/system/utils.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,13 @@ export function isTextEditor(editor: TextEditor): boolean {
125125

126126
export async function openEditor(
127127
uri: Uri,
128-
options: TextDocumentShowOptions & { rethrow?: boolean } = {},
128+
options?: TextDocumentShowOptions & { throwOnError?: boolean },
129129
): Promise<TextEditor | undefined> {
130-
const { rethrow, ...opts } = options;
130+
let throwOnError;
131+
if (options != null) {
132+
({ throwOnError, ...options } = options);
133+
}
134+
131135
try {
132136
if (isGitUri(uri)) {
133137
uri = uri.documentUri();
@@ -144,7 +148,7 @@ export async function openEditor(
144148
preserveFocus: false,
145149
preview: true,
146150
viewColumn: ViewColumn.Active,
147-
...opts,
151+
...options,
148152
});
149153
} catch (ex) {
150154
const msg: string = ex?.toString() ?? '';
@@ -154,13 +158,26 @@ export async function openEditor(
154158
return undefined;
155159
}
156160

157-
if (rethrow) throw ex;
161+
if (throwOnError) throw ex;
158162

159163
Logger.error(ex, 'openEditor');
160164
return undefined;
161165
}
162166
}
163167

168+
export async function openDiffEditor(
169+
lhs: Uri,
170+
rhs: Uri,
171+
title: string,
172+
options?: TextDocumentShowOptions,
173+
): Promise<void> {
174+
try {
175+
await executeCoreCommand('vscode.diff', lhs, rhs, title, options);
176+
} catch (ex) {
177+
Logger.error(ex, 'openDiffEditor');
178+
}
179+
}
180+
164181
export async function openWalkthrough(
165182
extensionId: string,
166183
walkthroughId: string,

0 commit comments

Comments
 (0)