@gedit/resource
Advanced tools
Comparing version 0.1.60 to 0.1.61
@@ -27,2 +27,3 @@ import type { TextDocumentContentChangeEvent } from 'vscode-languageserver-protocol'; | ||
protected readonly onSyncContentEmitter: Emitter<string | undefined>; | ||
protected readonly onErrorEmitter: Emitter<Error>; | ||
protected readonly contentChanges: ResourceChangeEvent[]; | ||
@@ -36,2 +37,3 @@ protected readonly toDisposeOnAutoSave: DisposableCollection; | ||
readonly onSyncContent: import("@gedit/utils").Event<string | undefined>; | ||
readonly onError: import("@gedit/utils").Event<Error>; | ||
protected _valid: boolean; | ||
@@ -38,0 +40,0 @@ resource: Resource; |
@@ -91,2 +91,3 @@ "use strict"; | ||
this.onSyncContentEmitter = new utils_1.Emitter(); | ||
this.onErrorEmitter = new utils_1.Emitter(); | ||
this.contentChanges = []; | ||
@@ -100,2 +101,3 @@ this.toDisposeOnAutoSave = new utils_1.DisposableCollection(); | ||
this.onSyncContent = this.onSyncContentEmitter.event; | ||
this.onError = this.onErrorEmitter.event; | ||
this._valid = false; | ||
@@ -112,2 +114,3 @@ this.saveCancellationTokenSource = new utils_1.CancellationTokenSource(); | ||
this.toDispose.push(this.onDidChangeContentEmitter); | ||
this.toDispose.push(this.onErrorEmitter); | ||
this.toDispose.push(utils_1.Disposable.create(function () { return _this.cancelSave(); })); | ||
@@ -253,3 +256,3 @@ this.toDispose.push(utils_1.Disposable.create(function () { return _this.cancelSync(); })); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var changes, version, lastChanged, content, e_2; | ||
var changes, version, lastChanged, content, e_2, isOutOfSync; | ||
return __generator(this, function (_a) { | ||
@@ -270,6 +273,6 @@ switch (_a.label) { | ||
content = this.options.saveAsString(lastChanged); | ||
console.log("-- save (" + this.resource.uri.displayName + ") --"); | ||
return [4 /*yield*/, common_1.Resource.save(this.resource, { content: content, options: { encoding: this.options.encoding, version: version } }, token)]; | ||
case 2: | ||
_a.sent(); | ||
console.log("-- save (" + this.resource.uri.displayName + ") --"); | ||
this.contentChanges.length = 0; | ||
@@ -286,3 +289,13 @@ this.resourceVersion = this.resource.version; | ||
e_2 = _a.sent(); | ||
if (!common_1.ResourceError.OutOfSync.is(e_2)) { | ||
this.contentChanges.length = 0; | ||
// TODO 可能会有数据丢失 | ||
this.setValid(true); | ||
this.setDirty(false); | ||
isOutOfSync = common_1.ResourceError.OutOfSync.is(e_2); | ||
// 自动同步 | ||
if (isOutOfSync) { | ||
this.sync(); | ||
} | ||
this.onErrorEmitter.fire(e_2); | ||
if (!isOutOfSync) { | ||
throw e_2; | ||
@@ -289,0 +302,0 @@ } |
{ | ||
"name": "@gedit/resource", | ||
"version": "0.1.60", | ||
"version": "0.1.61", | ||
"license": "MIT", | ||
@@ -12,4 +12,4 @@ "main": "lib/common/index", | ||
"dependencies": { | ||
"@gedit/application-common": "^0.1.60", | ||
"@gedit/utils": "^0.1.60", | ||
"@gedit/application-common": "^0.1.61", | ||
"@gedit/utils": "^0.1.63", | ||
"vscode-languageserver-protocol": "^3.15.3" | ||
@@ -32,3 +32,3 @@ }, | ||
}, | ||
"gitHead": "cb26efee4408f762aab24445d916164ea897fdfa" | ||
"gitHead": "9b41f77f8ae3b6aa3bf567402f699b5faaff532b" | ||
} |
@@ -37,2 +37,3 @@ import { injectable, inject } from 'inversify'; | ||
protected readonly onSyncContentEmitter = new Emitter<string | undefined>(); | ||
protected readonly onErrorEmitter = new Emitter<Error>(); | ||
protected readonly contentChanges: ResourceChangeEvent[] = []; | ||
@@ -46,2 +47,3 @@ protected readonly toDisposeOnAutoSave = new DisposableCollection(); | ||
readonly onSyncContent = this.onSyncContentEmitter.event; | ||
readonly onError = this.onErrorEmitter.event; | ||
protected _valid = false; | ||
@@ -60,2 +62,3 @@ resource: Resource; | ||
this.toDispose.push(this.onDidChangeContentEmitter); | ||
this.toDispose.push(this.onErrorEmitter); | ||
this.toDispose.push(Disposable.create(() => this.cancelSave())); | ||
@@ -185,4 +188,4 @@ this.toDispose.push(Disposable.create(() => this.cancelSync())); | ||
const content = this.options.saveAsString(lastChanged); | ||
await Resource.save(this.resource, { content, options: {encoding: this.options.encoding, version}}, token); | ||
console.log(`-- save (${this.resource.uri.displayName}) --`); | ||
await Resource.save(this.resource, { content, options: {encoding: this.options.encoding, version}}, token); | ||
this.contentChanges.length = 0; | ||
@@ -197,3 +200,13 @@ this.resourceVersion = this.resource.version; | ||
} catch (e) { | ||
if (!ResourceError.OutOfSync.is(e)) { | ||
this.contentChanges.length = 0; | ||
// TODO 可能会有数据丢失 | ||
this.setValid(true); | ||
this.setDirty(false); | ||
const isOutOfSync = ResourceError.OutOfSync.is(e); | ||
// 自动同步 | ||
if (isOutOfSync) { | ||
this.sync(); | ||
} | ||
this.onErrorEmitter.fire(e); | ||
if (!isOutOfSync) { | ||
throw e; | ||
@@ -200,0 +213,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
101079
1678
Updated@gedit/utils@^0.1.63