Browse Source

Fixes issue with line history refreshing on all selection changes

Changes line history to use GitLineTracker for better resource usage
main
Eric Amodio 6 years ago
parent
commit
d086131bb5
10 changed files with 254 additions and 246 deletions
  1. +8
    -2
      src/trackers/gitLineTracker.ts
  2. +5
    -9
      src/views/explorer.ts
  3. +3
    -3
      src/views/fileHistoryExplorer.ts
  4. +3
    -4
      src/views/lineHistoryExplorer.ts
  5. +3
    -3
      src/views/nodes.ts
  6. +1
    -1
      src/views/nodes/explorerNode.ts
  7. +11
    -5
      src/views/nodes/fileHistoryTrackerNode.ts
  8. +23
    -22
      src/views/nodes/lineHistoryTrackerNode.ts

+ 8
- 2
src/trackers/gitLineTracker.ts View File

@ -74,8 +74,12 @@ export class GitLineTracker extends LineTracker {
return this._subscriptions.has(subscriber);
}
start(subscriber: any, subscription: Disposable): void {
if (this.isSubscribed(subscriber)) return;
start(subscriber: any, subscription: Disposable): Disposable {
const disposable = {
dispose: () => this.stop(subscriber)
};
if (this.isSubscribed(subscriber)) return disposable;
this._subscriptions.set(subscriber, subscription);
@ -90,6 +94,8 @@ export class GitLineTracker extends LineTracker {
Container.tracker.onDidTriggerDirtyIdle(this.onDirtyIdleTriggered, this)
);
}
return disposable;
}
stop(subscriber: any) {

+ 5
- 9
src/views/explorer.ts View File

@ -22,14 +22,9 @@ import { isPageable } from './nodes/explorerNode';
import { ResultsExplorer } from './resultsExplorer';
export enum RefreshReason {
ActiveEditorChanged = 'active-editor-changed',
AutoRefreshChanged = 'auto-refresh-changed',
Command = 'command',
ConfigurationChanged = 'configuration',
NodeCommand = 'node-command',
RepoChanged = 'repo-changed',
ViewChanged = 'view-changed',
VisibleEditorsChanged = 'visible-editors-changed'
Command = 'Command',
ConfigurationChanged = 'ConfigurationChanged',
VisibilityChanged = 'VisibilityChanged'
}
export type Explorer = GitExplorer | FileHistoryExplorer | LineHistoryExplorer | ResultsExplorer;
@ -139,7 +134,8 @@ export abstract class ExplorerBase implements TreeDa
}
}
await node.refresh();
const cancel = await node.refresh();
if (cancel === true) return;
this.triggerNodeUpdate(node);
}

+ 3
- 3
src/views/fileHistoryExplorer.ts View File

@ -5,15 +5,15 @@ import { CommandContext, setCommandContext } from '../constants';
import { Container } from '../container';
import { ExplorerBase, RefreshReason } from './explorer';
import { RefreshNodeCommandArgs } from './explorerCommands';
import { ActiveFileHistoryNode, ExplorerNode } from './nodes';
import { ExplorerNode, FileHistoryTrackerNode } from './nodes';
export class FileHistoryExplorer extends ExplorerBase<ActiveFileHistoryNode> {
export class FileHistoryExplorer extends ExplorerBase<FileHistoryTrackerNode> {
constructor() {
super('gitlens.fileHistoryExplorer');
}
getRoot() {
return new ActiveFileHistoryNode(this);
return new FileHistoryTrackerNode(this);
}
protected registerCommands() {

+ 3
- 4
src/views/lineHistoryExplorer.ts View File

@ -5,16 +5,15 @@ import { CommandContext, setCommandContext } from '../constants';
import { Container } from '../container';
import { ExplorerBase, RefreshReason } from './explorer';
import { RefreshNodeCommandArgs } from './explorerCommands';
import { ExplorerNode } from './nodes';
import { ActiveLineHistoryNode } from './nodes/activeLineHistoryNode';
import { ExplorerNode, LineHistoryTrackerNode } from './nodes';
export class LineHistoryExplorer extends ExplorerBase<ActiveLineHistoryNode> {
export class LineHistoryExplorer extends ExplorerBase<LineHistoryTrackerNode> {
constructor() {
super('gitlens.lineHistoryExplorer');
}
getRoot() {
return new ActiveLineHistoryNode(this);
return new LineHistoryTrackerNode(this);
}
protected registerCommands() {

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

@ -1,14 +1,14 @@
'use strict';
export * from './nodes/explorerNode';
export * from './nodes/activeFileHistoryNode';
export * from './nodes/activeLineHistoryNode';
export * from './nodes/branchesNode';
export * from './nodes/branchNode';
export * from './nodes/commitFileNode';
export * from './nodes/commitNode';
export * from './nodes/fileHistoryNode';
export * from './nodes/activeFileHistoryNode';
export * from './nodes/fileHistoryTrackerNode';
export * from './nodes/lineHistoryNode';
export * from './nodes/lineHistoryTrackerNode';
export * from './nodes/remoteNode';
export * from './nodes/remotesNode';
export * from './nodes/repositoriesNode';

+ 1
- 1
src/views/nodes/explorerNode.ts View File

@ -65,7 +65,7 @@ export abstract class ExplorerNode {
return undefined;
}
refresh(): void | Promise<void> {}
refresh(): void | boolean | Promise<void> | Promise<boolean> {}
}
export abstract class ExplorerRefNode extends ExplorerNode {

src/views/nodes/activeFileHistoryNode.ts → src/views/nodes/fileHistoryTrackerNode.ts View File

@ -10,7 +10,7 @@ import { MessageNode } from './common';
import { ExplorerNode, ResourceType, SubscribeableExplorerNode, unknownGitUri } from './explorerNode';
import { FileHistoryNode } from './fileHistoryNode';
export class ActiveFileHistoryNode extends SubscribeableExplorerNode<FileHistoryExplorer> {
export class FileHistoryTrackerNode extends SubscribeableExplorerNode<FileHistoryExplorer> {
private _child: FileHistoryNode | undefined;
constructor(explorer: FileHistoryExplorer) {
@ -59,16 +59,18 @@ export class ActiveFileHistoryNode extends SubscribeableExplorerNode
(Container.git.isTrackable(this.uri) &&
window.visibleTextEditors.some(e => e.document && UriComparer.equals(e.document.uri, this.uri)))
) {
return;
return true;
}
this._uri = unknownGitUri;
this.resetChild();
return;
return false;
}
if (UriComparer.equals(editor!.document.uri, this.uri)) return;
if (UriComparer.equals(editor!.document.uri, this.uri)) {
return true;
}
let gitUri = await GitUri.fromUri(editor!.document.uri);
@ -86,7 +88,9 @@ export class ActiveFileHistoryNode extends SubscribeableExplorerNode
}
}
if (this.uri !== unknownGitUri && UriComparer.equals(uri || gitUri, this.uri)) return;
if (this.uri !== unknownGitUri && UriComparer.equals(uri || gitUri, this.uri)) {
return true;
}
if (uri !== undefined) {
gitUri = await GitUri.fromUri(uri);
@ -94,6 +98,8 @@ export class ActiveFileHistoryNode extends SubscribeableExplorerNode
this._uri = gitUri;
this.resetChild();
return false;
}
protected async subscribe() {

src/views/nodes/activeLineHistoryNode.ts → src/views/nodes/lineHistoryTrackerNode.ts View File

@ -1,23 +1,16 @@
'use strict';
import {
Disposable,
Selection,
TextEditor,
TextEditorSelectionChangeEvent,
TreeItem,
TreeItemCollapsibleState,
window
} from 'vscode';
import { Disposable, Selection, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { UriComparer } from '../../comparers';
import { Container } from '../../container';
import { GitUri } from '../../git/gitService';
import { Functions } from '../../system';
import { LinesChangeEvent } from '../../trackers/gitLineTracker';
import { LineHistoryExplorer } from '../lineHistoryExplorer';
import { MessageNode } from './common';
import { ExplorerNode, ResourceType, SubscribeableExplorerNode, unknownGitUri } from './explorerNode';
import { LineHistoryNode } from './lineHistoryNode';
export class ActiveLineHistoryNode extends SubscribeableExplorerNode<LineHistoryExplorer> {
export class LineHistoryTrackerNode extends SubscribeableExplorerNode<LineHistoryExplorer> {
private _child: LineHistoryNode | undefined;
private _selection: Selection | undefined;
@ -67,21 +60,21 @@ export class ActiveLineHistoryNode extends SubscribeableExplorerNode
(Container.git.isTrackable(this.uri) &&
window.visibleTextEditors.some(e => e.document && UriComparer.equals(e.document.uri, this.uri)))
) {
return;
return true;
}
this._uri = unknownGitUri;
this._selection = undefined;
this.resetChild();
return;
return false;
}
if (
UriComparer.equals(editor!.document.uri, this.uri) &&
(this._selection !== undefined && editor.selection.isEqual(this._selection))
) {
return;
return true;
}
const gitUri = await GitUri.fromUri(editor!.document.uri);
@ -91,26 +84,34 @@ export class ActiveLineHistoryNode extends SubscribeableExplorerNode
UriComparer.equals(gitUri, this.uri) &&
(this._selection !== undefined && editor.selection.isEqual(this._selection))
) {
return;
return true;
}
this._uri = gitUri;
this._selection = editor.selection;
this.resetChild();
return false;
}
protected async subscribe() {
return Disposable.from(
window.onDidChangeActiveTextEditor(Functions.debounce(this.onActiveEditorChanged, 500), this),
window.onDidChangeTextEditorSelection(Functions.debounce(this.onSelectionChanged, 500), this)
);
}
if (Container.lineTracker.isSubscribed(this)) return undefined;
private onActiveEditorChanged(editor: TextEditor | undefined) {
void this.explorer.refreshNode(this);
const onActiveLinesChanged = Functions.debounce(this.onActiveLinesChanged.bind(this), 250);
return Container.lineTracker.start(
this,
Disposable.from(
Container.lineTracker.onDidChangeActiveLines((e: LinesChangeEvent) => {
if (e.pending) return;
onActiveLinesChanged(e);
})
)
);
}
private onSelectionChanged(e: TextEditorSelectionChangeEvent) {
private onActiveLinesChanged(e: LinesChangeEvent) {
void this.explorer.refreshNode(this);
}
}

Loading…
Cancel
Save