Explorar el Código

Consolidates `vscode.diff` calls into a helper

main
Eric Amodio hace 1 año
padre
commit
f8a5d5a50b
Se han modificado 3 ficheros con 26 adiciones y 9 borrados
  1. +4
    -4
      src/commands/diffWith.ts
  2. +1
    -1
      src/commands/openFileFromRemote.ts
  3. +21
    -4
      src/system/utils.ts

+ 4
- 4
src/commands/diffWith.ts Ver fichero

@ -7,9 +7,10 @@ import { isCommit } from '../git/models/commit';
import { deletedOrMissing } from '../git/models/constants';
import { isShaLike, isUncommitted, shortenRevision } from '../git/models/reference';
import { showGenericErrorMessage } from '../messages';
import { command, executeCoreCommand } from '../system/command';
import { command } from '../system/command';
import { Logger } from '../system/logger';
import { basename } from '../system/path';
import { openDiffEditor } from '../system/utils';
import { Command } from './base';
export interface DiffWithCommandArgsRevision {
@ -179,13 +180,12 @@ export class DiffWithCommand extends Command {
args.showOptions.selection = new Range(args.line, 0, args.line, 0);
}
void (await executeCoreCommand(
'vscode.diff',
await openDiffEditor(
lhs ?? this.container.git.getRevisionUri(deletedOrMissing, args.lhs.uri.fsPath, args.repoPath),
rhs ?? this.container.git.getRevisionUri(deletedOrMissing, args.rhs.uri.fsPath, args.repoPath),
title,
args.showOptions,
));
);
} catch (ex) {
Logger.error(ex, 'DiffWithCommand', 'getVersionedFile');
void showGenericErrorMessage('Unable to open compare');

+ 1
- 1
src/commands/openFileFromRemote.ts Ver fichero

@ -54,7 +54,7 @@ export class OpenFileFromRemoteCommand extends Command {
}
try {
await openEditor(local.uri, { selection: selection, rethrow: true });
await openEditor(local.uri, { selection: selection, throwOnError: true });
} catch {
const uris = await window.showOpenDialog({
title: 'Open local file',

+ 21
- 4
src/system/utils.ts Ver fichero

@ -125,9 +125,13 @@ export function isTextEditor(editor: TextEditor): boolean {
export async function openEditor(
uri: Uri,
options: TextDocumentShowOptions & { rethrow?: boolean } = {},
options?: TextDocumentShowOptions & { throwOnError?: boolean },
): Promise<TextEditor | undefined> {
const { rethrow, ...opts } = options;
let throwOnError;
if (options != null) {
({ throwOnError, ...options } = options);
}
try {
if (isGitUri(uri)) {
uri = uri.documentUri();
@ -144,7 +148,7 @@ export async function openEditor(
preserveFocus: false,
preview: true,
viewColumn: ViewColumn.Active,
...opts,
...options,
});
} catch (ex) {
const msg: string = ex?.toString() ?? '';
@ -154,13 +158,26 @@ export async function openEditor(
return undefined;
}
if (rethrow) throw ex;
if (throwOnError) throw ex;
Logger.error(ex, 'openEditor');
return undefined;
}
}
export async function openDiffEditor(
lhs: Uri,
rhs: Uri,
title: string,
options?: TextDocumentShowOptions,
): Promise<void> {
try {
await executeCoreCommand('vscode.diff', lhs, rhs, title, options);
} catch (ex) {
Logger.error(ex, 'openDiffEditor');
}
}
export async function openWalkthrough(
extensionId: string,
walkthroughId: string,

Cargando…
Cancelar
Guardar