From 331f68e00a46d7888be49156ee21bd07e4df872d Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 12 Apr 2023 00:23:54 -0400 Subject: [PATCH] Adds setLogScopeExit function --- src/annotations/lineAnnotationController.ts | 15 +++++++------- src/commands/switchMode.ts | 6 ++---- src/git/gitProviderService.ts | 9 +++++---- src/plus/gitlab/gitlab.ts | 6 ++---- src/plus/subscription/authenticationProvider.ts | 6 ++---- src/system/keyboard.ts | 22 ++++++--------------- src/system/logger.scope.ts | 6 ++++++ src/trackers/gitLineTracker.ts | 26 +++++++------------------ src/views/nodes/fileHistoryTrackerNode.ts | 14 ++++--------- src/views/nodes/lineHistoryTrackerNode.ts | 14 ++++--------- 10 files changed, 45 insertions(+), 79 deletions(-) diff --git a/src/annotations/lineAnnotationController.ts b/src/annotations/lineAnnotationController.ts index 5a8be14..76d9023 100644 --- a/src/annotations/lineAnnotationController.ts +++ b/src/annotations/lineAnnotationController.ts @@ -16,8 +16,8 @@ import { debug, log } from '../system/decorators/log'; import { once } from '../system/event'; import { count, every, filter } from '../system/iterable'; import { Logger } from '../system/logger'; -import type { LogScope } from '../system/logger.scope'; -import { getLogScope } from '../system/logger.scope'; +import type { LogScope} from '../system/logger.scope'; +import { getLogScope , setLogScopeExit } from '../system/logger.scope'; import type { PromiseCancelledErrorWithId } from '../system/promise'; import { PromiseCancelledError, raceAll } from '../system/promise'; import { isTextEditor } from '../system/utils'; @@ -191,9 +191,10 @@ export class LineAnnotationController implements Disposable { const selections = this.container.lineTracker.selections; if (editor == null || selections == null || !isTextEditor(editor)) { - if (scope != null) { - scope.exitDetails = ` ${GlyphChars.Dot} Skipped because there is no valid editor or no valid selections`; - } + setLogScopeExit( + scope, + ` ${GlyphChars.Dot} Skipped because there is no valid editor or no valid selections`, + ); this.clear(this._editor); return; @@ -208,9 +209,7 @@ export class LineAnnotationController implements Disposable { const cfg = configuration.get('currentLine'); if (this.suspended) { - if (scope != null) { - scope.exitDetails = ` ${GlyphChars.Dot} Skipped because the controller is suspended`; - } + setLogScopeExit(scope, ` ${GlyphChars.Dot} Skipped because the controller is suspended`); this.clear(editor); return; diff --git a/src/commands/switchMode.ts b/src/commands/switchMode.ts index 181f700..e19ba1f 100644 --- a/src/commands/switchMode.ts +++ b/src/commands/switchMode.ts @@ -5,7 +5,7 @@ import { showModePicker } from '../quickpicks/modePicker'; import { command } from '../system/command'; import { configuration } from '../system/configuration'; import { log } from '../system/decorators/log'; -import { getLogScope } from '../system/logger.scope'; +import { getLogScope, setLogScopeExit } from '../system/logger.scope'; import { Command } from './base'; @command() @@ -21,9 +21,7 @@ export class SwitchModeCommand extends Command { const pick = await showModePicker(); if (pick === undefined) return; - if (scope != null) { - scope.exitDetails = ` \u2014 mode=${pick.key ?? ''}`; - } + setLogScopeExit(scope, ` \u2014 mode=${pick.key ?? ''}`); const active = configuration.get('mode.active'); if (active === pick.key) return; diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index 3f949c0..1773153 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -31,7 +31,7 @@ import type { Deferrable } from '../system/function'; import { debounce } from '../system/function'; import { count, filter, first, flatMap, join, map, some } from '../system/iterable'; import { Logger } from '../system/logger'; -import { getLogScope } from '../system/logger.scope'; +import { getLogScope, setLogScopeExit } from '../system/logger.scope'; import { getBestPath, getScheme, isAbsolute, maybeUri, normalizePath } from '../system/path'; import { cancellable, fastestSettled, getSettledValue, isPromise, PromiseCancelledError } from '../system/promise'; import { VisitedPathsTrie } from '../system/trie'; @@ -519,9 +519,10 @@ export class GitProviderService implements Disposable { ); } - if (scope != null) { - scope.exitDetails = ` ${GlyphChars.Dot} workspaceFolders=${workspaceFolders?.length}, git.autoRepositoryDetection=${autoRepositoryDetection}`; - } + setLogScopeExit( + scope, + ` ${GlyphChars.Dot} workspaceFolders=${workspaceFolders?.length}, git.autoRepositoryDetection=${autoRepositoryDetection}`, + ); } getOpenProviders(): GitProvider[] { diff --git a/src/plus/gitlab/gitlab.ts b/src/plus/gitlab/gitlab.ts index a5d0cc9..a493fe7 100644 --- a/src/plus/gitlab/gitlab.ts +++ b/src/plus/gitlab/gitlab.ts @@ -29,7 +29,7 @@ import { debug } from '../../system/decorators/log'; import { Logger } from '../../system/logger'; import { LogLevel } from '../../system/logger.constants'; import type { LogScope } from '../../system/logger.scope'; -import { getLogScope } from '../../system/logger.scope'; +import { getLogScope, setLogScopeExit } from '../../system/logger.scope'; import { Stopwatch } from '../../system/stopwatch'; import { equalsIgnoreCase } from '../../system/string'; import type { GitLabCommit, GitLabIssue, GitLabMergeRequest, GitLabMergeRequestREST, GitLabUser } from './models'; @@ -674,9 +674,7 @@ $search: String! const projectId = match[1]; - if (scope != null) { - scope.exitDetails = `\u2022 projectId=${projectId}`; - } + setLogScopeExit(scope, ` \u2022 projectId=${projectId}`); return projectId; } catch (ex) { if (ex instanceof ProviderRequestNotFoundError) return undefined; diff --git a/src/plus/subscription/authenticationProvider.ts b/src/plus/subscription/authenticationProvider.ts index 74b9eec..dc91f47 100644 --- a/src/plus/subscription/authenticationProvider.ts +++ b/src/plus/subscription/authenticationProvider.ts @@ -8,7 +8,7 @@ import { uuid } from '@env/crypto'; import type { Container, Environment } from '../../container'; import { debug } from '../../system/decorators/log'; import { Logger } from '../../system/logger'; -import { getLogScope } from '../../system/logger.scope'; +import { getLogScope, setLogScopeExit } from '../../system/logger.scope'; import type { ServerConnection } from './serverConnection'; interface StoredSession { @@ -102,9 +102,7 @@ export class SubscriptionAuthenticationProvider implements AuthenticationProvide const sessions = await this._sessionsPromise; const filtered = scopes != null ? sessions.filter(s => getScopesKey(s.scopes) === scopesKey) : sessions; - if (scope != null) { - scope.exitDetails = ` \u2022 Found ${filtered.length} sessions`; - } + setLogScopeExit(scope, ` \u2022 Found ${filtered.length} sessions`); return filtered; } diff --git a/src/system/keyboard.ts b/src/system/keyboard.ts index ca3eeff..ed427ab 100644 --- a/src/system/keyboard.ts +++ b/src/system/keyboard.ts @@ -5,7 +5,7 @@ import { registerCommand } from './command'; import { setContext } from './context'; import { log } from './decorators/log'; import { Logger } from './logger'; -import { getLogScope } from './logger.scope'; +import { getLogScope, setLogScopeExit } from './logger.scope'; export declare interface KeyCommand { onDidPressKey?(key: Keys): void | Promise; @@ -40,9 +40,7 @@ export class KeyboardScope implements Disposable { const index = mappings.indexOf(this._mapping); const scope = getLogScope(); - if (scope != null) { - scope.exitDetails = ` \u2022 index=${index}`; - } + setLogScopeExit(scope, ` \u2022 index=${index}`); if (index === mappings.length - 1) { mappings.pop(); @@ -66,9 +64,7 @@ export class KeyboardScope implements Disposable { const mapping = mappings[mappings.length - 1]; if (mapping !== this._mapping || mapping[key] == null) { - if (scope != null) { - scope.exitDetails = ' \u2022 skipped'; - } + setLogScopeExit(scope, ' \u2022 skipped'); return; } @@ -117,9 +113,7 @@ export class KeyboardScope implements Disposable { const mapping = mappings[mappings.length - 1]; if (mapping !== this._mapping) { - if (scope != null) { - scope.exitDetails = ' \u2022 skipped'; - } + setLogScopeExit(scope, ' \u2022 skipped'); return; } @@ -176,9 +170,7 @@ export class Keyboard implements Disposable { const scope = getLogScope(); if (!mappings.length) { - if (scope != null) { - scope.exitDetails = ' \u2022 skipped, no mappings'; - } + setLogScopeExit(scope, ' \u2022 skipped, no mappings'); return; } @@ -191,9 +183,7 @@ export class Keyboard implements Disposable { command = await command(); } if (typeof command?.onDidPressKey !== 'function') { - if (scope != null) { - scope.exitDetails = ' \u2022 skipped, no callback'; - } + setLogScopeExit(scope, ' \u2022 skipped, no callback'); return; } diff --git a/src/system/logger.scope.ts b/src/system/logger.scope.ts index 345ee94..17f2e44 100644 --- a/src/system/logger.scope.ts +++ b/src/system/logger.scope.ts @@ -39,3 +39,9 @@ export function getNextLogScopeId(): number { export function setLogScope(scopeId: number, scope: LogScope) { scopes.set(scopeId, scope); } + +export function setLogScopeExit(scope: LogScope | undefined, details: string): void { + if (scope == null) return; + + scope.exitDetails = details; +} diff --git a/src/trackers/gitLineTracker.ts b/src/trackers/gitLineTracker.ts index 8fedc98..fab8e2d 100644 --- a/src/trackers/gitLineTracker.ts +++ b/src/trackers/gitLineTracker.ts @@ -5,7 +5,7 @@ import type { Container } from '../container'; import type { GitCommit } from '../git/models/commit'; import { configuration } from '../system/configuration'; import { debug } from '../system/decorators/log'; -import { getLogScope } from '../system/logger.scope'; +import { getLogScope, setLogScopeExit } from '../system/logger.scope'; import type { DocumentBlameStateChangeEvent, DocumentContentChangeEvent, @@ -133,18 +133,14 @@ export class GitLineTracker extends LineTracker { const scope = getLogScope(); if (!this.includes(selections)) { - if (scope != null) { - scope.exitDetails = ` ${GlyphChars.Dot} lines no longer match`; - } + setLogScopeExit(scope, ` ${GlyphChars.Dot} lines no longer match`); return false; } const trackedDocument = await this.container.tracker.getOrAdd(editor.document); if (!trackedDocument.isBlameable) { - if (scope != null) { - scope.exitDetails = ` ${GlyphChars.Dot} document is not blameable`; - } + setLogScopeExit(scope, ` ${GlyphChars.Dot} document is not blameable`); return false; } @@ -156,9 +152,7 @@ export class GitLineTracker extends LineTracker { editor?.document, ); if (blameLine == null) { - if (scope != null) { - scope.exitDetails = ` ${GlyphChars.Dot} blame failed`; - } + setLogScopeExit(scope, ` ${GlyphChars.Dot} blame failed`); return false; } @@ -167,9 +161,7 @@ export class GitLineTracker extends LineTracker { } else { const blame = await this.container.git.getBlame(trackedDocument.uri, editor.document); if (blame == null) { - if (scope != null) { - scope.exitDetails = ` ${GlyphChars.Dot} blame failed`; - } + setLogScopeExit(scope, ` ${GlyphChars.Dot} blame failed`); return false; } @@ -183,17 +175,13 @@ export class GitLineTracker extends LineTracker { // Check again because of the awaits above if (!this.includes(selections)) { - if (scope != null) { - scope.exitDetails = ` ${GlyphChars.Dot} lines no longer match`; - } + setLogScopeExit(scope, ` ${GlyphChars.Dot} lines no longer match`); return false; } if (!trackedDocument.isBlameable) { - if (scope != null) { - scope.exitDetails = ` ${GlyphChars.Dot} document is not blameable`; - } + setLogScopeExit(scope, ` ${GlyphChars.Dot} document is not blameable`); return false; } diff --git a/src/views/nodes/fileHistoryTrackerNode.ts b/src/views/nodes/fileHistoryTrackerNode.ts index 5d22663..82d176e 100644 --- a/src/views/nodes/fileHistoryTrackerNode.ts +++ b/src/views/nodes/fileHistoryTrackerNode.ts @@ -11,7 +11,7 @@ import { debug, log } from '../../system/decorators/log'; import type { Deferrable } from '../../system/function'; import { debounce } from '../../system/function'; import { Logger } from '../../system/logger'; -import { getLogScope } from '../../system/logger.scope'; +import { getLogScope, setLogScopeExit } from '../../system/logger.scope'; import { isVirtualUri } from '../../system/utils'; import type { FileHistoryView } from '../fileHistoryView'; import { FileHistoryNode } from './fileHistoryNode'; @@ -159,16 +159,12 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode