Browse Source

Fixes tracked docs not properly waiting for init

main
Eric Amodio 6 years ago
parent
commit
85c2abead2
2 changed files with 24 additions and 19 deletions
  1. +13
    -9
      src/trackers/documentTracker.ts
  2. +11
    -10
      src/trackers/trackedDocument.ts

+ 13
- 9
src/trackers/documentTracker.ts View File

@ -174,9 +174,9 @@ export class DocumentTracker extends Disposable {
// }
// }
async add(document: TextDocument): Promise<TrackedDocument<T>>;
async add(uri: Uri): Promise<TrackedDocument<T>>;
async add(documentOrId: TextDocument | Uri): Promise<TrackedDocument<T>> {
add(document: TextDocument): Promise<TrackedDocument<T>>;
add(uri: Uri): Promise<TrackedDocument<T>>;
add(documentOrId: TextDocument | Uri): Promise<TrackedDocument<T>> {
return this._add(documentOrId);
}
@ -188,17 +188,21 @@ export class DocumentTracker extends Disposable {
this._documentMap.clear();
}
async get(fileName: string): Promise<TrackedDocument<T> | undefined>;
async get(document: TextDocument): Promise<TrackedDocument<T> | undefined>;
async get(uri: Uri): Promise<TrackedDocument<T> | undefined>;
async get(documentOrId: string | TextDocument | Uri): Promise<TrackedDocument<T> | undefined> {
return await this._get(documentOrId);
get(fileName: string): Promise<TrackedDocument<T> | undefined>;
get(document: TextDocument): Promise<TrackedDocument<T> | undefined>;
get(uri: Uri): Promise<TrackedDocument<T> | undefined>;
get(documentOrId: string | TextDocument | Uri): Promise<TrackedDocument<T> | undefined> {
return this._get(documentOrId);
}
async getOrAdd(document: TextDocument): Promise<TrackedDocument<T>>;
async getOrAdd(uri: Uri): Promise<TrackedDocument<T>>;
async getOrAdd(documentOrId: TextDocument | Uri): Promise<TrackedDocument<T>> {
return await this._get(documentOrId) || await this._add(documentOrId);
let doc = await this._get(documentOrId);
if (doc === undefined) {
doc = await this._add(documentOrId);
}
return doc;
}
has(fileName: string): boolean;

+ 11
- 10
src/trackers/trackedDocument.ts View File

@ -23,7 +23,7 @@ export class TrackedDocument extends Disposable {
private _disposable: Disposable | undefined;
private _disposed: boolean = false;
private _repo: (Repository | undefined) | Promise<Repository | undefined>;
private _repo: Promise<Repository | undefined>;
private _uri!: GitUri;
constructor(
@ -43,7 +43,7 @@ export class TrackedDocument extends Disposable {
this._disposable && this._disposable.dispose();
}
private async initialize(uri: Uri) {
private async initialize(uri: Uri): Promise<Repository | undefined> {
// Since there is a bit of a chicken & egg problem with the DocumentTracker and the GitService, wait for the GitService to load if it isn't
if (Container.git === undefined) {
if (!await Functions.waitUntil(() => Container.git !== undefined, 2000)) {
@ -53,18 +53,16 @@ export class TrackedDocument extends Disposable {
}
this._uri = await GitUri.fromUri(uri);
if (this._disposed) return;
if (this._disposed) return undefined;
const repo = await Container.git.getRepository(this._uri);
if (this._disposed) return;
this._repo = repo;
if (this._disposed) return undefined;
if (repo !== undefined) {
this._disposable = repo.onDidChange(this.onRepositoryChanged, this);
}
await this.update({ initializing: true });
await this.update({ initializing: true, repo: repo });
return repo;
}
@ -155,7 +153,7 @@ export class TrackedDocument extends Disposable {
this._blameFailed = true;
if (wasBlameable && isActiveDocument(this._document)) {
this.update({ forceBlameChange: true});
this.update({ forceBlameChange: true });
}
}
@ -167,7 +165,7 @@ export class TrackedDocument extends Disposable {
this._forceDirtyStateChangeOnNextDocumentChange = true;
}
async update(options: { forceBlameChange?: boolean, initializing?: boolean } = {}) {
async update(options: { forceBlameChange?: boolean, initializing?: boolean, repo?: Repository } = {}) {
if (this._disposed || this._uri === undefined) {
this._hasRemotes = false;
this._isTracked = false;
@ -184,7 +182,10 @@ export class TrackedDocument extends Disposable {
let repo = undefined;
if (this._isTracked) {
repo = await this._repo;
repo = options.repo;
if (repo === undefined) {
repo = await this._repo;
}
}
if (repo !== undefined) {

Loading…
Cancel
Save