未验证 提交 f6d0541e 编写于 作者: A Alex Dima

Add troubleshooting logs

上级 5329ea8f
......@@ -168,6 +168,11 @@ export class SingleModelEditStackElement implements IResourceUndoRedoElement {
this._data = SingleModelEditStackData.create(model, beforeCursorState);
}
public toString(): string {
const data = (this._data instanceof SingleModelEditStackData ? this._data : SingleModelEditStackData.deserialize(this._data));
return data.changes.map(change => change.toString()).join(', ');
}
public matchesResource(resource: URI): boolean {
const uri = (URI.isUri(this.model) ? this.model : this.model.uri);
return (uri.toString() === resource.toString());
......
......@@ -31,6 +31,16 @@ export class TextChange {
public readonly newText: string
) { }
public toString(): string {
if (this.oldText.length === 0) {
return `(insert@${this.oldPosition} "${this.newText}")`;
}
if (this.newText.length === 0) {
return `(delete@${this.oldPosition} "${this.oldText}")`;
}
return `(replace@${this.oldPosition} "${this.oldText}" with "${this.newText}")`;
}
private static _writeStringSize(str: string): number {
return (
4 + 2 * str.length
......
......@@ -14,6 +14,8 @@ import { Schemas } from 'vs/base/common/network';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IDisposable, Disposable, isDisposable } from 'vs/base/common/lifecycle';
const DEBUG = false;
function getResourceLabel(resource: URI): string {
return resource.scheme === Schemas.file ? resource.fsPath : resource.path;
}
......@@ -42,6 +44,10 @@ class ResourceStackElement {
public setValid(isValid: boolean): void {
this.isValid = isValid;
}
public toString(): string {
return `[VALID] ${this.actual}`;
}
}
const enum RemovedResourceReason {
......@@ -143,6 +149,10 @@ class WorkspaceStackElement {
}
}
}
public toString(): string {
return `[VALID] ${this.actual}`;
}
}
type StackElement = ResourceStackElement | WorkspaceStackElement;
......@@ -178,6 +188,18 @@ class ResourceEditStack {
this.versionId++;
}
public toString(): string {
let result: string[] = [];
result.push(`* ${this.strResource}:`);
for (let i = 0; i < this._past.length; i++) {
result.push(` * [UNDO] ${this._past[i]}`);
}
for (let i = this._future.length - 1; i >= 0; i--) {
result.push(` * [REDO] ${this._future[i]}`);
}
return result.join('\n');
}
public flushAllElements(): void {
this._past = [];
this._future = [];
......@@ -383,6 +405,16 @@ export class UndoRedoService implements IUndoRedoService {
return resource.toString();
}
private _print(label: string): void {
console.log(`------------------------------------`);
console.log(`AFTER ${label}: `);
let str: string[] = [];
for (const element of this._editStacks) {
str.push(element[1].toString());
}
console.log(str.join('\n'));
}
public pushElement(element: IUndoRedoElement): void {
if (element.type === UndoRedoElementType.Resource) {
const resourceLabel = getResourceLabel(element.resource);
......@@ -410,6 +442,9 @@ export class UndoRedoService implements IUndoRedoService {
this._pushElement(new WorkspaceStackElement(element, resourceLabels, strResources));
}
}
if (DEBUG) {
this._print('pushElement');
}
}
private _pushElement(element: StackElement): void {
......@@ -487,6 +522,9 @@ export class UndoRedoService implements IUndoRedoService {
editStack.dispose();
this._editStacks.delete(strResource);
}
if (DEBUG) {
this._print('removeElements');
}
}
public setElementsValidFlag(resource: URI, isValid: boolean, filter: (element: IUndoRedoElement) => boolean): void {
......@@ -495,6 +533,9 @@ export class UndoRedoService implements IUndoRedoService {
const editStack = this._editStacks.get(strResource)!;
editStack.setElementsValidFlag(isValid, filter);
}
if (DEBUG) {
this._print('setElementsValidFlag');
}
}
public hasElements(resource: URI): boolean {
......@@ -774,10 +815,16 @@ export class UndoRedoService implements IUndoRedoService {
return;
}
if (element.type === UndoRedoElementType.Workspace) {
return this._workspaceUndo(strResource, element);
} else {
return this._resourceUndo(editStack, element);
try {
if (element.type === UndoRedoElementType.Workspace) {
return this._workspaceUndo(strResource, element);
} else {
return this._resourceUndo(editStack, element);
}
} finally {
if (DEBUG) {
this._print('undo');
}
}
}
......@@ -903,10 +950,16 @@ export class UndoRedoService implements IUndoRedoService {
return;
}
if (element.type === UndoRedoElementType.Workspace) {
return this._workspaceRedo(strResource, element);
} else {
return this._resourceRedo(editStack, element);
try {
if (element.type === UndoRedoElementType.Workspace) {
return this._workspaceRedo(strResource, element);
} else {
return this._resourceRedo(editStack, element);
}
} finally {
if (DEBUG) {
this._print('redo');
}
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册