Skip to content

Commit

Permalink
Avoids more circular references
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Feb 7, 2022
1 parent 42aca90 commit 7b5c5ff
Show file tree
Hide file tree
Showing 145 changed files with 764 additions and 688 deletions.
8 changes: 4 additions & 4 deletions src/annotations/annotations.ts
Expand Up @@ -16,7 +16,7 @@ import { Colors, GlyphChars } from '../constants';
import { Container } from '../container';
import { CommitFormatOptions, CommitFormatter } from '../git/formatters';
import { GitCommit } from '../git/models';
import { Strings } from '../system';
import { getWidth, interpolate, pad } from '../system/string';
import { toRgba } from '../webviews/apps/shared/colors';

export interface ComputedHeatmap {
Expand Down Expand Up @@ -157,7 +157,7 @@ export class Annotations {
}

const message = CommitFormatter.fromTemplate(format, commit, dateFormatOrFormatOptions);
decoration.renderOptions!.before!.contentText = Strings.pad(message.replace(/ /g, GlyphChars.Space), 1, 1);
decoration.renderOptions!.before!.contentText = pad(message.replace(/ /g, GlyphChars.Space), 1, 1);

return decoration;
}
Expand Down Expand Up @@ -185,7 +185,7 @@ export class Annotations {

if (chars >= 0) {
// Add the chars of the template string (without tokens)
chars += Strings.getWidth(Strings.interpolate(format, undefined));
chars += getWidth(interpolate(format, undefined));
// If we have chars, add a bit of padding
if (chars > 0) {
chars += 3;
Expand Down Expand Up @@ -251,7 +251,7 @@ export class Annotations {
after: {
backgroundColor: new ThemeColor(Colors.TrailingLineBackgroundColor),
color: new ThemeColor(Colors.TrailingLineForegroundColor),
contentText: Strings.pad(message.replace(/ /g, GlyphChars.Space), 1, 1),
contentText: pad(message.replace(/ /g, GlyphChars.Space), 1, 1),
fontWeight: 'normal',
fontStyle: 'normal',
// Pull the decoration out of the document flow if we want to be scrollable
Expand Down
2 changes: 1 addition & 1 deletion src/annotations/blameAnnotationProvider.ts
Expand Up @@ -4,7 +4,7 @@ import { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitBlame, GitCommit } from '../git/models';
import { Hovers } from '../hovers/hovers';
import { log } from '../system';
import { log } from '../system/decorators/log';
import { GitDocumentState, TrackedDocument } from '../trackers/gitDocumentTracker';
import { AnnotationProviderBase } from './annotationProvider';
import { ComputedHeatmap, getHeatmapColors } from './annotations';
Expand Down
16 changes: 8 additions & 8 deletions src/annotations/gutterBlameAnnotationProvider.ts
Expand Up @@ -5,9 +5,11 @@ import { Container } from '../container';
import { CommitFormatOptions, CommitFormatter } from '../git/formatters';
import { GitBlame, GitCommit } from '../git/models';
import { Logger } from '../logger';
import { Arrays, Iterables, Strings } from '../system';
import { filterMap } from '../system/array';
import { log } from '../system/decorators/log';
import { first } from '../system/iterable';
import { Stopwatch } from '../system/stopwatch';
import { getTokensFromTemplate, getWidth, TokenOptions } from '../system/string';
import { GitDocumentState } from '../trackers/gitDocumentTracker';
import { TrackedDocument } from '../trackers/trackedDocument';
import { AnnotationContext } from './annotationProvider';
Expand Down Expand Up @@ -44,8 +46,8 @@ export class GutterBlameAnnotationProvider extends BlameAnnotationProviderBase {
const cfg = this.container.config.blame;

// Precalculate the formatting options so we don't need to do it on each iteration
const tokenOptions = Strings.getTokensFromTemplate(cfg.format).reduce<{
[token: string]: Strings.TokenOptions | undefined;
const tokenOptions = getTokensFromTemplate(cfg.format).reduce<{
[token: string]: TokenOptions | undefined;
}>((map, token) => {
map[token.key] = token.options;
return map;
Expand Down Expand Up @@ -102,9 +104,7 @@ export class GutterBlameAnnotationProvider extends BlameAnnotationProviderBase {
gutter.renderOptions = {
before: {
...gutter.renderOptions!.before,
contentText: GlyphChars.Space.repeat(
Strings.getWidth(gutter.renderOptions!.before!.contentText!),
),
contentText: GlyphChars.Space.repeat(getWidth(gutter.renderOptions!.before!.contentText!)),
},
};

Expand Down Expand Up @@ -191,15 +191,15 @@ export class GutterBlameAnnotationProvider extends BlameAnnotationProviderBase {
sha = commitLine?.sha;
}
} else {
sha = Iterables.first(blame.commits.values()).sha;
sha = first(blame.commits.values()).sha;
}

if (!sha) {
this.editor.setDecorations(Decorations.gutterBlameHighlight, []);
return;
}

const highlightDecorationRanges = Arrays.filterMap(blame.lines, l =>
const highlightDecorationRanges = filterMap(blame.lines, l =>
l.sha === sha
? // editor lines are 0-based
this.editor.document.validateRange(new Range(l.line - 1, 0, l.line - 1, Number.MAX_SAFE_INTEGER))
Expand Down
6 changes: 3 additions & 3 deletions src/api/actionRunners.ts
Expand Up @@ -3,8 +3,8 @@ import { Config, configuration } from '../configuration';
import { Commands, ContextKeys } from '../constants';
import { Container } from '../container';
import { setContext } from '../context';
import { getQuickPickIgnoreFocusOut } from '../quickpicks';
import { Strings } from '../system';
import { sortCompare } from '../system/string';
import { getQuickPickIgnoreFocusOut } from '../system/utils';
import type { Action, ActionContext, ActionRunner } from './gitlens';

type Actions = ActionContext['type'];
Expand Down Expand Up @@ -255,7 +255,7 @@ export class ActionRunners implements Disposable {
if (runners.length > 1 || runners.every(r => r.type !== ActionRunnerType.BuiltIn)) {
const items: (ActionRunnerQuickPickItem | NoActionRunnersQuickPickItem)[] = runners
// .filter(r => r.when(context))
.sort((a, b) => a.order - b.order || Strings.sortCompare(a.name, b.name))
.sort((a, b) => a.order - b.order || sortCompare(a.name, b.name))
.map(r => new ActionRunnerQuickPickItem(r, context));

if (items.length === 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/addAuthors.ts
@@ -1,7 +1,8 @@
import { SourceControl } from 'vscode';
import { Commands } from '../constants';
import type { Container } from '../container';
import { command, Command } from './base';
import { command } from '../system/command';
import { Command } from './base';
import { executeGitCommand } from './gitCommands.actions';

@command()
Expand Down
17 changes: 0 additions & 17 deletions src/commands/base.ts
Expand Up @@ -12,7 +12,6 @@ import {
} from 'vscode';
import type { ActionContext } from '../api/gitlens';
import { Commands } from '../constants';
import { Container } from '../container';
import {
GitBranch,
GitCommit,
Expand All @@ -26,22 +25,6 @@ import {
} from '../git/models';
import { ViewNode, ViewRefNode } from '../views/nodes';

interface CommandConstructor {
new (container: Container): Command;
}

const registrableCommands: CommandConstructor[] = [];

export function command(): ClassDecorator {
return (target: any) => {
registrableCommands.push(target);
};
}

export function registerCommands(container: Container): Disposable[] {
return registrableCommands.map(c => new c(container));
}

export function getCommandUri(uri?: Uri, editor?: TextEditor): Uri | undefined {
// Always use the editor.uri (if we have one), so we are correct for a split diff
return editor?.document?.uri ?? uri;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/browseRepoAtRevision.ts
Expand Up @@ -4,10 +4,10 @@ import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { executeCoreCommand } from '../system/command';
import { command, executeCoreCommand } from '../system/command';
import { basename } from '../system/path';
import { openWorkspace, OpenWorkspaceLocation } from '../system/utils';
import { ActiveEditorCommand, command, CommandContext, getCommandUri } from './base';
import { ActiveEditorCommand, CommandContext, getCommandUri } from './base';

export interface BrowseRepoAtRevisionCommandArgs {
uri?: Uri;
Expand Down
6 changes: 3 additions & 3 deletions src/commands/closeUnchangedFiles.ts
Expand Up @@ -4,10 +4,10 @@ import { Commands, CoreCommands } from '../constants';
import type { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { RepositoryPicker } from '../quickpicks';
import { executeCoreCommand } from '../system/command';
import { RepositoryPicker } from '../quickpicks/repositoryPicker';
import { command, executeCoreCommand } from '../system/command';
import { debounce } from '../system/function';
import { Command, command } from './base';
import { Command } from './base';

export interface CloseUnchangedFilesCommandArgs {
uris?: Uri[];
Expand Down
3 changes: 2 additions & 1 deletion src/commands/closeView.ts
Expand Up @@ -2,7 +2,8 @@ import { Commands, ContextKeys } from '../constants';
import type { Container } from '../container';
import { setContext } from '../context';
import { SyncedState } from '../storage';
import { command, Command, CommandContext } from './base';
import { command } from '../system/command';
import { Command, CommandContext } from './base';

@command()
export class CloseViewCommand extends Command {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/compareWith.ts
Expand Up @@ -3,8 +3,9 @@ import { Commands } from '../constants';
import type { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { RepositoryPicker } from '../quickpicks';
import { ActiveEditorCommand, command, CommandContext, getCommandUri } from './base';
import { RepositoryPicker } from '../quickpicks/repositoryPicker';
import { command } from '../system/command';
import { ActiveEditorCommand, CommandContext, getCommandUri } from './base';

export interface CompareWithCommandArgs {
ref1?: string;
Expand Down
5 changes: 3 additions & 2 deletions src/commands/copyCurrentBranch.ts
Expand Up @@ -3,8 +3,9 @@ import { Commands } from '../constants';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { RepositoryPicker } from '../quickpicks';
import { ActiveEditorCommand, command, getCommandUri } from './base';
import { RepositoryPicker } from '../quickpicks/repositoryPicker';
import { command } from '../system/command';
import { ActiveEditorCommand, getCommandUri } from './base';

@command()
export class CopyCurrentBranchCommand extends ActiveEditorCommand {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/copyMessageToClipboard.ts
Expand Up @@ -4,10 +4,10 @@ import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { Iterables } from '../system';
import { command } from '../system/command';
import { first } from '../system/iterable';
import {
ActiveEditorCommand,
command,
CommandContext,
getCommandUri,
isCommandContextViewNodeHasBranch,
Expand Down Expand Up @@ -60,7 +60,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
const log = await this.container.git.getLog(repoPath, { limit: 1 });
if (log == null) return;

const commit = Iterables.first(log.commits.values());
const commit = first(log.commits.values());
if (commit?.message == null) return;

args.message = commit.message;
Expand Down
6 changes: 3 additions & 3 deletions src/commands/copyShaToClipboard.ts
Expand Up @@ -4,10 +4,10 @@ import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { Iterables } from '../system';
import { command } from '../system/command';
import { first } from '../system/iterable';
import {
ActiveEditorCommand,
command,
CommandContext,
getCommandUri,
isCommandContextViewNodeHasBranch,
Expand Down Expand Up @@ -58,7 +58,7 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand {
const log = await this.container.git.getLog(repoPath, { limit: 1 });
if (log == null) return;

args.sha = Iterables.first(log.commits.values()).sha;
args.sha = first(log.commits.values()).sha;
} else if (args.sha == null) {
const blameline = editor?.selection.active.line ?? 0;
if (blameline < 0) return;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/createPullRequestOnRemote.ts
Expand Up @@ -2,8 +2,8 @@ import { Commands } from '../constants';
import type { Container } from '../container';
import { GitRemote } from '../git/models';
import { RemoteProvider, RemoteResource, RemoteResourceType } from '../git/remotes/provider';
import { executeCommand } from '../system/command';
import { Command, command } from './base';
import { command, executeCommand } from '../system/command';
import { Command } from './base';
import { OpenOnRemoteCommandArgs } from './openOnRemote';

export interface CreatePullRequestOnRemoteCommandArgs {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/diffLineWithPrevious.ts
Expand Up @@ -5,8 +5,8 @@ import { GitUri } from '../git/gitUri';
import { GitCommit } from '../git/models';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { executeCommand } from '../system/command';
import { ActiveEditorCommand, command, getCommandUri } from './base';
import { command, executeCommand } from '../system/command';
import { ActiveEditorCommand, getCommandUri } from './base';
import { DiffWithCommandArgs } from './diffWith';

export interface DiffLineWithPreviousCommandArgs {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/diffLineWithWorking.ts
Expand Up @@ -5,8 +5,8 @@ import { GitUri } from '../git/gitUri';
import { GitCommit, GitRevision } from '../git/models';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { executeCommand } from '../system/command';
import { ActiveEditorCommand, command, getCommandUri } from './base';
import { command, executeCommand } from '../system/command';
import { ActiveEditorCommand, getCommandUri } from './base';
import { DiffWithCommandArgs } from './diffWith';

export interface DiffLineWithWorkingCommandArgs {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/diffWith.ts
Expand Up @@ -4,9 +4,9 @@ import type { Container } from '../container';
import { GitCommit, GitRevision } from '../git/models';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { executeCoreCommand } from '../system/command';
import { command, executeCoreCommand } from '../system/command';
import { basename } from '../system/path';
import { command, Command } from './base';
import { Command } from './base';

export interface DiffWithCommandArgsRevision {
sha: string;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/diffWithNext.ts
Expand Up @@ -5,8 +5,8 @@ import { GitUri } from '../git/gitUri';
import { GitCommit } from '../git/models';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { executeCommand } from '../system/command';
import { ActiveEditorCommand, command, CommandContext, getCommandUri } from './base';
import { command, executeCommand } from '../system/command';
import { ActiveEditorCommand, CommandContext, getCommandUri } from './base';
import { DiffWithCommandArgs } from './diffWith';

export interface DiffWithNextCommandArgs {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/diffWithPrevious.ts
Expand Up @@ -5,9 +5,9 @@ import { GitUri } from '../git/gitUri';
import { GitCommit, GitRevision } from '../git/models';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { executeCommand } from '../system/command';
import { command, executeCommand } from '../system/command';
import { findOrOpenEditor } from '../system/utils';
import { ActiveEditorCommand, command, CommandContext, getCommandUri } from './base';
import { ActiveEditorCommand, CommandContext, getCommandUri } from './base';
import { DiffWithCommandArgs } from './diffWith';

export interface DiffWithPreviousCommandArgs {
Expand Down
11 changes: 6 additions & 5 deletions src/commands/diffWithRevision.ts
Expand Up @@ -5,10 +5,11 @@ import { GitUri } from '../git/gitUri';
import { GitRevision } from '../git/models';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { CommandQuickPickItem, CommitPicker } from '../quickpicks';
import { Strings } from '../system';
import { executeCommand } from '../system/command';
import { ActiveEditorCommand, command, getCommandUri } from './base';
import { CommitPicker } from '../quickpicks/commitPicker';
import { CommandQuickPickItem } from '../quickpicks/items/common';
import { command, executeCommand } from '../system/command';
import { pad } from '../system/string';
import { ActiveEditorCommand, getCommandUri } from './base';
import { DiffWithCommandArgs } from './diffWith';
import { DiffWithRevisionFromCommandArgs } from './diffWithRevisionFrom';

Expand Down Expand Up @@ -45,7 +46,7 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
: undefined),
);

const title = `Open Changes with Revision${Strings.pad(GlyphChars.Dot, 2, 2)}`;
const title = `Open Changes with Revision${pad(GlyphChars.Dot, 2, 2)}`;
const pick = await CommitPicker.show(
log,
`${title}${gitUri.getFormattedFileName({
Expand Down
13 changes: 7 additions & 6 deletions src/commands/diffWithRevisionFrom.ts
Expand Up @@ -4,11 +4,12 @@ import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitReference, GitRevision } from '../git/models';
import { Messages } from '../messages';
import { ReferencePicker, StashPicker } from '../quickpicks';
import { Strings } from '../system';
import { executeCommand } from '../system/command';
import { StashPicker } from '../quickpicks/commitPicker';
import { ReferencePicker } from '../quickpicks/referencePicker';
import { command, executeCommand } from '../system/command';
import { basename } from '../system/path';
import { ActiveEditorCommand, command, getCommandUri } from './base';
import { pad } from '../system/string';
import { ActiveEditorCommand, getCommandUri } from './base';
import { DiffWithCommandArgs } from './diffWith';

export interface DiffWithRevisionFromCommandArgs {
Expand Down Expand Up @@ -44,7 +45,7 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand {
let ref;
let sha;
if (args?.stash) {
const title = `Open Changes with Stash${Strings.pad(GlyphChars.Dot, 2, 2)}`;
const title = `Open Changes with Stash${pad(GlyphChars.Dot, 2, 2)}`;
const pick = await StashPicker.show(
this.container.git.getStash(gitUri.repoPath),
`${title}${gitUri.getFormattedFileName({ truncateTo: quickPickTitleMaxChars - title.length })}`,
Expand All @@ -60,7 +61,7 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand {
ref = pick.ref;
sha = ref;
} else {
const title = `Open Changes with Branch or Tag${Strings.pad(GlyphChars.Dot, 2, 2)}`;
const title = `Open Changes with Branch or Tag${pad(GlyphChars.Dot, 2, 2)}`;
const pick = await ReferencePicker.show(
gitUri.repoPath,
`${title}${gitUri.getFormattedFileName({ truncateTo: quickPickTitleMaxChars - title.length })}`,
Expand Down

0 comments on commit 7b5c5ff

Please sign in to comment.