소스 검색

Adds more debug logging

Allows `exit` bool tp @log/@debug decorators
main
Eric Amodio 1 년 전
부모
커밋
5dc51b208c
12개의 변경된 파일56개의 추가작업 그리고 45개의 파일을 삭제
  1. +11
    -10
      src/env/node/git/localGitProvider.ts
  2. +7
    -1
      src/extension.ts
  3. +13
    -6
      src/git/gitProviderService.ts
  4. +1
    -4
      src/git/gitUri.ts
  5. +1
    -1
      src/git/models/repository.ts
  6. +1
    -3
      src/git/remotes/richRemoteProvider.ts
  7. +13
    -9
      src/system/decorators/log.ts
  8. +5
    -1
      src/system/logger.ts
  9. +1
    -1
      src/trackers/gitLineTracker.ts
  10. +1
    -3
      src/views/nodes/fileHistoryTrackerNode.ts
  11. +1
    -3
      src/views/nodes/lineHistoryTrackerNode.ts
  12. +1
    -3
      src/vsls/host.ts

+ 11
- 10
src/env/node/git/localGitProvider.ts 파일 보기

@ -384,12 +384,11 @@ export class LocalGitProvider implements GitProvider, Disposable {
return location;
}
@debug({ exit: true })
async discoverRepositories(uri: Uri): Promise<Repository[]> {
if (uri.scheme !== Schemes.File) return [];
try {
void (await this.ensureGit());
const autoRepositoryDetection =
configuration.getAny<CoreGitConfiguration, boolean | 'subFolders' | 'openEditors'>(
'git.autoRepositoryDetection',
@ -398,6 +397,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
const folder = workspace.getWorkspaceFolder(uri);
if (folder == null) return [];
void (await this.ensureGit());
const repositories = await this.repositorySearch(
folder,
autoRepositoryDetection === false || autoRepositoryDetection === 'openEditors' ? 0 : undefined,
@ -430,6 +431,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
}
@debug({ exit: true })
openRepository(
folder: WorkspaceFolder | undefined,
uri: Uri,
@ -484,6 +486,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
];
}
@debug()
openRepositoryInitWatcher(): RepositoryInitWatcher {
const watcher = workspace.createFileSystemWatcher('**/.git', false, true, true);
return {
@ -511,6 +514,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
}
@debug<LocalGitProvider['visibility']>({ exit: r => `returned ${r[0]}` })
async visibility(repoPath: string): Promise<[visibility: RepositoryVisibility, cacheKey: string | undefined]> {
const remotes = await this.getRemotes(repoPath, { sort: true });
if (remotes.length === 0) return [RepositoryVisibility.Local, undefined];
@ -532,7 +536,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
: [RepositoryVisibility.Private, getVisibilityCacheKey(remotes)];
}
@debug<LocalGitProvider['getRemoteVisibility']>({ args: { 0: r => r.url } })
@debug<LocalGitProvider['getRemoteVisibility']>({ args: { 0: r => r.url }, exit: r => `returned ${r[0]}` })
private async getRemoteVisibility(
remote: GitRemote,
): Promise<[visibility: RepositoryVisibility, remote: GitRemote]> {
@ -572,10 +576,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
args: false,
singleLine: true,
prefix: (context, folder) => `${context.prefix}(${folder.uri.fsPath})`,
exit: result =>
`returned ${result.length} repositories${
result.length !== 0 ? ` (${result.map(r => r.path).join(', ')})` : ''
}`,
exit: r => `returned ${r.length} repositories ${r.length !== 0 ? Logger.toLoggable(r) : ''}`,
})
private async repositorySearch(folder: WorkspaceFolder, depth?: number): Promise<Repository[]> {
const scope = getLogScope();
@ -669,7 +670,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
return repositories;
}
@debug<LocalGitProvider['repositorySearchCore']>({ args: { 2: false, 3: false } })
@debug<LocalGitProvider['repositorySearchCore']>({ args: { 2: false, 3: false }, exit: true })
private repositorySearchCore(
root: string,
depth: number,
@ -746,7 +747,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
return Uri.joinPath(base, relativePath);
}
@log()
@log({ exit: true })
async getBestRevisionUri(repoPath: string, path: string, ref: string | undefined): Promise<Uri | undefined> {
if (ref === deletedOrMissing) return undefined;
@ -828,7 +829,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
return uri;
}
@log()
@log({ exit: true })
async getWorkingUri(repoPath: string, uri: Uri) {
let relativePath = this.getRelativePath(uri, repoPath);

+ 7
- 1
src/extension.ts 파일 보기

@ -20,7 +20,7 @@ import { configuration, Configuration } from './system/configuration';
import { setContext } from './system/context';
import { setDefaultDateLocales } from './system/date';
import { once } from './system/event';
import { Logger } from './system/logger';
import { getLoggableName, Logger } from './system/logger';
import { LogLevel } from './system/logger.constants';
import { flatten } from './system/object';
import { Stopwatch } from './system/stopwatch';
@ -49,6 +49,12 @@ export async function activate(context: ExtensionContext): Promise
if (isRepository(o) || isBranch(o) || isCommit(o) || isTag(o) || isViewNode(o)) return o.toString();
if ('uri' in o && o.uri instanceof Uri) {
return `${
'name' in o && 'index' in o ? 'WorkspaceFolder' : getLoggableName(o)
}(uri=${o.uri.toString(true)})`;
}
return undefined;
},
},

+ 13
- 6
src/git/gitProviderService.ts 파일 보기

@ -598,6 +598,7 @@ export class GitProviderService implements Disposable {
queueMicrotask(() => this.fireRepositoriesChanged(added));
}
@debug({ exit: true })
private async discoverRepositoriesCore(folder: WorkspaceFolder): Promise<Repository[]> {
const { provider } = this.getProvider(folder.uri);
@ -626,6 +627,7 @@ export class GitProviderService implements Disposable {
Map<undefined, Promise<FeatureAccess | RepoFeatureAccess>> = new Map();
async access(feature: PlusFeatures | undefined, repoPath: string | Uri): Promise<RepoFeatureAccess>;
async access(feature?: PlusFeatures, repoPath?: string | Uri): Promise<FeatureAccess | RepoFeatureAccess>;
@debug({ exit: true })
async access(feature?: PlusFeatures, repoPath?: string | Uri): Promise<FeatureAccess | RepoFeatureAccess> {
if (repoPath == null) {
let access = this._accessCache.get(undefined);
@ -653,7 +655,7 @@ export class GitProviderService implements Disposable {
feature?: PlusFeatures,
repoPath?: string | Uri,
): Promise<FeatureAccess | RepoFeatureAccess>;
@debug()
@debug({ exit: true })
private async accessCore(
_feature?: PlusFeatures,
repoPath?: string | Uri,
@ -745,6 +747,7 @@ export class GitProviderService implements Disposable {
if (allowed === false) throw new AccessDeniedError(subscription.current, subscription.required);
}
@debug({ exit: true })
supports(repoPath: string | Uri, feature: Features): Promise<boolean> {
const { provider } = this.getProvider(repoPath);
return provider.supports(feature);
@ -784,6 +787,7 @@ export class GitProviderService implements Disposable {
}
}
@debug<GitProviderService['getVisibilityInfoFromCache']>({ exit: r => `returned ${r?.visibility}` })
private getVisibilityInfoFromCache(key: string): RepositoryVisibilityInfo | undefined {
this.ensureRepoVisibilityCache();
const visibilityInfo = this._repoVisibilityCache?.get(key);
@ -830,10 +834,12 @@ export class GitProviderService implements Disposable {
void this.container.storage.store('repoVisibility', Array.from(this._repoVisibilityCache!.entries()));
}
@debug()
clearAllRepoVisibilityCaches(): void {
this.clearRepoVisibilityCache();
}
@debug()
clearAllOpenRepoVisibilityCaches(): void {
const openRepoProviderPaths = this.openRepositories.map(r => this.getProvider(r.path).path);
this.clearRepoVisibilityCache(openRepoProviderPaths);
@ -841,6 +847,7 @@ export class GitProviderService implements Disposable {
visibility(): Promise<RepositoriesVisibility>;
visibility(repoPath: string | Uri): Promise<RepositoryVisibility>;
@debug({ exit: true })
async visibility(repoPath?: string | Uri): Promise<RepositoriesVisibility | RepositoryVisibility> {
if (repoPath == null) {
let visibility = this._reposVisibilityCache;
@ -879,7 +886,7 @@ export class GitProviderService implements Disposable {
private visibilityCore(): Promise<RepositoriesVisibility>;
private visibilityCore(repoPath: string | Uri): Promise<RepositoryVisibility>;
@debug()
@debug({ exit: true })
private async visibilityCore(repoPath?: string | Uri): Promise<RepositoriesVisibility | RepositoryVisibility> {
async function getRepoVisibility(
this: GitProviderService,
@ -2234,7 +2241,7 @@ export class GitProviderService implements Disposable {
getBestRepository(uri?: Uri, editor?: TextEditor): Repository | undefined;
// eslint-disable-next-line @typescript-eslint/unified-signatures
getBestRepository(editor?: TextEditor): Repository | undefined;
@log<GitProviderService['getBestRepository']>({ exit: r =&gt; `returned ${r?.path}` })
@log({ exit: true })
getBestRepository(editorOrUri?: TextEditor | Uri, editor?: TextEditor): Repository | undefined {
const count = this.repositoryCount;
if (count === 0) return undefined;
@ -2256,7 +2263,7 @@ export class GitProviderService implements Disposable {
getBestRepositoryOrFirst(uri?: Uri, editor?: TextEditor): Repository | undefined;
// eslint-disable-next-line @typescript-eslint/unified-signatures
getBestRepositoryOrFirst(editor?: TextEditor): Repository | undefined;
@log<GitProviderService['getBestRepositoryOrFirst']>({ exit: r =&gt; `returned ${r?.path}` })
@log({ exit: true })
getBestRepositoryOrFirst(editorOrUri?: TextEditor | Uri, editor?: TextEditor): Repository | undefined {
const count = this.repositoryCount;
if (count === 0) return undefined;
@ -2275,7 +2282,7 @@ export class GitProviderService implements Disposable {
);
}
@log<GitProviderService['getOrOpenRepository']>({ exit: r =&gt; `returned ${r?.path}` })
@log({ exit: true })
async getOrOpenRepository(
uri: Uri,
options?: { closeOnOpen?: boolean; detectNested?: boolean; force?: boolean },
@ -2370,7 +2377,7 @@ export class GitProviderService implements Disposable {
getRepository(uri: Uri): Repository | undefined;
getRepository(path: string): Repository | undefined;
getRepository(pathOrUri: string | Uri): Repository | undefined;
@log<GitProviderService['getRepository']>({ exit: r =&gt; `returned ${r?.path}` })
@log({ exit: true })
getRepository(pathOrUri?: string | Uri): Repository | undefined {
if (this.repositoryCount === 0) return undefined;
if (pathOrUri == null) return undefined;

+ 1
- 4
src/git/gitUri.ts 파일 보기

@ -7,7 +7,6 @@ import { UriComparer } from '../system/comparers';
import { debug } from '../system/decorators/log';
import { memoize } from '../system/decorators/memoize';
import { formatPath } from '../system/formatPath';
import { Logger } from '../system/logger';
import { basename, getBestPath, normalizePath, relativeDir, splitPath } from '../system/path';
// import { CharCode } from '../system/string';
import { isVirtualUri } from '../system/utils';
@ -246,9 +245,7 @@ export class GitUri extends (Uri as any as UriEx) {
return new GitUri(uri);
}
@debug({
exit: uri => `returned ${Logger.toLoggable(uri)}`,
})
@debug({ exit: true })
static async fromUri(uri: Uri): Promise<GitUri> {
if (isGitUri(uri)) return uri;
if (!Container.instance.git.isTrackable(uri)) return new GitUri(uri);

+ 1
- 1
src/git/models/repository.ts 파일 보기

@ -655,7 +655,7 @@ export class Repository implements Disposable {
}
@gate()
@log<Repository['getMainRepository']>({ exit: r =&gt; `returned ${r?.path}` })
@log({ exit: true })
async getMainRepository(): Promise<Repository | undefined> {
const gitDir = await this.getGitDir();
if (gitDir?.commonUri == null) return this;

+ 1
- 3
src/git/remotes/richRemoteProvider.ts 파일 보기

@ -182,9 +182,7 @@ export abstract class RichRemoteProvider extends RemoteProvider {
}
@gate()
@debug<RichRemoteProvider['isConnected']>({
exit: connected => `returned ${connected}`,
})
@debug({ exit: true })
async isConnected(): Promise<boolean> {
return (await this.session()) != null;
}

+ 13
- 9
src/system/decorators/log.ts 파일 보기

@ -31,7 +31,7 @@ interface LogOptions any> {
};
condition?(...args: Parameters<T>): boolean;
enter?(...args: Parameters<T>): string;
exit?(result: PromiseType<ReturnType<T>>): string;
exit?: ((result: PromiseType<ReturnType<T>>) => string) | boolean;
prefix?(context: LogContext, ...args: Parameters<T>): string;
sanitize?(key: string, value: any): any;
logThreshold?: number;
@ -61,10 +61,10 @@ export function log any>(options?: LogOptions, deb
let exitFn: LogOptions<T>['exit'] | undefined;
let prefixFn: LogOptions<T>['prefix'] | undefined;
let sanitizeFn: LogOptions<T>['sanitize'] | undefined;
let logThreshold = 0;
let scoped = false;
let singleLine = false;
let timed = true;
let logThreshold: NonNullable<LogOptions<T>['logThreshold']> = 0;
let scoped: NonNullable<LogOptions<T>['scoped']> = false;
let singleLine: NonNullable<LogOptions<T>['singleLine']> = false;
let timed: NonNullable<LogOptions<T>['timed']> = true;
if (options != null) {
({
args: overrides,
@ -256,10 +256,14 @@ export function log any>(options?: LogOptions, deb
let exit;
if (exitFn != null) {
try {
exit = exitFn(r);
} catch (ex) {
exit = `@log.exit error: ${ex}`;
if (typeof exitFn === 'function') {
try {
exit = exitFn(r);
} catch (ex) {
exit = `@log.exit error: ${ex}`;
}
} else if (exitFn === true) {
exit = `returned ${Logger.toLoggable(r)}`;
}
} else {
exit = 'completed';

+ 5
- 1
src/system/logger.ts 파일 보기

@ -173,9 +173,13 @@ export const Logger = new (class Logger {
this.output?.show?.(preserveFocus);
}
toLoggable(o: any, sanitize?: ((key: string, value: any) => any) | undefined) {
toLoggable(o: any, sanitize?: ((key: string, value: any) => any) | undefined): string {
if (typeof o !== 'object') return String(o);
if (Array.isArray(o)) {
return `[${o.map(i => this.toLoggable(i, sanitize)).join(', ')}]`;
}
const loggable = this.provider!.toLoggable?.(o);
if (loggable != null) return loggable;

+ 1
- 1
src/trackers/gitLineTracker.ts 파일 보기

@ -127,7 +127,7 @@ export class GitLineTracker extends LineTracker {
@debug<GitLineTracker['updateState']>({
args: { 0: selections => selections?.map(s => s.active).join(','), 1: e => e.document.uri.toString(true) },
exit: updated => `returned ${updated}`,
exit: true,
})
private async updateState(selections: LineSelection[], editor: TextEditor): Promise<boolean> {
const scope = getLogScope();

+ 1
- 3
src/views/nodes/fileHistoryTrackerNode.ts 파일 보기

@ -131,9 +131,7 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode
}
@gate()
@debug({
exit: r => `returned ${r}`,
})
@debug({ exit: true })
override async refresh(reset: boolean = false) {
const scope = getLogScope();

+ 1
- 3
src/views/nodes/lineHistoryTrackerNode.ts 파일 보기

@ -138,9 +138,7 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode
}
@gate()
@debug({
exit: r => `returned ${r}`,
})
@debug({ exit: true })
override async refresh(reset: boolean = false) {
const scope = getLogScope();

+ 1
- 3
src/vsls/host.ts 파일 보기

@ -220,9 +220,7 @@ export class VslsHostService implements Disposable {
return { repositories: repositories };
}
@debug({
exit: result => `returned ${result.toString(true)}`,
})
@debug({ exit: true })
private convertLocalUriToShared(localUri: Uri) {
const scope = getLogScope();

불러오는 중...
취소
저장