Procházet zdrojové kódy

Consolidates `vscode.diff` calls into a helper

main
Eric Amodio před 1 rokem
rodič
revize
f8a5d5a50b
3 změnil soubory, kde provedl 26 přidání a 9 odebrání
  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 Zobrazit soubor

@ -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 Zobrazit soubor

@ -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 Zobrazit soubor

@ -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,

Načítá se…
Zrušit
Uložit