Browse Source

Improves logging type-safety

main
Eric Amodio 3 years ago
parent
commit
fae7449a0b
15 changed files with 146 additions and 300 deletions
  1. +9
    -8
      src/annotations/autolinks.ts
  2. +36
    -97
      src/git/gitProviderService.ts
  3. +23
    -72
      src/git/providers/localGitProvider.ts
  4. +6
    -36
      src/github/github.ts
  5. +11
    -10
      src/hovers/lineHoverController.ts
  6. +2
    -2
      src/statusbar/statusBarController.ts
  7. +27
    -8
      src/system/decorators/log.ts
  8. +10
    -15
      src/trackers/gitLineTracker.ts
  9. +2
    -2
      src/views/nodes/lineHistoryTrackerNode.ts
  10. +3
    -7
      src/views/nodes/repositoryNode.ts
  11. +1
    -5
      src/views/nodes/viewNode.ts
  12. +1
    -3
      src/views/searchAndCompareView.ts
  13. +12
    -24
      src/views/viewBase.ts
  14. +2
    -10
      src/vsls/vsls.ts
  15. +1
    -1
      src/webviews/rebaseEditor.ts

+ 9
- 8
src/annotations/autolinks.ts View File

@ -47,11 +47,11 @@ export class Autolinks implements Disposable {
}
}
@debug({
@debug<Autolinks['getIssueOrPullRequestLinks']>({
args: {
0: (message: string) => message.substring(0, 50),
1: _ => false,
2: ({ timeout }) => timeout,
0: message => message.substring(0, 50),
1: false,
2: options => options?.timeout,
},
})
async getIssueOrPullRequestLinks(message: string, remote: GitRemote, { timeout }: { timeout?: number } = {}) {
@ -101,11 +101,12 @@ export class Autolinks implements Disposable {
return issuesOrPullRequests;
}
@debug({
@debug<Autolinks['linkify']>({
args: {
0: (text: string) => text.substring(0, 30),
2: _ => false,
3: _ => false,
0: text => text.substring(0, 30),
2: remotes => remotes?.length,
3: issuesOrPullRequests => issuesOrPullRequests?.size,
4: footnotes => footnotes?.size,
},
})
linkify(

+ 36
- 97
src/git/gitProviderService.ts View File

@ -163,7 +163,7 @@ export class GitProviderService implements Disposable {
}
}
@debug()
@debug<GitProviderService['onWindowStateChanged']>({ args: { 0: e => `focused=${e.focused}` } })
private onWindowStateChanged(e: WindowState) {
if (e.focused) {
this._repositories.forEach(r => r.resume());
@ -268,7 +268,7 @@ export class GitProviderService implements Disposable {
* @param provider A provider for handling git operations
* @returns A disposable to unregister the {@link GitProvider}
*/
@log({ args: { 1: () => false }, singleLine: true })
@log({ args: { 1: false }, singleLine: true })
register(id: GitProviderId, provider: GitProvider): Disposable {
if (this._providers.has(id)) throw new Error(`Provider '${id}' has already been registered`);
@ -364,7 +364,7 @@ export class GitProviderService implements Disposable {
private _discoveredWorkspaceFolders = new Map<WorkspaceFolder, Promise<Repository[]>>();
@log<GitProviderService['discoverRepositories']>({ args: { 0: folders => `${folders.length}` } })
@log<GitProviderService['discoverRepositories']>({ args: { 0: folders => folders.length } })
async discoverRepositories(folders: readonly WorkspaceFolder[], options?: { force?: boolean }): Promise<void> {
const promises = [];
@ -587,12 +587,7 @@ export class GitProviderService implements Disposable {
void Promise.allSettled([...this._providers.values()].map(provider => provider.resetCaches(...cache)));
}
@log({
args: {
0: (repoPath: string) => repoPath,
1: (uris: Uri[]) => `${uris.length}`,
},
})
@log<GitProviderService['excludeIgnoredUris']>({ args: { 1: uris => uris.length } })
async excludeIgnoredUris(repoPath: string, uris: Uri[]): Promise<Uri[]> {
const { provider, path } = this.getProvider(repoPath);
return provider.excludeIgnoredUris(path, uris);
@ -611,11 +606,7 @@ export class GitProviderService implements Disposable {
@gate<GitProviderService['fetchAll']>(
(repos, opts) => `${repos == null ? '' : repos.map(r => r.id).join(',')}|${JSON.stringify(opts)}`,
)
@log({
args: {
0: (repos?: Repository[]) => (repos == null ? false : repos.map(r => r.name).join(', ')),
},
})
@log<GitProviderService['fetchAll']>({ args: { 0: repos => repos?.map(r => r.name).join(', ') } })
async fetchAll(repositories?: Repository[], options?: { all?: boolean; prune?: boolean }) {
if (repositories == null) {
repositories = this.openRepositories;
@ -640,11 +631,7 @@ export class GitProviderService implements Disposable {
@gate<GitProviderService['pullAll']>(
(repos, opts) => `${repos == null ? '' : repos.map(r => r.id).join(',')}|${JSON.stringify(opts)}`,
)
@log({
args: {
0: (repos?: Repository[]) => (repos == null ? false : repos.map(r => r.name).join(', ')),
},
})
@log<GitProviderService['pullAll']>({ args: { 0: repos => repos?.map(r => r.name).join(', ') } })
async pullAll(repositories?: Repository[], options?: { rebase?: boolean }) {
if (repositories == null) {
repositories = this.openRepositories;
@ -667,11 +654,7 @@ export class GitProviderService implements Disposable {
}
@gate<GitProviderService['pushAll']>(repos => `${repos == null ? '' : repos.map(r => r.id).join(',')}`)
@log({
args: {
0: (repos?: Repository[]) => (repos == null ? false : repos.map(r => r.name).join(', ')),
},
})
@log<GitProviderService['pushAll']>({ args: { 0: repos => repos?.map(r => r.name).join(', ') } })
async pushAll(
repositories?: Repository[],
options?: {
@ -702,11 +685,8 @@ export class GitProviderService implements Disposable {
);
}
@log({
args: {
0: (editor: TextEditor) =>
editor != null ? `TextEditor(${Logger.toLoggable(editor.document.uri)})` : 'undefined',
},
@log<GitProviderService['getActiveRepository']>({
args: { 0: e => (e != null ? `TextEditor(${Logger.toLoggable(e.document.uri)})` : undefined) },
})
async getActiveRepository(editor?: TextEditor): Promise<Repository | undefined> {
const repoPath = await this.getActiveRepoPath(editor);
@ -715,11 +695,8 @@ export class GitProviderService implements Disposable {
return this.getRepository(repoPath);
}
@log({
args: {
0: (editor: TextEditor) =>
editor != null ? `TextEditor(${Logger.toLoggable(editor.document.uri)})` : 'undefined',
},
@log<GitProviderService['getActiveRepoPath']>({
args: { 0: e => (e != null ? `TextEditor(${Logger.toLoggable(e.document.uri)})` : undefined) },
})
async getActiveRepoPath(editor?: TextEditor): Promise<string | undefined> {
editor = editor ?? window.activeTextEditor;
@ -743,11 +720,7 @@ export class GitProviderService implements Disposable {
return provider.getBlameForFile(uri);
}
@log({
args: {
1: _contents => '<contents>',
},
})
@log<GitProviderService['getBlameForFileContents']>({ args: { 1: '<contents>' } })
async getBlameForFileContents(uri: GitUri, contents: string): Promise<GitBlame | undefined> {
const { provider } = this.getProvider(uri);
return provider.getBlameForFileContents(uri, contents);
@ -763,11 +736,7 @@ export class GitProviderService implements Disposable {
return provider.getBlameForLine(uri, editorLine, options);
}
@log({
args: {
2: _contents => '<contents>',
},
})
@log<GitProviderService['getBlameForLineContents']>({ args: { 2: '<contents>' } })
async getBlameForLineContents(
uri: GitUri,
editorLine: number, // editor lines are 0-based
@ -784,21 +753,13 @@ export class GitProviderService implements Disposable {
return provider.getBlameForRange(uri, range);
}
@log({
args: {
2: _contents => '<contents>',
},
})
@log<GitProviderService['getBlameForRangeContents']>({ args: { 2: '<contents>' } })
async getBlameForRangeContents(uri: GitUri, range: Range, contents: string): Promise<GitBlameLines | undefined> {
const { provider } = this.getProvider(uri);
return provider.getBlameForRangeContents(uri, range, contents);
}
@log({
args: {
0: _blame => '<blame>',
},
})
@log<GitProviderService['getBlameForRangeSync']>({ args: { 0: '<blame>' } })
getBlameForRangeSync(blame: GitBlame, uri: GitUri, range: Range): GitBlameLines | undefined {
const { provider } = this.getProvider(uri);
return provider.getBlameForRangeSync(blame, uri, range);
@ -812,11 +773,7 @@ export class GitProviderService implements Disposable {
return provider.getBranch(path);
}
@log({
args: {
0: b => b.name,
},
})
@log<GitProviderService['getBranchAheadRange']>({ args: { 0: b => b.name } })
async getBranchAheadRange(branch: GitBranch): Promise<string | undefined> {
if (branch.state.ahead > 0) {
return GitRevision.createRange(branch.upstream?.name, branch.ref);
@ -848,11 +805,7 @@ export class GitProviderService implements Disposable {
return undefined;
}
@log({
args: {
1: () => false,
},
})
@log({ args: { 1: false } })
async getBranches(
repoPath: string | Uri | undefined,
options?: {
@ -945,7 +898,7 @@ export class GitProviderService implements Disposable {
return provider.getCommitBranches(path, ref, options);
}
@log()
@log<GitProviderService['getAheadBehindCommitCount']>({ args: { 1: refs => refs.join(',') } })
getAheadBehindCommitCount(
repoPath: string | Uri,
refs: string[],
@ -1022,11 +975,7 @@ export class GitProviderService implements Disposable {
return provider.getDiffForFile(uri, ref1, ref2, originalFileName);
}
@log({
args: {
1: _contents => '<contents>',
},
})
@log<GitProviderService['getDiffForFileContents']>({ args: { 1: '<contents>' } })
async getDiffForFileContents(
uri: GitUri,
ref: string,
@ -1248,11 +1197,7 @@ export class GitProviderService implements Disposable {
options != null ? `|${options.limit ?? -1}:${options.include?.join(',')}` : ''
}`;
})
@debug<GitProviderService['getPullRequestForBranch']>({
args: {
1: (remoteOrProvider: GitRemote | RichRemoteProvider) => remoteOrProvider.name,
},
})
@debug<GitProviderService['getPullRequestForBranch']>({ args: { 1: remoteOrProvider => remoteOrProvider.name } })
async getPullRequestForBranch(
branch: string,
remoteOrProvider: GitRemote | RichRemoteProvider,
@ -1305,11 +1250,7 @@ export class GitProviderService implements Disposable {
options?.timeout
}`;
})
@debug<GitProviderService['getPullRequestForCommit']>({
args: {
1: (remoteOrProvider: GitRemote | RichRemoteProvider) => remoteOrProvider.name,
},
})
@debug<GitProviderService['getPullRequestForCommit']>({ args: { 1: remoteOrProvider => remoteOrProvider.name } })
async getPullRequestForCommit(
ref: string,
remoteOrProvider: GitRemote | RichRemoteProvider,
@ -1368,7 +1309,12 @@ export class GitProviderService implements Disposable {
options?.includeDisconnected ?? false
}`,
)
@log({ args: { 0: () => false } })
@log<GitProviderService['getRichRemoteProvider']>({
args: {
0: remotesOrRepoPath =>
Array.isArray(remotesOrRepoPath) ? remotesOrRepoPath.map(r => r.name).join(',') : remotesOrRepoPath,
},
})
async getRichRemoteProvider(
remotesOrRepoPath: GitRemote[] | string | Uri | undefined,
options?: { includeDisconnected?: boolean },
@ -1412,9 +1358,7 @@ export class GitProviderService implements Disposable {
async getRepoPath(filePath: string, options?: { ref?: string }): Promise<string | undefined>;
async getRepoPath(uri: Uri | undefined, options?: { ref?: string }): Promise<string | undefined>;
@log<GitProviderService['getRepoPath']>({
exit: path => `returned ${path}`,
})
@log<GitProviderService['getRepoPath']>({ exit: path => `returned ${path}` })
async getRepoPath(
filePathOrUri: string | Uri | undefined,
options?: { ref?: string },
@ -1474,7 +1418,9 @@ export class GitProviderService implements Disposable {
return rp;
}
@log()
@log<GitProviderService['getRepoPathOrActive']>({
args: { 1: e => (e != null ? `TextEditor(${Logger.toLoggable(e.document.uri)})` : undefined) },
})
async getRepoPathOrActive(uri: Uri | undefined, editor: TextEditor | undefined) {
const repoPath = await this.getRepoPath(uri);
if (repoPath) return repoPath;
@ -1601,11 +1547,7 @@ export class GitProviderService implements Disposable {
return provider.getStatusForRepo(path);
}
@log({
args: {
1: () => false,
},
})
@log({ args: { 1: false } })
async getTags(
repoPath: string | Uri | undefined,
options?: { filter?: (t: GitTag) => boolean; sort?: boolean | TagSortOptions },
@ -1660,7 +1602,7 @@ export class GitProviderService implements Disposable {
return provider.getWorkingUri(path, uri);
}
@log()
@log({ args: { 1: false } })
async hasBranchOrTag(
repoPath: string | Uri | undefined,
options?: {
@ -1693,11 +1635,8 @@ export class GitProviderService implements Disposable {
return repository.hasUpstreamBranch();
}
@log({
args: {
1: (editor: TextEditor) =>
editor != null ? `TextEditor(${Logger.toLoggable(editor.document.uri)})` : 'undefined',
},
@log<GitProviderService['isActiveRepoPath']>({
args: { 1: e => (e != null ? `TextEditor(${Logger.toLoggable(e.document.uri)})` : undefined) },
})
async isActiveRepoPath(repoPath: string | undefined, editor?: TextEditor): Promise<boolean> {
if (repoPath == null) return false;
@ -1830,7 +1769,7 @@ export class GitProviderService implements Disposable {
return provider.stashDelete(path, stashName, ref);
}
@log()
@log<GitProviderService['stashSave']>({ args: { 2: uris => uris?.length } })
stashSave(
repoPath: string | Uri,
message?: string,

+ 23
- 72
src/git/providers/localGitProvider.ts View File

@ -396,14 +396,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
return repositories;
}
@debug({
args: {
0: (root: string) => root,
1: (depth: number) => `${depth}`,
2: () => false,
3: () => false,
},
})
@debug<LocalGitProvider['repositorySearchCore']>({ args: { 2: false, 3: false } })
private repositorySearchCore(
root: string,
depth: number,
@ -564,12 +557,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
}
@log({
args: {
0: (repoPath: string) => repoPath,
1: (uris: Uri[]) => `${uris.length}`,
},
})
@log<LocalGitProvider['excludeIgnoredUris']>({ args: { 1: uris => uris.length } })
async excludeIgnoredUris(repoPath: string, uris: Uri[]): Promise<Uri[]> {
const paths = new Map<string, Uri>(uris.map(u => [Strings.normalizePath(u.fsPath), u]));
@ -690,11 +678,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
}
@log({
args: {
1: _contents => '<contents>',
},
})
@log<LocalGitProvider['getBlameForFileContents']>({ args: { 1: '<contents>' } })
async getBlameForFileContents(uri: GitUri, contents: string): Promise<GitBlame | undefined> {
const cc = Logger.getCorrelationContext();
@ -823,11 +807,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
}
@log({
args: {
2: _contents => '<contents>',
},
})
@log<LocalGitProvider['getBlameForLineContents']>({ args: { 2: '<contents>' } })
async getBlameForLineContents(
uri: GitUri,
editorLine: number, // editor lines are 0-based
@ -886,11 +866,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
return this.getBlameForRangeSync(blame, uri, range);
}
@log({
args: {
2: _contents => '<contents>',
},
})
@log<LocalGitProvider['getBlameForRangeContents']>({ args: { 2: '<contents>' } })
async getBlameForRangeContents(uri: GitUri, range: Range, contents: string): Promise<GitBlameLines | undefined> {
const blame = await this.getBlameForFileContents(uri, contents);
if (blame == null) return undefined;
@ -898,11 +874,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
return this.getBlameForRangeSync(blame, uri, range);
}
@log({
args: {
0: _blame => '<blame>',
},
})
@log<LocalGitProvider['getBlameForRangeContents']>({ args: { 0: '<blame>' } })
getBlameForRangeSync(blame: GitBlame, uri: GitUri, range: Range): GitBlameLines | undefined {
if (blame.lines.length === 0) return { allLines: blame.lines, ...blame };
@ -1021,11 +993,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
// return undefined;
// }
@log({
args: {
1: () => false,
},
})
@log({ args: { 1: false } })
async getBranches(
repoPath: string | undefined,
options: {
@ -1188,7 +1156,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
.filter(<T>(i?: T): i is T => Boolean(i));
}
@log()
@log<LocalGitProvider['getAheadBehindCommitCount']>({ args: { 1: refs => refs.join(',') } })
getAheadBehindCommitCount(
repoPath: string,
refs: string[],
@ -1472,11 +1440,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
}
@log({
args: {
1: _contents => '<contents>',
},
})
@log<LocalGitProvider['getDiffForFileContents']>({ args: { 1: '<contents>' } })
async getDiffForFileContents(
uri: GitUri,
ref: string,
@ -2759,11 +2723,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
options != null ? `|${options.limit ?? -1}:${options.include?.join(',')}` : ''
}`;
})
@debug<LocalGitProvider['getPullRequestForBranch']>({
args: {
1: (remoteOrProvider: GitRemote | RichRemoteProvider) => remoteOrProvider.name,
},
})
@debug<LocalGitProvider['getPullRequestForBranch']>({ args: { 1: remoteOrProvider => remoteOrProvider.name } })
async getPullRequestForBranch(
branch: string,
remoteOrProvider: GitRemote | RichRemoteProvider,
@ -2816,11 +2776,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
options?.timeout
}`;
})
@debug<LocalGitProvider['getPullRequestForCommit']>({
args: {
1: (remoteOrProvider: GitRemote | RichRemoteProvider) => remoteOrProvider.name,
},
})
@debug<LocalGitProvider['getPullRequestForCommit']>({ args: { 1: remoteOrProvider => remoteOrProvider.name } })
async getPullRequestForCommit(
ref: string,
remoteOrProvider: GitRemote | RichRemoteProvider,
@ -2933,7 +2889,12 @@ export class LocalGitProvider implements GitProvider, Disposable {
options?.includeDisconnected ?? false
}`,
)
@log({ args: { 0: () => false } })
@log<LocalGitProvider['getRichRemoteProvider']>({
args: {
0: remotesOrRepoPath =>
Array.isArray(remotesOrRepoPath) ? remotesOrRepoPath.map(r => r.name).join(',') : remotesOrRepoPath,
},
})
async getRichRemoteProvider(
remotesOrRepoPath: GitRemote[] | string | undefined,
{ includeDisconnected }: { includeDisconnected?: boolean } = {},
@ -3240,11 +3201,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
return status;
}
@log({
args: {
1: () => false,
},
})
@log({ args: { 1: false } })
async getTags(
repoPath: string | undefined,
options: { filter?: (t: GitTag) => boolean; sort?: boolean | TagSortOptions } = {},
@ -3382,7 +3339,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
return (await fsExists(uri.fsPath)) ? uri : undefined;
}
@log()
@log({ args: { 1: false } })
async hasBranchOrTag(
repoPath: string | undefined,
{
@ -3425,11 +3382,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
return repository.hasUpstreamBranch();
}
@log({
args: {
1: (editor: TextEditor) =>
editor != null ? `TextEditor(${Logger.toLoggable(editor.document.uri)})` : 'undefined',
},
@log<GitProviderService['isActiveRepoPath']>({
args: { 1: e => (e != null ? `TextEditor(${Logger.toLoggable(e.document.uri)})` : undefined) },
})
async isActiveRepoPath(repoPath: string | undefined, editor?: TextEditor): Promise<boolean> {
if (repoPath == null) return false;
@ -3452,10 +3406,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
);
}
@log<LocalGitProvider['isTracked']>({
exit: tracked => `returned ${tracked}`,
singleLine: true,
})
@log<LocalGitProvider['isTracked']>({ exit: tracked => `returned ${tracked}`, singleLine: true })
async isTracked(
fileNameOrUri: string | GitUri,
repoPath?: string,
@ -3723,7 +3674,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
await Git.stash__delete(repoPath, stashName, ref);
}
@log()
@log<LocalGitProvider['stashSave']>({ args: { 2: uris => uris?.length } })
async stashSave(
repoPath: string,
message?: string,

+ 6
- 36
src/github/github.ts View File

@ -14,12 +14,7 @@ import { Logger } from '../logger';
import { debug } from '../system';
export class GitHubApi {
@debug({
args: {
0: (p: RichRemoteProvider) => p.name,
1: _ => '<token>',
},
})
@debug<GitHubApi['getAccountForCommit']>({ args: { 0: p => p.name, 1: '<token>' } })
async getAccountForCommit(
provider: RichRemoteProvider,
token: string,
@ -99,12 +94,7 @@ export class GitHubApi {
}
}
@debug({
args: {
0: (p: RichRemoteProvider) => p.name,
1: _ => '<token>',
},
})
@debug<GitHubApi['getAccountForEmail']>({ args: { 0: p => p.name, 1: '<token>' } })
async getAccountForEmail(
provider: RichRemoteProvider,
token: string,
@ -178,12 +168,7 @@ export class GitHubApi {
}
}
@debug({
args: {
0: (p: RichRemoteProvider) => p.name,
1: _ => '<token>',
},
})
@debug<GitHubApi['getDefaultBranch']>({ args: { 0: p => p.name, 1: '<token>' } })
async getDefaultBranch(
provider: RichRemoteProvider,
token: string,
@ -240,12 +225,7 @@ export class GitHubApi {
}
}
@debug({
args: {
0: (p: RichRemoteProvider) => p.name,
1: _ => '<token>',
},
})
@debug<GitHubApi['getIssueOrPullRequest']>({ args: { 0: p => p.name, 1: '<token>' } })
async getIssueOrPullRequest(
provider: RichRemoteProvider,
token: string,
@ -318,12 +298,7 @@ export class GitHubApi {
}
}
@debug({
args: {
0: (p: RichRemoteProvider) => p.name,
1: _ => '<token>',
},
})
@debug<GitHubApi['getPullRequestForBranch']>({ args: { 0: p => p.name, 1: '<token>' } })
async getPullRequestForBranch(
provider: RichRemoteProvider,
token: string,
@ -429,12 +404,7 @@ export class GitHubApi {
}
}
@debug({
args: {
0: (p: RichRemoteProvider) => p.name,
1: _ => '<token>',
},
})
@debug<GitHubApi['getPullRequestForCommit']>({ args: { 0: p => p.name, 1: '<token>' } })
async getPullRequestForCommit(
provider: RichRemoteProvider,
token: string,

+ 11
- 10
src/hovers/lineHoverController.ts View File

@ -15,6 +15,7 @@ import {
import { UriComparer } from '../comparers';
import { configuration, FileAnnotationType } from '../configuration';
import { Container } from '../container';
import { Logger } from '../logger';
import { debug } from '../system';
import { LinesChangeEvent } from '../trackers/gitLineTracker';
import { Hovers } from './hovers';
@ -60,9 +61,9 @@ export class LineHoverController implements Disposable {
}
}
@debug({
@debug<LineHoverController['onActiveLinesChanged']>({
args: {
0: (e: LinesChangeEvent) =>
0: e =>
`editor=${e.editor?.document.uri.toString(true)}, selections=${e.selections
?.map(s => `[${s.anchor}-${s.active}]`)
.join(',')}, pending=${Boolean(e.pending)}, reason=${e.reason}`,
@ -82,11 +83,11 @@ export class LineHoverController implements Disposable {
this.register(e.editor);
}
@debug({
@debug<LineHoverController['provideDetailsHover']>({
args: {
0: document => document.uri.toString(true),
1: (position: Position) => `${position.line}:${position.character}`,
2: () => false,
0: document => Logger.toLoggable(document.uri),
1: position => `${position.line}:${position.character}`,
2: false,
},
})
async provideDetailsHover(
@ -156,11 +157,11 @@ export class LineHoverController implements Disposable {
return new Hover(message, range);
}
@debug({
@debug<LineHoverController['provideChangesHover']>({
args: {
0: document => document.uri.toString(true),
1: (position: Position) => `${position.line}:${position.character}`,
2: () => false,
0: document => Logger.toLoggable(document.uri),
1: position => `${position.line}:${position.character}`,
2: false,
},
})
async provideChangesHover(

+ 2
- 2
src/statusbar/statusBarController.ts View File

@ -130,9 +130,9 @@ export class StatusBarController implements Disposable {
}
}
@debug({
@debug<StatusBarController['onActiveLinesChanged']>({
args: {
0: (e: LinesChangeEvent) =>
0: e =>
`editor=${e.editor?.document.uri.toString(true)}, selections=${e.selections
?.map(s => `[${s.anchor}-${s.active}]`)
.join(',')}, pending=${Boolean(e.pending)}, reason=${e.reason}`,

+ 27
- 8
src/system/decorators/log.ts View File

@ -52,7 +52,16 @@ export function logName(fn: (c: T, name: string) => string) {
export function debug<T extends (...arg: any) => any>(
options: {
args?: false | Record<string, (arg: any) => string | false>;
args?:
| false
| {
0?: ((arg: Parameters<T>[0]) => unknown) | string | false;
1?: ((arg: Parameters<T>[1]) => unknown) | string | false;
2?: ((arg: Parameters<T>[2]) => unknown) | string | false;
3?: ((arg: Parameters<T>[3]) => unknown) | string | false;
4?: ((arg: Parameters<T>[4]) => unknown) | string | false;
[key: number]: (((arg: any) => unknown) | string | false) | undefined;
};
condition?(...args: Parameters<T>): boolean;
correlate?: boolean;
enter?(...args: Parameters<T>): string;
@ -70,7 +79,16 @@ type PromiseType = T extends Promise ? U : T;
export function log<T extends (...arg: any) => any>(
options: {
args?: false | Record<number, (arg: any) => string | false>;
args?:
| false
| {
0?: ((arg: Parameters<T>[0]) => unknown) | string | false;
1?: ((arg: Parameters<T>[1]) => unknown) | string | false;
2?: ((arg: Parameters<T>[2]) => unknown) | string | false;
3?: ((arg: Parameters<T>[3]) => unknown) | string | false;
4?: ((arg: Parameters<T>[4]) => unknown) | string | false;
[key: number]: (((arg: any) => unknown) | string | false) | undefined;
};
condition?(...args: Parameters<T>): boolean;
correlate?: boolean;
debug?: boolean;
@ -163,16 +181,17 @@ export function log any>(
logFn(`${prefix}${enter}`);
}
} else {
const argFns = typeof options.args === 'object' ? options.args : undefined;
let argFn;
const argControllers = typeof options.args === 'object' ? options.args : undefined;
let argController;
let loggable;
loggableParams = filterMap(args, (v: any, index: number) => {
const p = parameters[index];
argFn = argFns !== undefined ? argFns[index] : undefined;
if (argFn !== undefined) {
loggable = argFn(v);
if (loggable === false) return undefined;
argController = argControllers != null ? argControllers[index] : undefined;
if (argController != null) {
if (typeof argController === 'boolean') return undefined;
if (typeof argController === 'string') return argController;
loggable = String(argController(v));
} else {
loggable = Logger.toLoggable(v, options.sanitize);
}

+ 10
- 15
src/trackers/gitLineTracker.ts View File

@ -60,9 +60,9 @@ export class GitLineTracker extends LineTracker {
this._subscriptionOnlyWhenActive = undefined;
}
@debug({
@debug<GitLineTracker['onBlameStateChanged']>({
args: {
0: (e: DocumentBlameStateChangeEvent<GitDocumentState>) =>
0: e =>
`editor=${e.editor.document.uri.toString(true)}, doc=${e.document.uri.toString(true)}, blameable=${
e.blameable
}`,
@ -72,10 +72,9 @@ export class GitLineTracker extends LineTracker {
this.trigger('editor');
}
@debug({
@debug<GitLineTracker['onContentChanged']>({
args: {
0: (e: DocumentContentChangeEvent<GitDocumentState>) =>
`editor=${e.editor.document.uri.toString(true)}, doc=${e.document.uri.toString(true)}`,
0: e => `editor=${e.editor.document.uri.toString(true)}, doc=${e.document.uri.toString(true)}`,
},
})
private onContentChanged(e: DocumentContentChangeEvent<GitDocumentState>) {
@ -92,10 +91,9 @@ export class GitLineTracker extends LineTracker {
}
}
@debug({
@debug<GitLineTracker['onDirtyIdleTriggered']>({
args: {
0: (e: DocumentDirtyIdleTriggerEvent<GitDocumentState>) =>
`editor=${e.editor.document.uri.toString(true)}, doc=${e.document.uri.toString(true)}`,
0: e => `editor=${e.editor.document.uri.toString(true)}, doc=${e.document.uri.toString(true)}`,
},
})
private onDirtyIdleTriggered(e: DocumentDirtyIdleTriggerEvent<GitDocumentState>) {
@ -105,9 +103,9 @@ export class GitLineTracker extends LineTracker {
this.resume();
}
@debug({
@debug<GitLineTracker['onDirtyStateChanged']>({
args: {
0: (e: DocumentDirtyStateChangeEvent<GitDocumentState>) =>
0: e =>
`editor=${e.editor.document.uri.toString(true)}, doc=${e.document.uri.toString(true)}, dirty=${
e.dirty
}`,
@ -121,11 +119,8 @@ export class GitLineTracker extends LineTracker {
}
}
@debug({
args: {
0: (selections: LineSelection[]) => selections?.map(s => s.active).join(','),
1: (editor: TextEditor) => editor.document.uri.toString(true),
},
@debug<GitLineTracker['updateState']>({
args: { 0: selections => selections?.map(s => s.active).join(','), 1: e => e.document.uri.toString(true) },
exit: updated => `returned ${updated}`,
singleLine: true,
})

+ 2
- 2
src/views/nodes/lineHistoryTrackerNode.ts View File

@ -226,9 +226,9 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode
);
}
@debug({
@debug<LineHistoryTrackerNode['onActiveLinesChanged']>({
args: {
0: (e: LinesChangeEvent) =>
0: e =>
`editor=${e.editor?.document.uri.toString(true)}, selections=${e.selections
?.map(s => `[${s.anchor}-${s.active}]`)
.join(',')}, pending=${Boolean(e.pending)}, reason=${e.reason}`,

+ 3
- 7
src/views/nodes/repositoryNode.ts View File

@ -358,9 +358,9 @@ export class RepositoryNode extends SubscribeableViewNode {
private _repoUpdatedAt: number = this.repo.updatedAt;
@debug({
@debug<RepositoryNode['onFileSystemChanged']>({
args: {
0: (e: RepositoryFileSystemChangeEvent) =>
0: e =>
`{ repository: ${e.repository?.name ?? ''}, uris(${e.uris.length}): [${e.uris
.slice(0, 1)
.map(u => u.fsPath)
@ -397,11 +397,7 @@ export class RepositoryNode extends SubscribeableViewNode {
void this.triggerChange(false);
}
@debug({
args: {
0: (e: RepositoryChangeEvent) => e.toString(),
},
})
@debug<RepositoryNode['onRepositoryChanged']>({ args: { 0: e => e.toString() } })
private onRepositoryChanged(e: RepositoryChangeEvent) {
this._repoUpdatedAt = this.repo.updatedAt;

+ 1
- 5
src/views/nodes/viewNode.ts View File

@ -491,11 +491,7 @@ export abstract class RepositoryFolderNode<
protected abstract changed(e: RepositoryChangeEvent): boolean;
@debug({
args: {
0: (e: RepositoryChangeEvent) => e.toString(),
},
})
@debug<RepositoryFolderNode['onRepositoryChanged']>({ args: { 0: e => e.toString() } })
private onRepositoryChanged(e: RepositoryChangeEvent) {
this._repoUpdatedAt = this.repo.updatedAt;

+ 1
- 3
src/views/searchAndCompareView.ts View File

@ -95,9 +95,7 @@ export class SearchAndCompareViewNode extends ViewNode {
}
}
@log({
args: { 0: (n: ViewNode) => n.toString() },
})
@log<SearchAndCompareViewNode['dismiss']>({ args: { 0: n => n.toString() } })
dismiss(node: ComparePickerNode | CompareResultsNode | SearchResultsNode) {
if (node === this.comparePicker) {
this.removeComparePicker();

+ 12
- 24
src/views/viewBase.ts View File

@ -323,16 +323,10 @@ export abstract class ViewBase<
token?: CancellationToken;
},
): Promise<ViewNode | undefined>;
@log({
@log<ViewBase<RootNode, ViewConfig>['findNode']>({
args: {
0: (predicate: string | ((node: ViewNode) => boolean)) =>
typeof predicate === 'string' ? predicate : 'function',
1: (opts: {
allowPaging?: boolean;
canTraverse?: (node: ViewNode) => boolean | Promise<boolean>;
maxDepth?: number;
token?: CancellationToken;
}) => `options=${JSON.stringify({ ...opts, canTraverse: undefined, token: undefined })}`,
0: predicate => (typeof predicate === 'string' ? predicate : '<function>'),
1: opts => `options=${JSON.stringify({ ...opts, canTraverse: undefined, token: undefined })}`,
},
})
async findNode(
@ -493,9 +487,7 @@ export abstract class ViewBase<
this.triggerNodeChange();
}
@debug({
args: { 0: (n: ViewNode) => n.toString() },
})
@debug<ViewBase<RootNode, ViewConfig>['refreshNode']>({ args: { 0: n => n.toString() } })
async refreshNode(node: ViewNode, reset: boolean = false, force: boolean = false) {
const cancel = await node.refresh?.(reset);
if (!force && cancel === true) return;
@ -503,9 +495,7 @@ export abstract class ViewBase<
this.triggerNodeChange(node);
}
@log({
args: { 0: (n: ViewNode) => n.toString() },
})
@log<ViewBase<RootNode, ViewConfig>['reveal']>({ args: { 0: n => n.toString() } })
async reveal(
node: ViewNode,
options?: {
@ -537,11 +527,8 @@ export abstract class ViewBase<
return this._lastKnownLimits.get(node.id);
}
@debug({
args: {
0: (n: ViewNode & PageableViewNode) => n.toString(),
3: (n?: ViewNode) => (n == null ? '' : n.toString()),
},
@debug<ViewBase<RootNode, ViewConfig>['loadMoreNodeChildren']>({
args: { 0: n => n.toString(), 2: n => n?.toString() },
})
async loadMoreNodeChildren(
node: ViewNode & PageableViewNode,
@ -556,14 +543,15 @@ export abstract class ViewBase<
this._lastKnownLimits.set(node.id, node.limit);
}
@debug({ args: { 0: (n: ViewNode) => n.toString() }, singleLine: true })
@debug<ViewBase<RootNode, ViewConfig>['resetNodeLastKnownLimit']>({
args: { 0: n => n.toString() },
singleLine: true,
})
resetNodeLastKnownLimit(node: PageableViewNode) {
this._lastKnownLimits.delete(node.id);
}
@debug({
args: { 0: (n: ViewNode) => (n != null ? n.toString() : '') },
})
@debug<ViewBase<RootNode, ViewConfig>['triggerNodeChange']>({ args: { 0: n => n?.toString() } })
triggerNodeChange(node?: ViewNode) {
// Since the root node won't actually refresh, force everything
this._onDidChangeTreeData.fire(node != null && node !== this.root ? node : undefined);

+ 2
- 10
src/vsls/vsls.ts View File

@ -124,11 +124,7 @@ export class VslsController implements Disposable {
return contacts.contacts[email];
}
@debug({
args: {
0: (emails: string[]) => `length=${emails.length}`,
},
})
@debug<VslsController['getContacts']>({ args: { 0: emails => emails.length } })
private async getContacts(emails: string[]) {
const api = await this._api;
if (api == null) return undefined;
@ -145,11 +141,7 @@ export class VslsController implements Disposable {
return contactStatusToPresence(contact.status);
}
@debug({
args: {
0: (emails: string[]) => `length=${emails.length}`,
},
})
@debug<VslsController['getContactsPresence']>({ args: { 0: emails => emails.length } })
async getContactsPresence(emails: string[]): Promise<Map<string, ContactPresence> | undefined> {
const contacts = await this.getContacts(emails);
if (contacts == null) return undefined;

+ 1
- 1
src/webviews/rebaseEditor.ts View File

@ -162,7 +162,7 @@ export class RebaseEditorProvider implements CustomTextEditorProvider, Disposabl
await configuration.updateAny('workbench.editorAssociations', associations, ConfigurationTarget.Global);
}
@debug<RebaseEditorProvider['resolveCustomTextEditor']>({ args: false })
@debug({ args: false })
async resolveCustomTextEditor(document: TextDocument, panel: WebviewPanel, _token: CancellationToken) {
const repoPath = Strings.normalizePath(Uri.joinPath(document.uri, '..', '..', '..').fsPath);
const repo = await this.container.git.getRepository(repoPath);

Loading…
Cancel
Save