瀏覽代碼

Moves some util functions to utils

Moves repo picking utils to RepositoryPicker
main
Eric Amodio 2 年之前
父節點
當前提交
a44ca2d5de
共有 18 個檔案被更改,包括 209 行新增218 行删除
  1. +2
    -10
      src/commands/browseRepoAtRevision.ts
  2. +5
    -4
      src/commands/closeUnchangedFiles.ts
  3. +1
    -139
      src/commands/common.ts
  4. +3
    -9
      src/commands/compareWith.ts
  5. +5
    -4
      src/commands/copyCurrentBranch.ts
  6. +2
    -9
      src/commands/diffWithPrevious.ts
  7. +4
    -4
      src/commands/externalDiff.ts
  8. +1
    -2
      src/commands/gitCommands.actions.ts
  9. +8
    -7
      src/commands/openBranchOnRemote.ts
  10. +8
    -6
      src/commands/openBranchesOnRemote.ts
  11. +6
    -4
      src/commands/openChangedFiles.ts
  12. +4
    -3
      src/commands/openDirectoryCompare.ts
  13. +2
    -1
      src/commands/openFileFromRemote.ts
  14. +10
    -8
      src/commands/openRepoOnRemote.ts
  15. +2
    -1
      src/commands/openWorkingFile.ts
  16. +34
    -2
      src/quickpicks/repositoryPicker.ts
  17. +109
    -2
      src/system/utils.ts
  18. +3
    -3
      src/views/searchAndCompareView.ts

+ 2
- 10
src/commands/browseRepoAtRevision.ts 查看文件

@ -5,16 +5,8 @@ import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { basename } from '../system/path';
import {
ActiveEditorCommand,
command,
CommandContext,
Commands,
executeCoreCommand,
getCommandUri,
openWorkspace,
OpenWorkspaceLocation,
} from './common';
import { openWorkspace, OpenWorkspaceLocation } from '../system/utils';
import { ActiveEditorCommand, command, CommandContext, Commands, executeCoreCommand, getCommandUri } from './common';
export interface BrowseRepoAtRevisionCommandArgs {
uri?: Uri;

+ 5
- 4
src/commands/closeUnchangedFiles.ts 查看文件

@ -4,8 +4,9 @@ import { CoreCommands } from '../constants';
import type { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { RepositoryPicker } from '../quickpicks';
import { debounce } from '../system/function';
import { Command, command, Commands, executeCoreCommand, getRepoPathOrPrompt } from './common';
import { Command, command, Commands, executeCoreCommand } from './common';
export interface CloseUnchangedFilesCommandArgs {
uris?: Uri[];
@ -24,10 +25,10 @@ export class CloseUnchangedFilesCommand extends Command {
try {
if (args.uris == null) {
const repoPath = await getRepoPathOrPrompt('Close All Unchanged Files');
if (!repoPath) return;
const repository = await RepositoryPicker.getRepositoryOrShow('Close All Unchanged Files');
if (repository == null) return;
const status = await this.container.git.getStatusForRepo(repoPath);
const status = await this.container.git.getStatusForRepo(repository.uri);
if (status == null) {
void window.showWarningMessage('Unable to close unchanged files');

+ 1
- 139
src/commands/common.ts 查看文件

@ -4,19 +4,15 @@ import {
GitTimelineItem,
SourceControlResourceGroup,
SourceControlResourceState,
TextDocumentShowOptions,
TextEditor,
TextEditorEdit,
TimelineItem,
Uri,
ViewColumn,
window,
workspace,
} from 'vscode';
import type { Action, ActionContext } from '../api/gitlens';
import { CoreCommands, CoreGitCommands, ImageMimetypes, Schemes } from '../constants';
import { CoreCommands, CoreGitCommands } from '../constants';
import { Container } from '../container';
import { GitUri } from '../git/gitUri';
import {
GitBranch,
GitCommit,
@ -28,9 +24,6 @@ import {
GitTag,
Repository,
} from '../git/models';
import { Logger } from '../logger';
import { CommandQuickPickItem, RepositoryPicker } from '../quickpicks';
import { extname } from '../system/path';
import { ViewNode, ViewRefNode } from '../views/nodes';
export const enum Commands {
@ -275,34 +268,6 @@ export function getCommandUri(uri?: Uri, editor?: TextEditor): Uri | undefined {
return editor?.document?.uri ?? uri;
}
export async function getRepoPathOrActiveOrPrompt(uri: Uri | undefined, editor: TextEditor | undefined, title: string) {
const repository = Container.instance.git.getBestRepository(uri, editor);
if (repository != null) return repository.path;
const pick = await RepositoryPicker.show(title);
if (pick instanceof CommandQuickPickItem) {
await pick.execute();
return undefined;
}
return pick?.repoPath;
}
export async function getRepoPathOrPrompt(title: string, uri?: Uri) {
if (uri == null) return Container.instance.git.highlander?.path;
const repoPath = (await Container.instance.git.getOrOpenRepository(uri))?.path;
if (repoPath) return repoPath;
const pick = await RepositoryPicker.show(title);
if (pick instanceof CommandQuickPickItem) {
void (await pick.execute());
return undefined;
}
return pick?.repoPath;
}
export interface CommandContextParsingOptions {
expectsEditor: boolean;
}
@ -696,106 +661,3 @@ export abstract class EditorCommand implements Disposable {
abstract execute(editor: TextEditor, edit: TextEditorEdit, ...args: any[]): any;
}
export function findEditor(uri: Uri): TextEditor | undefined {
const active = window.activeTextEditor;
const normalizedUri = uri.toString();
for (const e of [...(active != null ? [active] : []), ...window.visibleTextEditors]) {
// Don't include diff editors
if (e.document.uri.toString() === normalizedUri && e?.viewColumn != null) {
return e;
}
}
return undefined;
}
export async function findOrOpenEditor(
uri: Uri,
options?: TextDocumentShowOptions & { throwOnError?: boolean },
): Promise<TextEditor | undefined> {
const e = findEditor(uri);
if (e != null) {
if (!options?.preserveFocus) {
await window.showTextDocument(e.document, { ...options, viewColumn: e.viewColumn });
}
return e;
}
return openEditor(uri, { viewColumn: window.activeTextEditor?.viewColumn, ...options });
}
export function findOrOpenEditors(uris: Uri[]): void {
const normalizedUris = new Map(uris.map(uri => [uri.toString(), uri]));
for (const e of window.visibleTextEditors) {
// Don't include diff editors
if (e?.viewColumn != null) {
normalizedUris.delete(e.document.uri.toString());
}
}
for (const uri of normalizedUris.values()) {
void executeCoreCommand(CoreCommands.Open, uri, { background: true, preview: false });
}
}
export async function openEditor(
uri: Uri,
options: TextDocumentShowOptions & { rethrow?: boolean } = {},
): Promise<TextEditor | undefined> {
const { rethrow, ...opts } = options;
try {
if (GitUri.is(uri)) {
uri = uri.documentUri();
}
if (uri.scheme === Schemes.GitLens && ImageMimetypes[extname(uri.fsPath)]) {
await executeCoreCommand(CoreCommands.Open, uri);
return undefined;
}
const document = await workspace.openTextDocument(uri);
return window.showTextDocument(document, {
preserveFocus: false,
preview: true,
viewColumn: ViewColumn.Active,
...opts,
});
} catch (ex) {
const msg: string = ex?.toString() ?? '';
if (msg.includes('File seems to be binary and cannot be opened as text')) {
await executeCoreCommand(CoreCommands.Open, uri);
return undefined;
}
if (rethrow) throw ex;
Logger.error(ex, 'openEditor');
return undefined;
}
}
export const enum OpenWorkspaceLocation {
CurrentWindow = 'currentWindow',
NewWindow = 'newWindow',
AddToWorkspace = 'addToWorkspace',
}
export function openWorkspace(
uri: Uri,
options: { location?: OpenWorkspaceLocation; name?: string } = { location: OpenWorkspaceLocation.CurrentWindow },
): void {
if (options?.location === OpenWorkspaceLocation.AddToWorkspace) {
const count = workspace.workspaceFolders?.length ?? 0;
return void workspace.updateWorkspaceFolders(count, 0, { uri: uri, name: options?.name });
}
return void executeCoreCommand(CoreCommands.OpenFolder, uri, {
forceNewWindow: options?.location === OpenWorkspaceLocation.NewWindow,
});
}

+ 3
- 9
src/commands/compareWith.ts 查看文件

@ -2,14 +2,8 @@ import { TextEditor, Uri } from 'vscode';
import type { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import {
ActiveEditorCommand,
command,
CommandContext,
Commands,
getCommandUri,
getRepoPathOrActiveOrPrompt,
} from './common';
import { RepositoryPicker } from '../quickpicks';
import { ActiveEditorCommand, command, CommandContext, Commands, getCommandUri } from './common';
export interface CompareWithCommandArgs {
ref1?: string;
@ -71,7 +65,7 @@ export class CompareWithCommand extends ActiveEditorCommand {
break;
}
const repoPath = await getRepoPathOrActiveOrPrompt(uri, editor, title);
const repoPath = (await RepositoryPicker.getBestRepositoryOrShow(uri, editor, title))?.path;
if (!repoPath) return;
if (args.ref1 != null && args.ref2 != null) {

+ 5
- 4
src/commands/copyCurrentBranch.ts 查看文件

@ -2,7 +2,8 @@ import { env, TextEditor, Uri, window } from 'vscode';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { ActiveEditorCommand, command, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common';
import { RepositoryPicker } from '../quickpicks';
import { ActiveEditorCommand, command, Commands, getCommandUri } from './common';
@command()
export class CopyCurrentBranchCommand extends ActiveEditorCommand {
@ -15,11 +16,11 @@ export class CopyCurrentBranchCommand extends ActiveEditorCommand {
const gitUri = uri != null ? await GitUri.fromUri(uri) : undefined;
const repoPath = await getRepoPathOrActiveOrPrompt(gitUri, editor, 'Copy Current Branch Name');
if (!repoPath) return;
const repository = await RepositoryPicker.getBestRepositoryOrShow(gitUri, editor, 'Copy Current Branch Name');
if (repository == null) return;
try {
const branch = await this.container.git.getBranch(repoPath);
const branch = await repository.getBranch();
if (branch?.name) {
await env.clipboard.writeText(branch.name);
}

+ 2
- 9
src/commands/diffWithPrevious.ts 查看文件

@ -4,15 +4,8 @@ import { GitUri } from '../git/gitUri';
import { GitCommit, GitRevision } from '../git/models';
import { Logger } from '../logger';
import { Messages } from '../messages';
import {
ActiveEditorCommand,
command,
CommandContext,
Commands,
executeCommand,
findOrOpenEditor,
getCommandUri,
} from './common';
import { findOrOpenEditor } from '../system/utils';
import { ActiveEditorCommand, command, CommandContext, Commands, executeCommand, getCommandUri } from './common';
import { DiffWithCommandArgs } from './diffWith';
export interface DiffWithPreviousCommandArgs {

+ 4
- 4
src/commands/externalDiff.ts 查看文件

@ -6,13 +6,13 @@ import { GitUri } from '../git/gitUri';
import { GitRevision } from '../git/models';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { RepositoryPicker } from '../quickpicks';
import { Arrays } from '../system';
import {
command,
Command,
CommandContext,
Commands,
getRepoPathOrPrompt,
isCommandContextViewNodeHasFileCommit,
isCommandContextViewNodeHasFileRefs,
} from './common';
@ -87,10 +87,10 @@ export class ExternalDiffCommand extends Command {
if (context.command === Commands.ExternalDiffAll) {
if (args.files == null) {
const repoPath = await getRepoPathOrPrompt('Open All Changes (difftool)');
if (!repoPath) return undefined;
const repository = await RepositoryPicker.getRepositoryOrShow('Open All Changes (difftool)');
if (repository == null) return undefined;
const status = await this.container.git.getStatusForRepo(repoPath);
const status = await this.container.git.getStatusForRepo(repository.uri);
if (status == null) {
return window.showInformationMessage("The repository doesn't have any changes");
}

+ 1
- 2
src/commands/gitCommands.actions.ts 查看文件

@ -6,8 +6,6 @@ import {
DiffWithWorkingCommandArgs,
executeCommand,
executeEditorCommand,
findOrOpenEditor,
findOrOpenEditors,
GitCommandsCommandArgs,
OpenWorkingFileCommandArgs,
} from '../commands';
@ -28,6 +26,7 @@ import {
Repository,
} from '../git/models';
import { RepositoryPicker } from '../quickpicks';
import { findOrOpenEditor, findOrOpenEditors } from '../system/utils';
import { ViewsWithRepositoryFolders } from '../views/viewBase';
import { ResetGitCommandArgs } from './git/reset';

+ 8
- 7
src/commands/openBranchOnRemote.ts 查看文件

@ -3,7 +3,7 @@ import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { RemoteResourceType } from '../git/remotes/provider';
import { Logger } from '../logger';
import { CommandQuickPickItem, ReferencePicker, ReferencesQuickPickIncludes } from '../quickpicks';
import { CommandQuickPickItem, ReferencePicker, ReferencesQuickPickIncludes, RepositoryPicker } from '../quickpicks';
import {
ActiveEditorCommand,
command,
@ -11,7 +11,6 @@ import {
Commands,
executeCommand,
getCommandUri,
getRepoPathOrActiveOrPrompt,
isCommandContextViewNodeHasBranch,
} from './common';
import { OpenOnRemoteCommandArgs } from './openOnRemote';
@ -49,11 +48,13 @@ export class OpenBranchOnRemoteCommand extends ActiveEditorCommand {
const gitUri = uri != null ? await GitUri.fromUri(uri) : undefined;
const repoPath = await getRepoPathOrActiveOrPrompt(
gitUri,
editor,
args?.clipboard ? 'Copy Remote Branch Url' : 'Open Branch On Remote',
);
const repoPath = (
await RepositoryPicker.getBestRepositoryOrShow(
gitUri,
editor,
args?.clipboard ? 'Copy Remote Branch Url' : 'Open Branch On Remote',
)
)?.path;
if (!repoPath) return;
args = { ...args };

+ 8
- 6
src/commands/openBranchesOnRemote.ts 查看文件

@ -3,6 +3,7 @@ import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { RemoteResourceType } from '../git/remotes/provider';
import { Logger } from '../logger';
import { RepositoryPicker } from '../quickpicks';
import {
ActiveEditorCommand,
command,
@ -10,7 +11,6 @@ import {
Commands,
executeCommand,
getCommandUri,
getRepoPathOrActiveOrPrompt,
isCommandContextViewNodeHasRemote,
} from './common';
import { OpenOnRemoteCommandArgs } from './openOnRemote';
@ -47,11 +47,13 @@ export class OpenBranchesOnRemoteCommand extends ActiveEditorCommand {
const gitUri = uri != null ? await GitUri.fromUri(uri) : undefined;
const repoPath = await getRepoPathOrActiveOrPrompt(
gitUri,
editor,
args?.clipboard ? 'Copy Remote Branches Url' : 'Open Branches on Remote',
);
const repoPath = (
await RepositoryPicker.getBestRepositoryOrShow(
gitUri,
editor,
args?.clipboard ? 'Copy Remote Branches Url' : 'Open Branches on Remote',
)
)?.path;
if (!repoPath) return;
try {

+ 6
- 4
src/commands/openChangedFiles.ts 查看文件

@ -2,8 +2,10 @@ import { Uri, window } from 'vscode';
import type { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { RepositoryPicker } from '../quickpicks';
import { Arrays } from '../system';
import { Command, command, Commands, findOrOpenEditors, getRepoPathOrPrompt } from './common';
import { findOrOpenEditors } from '../system/utils';
import { Command, command, Commands } from './common';
export interface OpenChangedFilesCommandArgs {
uris?: Uri[];
@ -20,10 +22,10 @@ export class OpenChangedFilesCommand extends Command {
try {
if (args.uris == null) {
const repoPath = await getRepoPathOrPrompt('Open All Changed Files');
if (!repoPath) return;
const repository = await RepositoryPicker.getRepositoryOrShow('Open All Changed Files');
if (repository == null) return;
const status = await this.container.git.getStatusForRepo(repoPath);
const status = await this.container.git.getStatusForRepo(repository.uri);
if (status == null) {
void window.showWarningMessage('Unable to open changed files');

+ 4
- 3
src/commands/openDirectoryCompare.ts 查看文件

@ -3,7 +3,7 @@ import { GitActions } from '../commands';
import type { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { ReferencePicker } from '../quickpicks';
import { ReferencePicker, RepositoryPicker } from '../quickpicks';
import { CompareResultsNode } from '../views/nodes';
import {
ActiveEditorCommand,
@ -11,7 +11,6 @@ import {
CommandContext,
Commands,
getCommandUri,
getRepoPathOrActiveOrPrompt,
isCommandContextViewNodeHasRef,
} from './common';
@ -63,7 +62,9 @@ export class OpenDirectoryCompareCommand extends ActiveEditorCommand {
args = { ...args };
try {
const repoPath = await getRepoPathOrActiveOrPrompt(uri, editor, 'Directory Compare Working Tree With');
const repoPath = (
await RepositoryPicker.getBestRepositoryOrShow(uri, editor, 'Directory Compare Working Tree With')
)?.path;
if (!repoPath) return;
if (!args.ref1) {

+ 2
- 1
src/commands/openFileFromRemote.ts 查看文件

@ -1,6 +1,7 @@
import { env, Range, Uri, window } from 'vscode';
import type { Container } from '../container';
import { command, Command, Commands, openEditor } from './common';
import { openEditor } from '../system/utils';
import { command, Command, Commands } from './common';
@command()
export class OpenFileFromRemoteCommand extends Command {

+ 10
- 8
src/commands/openRepoOnRemote.ts 查看文件

@ -3,6 +3,7 @@ import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { RemoteResourceType } from '../git/remotes/provider';
import { Logger } from '../logger';
import { RepositoryPicker } from '../quickpicks';
import {
ActiveEditorCommand,
command,
@ -10,7 +11,6 @@ import {
Commands,
executeCommand,
getCommandUri,
getRepoPathOrActiveOrPrompt,
isCommandContextViewNodeHasRemote,
} from './common';
import { OpenOnRemoteCommandArgs } from './openOnRemote';
@ -43,13 +43,15 @@ export class OpenRepoOnRemoteCommand extends ActiveEditorCommand {
const gitUri = uri != null ? await GitUri.fromUri(uri) : undefined;
const repoPath = await getRepoPathOrActiveOrPrompt(
gitUri,
editor,
args?.clipboard
? 'Choose which repository to copy the url from'
: 'Choose which repository to open on remote',
);
const repoPath = (
await RepositoryPicker.getBestRepositoryOrShow(
gitUri,
editor,
args?.clipboard
? 'Choose which repository to copy the url from'
: 'Choose which repository to open on remote',
)
)?.path;
if (!repoPath) return;
try {

+ 2
- 1
src/commands/openWorkingFile.ts 查看文件

@ -4,7 +4,8 @@ import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { ActiveEditorCommand, command, Commands, findOrOpenEditor, getCommandUri } from './common';
import { findOrOpenEditor } from '../system/utils';
import { ActiveEditorCommand, command, Commands, getCommandUri } from './common';
export interface OpenWorkingFileCommandArgs {
uri?: Uri;

+ 34
- 2
src/quickpicks/repositoryPicker.ts 查看文件

@ -1,10 +1,42 @@
import { Disposable, window } from 'vscode';
import { Disposable, TextEditor, Uri, window } from 'vscode';
import { Container } from '../container';
import { Repository } from '../git/models';
import { getQuickPickIgnoreFocusOut, RepositoryQuickPickItem } from '../quickpicks';
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, RepositoryQuickPickItem } from '../quickpicks';
import { Iterables } from '../system';
export namespace RepositoryPicker {
export async function getBestRepositoryOrShow(
uri: Uri | undefined,
editor: TextEditor | undefined,
title: string,
): Promise<Repository | undefined> {
const repository = Container.instance.git.getBestRepository(uri, editor);
if (repository != null) return repository;
const pick = await RepositoryPicker.show(title);
if (pick instanceof CommandQuickPickItem) {
await pick.execute();
return undefined;
}
return pick?.item;
}
export async function getRepositoryOrShow(title: string, uri?: Uri): Promise<Repository | undefined> {
if (uri == null) return Container.instance.git.highlander;
const repository = await Container.instance.git.getOrOpenRepository(uri);
if (repository != null) return repository;
const pick = await RepositoryPicker.show(title);
if (pick instanceof CommandQuickPickItem) {
void (await pick.execute());
return undefined;
}
return pick?.item;
}
export async function show(
title: string | undefined,
placeholder: string = 'Choose a repository',

+ 109
- 2
src/system/utils.ts 查看文件

@ -1,5 +1,54 @@
import { TextDocument, TextEditor, window } from 'vscode';
import { Schemes } from '../constants';
import { TextDocument, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace } from 'vscode';
import { executeCoreCommand } from '../commands';
import { CoreCommands, ImageMimetypes, Schemes } from '../constants';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { extname } from './path';
export function findEditor(uri: Uri): TextEditor | undefined {
const active = window.activeTextEditor;
const normalizedUri = uri.toString();
for (const e of [...(active != null ? [active] : []), ...window.visibleTextEditors]) {
// Don't include diff editors
if (e.document.uri.toString() === normalizedUri && e?.viewColumn != null) {
return e;
}
}
return undefined;
}
export async function findOrOpenEditor(
uri: Uri,
options?: TextDocumentShowOptions & { throwOnError?: boolean },
): Promise<TextEditor | undefined> {
const e = findEditor(uri);
if (e != null) {
if (!options?.preserveFocus) {
await window.showTextDocument(e.document, { ...options, viewColumn: e.viewColumn });
}
return e;
}
return openEditor(uri, { viewColumn: window.activeTextEditor?.viewColumn, ...options });
}
export function findOrOpenEditors(uris: Uri[]): void {
const normalizedUris = new Map(uris.map(uri => [uri.toString(), uri]));
for (const e of window.visibleTextEditors) {
// Don't include diff editors
if (e?.viewColumn != null) {
normalizedUris.delete(e.document.uri.toString());
}
}
for (const uri of normalizedUris.values()) {
void executeCoreCommand(CoreCommands.Open, uri, { background: true, preview: false });
}
}
export function getEditorIfActive(document: TextDocument): TextEditor | undefined {
const editor = window.activeTextEditor;
@ -27,3 +76,61 @@ export function isTextEditor(editor: TextEditor): boolean {
const scheme = editor.document.uri.scheme;
return scheme !== Schemes.Output && scheme !== Schemes.DebugConsole;
}
export async function openEditor(
uri: Uri,
options: TextDocumentShowOptions & { rethrow?: boolean } = {},
): Promise<TextEditor | undefined> {
const { rethrow, ...opts } = options;
try {
if (GitUri.is(uri)) {
uri = uri.documentUri();
}
if (uri.scheme === Schemes.GitLens && ImageMimetypes[extname(uri.fsPath)]) {
await executeCoreCommand(CoreCommands.Open, uri);
return undefined;
}
const document = await workspace.openTextDocument(uri);
return window.showTextDocument(document, {
preserveFocus: false,
preview: true,
viewColumn: ViewColumn.Active,
...opts,
});
} catch (ex) {
const msg: string = ex?.toString() ?? '';
if (msg.includes('File seems to be binary and cannot be opened as text')) {
await executeCoreCommand(CoreCommands.Open, uri);
return undefined;
}
if (rethrow) throw ex;
Logger.error(ex, 'openEditor');
return undefined;
}
}
export const enum OpenWorkspaceLocation {
CurrentWindow = 'currentWindow',
NewWindow = 'newWindow',
AddToWorkspace = 'addToWorkspace',
}
export function openWorkspace(
uri: Uri,
options: { location?: OpenWorkspaceLocation; name?: string } = { location: OpenWorkspaceLocation.CurrentWindow },
): void {
if (options?.location === OpenWorkspaceLocation.AddToWorkspace) {
const count = workspace.workspaceFolders?.length ?? 0;
return void workspace.updateWorkspaceFolders(count, 0, { uri: uri, name: options?.name });
}
return void executeCoreCommand(CoreCommands.OpenFolder, uri, {
forceNewWindow: options?.location === OpenWorkspaceLocation.NewWindow,
});
}

+ 3
- 3
src/views/searchAndCompareView.ts 查看文件

@ -1,12 +1,12 @@
import { commands, ConfigurationChangeEvent, Disposable, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Commands, executeCommand, getRepoPathOrPrompt } from '../commands';
import { Commands, executeCommand } from '../commands';
import { configuration, SearchAndCompareViewConfig, ViewFilesLayout } from '../configuration';
import { Container } from '../container';
import { ContextKeys, setContext } from '../context';
import { GitUri } from '../git/gitUri';
import { GitLog, GitRevision } from '../git/models';
import { SearchPattern } from '../git/search';
import { ReferencePicker, ReferencesQuickPickIncludes } from '../quickpicks';
import { ReferencePicker, ReferencesQuickPickIncludes, RepositoryPicker } from '../quickpicks';
import { NamedRef, PinnedItem, PinnedItems, WorkspaceState } from '../storage';
import { filterMap } from '../system/array';
import { gate } from '../system/decorators/gate';
@ -179,7 +179,7 @@ export class SearchAndCompareViewNode extends ViewNode {
async selectForCompare(repoPath?: string, ref?: string | NamedRef, options?: { prompt?: boolean }) {
if (repoPath == null) {
repoPath = await getRepoPathOrPrompt('Compare');
repoPath = (await RepositoryPicker.getRepositoryOrShow('Compare'))?.path;
}
if (repoPath == null) return;

Loading…
取消
儲存