Procházet zdrojové kódy

Reworks document tracker to only track by object

Removes unused key property
main
Eric Amodio před 2 roky
rodič
revize
e7b523a75e
6 změnil soubory, kde provedl 34 přidání a 40 odebrání
  1. +7
    -7
      src/env/node/git/localGitProvider.ts
  2. +2
    -2
      src/plus/github/githubGitProvider.ts
  3. +5
    -0
      src/system/utils.ts
  4. +18
    -25
      src/trackers/documentTracker.ts
  5. +0
    -2
      src/trackers/gitDocumentTracker.ts
  6. +2
    -4
      src/trackers/trackedDocument.ts

+ 7
- 7
src/env/node/git/localGitProvider.ts Zobrazit soubor

@ -1084,7 +1084,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
key += `:${uri.sha}`;
}
const doc = await this.container.tracker.getOrAdd(uri);
const doc = await this.container.tracker.getOrAdd(document ?? uri);
if (this.useCaching) {
if (doc.state != null) {
const cachedBlame = doc.state.getBlame(key);
@ -1097,7 +1097,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
Logger.debug(cc, `Cache miss: '${key}'`);
if (doc.state == null) {
doc.state = new GitDocumentState(doc.key);
doc.state = new GitDocumentState();
}
}
@ -1176,7 +1176,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
Logger.debug(cc, `Cache miss: ${key}`);
if (doc.state == null) {
doc.state = new GitDocumentState(doc.key);
doc.state = new GitDocumentState();
}
}
@ -1248,7 +1248,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
if (document?.isDirty) return this.getBlameForLineContents(uri, editorLine, document.getText(), options);
if (!options?.forceSingleLine && this.useCaching) {
const blame = await this.getBlame(uri);
const blame = await this.getBlame(uri, document);
if (blame == null) return undefined;
let blameLine = blame.lines[editorLine];
@ -1841,7 +1841,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
Logger.debug(cc, `Cache miss: '${key}'`);
if (doc.state == null) {
doc.state = new GitDocumentState(doc.key);
doc.state = new GitDocumentState();
}
}
@ -1929,7 +1929,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
Logger.debug(cc, `Cache miss: ${key}`);
if (doc.state == null) {
doc.state = new GitDocumentState(doc.key);
doc.state = new GitDocumentState();
}
}
@ -2546,7 +2546,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
Logger.debug(cc, `Cache miss: '${key}'`);
if (doc.state == null) {
doc.state = new GitDocumentState(doc.key);
doc.state = new GitDocumentState();
}
}

+ 2
- 2
src/plus/github/githubGitProvider.ts Zobrazit soubor

@ -433,7 +433,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
Logger.debug(cc, `Cache miss: '${key}'`);
if (doc.state == null) {
doc.state = new GitDocumentState(doc.key);
doc.state = new GitDocumentState();
}
const promise = this.getBlameCore(uri, doc, key, cc);
@ -1716,7 +1716,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
Logger.debug(cc, `Cache miss: '${key}'`);
if (doc.state == null) {
doc.state = new GitDocumentState(doc.key);
doc.state = new GitDocumentState();
}
}

+ 5
- 0
src/system/utils.ts Zobrazit soubor

@ -6,6 +6,11 @@ import { Logger } from '../logger';
import { executeCoreCommand } from './command';
import { extname } from './path';
export function findTextDocument(uri: Uri): TextDocument | undefined {
const normalizedUri = uri.toString();
return workspace.textDocuments.find(d => d.uri.toString() === normalizedUri);
}
export function findEditor(uri: Uri): TextEditor | undefined {
const active = window.activeTextEditor;
const normalizedUri = uri.toString();

+ 18
- 25
src/trackers/documentTracker.ts Zobrazit soubor

@ -26,8 +26,7 @@ import { debug } from '../system/decorators/log';
import { once } from '../system/event';
import { debounce, Deferrable } from '../system/function';
import { filter, join, map } from '../system/iterable';
import { getBestPath } from '../system/path';
import { isActiveDocument, isTextEditor } from '../system/utils';
import { findTextDocument, isActiveDocument, isTextEditor } from '../system/utils';
import { DocumentBlameStateChangeEvent, TrackedDocument } from './trackedDocument';
export * from './trackedDocument';
@ -72,8 +71,7 @@ export class DocumentTracker implements Disposable {
private _dirtyIdleTriggerDelay: number;
private readonly _disposable: Disposable;
// TODO@eamodio: replace with a trie?
protected readonly _documentMap = new Map<TextDocument | string, Promise<TrackedDocument<T>>>();
protected readonly _documentMap = new Map<TextDocument, Promise<TrackedDocument<T>>>();
constructor(protected readonly container: Container) {
this._disposable = Disposable.from(
@ -273,12 +271,9 @@ export class DocumentTracker implements Disposable {
}
private async addCore(document: TextDocument): Promise<TrackedDocument<T>> {
const key = getUriKey(document.uri);
// Always start out false, so we will fire the event if needed
const doc = TrackedDocument.create<T>(
document,
key,
// Always start out false, so we will fire the event if needed
false,
{
onDidBlameStateChange: (e: DocumentBlameStateChangeEvent<T>) => this._onDidChangeBlameState.fire(e),
@ -287,7 +282,6 @@ export class DocumentTracker implements Disposable {
);
this._documentMap.set(document, doc);
this._documentMap.set(key, doc);
return doc;
}
@ -304,22 +298,22 @@ export class DocumentTracker implements Disposable {
get(uri: Uri): Promise<TrackedDocument<T>> | undefined;
get(documentOrUri: TextDocument | Uri): Promise<TrackedDocument<T>> | undefined;
get(documentOrUri: TextDocument | Uri): Promise<TrackedDocument<T>> | undefined {
let key;
if (GitUri.is(documentOrUri)) {
key = getUriKey(documentOrUri.documentUri());
} else if (documentOrUri instanceof Uri) {
key = getUriKey(documentOrUri);
} else {
key = documentOrUri;
if (documentOrUri instanceof Uri) {
const document = findTextDocument(documentOrUri);
if (document == null) return undefined;
documentOrUri = document;
}
const doc = this._documentMap.get(key);
const doc = this._documentMap.get(documentOrUri);
return doc;
}
getOrAdd(document: TextDocument): Promise<TrackedDocument<T>>;
getOrAdd(uri: Uri): Promise<TrackedDocument<T>>;
async getOrAdd(documentOrUri: TextDocument | Uri): Promise<TrackedDocument<T>> {
if (documentOrUri instanceof Uri) {
documentOrUri = findTextDocument(documentOrUri) ?? documentOrUri;
}
const doc = this.get(documentOrUri) ?? this.add(documentOrUri);
return doc;
}
@ -328,8 +322,12 @@ export class DocumentTracker implements Disposable {
has(uri: Uri): boolean;
has(documentOrUri: TextDocument | Uri): boolean {
if (documentOrUri instanceof Uri) {
return this._documentMap.has(getUriKey(documentOrUri));
const document = findTextDocument(documentOrUri);
if (document == null) return false;
documentOrUri = document;
}
return this._documentMap.has(documentOrUri);
}
@ -340,7 +338,6 @@ export class DocumentTracker implements Disposable {
}
this._documentMap.delete(document);
this._documentMap.delete(getUriKey(document.uri));
(tracked ?? (await promise))?.dispose();
}
@ -475,7 +472,3 @@ class EmptyTextDocument implements TextDocument {
class BinaryTextDocument extends EmptyTextDocument {}
class MissingRevisionTextDocument extends EmptyTextDocument {}
function getUriKey(pathOrUri: string | Uri): string {
return getBestPath(pathOrUri);
}

+ 0
- 2
src/trackers/gitDocumentTracker.ts Zobrazit soubor

@ -18,8 +18,6 @@ export class GitDocumentState {
private readonly diffCache = new Map<string, CachedDiff>();
private readonly logCache = new Map<string, CachedLog>();
constructor(public readonly key: string) {}
clearBlame(key?: string): void {
if (key == null) {
this.blameCache.clear();

+ 2
- 4
src/trackers/trackedDocument.ts Zobrazit soubor

@ -17,12 +17,11 @@ export interface DocumentBlameStateChangeEvent {
export class TrackedDocument<T> implements Disposable {
static async create<T>(
document: TextDocument,
key: string,
dirty: boolean,
eventDelegates: { onDidBlameStateChange(e: DocumentBlameStateChangeEvent<T>): void },
container: Container,
) {
const doc = new TrackedDocument(document, key, dirty, eventDelegates, container);
const doc = new TrackedDocument(document, dirty, eventDelegates, container);
await doc.initialize();
return doc;
}
@ -40,7 +39,6 @@ export class TrackedDocument implements Disposable {
private constructor(
readonly document: TextDocument,
public readonly key: string,
public dirty: boolean,
private _eventDelegates: { onDidBlameStateChange(e: DocumentBlameStateChangeEvent<T>): void },
private readonly container: Container,
@ -126,7 +124,7 @@ export class TrackedDocument implements Disposable {
if (this.state != null) {
this.state = undefined;
Logger.log(`Reset state for '${this.key}', reason=${reason}`);
Logger.log(`Reset state for '${this.document.uri.toString(true)}', reason=${reason}`);
}
if (reason === 'repository' && isActiveDocument(this.document)) {

Načítá se…
Zrušit
Uložit