vscode-zap
Advanced tools
Comparing version 0.0.32 to 0.0.33
@@ -15,2 +15,3 @@ import * as vscode from "vscode"; | ||
constructor(serverOptions: ServerOptions, clientOptions: ClientOptions, environment: IEnvironment); | ||
private initializeConnection(); | ||
dispose(): void; | ||
@@ -21,7 +22,14 @@ queryRefInfo(refID: RefIdentifier): Thenable<RefInfoResult>; | ||
stop(): Thenable<void>; | ||
private activeRefUpdateEmitter; | ||
readonly onDidChangeActiveRef: vscode.Event<string>; | ||
private activeRef; | ||
private monitorActiveRef(); | ||
private resolvedRefUpdateEmitter; | ||
readonly onDidChangeResolvedRef: vscode.Event<string>; | ||
/** | ||
* resolvedRef is the current Zap ref (for non-symbolic refs) or | ||
* its target (for symbolic refs). For example, if | ||
* this.environment.zapRef is "HEAD", then resolvedRef might be | ||
* "mybranch". | ||
*/ | ||
private resolvedRef?; | ||
private resolveRef(); | ||
private monitorResolvedRef(); | ||
showRefSelectMenu(): Thenable<void>; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
const vscode = require("vscode"); | ||
@@ -21,4 +13,3 @@ const client_1 = require("libzap/lib/remote/client"); | ||
this.toDispose = []; | ||
this.activeRefUpdateEmitter = new vscode.EventEmitter(); | ||
this.activeRef = this.environment.zapRef; | ||
this.resolvedRefUpdateEmitter = new vscode.EventEmitter(); | ||
this.client = new client_1.Client(this.serverOptions, this.clientOptions); | ||
@@ -30,18 +21,37 @@ this.handler = new handler_1.Handler(this.client); | ||
this.client.registerHandler(handler_1.Handler.id, this.handler); | ||
this.monitorActiveRef(); | ||
this.monitorResolvedRef(); | ||
// Reestablish watch and reattach workspace whenever we | ||
// reconnect (and on the first time we connect). | ||
// reconnect (and on the first time we connect)... | ||
this.client.onDidChangeState((event) => { | ||
if (event.newState === client_1.State.Running) { | ||
// TODO(sqs): dont watch "*", only watch what we care | ||
// about, to reduce network traffic | ||
return this.handler.repoWatch({ repo: this.environment.repo, refspec: "*" }).then(() => { | ||
return this.handler.attachWorkspace({ | ||
repo: this.environment.repo, | ||
ref: this.environment.zapRef, | ||
}, this.workspace); | ||
}); | ||
let p; | ||
if (!this.resolvedRef) { | ||
p = this.resolveRef(); | ||
} | ||
else { | ||
p = Promise.resolve(void 0); | ||
} | ||
return p.then(() => this.initializeConnection()); | ||
} | ||
}); | ||
// ...and when we switch refs. | ||
this.onDidChangeResolvedRef(() => { | ||
return this.initializeConnection(); | ||
}); | ||
} | ||
initializeConnection() { | ||
// The latest watch refspec overwrites all previous watch | ||
// refspecs, so this unwatches past things. | ||
// | ||
// Also, a ref is a valid refspec, as long as it doesn't | ||
// contain "*". | ||
return this.handler.repoWatch({ repo: this.environment.repo, refspec: this.resolvedRef }).then(() => { | ||
return this.handler.attachWorkspace({ | ||
repo: this.environment.repo, | ||
ref: this.resolvedRef, | ||
}, this.workspace); | ||
}).then(() => null, (err) => { | ||
console.error(`Error watching repo: ${err}`); | ||
}); | ||
} | ||
dispose() { | ||
@@ -73,16 +83,28 @@ if (this.client.needsStop()) { | ||
} | ||
get onDidChangeActiveRef() { return this.activeRefUpdateEmitter.event; } | ||
monitorActiveRef() { | ||
get onDidChangeResolvedRef() { return this.resolvedRefUpdateEmitter.event; } | ||
resolveRef() { | ||
return this.queryRefInfo({ repo: this.environment.repo, ref: this.environment.zapRef }).then(info => { | ||
if (!info.target) { | ||
throw new Error(`new ref ${this.environment.zapRef} is not a symbolic ref: ${JSON.stringify(info)}`); | ||
} | ||
this.resolvedRef = info.target; | ||
this.resolvedRefUpdateEmitter.fire(this.resolvedRef); | ||
}).then(() => null, (err) => { | ||
console.error(`Error resolving new ref ${this.environment.zapRef}: ${err}`); | ||
}); | ||
} | ||
monitorResolvedRef() { | ||
// This gets called on the web, where non-symbolic refs are | ||
// used. | ||
// used. On the desktop, this.environment.zapRef is always | ||
// "HEAD". | ||
// | ||
// TODO(sqs): when we use symbolic refs on the web, we will | ||
// have to update this to resolve symbolic refs before | ||
// triggering an update, or else activeRef will refer to a | ||
// triggering an update, or else resolvedRef will refer to a | ||
// symbolic ref until onDidUpdateSymbolicRef updates it to its | ||
// target. | ||
this.environment.onDidChangeZapRef((newRef) => { | ||
if (newRef !== this.activeRef) { | ||
this.activeRef = newRef; | ||
this.activeRefUpdateEmitter.fire(this.activeRef); | ||
if (newRef !== this.resolvedRef) { | ||
this.resolvedRef = undefined; // until we resolve it | ||
return this.resolveRef(); | ||
} | ||
@@ -93,17 +115,8 @@ }, null, this.toDispose); | ||
if (e.repo === this.environment.repo && e.ref === this.environment.zapRef) { | ||
if (e.newTarget !== this.activeRef) { | ||
this.activeRef = e.newTarget; | ||
this.activeRefUpdateEmitter.fire(this.activeRef); | ||
if (e.newTarget !== this.resolvedRef) { | ||
this.resolvedRef = e.newTarget; | ||
this.resolvedRefUpdateEmitter.fire(this.resolvedRef); | ||
} | ||
} | ||
}, null, this.toDispose); | ||
// React to changes from either of the two paths above. | ||
this.onDidChangeActiveRef(() => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
yield this.handler.attachWorkspace({ repo: this.environment.repo, ref: this.activeRef }, this.workspace); | ||
} | ||
catch (err) { | ||
console.error(`Failed changing active ref to ${this.activeRef}: ${err}`); | ||
} | ||
}), null, this.toDispose); | ||
} | ||
@@ -110,0 +123,0 @@ showRefSelectMenu() { |
@@ -7,3 +7,4 @@ import { MessageStream } from "libzap/lib/remote/client"; | ||
/** | ||
* zapRef is the current Zap ref (e.g., "mybranch"). | ||
* zapRef is the current Zap ref name (e.g., "mybranch" or | ||
* "HEAD"). This is always "HEAD" on the desktop. | ||
*/ | ||
@@ -10,0 +11,0 @@ readonly zapRef: string; |
@@ -26,3 +26,3 @@ // This is the extension's shared entrypoint. All platforms call this | ||
controller.client.registerHandler(status_2.StatusHandler.id, statusHandler); | ||
controller.onDidChangeActiveRef(activeRef => { | ||
controller.onDidChangeResolvedRef(activeRef => { | ||
statusHandler.setActiveRef(activeRef); | ||
@@ -29,0 +29,0 @@ }, null, ctx.subscriptions); |
@@ -5,3 +5,3 @@ { | ||
"description": "WIP", | ||
"version": "0.0.32", | ||
"version": "0.0.33", | ||
"publisher": "sqs", | ||
@@ -42,3 +42,3 @@ "preview": true, | ||
"dependencies": { | ||
"libzap": "^0.0.32", | ||
"libzap": "^0.0.33", | ||
"open": "^0.0.5", | ||
@@ -45,0 +45,0 @@ "vscode-jsonrpc": "3.0.1-alpha.7" |
@@ -29,20 +29,40 @@ import * as vscode from "vscode"; | ||
this.monitorActiveRef(); | ||
this.monitorResolvedRef(); | ||
// Reestablish watch and reattach workspace whenever we | ||
// reconnect (and on the first time we connect). | ||
// reconnect (and on the first time we connect)... | ||
this.client.onDidChangeState((event: StateChangeEvent) => { | ||
if (event.newState === State.Running) { | ||
// TODO(sqs): dont watch "*", only watch what we care | ||
// about, to reduce network traffic | ||
return this.handler.repoWatch({ repo: this.environment.repo, refspec: "*" }).then(() => { | ||
return this.handler.attachWorkspace({ | ||
repo: this.environment.repo, | ||
ref: this.environment.zapRef, | ||
}, this.workspace); | ||
}); | ||
let p: Thenable<void>; | ||
if (!this.resolvedRef) { | ||
p = this.resolveRef(); | ||
} else { | ||
p = Promise.resolve(void 0); | ||
} | ||
return p.then(() => this.initializeConnection()); | ||
} | ||
}); | ||
// ...and when we switch refs. | ||
this.onDidChangeResolvedRef(() => { | ||
return this.initializeConnection(); | ||
}); | ||
} | ||
private initializeConnection(): Thenable<void> { | ||
// The latest watch refspec overwrites all previous watch | ||
// refspecs, so this unwatches past things. | ||
// | ||
// Also, a ref is a valid refspec, as long as it doesn't | ||
// contain "*". | ||
return this.handler.repoWatch({ repo: this.environment.repo, refspec: this.resolvedRef! }).then(() => { | ||
return this.handler.attachWorkspace({ | ||
repo: this.environment.repo, | ||
ref: this.resolvedRef!, | ||
}, this.workspace); | ||
}).then(() => null, (err) => { | ||
console.error(`Error watching repo: ${err}`); | ||
}); | ||
} | ||
public dispose(): void { | ||
@@ -75,18 +95,39 @@ if (this.client.needsStop()) { | ||
private activeRefUpdateEmitter = new vscode.EventEmitter<string>(); | ||
public get onDidChangeActiveRef(): vscode.Event<string> { return this.activeRefUpdateEmitter.event; } | ||
private activeRef: string = this.environment.zapRef; | ||
private monitorActiveRef(): void { | ||
private resolvedRefUpdateEmitter = new vscode.EventEmitter<string>(); | ||
public get onDidChangeResolvedRef(): vscode.Event<string> { return this.resolvedRefUpdateEmitter.event; } | ||
/** | ||
* resolvedRef is the current Zap ref (for non-symbolic refs) or | ||
* its target (for symbolic refs). For example, if | ||
* this.environment.zapRef is "HEAD", then resolvedRef might be | ||
* "mybranch". | ||
*/ | ||
private resolvedRef?: string; | ||
private resolveRef(): Thenable<void> { | ||
return this.queryRefInfo({ repo: this.environment.repo, ref: this.environment.zapRef }).then(info => { | ||
if (!info.target) { | ||
throw new Error(`new ref ${this.environment.zapRef} is not a symbolic ref: ${JSON.stringify(info)}`); | ||
} | ||
this.resolvedRef = info.target; | ||
this.resolvedRefUpdateEmitter.fire(this.resolvedRef); | ||
}).then(() => null, (err) => { | ||
console.error(`Error resolving new ref ${this.environment.zapRef}: ${err}`); | ||
}); | ||
} | ||
private monitorResolvedRef(): void { | ||
// This gets called on the web, where non-symbolic refs are | ||
// used. | ||
// used. On the desktop, this.environment.zapRef is always | ||
// "HEAD". | ||
// | ||
// TODO(sqs): when we use symbolic refs on the web, we will | ||
// have to update this to resolve symbolic refs before | ||
// triggering an update, or else activeRef will refer to a | ||
// triggering an update, or else resolvedRef will refer to a | ||
// symbolic ref until onDidUpdateSymbolicRef updates it to its | ||
// target. | ||
this.environment.onDidChangeZapRef((newRef: string) => { | ||
if (newRef !== this.activeRef) { | ||
this.activeRef = newRef; | ||
this.activeRefUpdateEmitter.fire(this.activeRef); | ||
if (newRef !== this.resolvedRef) { | ||
this.resolvedRef = undefined; // until we resolve it | ||
return this.resolveRef(); | ||
} | ||
@@ -98,17 +139,8 @@ }, null, this.toDispose); | ||
if (e.repo === this.environment.repo && e.ref === this.environment.zapRef) { | ||
if (e.newTarget !== this.activeRef) { | ||
this.activeRef = e.newTarget; | ||
this.activeRefUpdateEmitter.fire(this.activeRef); | ||
if (e.newTarget !== this.resolvedRef) { | ||
this.resolvedRef = e.newTarget; | ||
this.resolvedRefUpdateEmitter.fire(this.resolvedRef); | ||
} | ||
} | ||
}, null, this.toDispose); | ||
// React to changes from either of the two paths above. | ||
this.onDidChangeActiveRef(async () => { | ||
try { | ||
await this.handler.attachWorkspace({ repo: this.environment.repo, ref: this.activeRef }, this.workspace); | ||
} catch (err) { | ||
console.error(`Failed changing active ref to ${this.activeRef}: ${err}`); | ||
} | ||
}, null, this.toDispose); | ||
} | ||
@@ -115,0 +147,0 @@ |
@@ -18,3 +18,4 @@ import { MessageStream } from "libzap/lib/remote/client"; | ||
/** | ||
* zapRef is the current Zap ref (e.g., "mybranch"). | ||
* zapRef is the current Zap ref name (e.g., "mybranch" or | ||
* "HEAD"). This is always "HEAD" on the desktop. | ||
*/ | ||
@@ -21,0 +22,0 @@ readonly zapRef: string; |
@@ -25,3 +25,3 @@ // This is the extension's shared entrypoint. All platforms call this | ||
controller.client.registerHandler(StatusHandler.id, statusHandler); | ||
controller.onDidChangeActiveRef(activeRef => { | ||
controller.onDidChangeResolvedRef(activeRef => { | ||
statusHandler.setActiveRef(activeRef); | ||
@@ -28,0 +28,0 @@ }, null, ctx.subscriptions); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
333018
4916
+ Addedlibzap@0.0.33(transitive)
- Removedlibzap@0.0.32(transitive)
Updatedlibzap@^0.0.33