From 496c35eaeff2c33d3f1256a25d83198ace6aa6b0 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 4 Feb 2022 18:41:59 -0500 Subject: [PATCH] Removes more system imports --- src/annotations/gutterBlameAnnotationProvider.ts | 4 +++- src/annotations/gutterChangesAnnotationProvider.ts | 3 ++- src/annotations/gutterHeatmapBlameAnnotationProvider.ts | 3 ++- src/avatars.ts | 16 +++++++++------- src/commands/closeUnchangedFiles.ts | 4 ++-- src/configuration.ts | 4 ++-- src/env/node/git/locator.ts | 2 +- src/git/fsProvider.ts | 6 ++++-- src/git/parsers/statusParser.ts | 2 +- src/keyboard.ts | 2 +- src/logger.ts | 2 +- src/system.ts | 10 ---------- src/system/array.ts | 1 + src/system/function.ts | 1 + src/system/object.ts | 1 + src/trackers/lineTracker.ts | 9 +++++---- src/views/nodes/viewNode.ts | 15 +++++++++------ 17 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/annotations/gutterBlameAnnotationProvider.ts b/src/annotations/gutterBlameAnnotationProvider.ts index 23e8be5..094aec7 100644 --- a/src/annotations/gutterBlameAnnotationProvider.ts +++ b/src/annotations/gutterBlameAnnotationProvider.ts @@ -5,7 +5,9 @@ import { Container } from '../container'; import { CommitFormatOptions, CommitFormatter } from '../git/formatters'; import { GitBlame, GitCommit } from '../git/models'; import { Logger } from '../logger'; -import { Arrays, Iterables, log, Stopwatch, Strings } from '../system'; +import { Arrays, Iterables, Strings } from '../system'; +import { log } from '../system/decorators/log'; +import { Stopwatch } from '../system/stopwatch'; import { GitDocumentState } from '../trackers/gitDocumentTracker'; import { TrackedDocument } from '../trackers/trackedDocument'; import { AnnotationContext } from './annotationProvider'; diff --git a/src/annotations/gutterChangesAnnotationProvider.ts b/src/annotations/gutterChangesAnnotationProvider.ts index dc92eed..af5de36 100644 --- a/src/annotations/gutterChangesAnnotationProvider.ts +++ b/src/annotations/gutterChangesAnnotationProvider.ts @@ -17,7 +17,8 @@ import { Container } from '../container'; import { GitCommit, GitDiff } from '../git/models'; import { Hovers } from '../hovers/hovers'; import { Logger } from '../logger'; -import { log, Stopwatch } from '../system'; +import { log } from '../system/decorators/log'; +import { Stopwatch } from '../system/stopwatch'; import { GitDocumentState, TrackedDocument } from '../trackers/gitDocumentTracker'; import { AnnotationContext, AnnotationProviderBase } from './annotationProvider'; import { Decorations } from './fileAnnotationController'; diff --git a/src/annotations/gutterHeatmapBlameAnnotationProvider.ts b/src/annotations/gutterHeatmapBlameAnnotationProvider.ts index 925a5d9..1fbcedd 100644 --- a/src/annotations/gutterHeatmapBlameAnnotationProvider.ts +++ b/src/annotations/gutterHeatmapBlameAnnotationProvider.ts @@ -3,7 +3,8 @@ import { FileAnnotationType } from '../configuration'; import { Container } from '../container'; import { GitCommit } from '../git/models'; import { Logger } from '../logger'; -import { log, Stopwatch } from '../system'; +import { log } from '../system/decorators/log'; +import { Stopwatch } from '../system/stopwatch'; import { GitDocumentState } from '../trackers/gitDocumentTracker'; import { TrackedDocument } from '../trackers/trackedDocument'; import { AnnotationContext } from './annotationProvider'; diff --git a/src/avatars.ts b/src/avatars.ts index 6c1168b..7b9c864 100644 --- a/src/avatars.ts +++ b/src/avatars.ts @@ -3,16 +3,18 @@ import { GravatarDefaultStyle } from './config'; import { GlobalState } from './constants'; import { Container } from './container'; import { GitRevisionReference } from './git/models'; -import { Functions, Iterables, Strings } from './system'; +import { debounce } from './system/function'; +import { filterMap } from './system/iterable'; +import { base64, equalsIgnoreCase, md5 } from './system/string'; import { ContactPresenceStatus } from './vsls/vsls'; const _onDidFetchAvatar = new EventEmitter<{ email: string }>(); _onDidFetchAvatar.event( - Functions.debounce(() => { + debounce(() => { const avatars = avatarCache != null ? [ - ...Iterables.filterMap(avatarCache, ([key, avatar]) => + ...filterMap(avatarCache, ([key, avatar]) => avatar.uri != null ? [ key, @@ -89,7 +91,7 @@ export function getAvatarUri( return avatar.uri ?? avatar.fallback!; } - const hash = Strings.md5(email.trim().toLowerCase(), 'hex'); + const hash = md5(email.trim().toLowerCase(), 'hex'); const key = `${hash}:${size}`; const avatar = createOrUpdateAvatar(key, email, size, hash, defaultStyle); @@ -203,8 +205,8 @@ async function getAvatarUriFromRemoteProvider( avatar.timestamp = Date.now(); avatar.retries = 0; - if (account.email != null && Strings.equalsIgnoreCase(email, account.email)) { - avatarCache.set(`${Strings.md5(account.email.trim().toLowerCase(), 'hex')}:${size}`, { ...avatar }); + if (account.email != null && equalsIgnoreCase(email, account.email)) { + avatarCache.set(`${md5(account.email.trim().toLowerCase(), 'hex')}:${size}`, { ...avatar }); } _onDidFetchAvatar.fire({ email: email }); @@ -230,7 +232,7 @@ const presenceStatusColorMap = new Map([ export function getPresenceDataUri(status: ContactPresenceStatus) { let dataUri = presenceCache.get(status); if (dataUri == null) { - const contents = Strings.base64(` + const contents = base64(` `); diff --git a/src/commands/closeUnchangedFiles.ts b/src/commands/closeUnchangedFiles.ts index 675630d..e91a23b 100644 --- a/src/commands/closeUnchangedFiles.ts +++ b/src/commands/closeUnchangedFiles.ts @@ -4,7 +4,7 @@ import { BuiltInCommands } from '../constants'; import type { Container } from '../container'; import { Logger } from '../logger'; import { Messages } from '../messages'; -import { Functions } from '../system'; +import { debounce } from '../system/function'; import { Command, command, Commands, getRepoPathOrPrompt } from './common'; export interface CloseUnchangedFilesCommandArgs { @@ -44,7 +44,7 @@ export class CloseUnchangedFilesCommand extends Command { } const disposable = window.onDidChangeActiveTextEditor( - Functions.debounce((e: TextEditor | undefined) => this._onEditorChangedFn?.(e), 50), + debounce((e: TextEditor | undefined) => this._onEditorChangedFn?.(e), 50), ); let editor = window.activeTextEditor; diff --git a/src/configuration.ts b/src/configuration.ts index c44f3ca..4aa5610 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -10,7 +10,7 @@ import { workspace, } from 'vscode'; import { Config } from './config'; -import { Objects } from './system'; +import { areEqual } from './system/object'; const configPrefix = 'gitlens'; @@ -286,7 +286,7 @@ export class Configuration { return configuration.update( section, - Objects.areEqual(value, inspect.defaultValue) ? undefined : value, + areEqual(value, inspect.defaultValue) ? undefined : value, ConfigurationTarget.Global, ); } diff --git a/src/env/node/git/locator.ts b/src/env/node/git/locator.ts index 5ea77f7..ca120b9 100644 --- a/src/env/node/git/locator.ts +++ b/src/env/node/git/locator.ts @@ -1,8 +1,8 @@ import { join as joinPaths } from 'path'; import { GlyphChars } from '../../../constants'; import { LogLevel } from '../../../logger'; -import { Stopwatch } from '../../../system'; import { any } from '../../../system/promise'; +import { Stopwatch } from '../../../system/stopwatch'; import { findExecutable, run } from './shell'; export class UnableToFindGitError extends Error { diff --git a/src/git/fsProvider.ts b/src/git/fsProvider.ts index 1a54160..cc9762a 100644 --- a/src/git/fsProvider.ts +++ b/src/git/fsProvider.ts @@ -14,8 +14,10 @@ import { isLinux } from '@env/platform'; import { Schemes } from '../constants'; import { Container } from '../container'; import { GitUri } from '../git/gitUri'; -import { debug, Iterables, TernarySearchTree } from '../system'; +import { debug } from '../system/decorators/log'; +import { map } from '../system/iterable'; import { normalizePath, relative } from '../system/path'; +import { TernarySearchTree } from '../system/searchTree'; import { GitRevision, GitTreeEntry } from './models'; const emptyArray = new Uint8Array(0); @@ -65,7 +67,7 @@ export class GitFileSystemProvider implements FileSystemProvider, Disposable { if (tree === undefined) throw FileSystemError.FileNotFound(uri); const items = [ - ...Iterables.map(tree, t => [ + ...map(tree, t => [ path != null && path.length !== 0 ? normalizePath(relative(path, t.path)) : t.path, typeToFileType(t.type), ]), diff --git a/src/git/parsers/statusParser.ts b/src/git/parsers/statusParser.ts index f310785..198af3f 100644 --- a/src/git/parsers/statusParser.ts +++ b/src/git/parsers/statusParser.ts @@ -1,4 +1,4 @@ -import { debug } from '../../system'; +import { debug } from '../../system/decorators/log'; import { normalizePath } from '../../system/path'; import { GitStatus, GitStatusFile } from '../models'; diff --git a/src/keyboard.ts b/src/keyboard.ts index 17b0f75..8f53857 100644 --- a/src/keyboard.ts +++ b/src/keyboard.ts @@ -1,7 +1,7 @@ import { commands, Disposable } from 'vscode'; import { ContextKeys, setContext } from './constants'; import { Logger } from './logger'; -import { log } from './system'; +import { log } from './system/decorators/log'; export declare interface KeyCommand { onDidPressKey?(key: Keys): void | Promise; diff --git a/src/logger.ts b/src/logger.ts index f3b3ad6..e87b96b 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,6 +1,6 @@ import { ExtensionContext, ExtensionMode, OutputChannel, Uri, window } from 'vscode'; import { OutputLevel } from './configuration'; -import { getCorrelationContext, getNextCorrelationId } from './system'; +import { getCorrelationContext, getNextCorrelationId } from './system/decorators/log'; const emptyStr = ''; const outputChannelName = 'GitLens'; diff --git a/src/system.ts b/src/system.ts index 8854c91..b953a68 100644 --- a/src/system.ts +++ b/src/system.ts @@ -20,17 +20,7 @@ declare global { } export * as Arrays from './system/array'; -export * as Dates from './system/date'; export * from './system/decorators/gate'; export * from './system/decorators/log'; -export * from './system/decorators/memoize'; -export * from './system/decorators/serialize'; -export * from './system/decorators/timeout'; -export * as Encoding from './system/encoding'; -export * as Functions from './system/function'; export * as Iterables from './system/iterable'; -export * as Objects from './system/object'; -export * from './system/searchTree'; -export * from './system/stopwatch'; export * as Strings from './system/string'; -export * as Versions from './system/version'; diff --git a/src/system/array.ts b/src/system/array.ts index fea52bf..fd661c2 100644 --- a/src/system/array.ts +++ b/src/system/array.ts @@ -1,3 +1,4 @@ +// eslint-disable-next-line no-restricted-imports export { findLastIndex, intersectionWith as intersection } from 'lodash-es'; export function chunk(source: T[], size: number): T[][] { diff --git a/src/system/function.ts b/src/system/function.ts index 42b5f04..c372501 100644 --- a/src/system/function.ts +++ b/src/system/function.ts @@ -1,3 +1,4 @@ +// eslint-disable-next-line no-restricted-imports import { debounce as _debounce, once as _once } from 'lodash-es'; import { Disposable } from 'vscode'; diff --git a/src/system/object.ts b/src/system/object.ts index 9de9fd0..a0f8015 100644 --- a/src/system/object.ts +++ b/src/system/object.ts @@ -1,3 +1,4 @@ +// eslint-disable-next-line no-restricted-imports export { isEqual as areEqual } from 'lodash-es'; export function flatten(o: any, prefix: string = '', stringify: boolean = false): Record { diff --git a/src/trackers/lineTracker.ts b/src/trackers/lineTracker.ts index 58603bf..fe5e5eb 100644 --- a/src/trackers/lineTracker.ts +++ b/src/trackers/lineTracker.ts @@ -1,7 +1,8 @@ import { Disposable, Event, EventEmitter, Selection, TextEditor, TextEditorSelectionChangeEvent, window } from 'vscode'; import { isTextEditor } from '../constants'; import { Logger } from '../logger'; -import { debug, Functions } from '../system'; +import { debug } from '../system/decorators/log'; +import { debounce, Deferrable } from '../system/function'; export interface LinesChangeEvent { readonly editor: TextEditor | undefined; @@ -134,7 +135,7 @@ export class LineTracker implements Disposable { Logger.debug(cc, 'Starting line tracker...'); this._disposable = Disposable.from( - window.onDidChangeActiveTextEditor(Functions.debounce(this.onActiveTextEditorChanged, 0), this), + window.onDidChangeActiveTextEditor(debounce(this.onActiveTextEditorChanged, 0), this), window.onDidChangeTextEditorSelection(this.onTextEditorSelectionChanged, this), this.onStart?.() ?? { dispose: () => {} }, ); @@ -200,7 +201,7 @@ export class LineTracker implements Disposable { this.onLinesChanged({ editor: this._editor, selections: this.selections, reason: reason }); } - private _linesChangedDebounced: Functions.Deferrable<(e: LinesChangeEvent) => void> | undefined; + private _linesChangedDebounced: Deferrable<(e: LinesChangeEvent) => void> | undefined; private onLinesChanged(e: LinesChangeEvent) { if (e.selections == null) { @@ -218,7 +219,7 @@ export class LineTracker implements Disposable { } if (this._linesChangedDebounced == null) { - this._linesChangedDebounced = Functions.debounce( + this._linesChangedDebounced = debounce( (e: LinesChangeEvent) => { if (e.editor !== window.activeTextEditor) return; // Make sure we are still on the same lines diff --git a/src/views/nodes/viewNode.ts b/src/views/nodes/viewNode.ts index 0ac780f..ab885f5 100644 --- a/src/views/nodes/viewNode.ts +++ b/src/views/nodes/viewNode.ts @@ -21,7 +21,10 @@ import { RepositoryChangeEvent, } from '../../git/models'; import { Logger } from '../../logger'; -import { debug, Functions, gate, log, logName, Strings } from '../../system'; +import { gate } from '../../system/decorators/gate'; +import { debug, log, logName } from '../../system/decorators/log'; +import { is as isA } from '../../system/function'; +import { pad } from '../../system/string'; import { TreeViewNodeCollapsibleStateChangeEvent, View } from '../viewBase'; export const enum ContextValues { @@ -177,7 +180,7 @@ export interface PageableViewNode { export namespace PageableViewNode { export function is(node: ViewNode): node is ViewNode & PageableViewNode { - return Functions.is(node, 'loadMore'); + return isA(node, 'loadMore'); } } @@ -394,9 +397,9 @@ export abstract class RepositoryFolderNode< const lastFetched = (await this.repo.getLastFetched()) ?? 0; const status = branch.getTrackingStatus(); - item.description = `${status ? `${status}${Strings.pad(GlyphChars.Dot, 1, 1)}` : ''}${branch.name}${ + item.description = `${status ? `${status}${pad(GlyphChars.Dot, 1, 1)}` : ''}${branch.name}${ lastFetched - ? `${Strings.pad(GlyphChars.Dot, 1, 1)}Last fetched ${Repository.formatLastFetched(lastFetched)}` + ? `${pad(GlyphChars.Dot, 1, 1)}Last fetched ${Repository.formatLastFetched(lastFetched)}` : '' }`; @@ -414,7 +417,7 @@ export abstract class RepositoryFolderNode< item.tooltip = new MarkdownString( `${this.repo.formattedName ?? this.uri.repoPath ?? ''}${ lastFetched - ? `${Strings.pad(GlyphChars.Dash, 2, 2)}Last fetched ${Repository.formatLastFetched( + ? `${pad(GlyphChars.Dash, 2, 2)}Last fetched ${Repository.formatLastFetched( lastFetched, false, )}` @@ -559,7 +562,7 @@ interface AutoRefreshableView { } export function canAutoRefreshView(view: View): view is View & AutoRefreshableView { - return Functions.is(view, 'onDidChangeAutoRefresh'); + return isA(view, 'onDidChangeAutoRefresh'); } export function canClearNode(node: ViewNode): node is ViewNode & { clear(): void | Promise } {