Enables typescript strict mode

Fixes all the compile/lint issues
This commit is contained in:
Eric Amodio
2017-05-11 02:14:58 -04:00
parent 90245b1111
commit ee29596d45
52 changed files with 525 additions and 461 deletions

View File

@@ -35,7 +35,7 @@ export class BranchHistoryQuickPick {
description: `\u00a0 \u2014 \u00a0\u00a0 search for commits by message, author, files, or commit id`
}, Commands.ShowCommitSearch, [new GitUri(Uri.file(log.repoPath), { fileName: '', repoPath: log.repoPath }), undefined, undefined, currentCommand]));
let previousPageCommand: CommandQuickPickItem;
let previousPageCommand: CommandQuickPickItem | undefined = undefined;
if (log.truncated || log.sha) {
if (log.truncated) {
@@ -72,13 +72,14 @@ export class BranchHistoryQuickPick {
}, Commands.ShowQuickBranchHistory, [uri, branch, log.maxCount, goBackCommand, undefined, nextPageCommand]);
const last = Iterables.last(log.commits.values());
if (last != null) {
previousPageCommand = new CommandQuickPickItem({
label: `$(arrow-left) Show Previous Commits`,
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} older commits`
}, Commands.ShowQuickBranchHistory, [new GitUri(uri ? uri : last.uri, last), branch, log.maxCount, goBackCommand, undefined, npc]);
previousPageCommand = new CommandQuickPickItem({
label: `$(arrow-left) Show Previous Commits`,
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} older commits`
}, Commands.ShowQuickBranchHistory, [new GitUri(uri ? uri : last.uri, last), branch, log.maxCount, goBackCommand, undefined, npc]);
items.splice(0, 0, previousPageCommand);
items.splice(0, 0, previousPageCommand);
}
}
}

View File

@@ -11,7 +11,7 @@ export class BranchQuickPickItem implements QuickPickItem {
constructor(public branch: GitBranch) {
this.label = `${branch.current ? '$(check)\u00a0' : '\u00a0\u00a0\u00a0\u00a0'} ${branch.name}`;
this.description = branch.remote ? '\u00a0\u00a0 remote branch' : null;
this.description = branch.remote ? '\u00a0\u00a0 remote branch' : '';
}
}

View File

@@ -19,20 +19,20 @@ export class CommitWithFileStatusQuickPickItem extends OpenFileCommandQuickPickI
constructor(commit: GitCommit, status: IGitStatusFile) {
const icon = getGitStatusIcon(status.status);
let directory = GitService.normalizePath(path.dirname(status.fileName));
let directory: string | undefined = GitService.normalizePath(path.dirname(status.fileName));
if (!directory || directory === '.') {
directory = undefined;
directory = '';
}
const description = (status.status === 'R' && status.originalFileName)
? `${directory || ''} \u00a0\u2190\u00a0 ${status.originalFileName}`
? `${directory} \u00a0\u2190\u00a0 ${status.originalFileName}`
: directory;
let sha;
let shortSha;
if (status.status === 'D') {
sha = commit.previousSha;
shortSha = commit.previousShortSha;
sha = commit.previousSha!;
shortSha = commit.previousShortSha!;
}
else {
sha = commit.sha;
@@ -56,7 +56,7 @@ export class OpenCommitFilesCommandQuickPickItem extends OpenFilesCommandQuickPi
constructor(commit: GitLogCommit, item?: QuickPickItem) {
const uris = commit.fileStatuses.map(s => (s.status === 'D')
? GitService.toGitContentUri(commit.previousSha, commit.previousShortSha, s.fileName, commit.repoPath, s.originalFileName)
? GitService.toGitContentUri(commit.previousSha!, commit.previousShortSha!, s.fileName, commit.repoPath, s.originalFileName)
: GitService.toGitContentUri(commit.sha, commit.shortSha, s.fileName, commit.repoPath, s.originalFileName));
super(uris, item || {
@@ -74,7 +74,7 @@ export class OpenCommitWorkingTreeFilesCommandQuickPickItem extends OpenFilesCom
const uris = commit.fileStatuses.filter(_ => _.status !== 'D').map(_ => GitUri.fromFileStatus(_, repoPath));
super(uris, item || {
label: `$(file-symlink-file) Open Changed Working Files`,
description: undefined
description: ''
//detail: `Opens all of the changed file in the working tree`
});
}
@@ -142,13 +142,13 @@ export class CommitDetailsQuickPick {
items.splice(0, 0, goBackCommand);
}
let previousCommand: CommandQuickPickItem | (() => Promise<CommandQuickPickItem>);
let nextCommand: CommandQuickPickItem | (() => Promise<CommandQuickPickItem>);
let previousCommand: CommandQuickPickItem | (() => Promise<CommandQuickPickItem>) | undefined = undefined;
let nextCommand: CommandQuickPickItem | (() => Promise<CommandQuickPickItem>) | undefined = undefined;
if (!stash) {
// If we have the full history, we are good
if (repoLog && !repoLog.truncated && !repoLog.sha) {
previousCommand = commit.previousSha && new KeyCommandQuickPickItem(Commands.ShowQuickCommitDetails, [commit.previousUri, commit.previousSha, undefined, goBackCommand, repoLog]);
nextCommand = commit.nextSha && new KeyCommandQuickPickItem(Commands.ShowQuickCommitDetails, [commit.nextUri, commit.nextSha, undefined, goBackCommand, repoLog]);
previousCommand = commit.previousSha === undefined ? undefined : new KeyCommandQuickPickItem(Commands.ShowQuickCommitDetails, [commit.previousUri, commit.previousSha, undefined, goBackCommand, repoLog]);
nextCommand = commit.nextSha === undefined ? undefined : new KeyCommandQuickPickItem(Commands.ShowQuickCommitDetails, [commit.nextUri, commit.nextSha, undefined, goBackCommand, repoLog]);
}
else {
previousCommand = async () => {

View File

@@ -3,7 +3,7 @@ import { Arrays, Iterables } from '../system';
import { QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
import { Commands, Keyboard, KeyNoopCommand } from '../commands';
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, KeyCommandQuickPickItem, OpenFileCommandQuickPickItem } from './common';
import { GitLogCommit, GitService, GitUri, IGitLog } from '../gitService';
import { GitBranch, GitLogCommit, GitService, GitUri, IGitLog } from '../gitService';
import { OpenRemotesCommandQuickPickItem } from './remotes';
import * as moment from 'moment';
import * as path from 'path';
@@ -14,7 +14,7 @@ export class OpenCommitFileCommandQuickPickItem extends OpenFileCommandQuickPick
let description: string;
let uri: Uri;
if (commit.status === 'D') {
uri = GitService.toGitContentUri(commit.previousSha, commit.previousShortSha, commit.previousFileName, commit.repoPath, undefined);
uri = GitService.toGitContentUri(commit.previousSha!, commit.previousShortSha!, commit.previousFileName!, commit.repoPath, undefined);
description = `\u00a0 \u2014 \u00a0\u00a0 ${path.basename(commit.fileName)} in \u00a0$(git-commit) ${commit.previousShortSha} (deleted in \u00a0$(git-commit) ${commit.shortSha})`;
}
else {
@@ -51,8 +51,10 @@ export class CommitFileDetailsQuickPick {
const isUncommitted = commit.isUncommitted;
if (isUncommitted) {
// Since we can't trust the previous sha on an uncommitted commit, find the last commit for this file
commit = await git.getLogCommit(undefined, commit.uri.fsPath, { previous: true });
if (!commit) return undefined;
const c = await git.getLogCommit(undefined, commit.uri.fsPath, { previous: true });
if (c === undefined) return undefined;
commit = c;
}
if (!stash) {
@@ -99,7 +101,7 @@ export class CommitFileDetailsQuickPick {
items.push(new OpenRemotesCommandQuickPickItem(remotes, 'file', commit.fileName, undefined, commit, currentCommand));
}
if (commit.workingFileName && commit.status !== 'D') {
const branch = await git.getBranch(commit.repoPath || git.repoPath);
const branch = await git.getBranch(commit.repoPath || git.repoPath) as GitBranch;
items.push(new OpenRemotesCommandQuickPickItem(remotes, 'working-file', commit.workingFileName, branch.name, undefined, currentCommand));
}
}
@@ -122,13 +124,13 @@ export class CommitFileDetailsQuickPick {
items.splice(0, 0, goBackCommand);
}
let previousCommand: CommandQuickPickItem | (() => Promise<CommandQuickPickItem>);
let nextCommand: CommandQuickPickItem | (() => Promise<CommandQuickPickItem>);
let previousCommand: CommandQuickPickItem | (() => Promise<CommandQuickPickItem>) | undefined = undefined;
let nextCommand: CommandQuickPickItem | (() => Promise<CommandQuickPickItem>) | undefined = undefined;
if (!stash) {
// If we have the full history, we are good
if (fileLog && !fileLog.truncated && !fileLog.sha) {
previousCommand = commit.previousSha && new KeyCommandQuickPickItem(Commands.ShowQuickCommitFileDetails, [commit.previousUri, commit.previousSha, undefined, goBackCommand, fileLog]);
nextCommand = commit.nextSha && new KeyCommandQuickPickItem(Commands.ShowQuickCommitFileDetails, [commit.nextUri, commit.nextSha, undefined, goBackCommand, fileLog]);
previousCommand = commit.previousSha === undefined ? undefined : new KeyCommandQuickPickItem(Commands.ShowQuickCommitFileDetails, [commit.previousUri, commit.previousSha, undefined, goBackCommand, fileLog]);
nextCommand = commit.nextSha === undefined ? undefined : new KeyCommandQuickPickItem(Commands.ShowQuickCommitFileDetails, [commit.nextUri, commit.nextSha, undefined, goBackCommand, fileLog]);
}
else {
previousCommand = async () => {
@@ -138,6 +140,8 @@ export class CommitFileDetailsQuickPick {
// If we can't find the commit or the previous commit isn't available (since it isn't trustworthy)
if (!c || !c.previousSha) {
log = await git.getLogForFile(commit.repoPath, uri.fsPath, commit.sha, git.config.advanced.maxQuickHistory);
if (log === undefined) return KeyNoopCommand;
c = log && log.commits.get(commit.sha);
// Since we exclude merge commits in file log, just grab the first returned commit
if (!c && commit.isMerge) {

View File

@@ -8,7 +8,8 @@ import { GitCommit, GitLogCommit, GitStashCommit } from '../gitService';
import * as moment from 'moment';
export function getQuickPickIgnoreFocusOut() {
return !workspace.getConfiguration(ExtensionKey).get<IAdvancedConfig>('advanced').quickPick.closeOnFocusOut;
const cfg = workspace.getConfiguration(ExtensionKey).get<IAdvancedConfig>('advanced')!;
return !cfg.quickPick.closeOnFocusOut;
}
export function showQuickPickProgress(message: string, mapping?: KeyMapping, delay: boolean = false): CancellationTokenSource {
@@ -32,7 +33,7 @@ export function showQuickPickProgress(message: string, mapping?: KeyMapping, del
async function _showQuickPickProgress(message: string, cancellation: CancellationTokenSource, mapping?: KeyMapping) {
// Logger.log(`showQuickPickProgress`, `show`, message);
const scope: KeyboardScope = mapping && await Keyboard.instance.beginScope(mapping);
const scope: KeyboardScope | undefined = mapping && await Keyboard.instance.beginScope(mapping);
try {
await window.showQuickPick(_getInfiniteCancellablePromise(cancellation), {
@@ -64,21 +65,23 @@ export class CommandQuickPickItem implements QuickPickItem {
label: string;
description: string;
detail: string;
detail?: string | undefined;
constructor(item: QuickPickItem, protected command: Commands, protected args?: any[]) {
constructor(item: QuickPickItem, protected command: Commands | undefined, protected args?: any[]) {
Object.assign(this, item);
}
execute(): Thenable<{}> {
execute(): Thenable<{} | undefined> {
if (this.command === undefined) return Promise.resolve(undefined);
return commands.executeCommand(this.command, ...(this.args || []));
}
}
export class KeyCommandQuickPickItem extends CommandQuickPickItem {
constructor(protected command: Commands, protected args?: any[]) {
super({ label: undefined, description: undefined }, command, args);
constructor(command: Commands, args?: any[]) {
super({ label: '', description: '' } as QuickPickItem, command, args);
}
}
@@ -88,7 +91,7 @@ export class OpenFileCommandQuickPickItem extends CommandQuickPickItem {
super(item, undefined, undefined);
}
async execute(pinned: boolean = false): Promise<{}> {
async execute(pinned: boolean = false): Promise<{} | undefined> {
return this.open(pinned);
}
@@ -103,7 +106,7 @@ export class OpenFilesCommandQuickPickItem extends CommandQuickPickItem {
super(item, undefined, undefined);
}
async execute(): Promise<{}> {
async execute(): Promise<{} | undefined> {
for (const uri of this.uris) {
await openEditor(uri, true);
}
@@ -126,7 +129,7 @@ export class CommitQuickPickItem implements QuickPickItem {
if (commit instanceof GitStashCommit) {
this.label = `${commit.stashName}\u00a0\u2022\u00a0${message}`;
this.description = null;
this.description = '';
this.detail = `\u00a0 ${moment(commit.date).fromNow()}\u00a0\u00a0\u2022\u00a0 ${commit.getDiffStatus()}`;
}
else {

View File

@@ -21,7 +21,7 @@ export class FileHistoryQuickPick {
static async show(git: GitService, log: IGitLog, uri: GitUri, progressCancellation: CancellationTokenSource, goBackCommand?: CommandQuickPickItem, nextPageCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
const items = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c))) as (CommitQuickPickItem | CommandQuickPickItem)[];
let previousPageCommand: CommandQuickPickItem;
let previousPageCommand: CommandQuickPickItem | undefined = undefined;
let index = 0;
if (log.truncated || log.sha) {
@@ -63,18 +63,19 @@ export class FileHistoryQuickPick {
}, Commands.ShowQuickFileHistory, [uri, undefined, log.maxCount, goBackCommand, undefined, nextPageCommand]);
const last = Iterables.last(log.commits.values());
if (last != null) {
previousPageCommand = new CommandQuickPickItem({
label: `$(arrow-left) Show Previous Commits`,
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} older commits`
}, Commands.ShowQuickFileHistory, [new GitUri(uri, last), undefined, log.maxCount, goBackCommand, undefined, npc]);
previousPageCommand = new CommandQuickPickItem({
label: `$(arrow-left) Show Previous Commits`,
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} older commits`
}, Commands.ShowQuickFileHistory, [new GitUri(uri, last), undefined, log.maxCount, goBackCommand, undefined, npc]);
index++;
items.splice(0, 0, previousPageCommand);
index++;
items.splice(0, 0, previousPageCommand);
}
}
}
const branch = await git.getBranch(uri.repoPath);
const branch = await git.getBranch(uri.repoPath!);
const currentCommand = new CommandQuickPickItem({
label: `go back \u21A9`,
@@ -85,7 +86,7 @@ export class FileHistoryQuickPick {
if (!goBackCommand) {
items.splice(index++, 0, new CommandQuickPickItem({
label: `$(history) Show Branch History`,
description: `\u00a0 \u2014 \u00a0\u00a0 shows \u00a0$(git-branch) ${branch.name} history`
description: `\u00a0 \u2014 \u00a0\u00a0 shows \u00a0$(git-branch) ${branch!.name} history`
}, Commands.ShowQuickCurrentBranchHistory,
[
undefined,
@@ -93,9 +94,9 @@ export class FileHistoryQuickPick {
]));
}
const remotes = Arrays.uniqueBy(await git.getRemotes(uri.repoPath), _ => _.url, _ => !!_.provider);
const remotes = Arrays.uniqueBy(await git.getRemotes(uri.repoPath!), _ => _.url, _ => !!_.provider);
if (remotes.length) {
items.splice(index++, 0, new OpenRemotesCommandQuickPickItem(remotes, 'file', uri.getRelativePath(), branch.name, uri.sha, currentCommand));
items.splice(index++, 0, new OpenRemotesCommandQuickPickItem(remotes, 'file', uri.getRelativePath(), branch!.name, uri.sha, currentCommand));
}
if (goBackCommand) {

View File

@@ -12,8 +12,8 @@ export class OpenRemoteCommandQuickPickItem extends CommandQuickPickItem {
constructor(remote: GitRemote, type: RemoteOpenType, ...args: string[]) {
super({
label: `$(link-external) Open ${getNameFromRemoteOpenType(type)} in ${remote.provider.name}`,
description: `\u00a0 \u2014 \u00a0\u00a0 $(repo) ${remote.provider.path}`
label: `$(link-external) Open ${getNameFromRemoteOpenType(type)} in ${remote.provider!.name}`,
description: `\u00a0 \u2014 \u00a0\u00a0 $(repo) ${remote.provider!.path}`
}, undefined, undefined);
this.remote = remote;
@@ -22,7 +22,7 @@ export class OpenRemoteCommandQuickPickItem extends CommandQuickPickItem {
}
async execute(): Promise<{}> {
return this.remote.provider.open(this.type, ...this.args);
return this.remote.provider!.open(this.type, ...this.args!);
}
}
@@ -33,7 +33,7 @@ export class OpenRemotesCommandQuickPickItem extends CommandQuickPickItem {
constructor(remotes: GitRemote[], type: 'file', fileName: string, branch?: string, commit?: GitLogCommit, goBackCommand?: CommandQuickPickItem);
constructor(remotes: GitRemote[], type: 'file' | 'working-file', fileName: string, branch?: string, sha?: string, goBackCommand?: CommandQuickPickItem);
constructor(remotes: GitRemote[], type: RemoteOpenType, branchOrShaOrFileName: string, goBackCommandOrFileBranch?: CommandQuickPickItem | string, fileShaOrCommit?: string | GitLogCommit, goBackCommand?: CommandQuickPickItem) {
let fileBranch: string;
let fileBranch: string | undefined = undefined;
if (typeof goBackCommandOrFileBranch === 'string') {
fileBranch = goBackCommandOrFileBranch;
}
@@ -43,9 +43,9 @@ export class OpenRemotesCommandQuickPickItem extends CommandQuickPickItem {
const name = getNameFromRemoteOpenType(type);
let fileSha: string;
let description: string;
let placeHolder: string;
let fileSha: string | undefined = undefined;
let description: string | undefined = undefined;
let placeHolder: string | undefined = undefined;
switch (type) {
case 'branch':
description = `$(git-branch) ${branchOrShaOrFileName}`;
@@ -88,15 +88,15 @@ export class OpenRemotesCommandQuickPickItem extends CommandQuickPickItem {
const remote = remotes[0];
if (remotes.length === 1) {
super({
label: `$(link-external) Open ${name} in ${remote.provider.name}`,
description: `\u00a0 \u2014 \u00a0\u00a0 $(repo) ${remote.provider.path} \u00a0\u2022\u00a0 ${description}`
label: `$(link-external) Open ${name} in ${remote.provider!.name}`,
description: `\u00a0 \u2014 \u00a0\u00a0 $(repo) ${remote.provider!.path} \u00a0\u2022\u00a0 ${description}`
}, Commands.OpenInRemote, [undefined, remotes, type, [branchOrShaOrFileName, fileBranch, fileSha], goBackCommand]);
return;
}
const provider = remotes.every(_ => _.provider.name === remote.provider.name)
? remote.provider.name
const provider = remotes.every(_ => _.provider !== undefined && _.provider.name === remote.provider!.name)
? remote.provider!.name
: 'Remote';
super({

View File

@@ -11,13 +11,13 @@ export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPick
constructor(status: GitStatusFile, item?: QuickPickItem) {
const icon = status.getIcon();
let directory = GitService.normalizePath(path.dirname(status.fileName));
let directory: string | undefined = GitService.normalizePath(path.dirname(status.fileName));
if (!directory || directory === '.') {
directory = undefined;
directory = '';
}
let description = (status.status === 'R' && status.originalFileName)
? `${directory || ''} \u00a0\u2190\u00a0 ${status.originalFileName}`
? `${directory} \u00a0\u2190\u00a0 ${status.originalFileName}`
: directory;
super(status.Uri, item || {
@@ -34,7 +34,7 @@ export class OpenStatusFilesCommandQuickPickItem extends CommandQuickPickItem {
super(item || {
label: `$(file-symlink-file) Open Changed Files`,
description: undefined
description: ''
//detail: `Opens all of the changed files in the repository`
}, Commands.OpenChangedFiles, [undefined, uris]);
}
@@ -85,12 +85,12 @@ export class RepoStatusQuickPick {
items.splice(unstagedIndex, 0, new OpenStatusFilesCommandQuickPickItem(files.filter(_ => _.status !== 'D' && _.staged), {
label: `\u00a0\u00a0\u00a0\u00a0 $(file-symlink-file) Open Staged Files`,
description: undefined
description: ''
}));
items.push(new OpenStatusFilesCommandQuickPickItem(files.filter(_ => _.status !== 'D' && !_.staged), {
label: `\u00a0\u00a0\u00a0\u00a0 $(file-symlink-file) Open Unstaged Files`,
description: undefined
description: ''
}));
}
@@ -110,13 +110,13 @@ export class RepoStatusQuickPick {
items.push(new OpenStatusFilesCommandQuickPickItem(files.filter(_ => _.status !== 'D')));
items.push(new CommandQuickPickItem({
label: '$(x) Close Unchanged Files',
description: null
description: ''
}, Commands.CloseUnchangedFiles));
}
else {
items.push(new CommandQuickPickItem({
label: `No changes in the working tree`,
description: null
description: ''
}, Commands.ShowQuickRepoStatus, [undefined, goBackCommand]));
}
@@ -150,7 +150,7 @@ export class RepoStatusQuickPick {
if (status.upstream && !status.state.ahead && !status.state.behind) {
items.splice(0, 0, new CommandQuickPickItem({
label: `$(git-branch) ${status.branch} is up-to-date with \u00a0$(git-branch) ${status.upstream}`,
description: null
description: ''
}, Commands.ShowQuickRepoStatus, [undefined, goBackCommand]));
}