Преглед изворни кода

Adds once to ready event subscriptions

Avoids 'system' imports
main
Eric Amodio пре 2 година
родитељ
комит
bc19c22381
10 измењених фајлова са 64 додато и 39 уклоњено
  1. +7
    -5
      src/annotations/fileAnnotationController.ts
  2. +10
    -8
      src/annotations/lineAnnotationController.ts
  3. +2
    -1
      src/codelens/codeLensController.ts
  4. +2
    -1
      src/container.ts
  5. +8
    -6
      src/extension.ts
  6. +3
    -2
      src/hovers/lineHoverController.ts
  7. +2
    -1
      src/statusbar/statusBarController.ts
  8. +16
    -0
      src/system/event.ts
  9. +12
    -14
      src/trackers/documentTracker.ts
  10. +2
    -1
      src/views/viewBase.ts

+ 7
- 5
src/annotations/fileAnnotationController.ts Прегледај датотеку

@ -27,7 +27,9 @@ import { Colors, ContextKeys, isTextEditor, setContext } from '../constants';
import { Container } from '../container';
import { KeyboardScope } from '../keyboard';
import { Logger } from '../logger';
import { Functions, Iterables } from '../system';
import { once } from '../system/event';
import { debounce } from '../system/function';
import { find } from '../system/iterable';
import { basename } from '../system/path';
import {
DocumentBlameStateChangeEvent,
@ -80,7 +82,7 @@ export class FileAnnotationController implements Disposable {
constructor(private readonly container: Container) {
this._disposable = Disposable.from(
container.onReady(this.onReady, this),
once(container.onReady)(this.onReady, this),
configuration.onDidChange(this.onConfigurationChanged, this),
);
@ -293,7 +295,7 @@ export class FileAnnotationController implements Disposable {
const provider = this.getProvider(e.textEditor);
if (provider == null) {
// If we don't find an exact match, do a fuzzy match (since we can't properly track editors)
const fuzzyProvider = Iterables.find(
const fuzzyProvider = find(
this._annotationProviders.values(),
p => p.editor.document === e.textEditor.document,
);
@ -566,9 +568,9 @@ export class FileAnnotationController implements Disposable {
Logger.log('Add listener registrations for annotations');
this._annotationsDisposable = Disposable.from(
window.onDidChangeActiveTextEditor(Functions.debounce(this.onActiveTextEditorChanged, 50), this),
window.onDidChangeActiveTextEditor(debounce(this.onActiveTextEditorChanged, 50), this),
window.onDidChangeTextEditorViewColumn(this.onTextEditorViewColumnChanged, this),
window.onDidChangeVisibleTextEditors(Functions.debounce(this.onVisibleTextEditorsChanged, 50), this),
window.onDidChangeVisibleTextEditors(debounce(this.onVisibleTextEditorsChanged, 50), this),
workspace.onDidCloseTextDocument(this.onTextDocumentClosed, this),
this.container.tracker.onDidChangeBlameState(this.onBlameStateChanged, this),
this.container.tracker.onDidChangeDirtyState(this.onDirtyStateChanged, this),

+ 10
- 8
src/annotations/lineAnnotationController.ts Прегледај датотеку

@ -17,7 +17,9 @@ import { CommitFormatter } from '../git/formatters';
import { GitBlameCommit, PullRequest } from '../git/models';
import { Authentication } from '../git/remotes/provider';
import { LogCorrelationContext, Logger } from '../logger';
import { debug, Iterables, log } from '../system';
import { debug, log } from '../system/decorators/log';
import { once } from '../system/event';
import { count, every, filterMap } from '../system/iterable';
import { PromiseCancelledError, PromiseCancelledErrorWithId, raceAll } from '../system/promise';
import { LinesChangeEvent, LineSelection } from '../trackers/gitLineTracker';
import { Annotations } from './annotations';
@ -38,7 +40,7 @@ export class LineAnnotationController implements Disposable {
constructor(private readonly container: Container) {
this._disposable = Disposable.from(
container.onReady(this.onReady, this),
once(container.onReady)(this.onReady, this),
configuration.onDidChange(this.onConfigurationChanged, this),
container.fileAnnotations.onDidToggleAnnotations(this.onFileAnnotationsToggled, this),
Authentication.onDidChange(() => void this.refresh(window.activeTextEditor)),
@ -175,7 +177,7 @@ export class LineAnnotationController implements Disposable {
ref => this.container.git.getPullRequestForCommit(ref, provider),
timeout,
);
if (prs.size === 0 || Iterables.every(prs.values(), pr => pr == null)) return undefined;
if (prs.size === 0 || every(prs.values(), pr => pr == null)) return undefined;
return prs;
}
@ -248,7 +250,7 @@ export class LineAnnotationController implements Disposable {
}
const commitLines = [
...Iterables.filterMap<LineSelection, [number, GitBlameCommit]>(selections, selection => {
...filterMap<LineSelection, [number, GitBlameCommit]>(selections, selection => {
const state = this.container.lineTracker.getState(selection.active);
if (state?.commit == null) {
Logger.debug(cc, `Line ${selection.active} returned no commit`);
@ -342,10 +344,10 @@ export class LineAnnotationController implements Disposable {
cc: LogCorrelationContext | undefined,
) {
// If there are any PRs that timed out, refresh the annotation(s) once they complete
const count = Iterables.count(prs.values(), pr => pr instanceof PromiseCancelledError);
if (cancellationToken.isCancellationRequested || count === 0) return;
const prCount = count(prs.values(), pr => pr instanceof PromiseCancelledError);
if (cancellationToken.isCancellationRequested || prCount === 0) return;
Logger.debug(cc, `${GlyphChars.Dot} ${count} pull request queries took too long (over ${timeout} ms)`);
Logger.debug(cc, `${GlyphChars.Dot} ${prCount} pull request queries took too long (over ${timeout} ms)`);
const resolved = new Map<string, PullRequest | undefined>();
for (const [key, value] of prs) {
@ -354,7 +356,7 @@ export class LineAnnotationController implements Disposable {
if (cancellationToken.isCancellationRequested || editor !== this._editor) return;
Logger.debug(cc, `${GlyphChars.Dot} ${count} pull request queries completed; refreshing...`);
Logger.debug(cc, `${GlyphChars.Dot} ${prCount} pull request queries completed; refreshing...`);
void this.refresh(editor, { prs: resolved });
}

+ 2
- 1
src/codelens/codeLensController.ts Прегледај датотеку

@ -3,6 +3,7 @@ import { configuration } from '../configuration';
import { ContextKeys, setContext } from '../constants';
import { Container } from '../container';
import { Logger } from '../logger';
import { once } from '../system/event';
import {
DocumentBlameStateChangeEvent,
DocumentDirtyIdleTriggerEvent,
@ -18,7 +19,7 @@ export class GitCodeLensController implements Disposable {
constructor(private readonly container: Container) {
this._disposable = Disposable.from(
container.onReady(this.onReady, this),
once(container.onReady)(this.onReady, this),
configuration.onDidChange(this.onConfigurationChanged, this),
);
}

+ 2
- 1
src/container.ts Прегледај датотеку

@ -20,7 +20,8 @@ import { LineHoverController } from './hovers/lineHoverController';
import { Keyboard } from './keyboard';
import { Logger } from './logger';
import { StatusBarController } from './statusbar/statusBarController';
import { log, memoize } from './system';
import { log } from './system/decorators/log';
import { memoize } from './system/decorators/memoize';
import { GitTerminalLinkProvider } from './terminal/linkProvider';
import { GitDocumentTracker } from './trackers/gitDocumentTracker';
import { GitLineTracker } from './trackers/gitLineTracker';

+ 8
- 6
src/extension.ts Прегледај датотеку

@ -11,7 +11,9 @@ import { GitBranch, GitCommit } from './git/models';
import { Logger, LogLevel } from './logger';
import { Messages } from './messages';
import { registerPartnerActionRunners } from './partners';
import { Stopwatch, Versions } from './system';
import { once } from './system/event';
import { Stopwatch } from './system/stopwatch';
import { compare } from './system/version';
import { ViewNode } from './views/nodes';
export function activate(context: ExtensionContext): Promise<GitLensApi | undefined> | undefined {
@ -68,7 +70,7 @@ export function activate(context: ExtensionContext): Promise
let previousVersion: string | undefined;
if (localVersion == null || syncedVersion == null) {
previousVersion = syncedVersion ?? localVersion;
} else if (Versions.compare(syncedVersion, localVersion) === 1) {
} else if (compare(syncedVersion, localVersion) === 1) {
previousVersion = syncedVersion;
} else {
previousVersion = localVersion;
@ -96,7 +98,7 @@ export function activate(context: ExtensionContext): Promise
// await migrateSettings(context, previousVersion);
const container = Container.create(context, cfg);
container.onReady(() => {
once(container.onReady)(() => {
context.subscriptions.push(...registerCommands(container));
registerBuiltInActionRunners(container);
registerPartnerActionRunners(context);
@ -106,7 +108,7 @@ export function activate(context: ExtensionContext): Promise
void context.globalState.update(GlobalState.Version, gitlensVersion);
// Only update our synced version if the new version is greater
if (syncedVersion == null || Versions.compare(gitlensVersion, syncedVersion) === 1) {
if (syncedVersion == null || compare(gitlensVersion, syncedVersion) === 1) {
void context.globalState.update(SyncedState.Version, gitlensVersion);
}
@ -141,10 +143,10 @@ export function deactivate() {
// async function migrateSettings(context: ExtensionContext, previousVersion: string | undefined) {
// if (previousVersion === undefined) return;
// const previous = Versions.fromString(previousVersion);
// const previous = fromString(previousVersion);
// try {
// if (Versions.compare(previous, Versions.from(11, 0, 0)) !== 1) {
// if (compare(previous, from(11, 0, 0)) !== 1) {
// }
// } catch (ex) {
// Logger.error(ex, 'migrateSettings');

+ 3
- 2
src/hovers/lineHoverController.ts Прегледај датотеку

@ -15,7 +15,8 @@ import { UriComparer } from '../comparers';
import { configuration, FileAnnotationType } from '../configuration';
import { Container } from '../container';
import { Logger } from '../logger';
import { debug } from '../system';
import { debug } from '../system/decorators/log';
import { once } from '../system/event';
import { LinesChangeEvent } from '../trackers/gitLineTracker';
import { Hovers } from './hovers';
@ -26,7 +27,7 @@ export class LineHoverController implements Disposable {
constructor(private readonly container: Container) {
this._disposable = Disposable.from(
container.onReady(this.onReady, this),
once(container.onReady)(this.onReady, this),
configuration.onDidChange(this.onConfigurationChanged, this),
);
}

+ 2
- 1
src/statusbar/statusBarController.ts Прегледај датотеку

@ -19,6 +19,7 @@ import { GitBlameCommit, PullRequest } from '../git/models';
import { Hovers } from '../hovers/hovers';
import { LogCorrelationContext, Logger } from '../logger';
import { debug } from '../system/decorators/log';
import { once } from '../system/event';
import { PromiseCancelledError } from '../system/promise';
import { LinesChangeEvent } from '../trackers/gitLineTracker';
@ -33,7 +34,7 @@ export class StatusBarController implements Disposable {
constructor(private readonly container: Container) {
this._disposable = Disposable.from(
container.onReady(this.onReady, this),
once(container.onReady)(this.onReady, this),
configuration.onDidChange(this.onConfigurationChanged, this),
);
}

+ 16
- 0
src/system/event.ts Прегледај датотеку

@ -0,0 +1,16 @@
import { Disposable, Event } from 'vscode';
export function once<T>(event: Event<T>): Event<T> {
return (listener: (e: T) => unknown, thisArgs?: unknown, disposables?: Disposable[]) => {
const result = event(
e => {
result.dispose();
return listener.call(thisArgs, e);
},
null,
disposables,
);
return result;
};
}

+ 12
- 14
src/trackers/documentTracker.ts Прегледај датотеку

@ -21,7 +21,9 @@ import { Container } from '../container';
import { RepositoriesChangeEvent } from '../git/gitProviderService';
import { GitUri } from '../git/gitUri';
import { RepositoryChange, RepositoryChangeComparisonMode, RepositoryChangeEvent } from '../git/models';
import { Functions, Iterables } from '../system';
import { once } from '../system/event';
import { debounce, Deferrable } from '../system/function';
import { filter, map } from '../system/iterable';
import { DocumentBlameStateChangeEvent, TrackedDocument } from './trackedDocument';
export * from './trackedDocument';
@ -71,11 +73,11 @@ export class DocumentTracker implements Disposable {
constructor(protected readonly container: Container) {
this._disposable = Disposable.from(
container.onReady(this.onReady, this),
once(container.onReady)(this.onReady, this),
configuration.onDidChange(this.onConfigurationChanged, this),
window.onDidChangeActiveTextEditor(this.onActiveTextEditorChanged, this),
// window.onDidChangeVisibleTextEditors(Functions.debounce(this.onVisibleEditorsChanged, 5000), this),
workspace.onDidChangeTextDocument(Functions.debounce(this.onTextDocumentChanged, 50), this),
// window.onDidChangeVisibleTextEditors(debounce(this.onVisibleEditorsChanged, 5000), this),
workspace.onDidChangeTextDocument(debounce(this.onTextDocumentChanged, 50), this),
workspace.onDidCloseTextDocument(this.onTextDocumentClosed, this),
workspace.onDidSaveTextDocument(this.onTextDocumentSaved, this),
this.container.git.onDidChangeRepositories(this.onRepositoriesChanged, this),
@ -348,12 +350,8 @@ export class DocumentTracker implements Disposable {
return doc;
}
private _dirtyIdleTriggeredDebounced:
| Functions.Deferrable<(e: DocumentDirtyIdleTriggerEvent<T>) => void>
| undefined;
private _dirtyStateChangedDebounced:
| Functions.Deferrable<(e: DocumentDirtyStateChangeEvent<T>) => void>
| undefined;
private _dirtyIdleTriggeredDebounced: Deferrable<(e: DocumentDirtyIdleTriggerEvent<T>) => void> | undefined;
private _dirtyStateChangedDebounced: Deferrable<(e: DocumentDirtyStateChangeEvent<T>) => void> | undefined;
private fireDocumentDirtyStateChanged(e: DocumentDirtyStateChangeEvent<T>) {
if (e.dirty) {
queueMicrotask(() => {
@ -365,7 +363,7 @@ export class DocumentTracker implements Disposable {
if (this._dirtyIdleTriggerDelay > 0) {
if (this._dirtyIdleTriggeredDebounced == null) {
this._dirtyIdleTriggeredDebounced = Functions.debounce(
this._dirtyIdleTriggeredDebounced = debounce(
(e: DocumentDirtyIdleTriggerEvent<T>) => {
if (this._dirtyIdleTriggeredDebounced?.pending!()) return;
@ -384,7 +382,7 @@ export class DocumentTracker implements Disposable {
}
if (this._dirtyStateChangedDebounced == null) {
this._dirtyStateChangedDebounced = Functions.debounce((e: DocumentDirtyStateChangeEvent<T>) => {
this._dirtyStateChangedDebounced = debounce((e: DocumentDirtyStateChangeEvent<T>) => {
if (window.activeTextEditor !== e.editor) return;
this._onDidChangeDirtyState.fire(e);
@ -396,8 +394,8 @@ export class DocumentTracker implements Disposable {
private reset(reason: 'config' | 'repository', changedRepoPaths?: Set<string>, removedRepoPaths?: Set<string>) {
void Promise.allSettled(
Iterables.map(
Iterables.filter(this._documentMap, ([key]) => typeof key === 'string'),
map(
filter(this._documentMap, ([key]) => typeof key === 'string'),
async ([, promise]) => {
const doc = await promise;
if (removedRepoPaths?.has(doc.uri.repoPath!)) {

+ 2
- 1
src/views/viewBase.ts Прегледај датотеку

@ -34,6 +34,7 @@ import {
import { Container } from '../container';
import { Logger } from '../logger';
import { debug, log } from '../system/decorators/log';
import { once } from '../system/event';
import { debounce } from '../system/function';
import { cancellable, isPromise } from '../system/promise';
import { BranchesView } from './branchesView';
@ -103,7 +104,7 @@ export abstract class ViewBase<
private readonly _lastKnownLimits = new Map<string, number | undefined>();
constructor(public readonly id: string, public readonly name: string, public readonly container: Container) {
this.disposables.push(container.onReady(this.onReady, this));
this.disposables.push(once(container.onReady)(this.onReady, this));
if (Logger.isDebugging || this.container.config.debug) {
function addDebuggingInfo(item: TreeItem, node: ViewNode, parent: ViewNode | undefined) {

Loading…
Откажи
Сачувај