Ver a proveniência

Hides commands not available in virtual workspaces

main
Eric Amodio há 2 anos
ascendente
cometimento
445edcc093
8 ficheiros alterados com 279 adições e 213 eliminações
  1. +187
    -183
      package.json
  2. +11
    -1
      src/commands/git/stash.ts
  3. +37
    -18
      src/commands/gitCommands.utils.ts
  4. +2
    -0
      src/constants.ts
  5. +7
    -5
      src/context.ts
  6. +2
    -2
      src/extension.ts
  7. +5
    -1
      src/git/gitProviderService.ts
  8. +28
    -3
      src/premium/github/githubGitProvider.ts

+ 187
- 183
package.json
A apresentação das diferenças no ficheiro foi suprimida por ser demasiado grande
Ver ficheiro


+ 11
- 1
src/commands/git/stash.ts Ver ficheiro

@ -1,6 +1,7 @@
import { QuickInputButtons, QuickPickItem, Uri, window } from 'vscode';
import { GlyphChars } from '../../constants';
import { ContextKeys, GlyphChars } from '../../constants';
import { Container } from '../../container';
import { getContext } from '../../context';
import { StashApplyError, StashApplyErrorReason } from '../../git/errors';
import { GitReference, GitStashCommit, GitStashReference, Repository } from '../../git/models';
import { Logger } from '../../logger';
@ -31,6 +32,7 @@ import {
interface Context {
repos: Repository[];
associatedView: ViewsWithRepositoryFolders;
readonly: boolean;
title: string;
}
@ -150,6 +152,10 @@ export class StashGitCommand extends QuickCommand {
const context: Context = {
repos: this.container.git.openRepositories,
associatedView: this.container.stashesView,
readonly:
getContext<boolean>(ContextKeys.Readonly, false) ||
getContext<boolean>(ContextKeys.Untrusted, false) ||
getContext<boolean>(ContextKeys.HasVirtualFolders, false),
title: this.title,
};
@ -158,6 +164,10 @@ export class StashGitCommand extends QuickCommand {
while (this.canStepsContinue(state)) {
context.title = this.title;
if (context.readonly) {
state.subcommand = 'list';
}
if (state.counter < 1 || state.subcommand == null) {
this.subcommand = undefined;

+ 37
- 18
src/commands/gitCommands.utils.ts Ver ficheiro

@ -1,5 +1,7 @@
import { GitCommandSorting } from '../config';
import { ContextKeys } from '../constants';
import type { Container } from '../container';
import { getContext } from '../context';
import { Usage, WorkspaceState } from '../storage';
import { BranchGitCommand } from './git/branch';
import { CherryPickGitCommand } from './git/cherry-pick';
@ -50,28 +52,45 @@ export class PickCommandStep implements QuickPickStep {
readonly title = 'GitLens';
constructor(private readonly container: Container, args?: GitCommandsCommandArgs) {
const hasVirtualFolders = getContext<boolean>(ContextKeys.HasVirtualFolders, false);
const readonly =
hasVirtualFolders ||
getContext<boolean>(ContextKeys.Readonly, false) ||
getContext<boolean>(ContextKeys.Untrusted, false);
this.items = [
new BranchGitCommand(container, args?.command === 'branch' ? args : undefined),
new CherryPickGitCommand(container, args?.command === 'cherry-pick' ? args : undefined),
new CoAuthorsGitCommand(container, args?.command === 'co-authors' ? args : undefined),
new FetchGitCommand(container, args?.command === 'fetch' ? args : undefined),
readonly ? undefined : new BranchGitCommand(container, args?.command === 'branch' ? args : undefined),
readonly
? undefined
: new CherryPickGitCommand(container, args?.command === 'cherry-pick' ? args : undefined),
hasVirtualFolders
? undefined
: new CoAuthorsGitCommand(container, args?.command === 'co-authors' ? args : undefined),
readonly ? undefined : new FetchGitCommand(container, args?.command === 'fetch' ? args : undefined),
new LogGitCommand(container, args?.command === 'log' ? args : undefined),
new MergeGitCommand(container, args?.command === 'merge' ? args : undefined),
new PullGitCommand(container, args?.command === 'pull' ? args : undefined),
new PushGitCommand(container, args?.command === 'push' ? args : undefined),
new RebaseGitCommand(container, args?.command === 'rebase' ? args : undefined),
new ResetGitCommand(container, args?.command === 'reset' ? args : undefined),
new RevertGitCommand(container, args?.command === 'revert' ? args : undefined),
readonly ? undefined : new MergeGitCommand(container, args?.command === 'merge' ? args : undefined),
readonly ? undefined : new PullGitCommand(container, args?.command === 'pull' ? args : undefined),
readonly ? undefined : new PushGitCommand(container, args?.command === 'push' ? args : undefined),
readonly ? undefined : new RebaseGitCommand(container, args?.command === 'rebase' ? args : undefined),
readonly ? undefined : new ResetGitCommand(container, args?.command === 'reset' ? args : undefined),
readonly ? undefined : new RevertGitCommand(container, args?.command === 'revert' ? args : undefined),
new SearchGitCommand(container, args?.command === 'search' || args?.command === 'grep' ? args : undefined),
new ShowGitCommand(container, args?.command === 'show' ? args : undefined),
new StashGitCommand(container, args?.command === 'stash' ? args : undefined),
new StatusGitCommand(container, args?.command === 'status' ? args : undefined),
new SwitchGitCommand(
container,
args?.command === 'switch' || args?.command === 'checkout' ? args : undefined,
),
new TagGitCommand(container, args?.command === 'tag' ? args : undefined),
];
hasVirtualFolders
? undefined
: new StashGitCommand(container, args?.command === 'stash' ? args : undefined),
hasVirtualFolders
? undefined
: new StatusGitCommand(container, args?.command === 'status' ? args : undefined),
readonly
? undefined
: new SwitchGitCommand(
container,
args?.command === 'switch' || args?.command === 'checkout' ? args : undefined,
),
readonly ? undefined : new TagGitCommand(container, args?.command === 'tag' ? args : undefined),
].filter(<T>(i: T | undefined): i is T => i != null);
if (this.container.config.gitCommands.sortBy === GitCommandSorting.Usage) {
const usage = this.container.storage.getWorkspace<Usage>(WorkspaceState.GitCommandPaletteUsage);

+ 2
- 0
src/constants.ts Ver ficheiro

@ -242,7 +242,9 @@ export const enum ContextKeys {
HasConnectedRemotes = 'gitlens:hasConnectedRemotes',
HasRemotes = 'gitlens:hasRemotes',
HasRichRemotes = 'gitlens:hasRichRemotes',
HasVirtualFolders = 'gitlens:hasVirtualFolders',
Readonly = 'gitlens:readonly',
Untrusted = 'gitlens:untrusted',
ViewsCanCompare = 'gitlens:views:canCompare',
ViewsCanCompareFile = 'gitlens:views:canCompare:file',
ViewsCommitsMyCommitsOnly = 'gitlens:views:commits:myCommitsOnly',

+ 7
- 5
src/context.ts Ver ficheiro

@ -1,16 +1,18 @@
import { commands } from 'vscode';
import { ContextKeys, CoreCommands } from './constants';
// const contextStorage = new Map<string, unknown>();
const contextStorage = new Map<string, unknown>();
// export function getContext(key: ContextKeys): unknown | undefined {
// return contextStorage.get(key);
// }
export function getContext<T>(key: ContextKeys): T | undefined;
export function getContext<T>(key: ContextKeys, defaultValue: T): T;
export function getContext<T>(key: ContextKeys, defaultValue?: T): T | undefined {
return (contextStorage.get(key) as T | undefined) ?? defaultValue;
}
export async function setContext(
key: ContextKeys | `${ContextKeys.ActionPrefix}${string}` | `${ContextKeys.KeyPrefix}${string}`,
value: unknown,
): Promise<void> {
// contextStorage.set(key, value);
contextStorage.set(key, value);
void (await commands.executeCommand(CoreCommands.SetContext, key, value));
}

+ 2
- 2
src/extension.ts Ver ficheiro

@ -60,9 +60,9 @@ export async function activate(context: ExtensionContext): Promise
}
if (!workspace.isTrusted) {
void setContext(ContextKeys.Readonly, true);
void setContext(ContextKeys.Untrusted, true);
context.subscriptions.push(
workspace.onDidGrantWorkspaceTrust(() => void setContext(ContextKeys.Readonly, undefined)),
workspace.onDidGrantWorkspaceTrust(() => void setContext(ContextKeys.Untrusted, undefined)),
);
}

+ 5
- 1
src/git/gitProviderService.ts Ver ficheiro

@ -27,7 +27,7 @@ import { WorkspaceState } from '../storage';
import { groupByFilterMap, groupByMap } from '../system/array';
import { gate } from '../system/decorators/gate';
import { debug, log } from '../system/decorators/log';
import { count, filter, first, flatMap, map } from '../system/iterable';
import { count, filter, first, flatMap, map, some } from '../system/iterable';
import { dirname, getBestPath, getScheme, isAbsolute, maybeUri, normalizePath } from '../system/path';
import { cancellable, isPromise, PromiseCancelledError } from '../system/promise';
import { VisitedPathsTrie } from '../system/trie';
@ -427,6 +427,10 @@ export class GitProviderService implements Disposable {
return groupByMap(repositories, r => r.provider.id);
}
hasOpenRepositories(id: GitProviderId): boolean {
return some(this.repositories, r => !r.closed && (id == null || id === r.provider.id));
}
private _discoveredWorkspaceFolders = new Map<WorkspaceFolder, Promise<Repository[]>>();
@log<GitProviderService['discoverRepositories']>({ args: { 0: folders => folders.length } })

+ 28
- 3
src/premium/github/githubGitProvider.ts Ver ficheiro

@ -15,8 +15,9 @@ import {
} from 'vscode';
import { encodeUtf8Hex } from '@env/hex';
import { configuration } from '../../configuration';
import { CharCode, Schemes } from '../../constants';
import { CharCode, ContextKeys, Schemes } from '../../constants';
import type { Container } from '../../container';
import { setContext } from '../../context';
import {
AuthenticationError,
AuthenticationErrorReason,
@ -156,6 +157,10 @@ export class GitHubGitProvider implements GitProvider, Disposable {
}
}
updateContext(): void {
void setContext(ContextKeys.HasVirtualFolders, this.container.git.hasOpenRepositories(this.descriptor.id));
}
openRepository(
folder: WorkspaceFolder | undefined,
uri: Uri,
@ -1334,10 +1339,30 @@ export class GitHubGitProvider implements GitProvider, Disposable {
@log()
async getLogForSearch(
_repoPath: string,
_search: SearchPattern,
repoPath: string,
search: SearchPattern,
_options?: { limit?: number; ordering?: string | null; skip?: number },
): Promise<GitLog | undefined> {
if (repoPath == null) return undefined;
const operations = SearchPattern.parseSearchOperations(search.pattern);
const values = operations.get('commit:');
if (values != null) {
const commit = await this.getCommit(repoPath, values[0]);
if (commit == null) return undefined;
return {
repoPath: repoPath,
commits: new Map([[commit.sha, commit]]),
sha: commit.sha,
range: undefined,
count: 1,
limit: 1,
hasMore: false,
};
}
// TODO@eamodio try implementing with the commit search api
return undefined;
}

Carregando…
Cancelar
Guardar