提交 f06db31f 编写于 作者: I isidor

Debug: save view state when it changes and not on shutdown

fixes #77060
上级 dea3abbb
...@@ -34,6 +34,7 @@ import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; ...@@ -34,6 +34,7 @@ import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { getSimpleEditorOptions, getSimpleCodeEditorWidgetOptions } from 'vs/workbench/contrib/codeEditor/browser/simpleEditorOptions'; import { getSimpleEditorOptions, getSimpleCodeEditorWidgetOptions } from 'vs/workbench/contrib/codeEditor/browser/simpleEditorOptions';
import { IRange, Range } from 'vs/editor/common/core/range'; import { IRange, Range } from 'vs/editor/common/core/range';
import { onUnexpectedError } from 'vs/base/common/errors';
const $ = dom.$; const $ = dom.$;
const IPrivateBreakpointWidgetService = createDecorator<IPrivateBreakpointWidgetService>('privateBreakopintWidgetService'); const IPrivateBreakpointWidgetService = createDecorator<IPrivateBreakpointWidgetService>('privateBreakopintWidgetService');
...@@ -190,7 +191,7 @@ export class BreakpointWidget extends ZoneWidget implements IPrivateBreakpointWi ...@@ -190,7 +191,7 @@ export class BreakpointWidget extends ZoneWidget implements IPrivateBreakpointWi
hitCondition, hitCondition,
logMessage logMessage
}); });
this.debugService.updateBreakpoints(this.breakpoint.uri, data, false); this.debugService.updateBreakpoints(this.breakpoint.uri, data, false).then(undefined, onUnexpectedError);
} else { } else {
const model = this.editor.getModel(); const model = this.editor.getModel();
if (model) { if (model) {
......
...@@ -15,6 +15,7 @@ import { getBreakpointMessageAndClassName } from 'vs/workbench/contrib/debug/bro ...@@ -15,6 +15,7 @@ import { getBreakpointMessageAndClassName } from 'vs/workbench/contrib/debug/bro
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { registerColor } from 'vs/platform/theme/common/colorRegistry'; import { registerColor } from 'vs/platform/theme/common/colorRegistry';
import { localize } from 'vs/nls'; import { localize } from 'vs/nls';
import { onUnexpectedError } from 'vs/base/common/errors';
interface IBreakpointDecoration { interface IBreakpointDecoration {
decorationId: string; decorationId: string;
...@@ -199,7 +200,7 @@ export class DebugEditorModelManager implements IWorkbenchContribution { ...@@ -199,7 +200,7 @@ export class DebugEditorModelManager implements IWorkbenchContribution {
} }
} }
this.debugService.updateBreakpoints(modelUri, data, true); this.debugService.updateBreakpoints(modelUri, data, true).then(undefined, onUnexpectedError);
} }
private onBreakpointsChange(): void { private onBreakpointsChange(): void {
......
...@@ -133,7 +133,6 @@ export class DebugService implements IDebugService { ...@@ -133,7 +133,6 @@ export class DebugService implements IDebugService {
this.viewModel = new ViewModel(contextKeyService); this.viewModel = new ViewModel(contextKeyService);
this.toDispose.push(this.fileService.onFileChanges(e => this.onFileChanges(e))); this.toDispose.push(this.fileService.onFileChanges(e => this.onFileChanges(e)));
this.toDispose.push(this.storageService.onWillSaveState(this.saveState, this));
this.lifecycleService.onShutdown(this.dispose, this); this.lifecycleService.onShutdown(this.dispose, this);
this.toDispose.push(this.extensionHostDebugService.onAttachSession(event => { this.toDispose.push(this.extensionHostDebugService.onAttachSession(event => {
...@@ -817,67 +816,82 @@ export class DebugService implements IDebugService { ...@@ -817,67 +816,82 @@ export class DebugService implements IDebugService {
addWatchExpression(name: string): void { addWatchExpression(name: string): void {
const we = this.model.addWatchExpression(name); const we = this.model.addWatchExpression(name);
this.viewModel.setSelectedExpression(we); this.viewModel.setSelectedExpression(we);
this.storeWatchExpressions();
} }
renameWatchExpression(id: string, newName: string): void { renameWatchExpression(id: string, newName: string): void {
return this.model.renameWatchExpression(id, newName); this.model.renameWatchExpression(id, newName);
this.storeWatchExpressions();
} }
moveWatchExpression(id: string, position: number): void { moveWatchExpression(id: string, position: number): void {
this.model.moveWatchExpression(id, position); this.model.moveWatchExpression(id, position);
this.storeWatchExpressions();
} }
removeWatchExpressions(id?: string): void { removeWatchExpressions(id?: string): void {
this.model.removeWatchExpressions(id); this.model.removeWatchExpressions(id);
this.storeWatchExpressions();
} }
//---- breakpoints //---- breakpoints
enableOrDisableBreakpoints(enable: boolean, breakpoint?: IEnablement): Promise<void> { async enableOrDisableBreakpoints(enable: boolean, breakpoint?: IEnablement): Promise<void> {
if (breakpoint) { if (breakpoint) {
this.model.setEnablement(breakpoint, enable); this.model.setEnablement(breakpoint, enable);
if (breakpoint instanceof Breakpoint) { if (breakpoint instanceof Breakpoint) {
return this.sendBreakpoints(breakpoint.uri); await this.sendBreakpoints(breakpoint.uri);
} else if (breakpoint instanceof FunctionBreakpoint) { } else if (breakpoint instanceof FunctionBreakpoint) {
return this.sendFunctionBreakpoints(); await this.sendFunctionBreakpoints();
} else {
await this.sendExceptionBreakpoints();
} }
} else {
return this.sendExceptionBreakpoints(); this.model.enableOrDisableAllBreakpoints(enable);
await this.sendAllBreakpoints();
} }
this.storeBreakpoints();
this.model.enableOrDisableAllBreakpoints(enable);
return this.sendAllBreakpoints();
} }
addBreakpoints(uri: uri, rawBreakpoints: IBreakpointData[], context: string): Promise<IBreakpoint[]> { async addBreakpoints(uri: uri, rawBreakpoints: IBreakpointData[], context: string): Promise<IBreakpoint[]> {
const breakpoints = this.model.addBreakpoints(uri, rawBreakpoints); const breakpoints = this.model.addBreakpoints(uri, rawBreakpoints);
breakpoints.forEach(bp => aria.status(nls.localize('breakpointAdded', "Added breakpoint, line {0}, file {1}", bp.lineNumber, uri.fsPath))); breakpoints.forEach(bp => aria.status(nls.localize('breakpointAdded', "Added breakpoint, line {0}, file {1}", bp.lineNumber, uri.fsPath)));
breakpoints.forEach(bp => this.telemetryDebugAddBreakpoint(bp, context)); breakpoints.forEach(bp => this.telemetryDebugAddBreakpoint(bp, context));
return this.sendBreakpoints(uri).then(() => breakpoints); await this.sendBreakpoints(uri);
this.storeBreakpoints();
return breakpoints;
} }
updateBreakpoints(uri: uri, data: Map<string, DebugProtocol.Breakpoint>, sendOnResourceSaved: boolean): void { async updateBreakpoints(uri: uri, data: Map<string, DebugProtocol.Breakpoint>, sendOnResourceSaved: boolean): Promise<void> {
this.model.updateBreakpoints(data); this.model.updateBreakpoints(data);
if (sendOnResourceSaved) { if (sendOnResourceSaved) {
this.breakpointsToSendOnResourceSaved.add(uri.toString()); this.breakpointsToSendOnResourceSaved.add(uri.toString());
} else { } else {
this.sendBreakpoints(uri); await this.sendBreakpoints(uri);
} }
this.storeBreakpoints();
} }
removeBreakpoints(id?: string): Promise<any> { async removeBreakpoints(id?: string): Promise<void> {
const toRemove = this.model.getBreakpoints().filter(bp => !id || bp.getId() === id); const toRemove = this.model.getBreakpoints().filter(bp => !id || bp.getId() === id);
toRemove.forEach(bp => aria.status(nls.localize('breakpointRemoved', "Removed breakpoint, line {0}, file {1}", bp.lineNumber, bp.uri.fsPath))); toRemove.forEach(bp => aria.status(nls.localize('breakpointRemoved', "Removed breakpoint, line {0}, file {1}", bp.lineNumber, bp.uri.fsPath)));
const urisToClear = distinct(toRemove, bp => bp.uri.toString()).map(bp => bp.uri); const urisToClear = distinct(toRemove, bp => bp.uri.toString()).map(bp => bp.uri);
this.model.removeBreakpoints(toRemove); this.model.removeBreakpoints(toRemove);
return Promise.all(urisToClear.map(uri => this.sendBreakpoints(uri))); await Promise.all(urisToClear.map(uri => this.sendBreakpoints(uri)));
this.storeBreakpoints();
} }
setBreakpointsActivated(activated: boolean): Promise<void> { setBreakpointsActivated(activated: boolean): Promise<void> {
this.model.setBreakpointsActivated(activated); this.model.setBreakpointsActivated(activated);
if (activated) {
this.storageService.store(DEBUG_BREAKPOINTS_ACTIVATED_KEY, 'false', StorageScope.WORKSPACE);
} else {
this.storageService.remove(DEBUG_BREAKPOINTS_ACTIVATED_KEY, StorageScope.WORKSPACE);
}
return this.sendAllBreakpoints(); return this.sendAllBreakpoints();
} }
...@@ -886,14 +900,16 @@ export class DebugService implements IDebugService { ...@@ -886,14 +900,16 @@ export class DebugService implements IDebugService {
this.viewModel.setSelectedFunctionBreakpoint(newFunctionBreakpoint); this.viewModel.setSelectedFunctionBreakpoint(newFunctionBreakpoint);
} }
renameFunctionBreakpoint(id: string, newFunctionName: string): Promise<void> { async renameFunctionBreakpoint(id: string, newFunctionName: string): Promise<void> {
this.model.renameFunctionBreakpoint(id, newFunctionName); this.model.renameFunctionBreakpoint(id, newFunctionName);
return this.sendFunctionBreakpoints(); await this.sendFunctionBreakpoints();
this.storeBreakpoints();
} }
removeFunctionBreakpoints(id?: string): Promise<void> { async removeFunctionBreakpoints(id?: string): Promise<void> {
this.model.removeFunctionBreakpoints(id); this.model.removeFunctionBreakpoints(id);
return this.sendFunctionBreakpoints(); await this.sendFunctionBreakpoints();
this.storeBreakpoints();
} }
sendAllBreakpoints(session?: IDebugSession): Promise<any> { sendAllBreakpoints(session?: IDebugSession): Promise<any> {
...@@ -993,7 +1009,16 @@ export class DebugService implements IDebugService { ...@@ -993,7 +1009,16 @@ export class DebugService implements IDebugService {
return result || []; return result || [];
} }
private saveState(): void { private storeWatchExpressions(): void {
const watchExpressions = this.model.getWatchExpressions();
if (watchExpressions.length) {
this.storageService.store(DEBUG_WATCH_EXPRESSIONS_KEY, JSON.stringify(watchExpressions.map(we => ({ name: we.name, id: we.getId() }))), StorageScope.WORKSPACE);
} else {
this.storageService.remove(DEBUG_WATCH_EXPRESSIONS_KEY, StorageScope.WORKSPACE);
}
}
private storeBreakpoints(): void {
const breakpoints = this.model.getBreakpoints(); const breakpoints = this.model.getBreakpoints();
if (breakpoints.length) { if (breakpoints.length) {
this.storageService.store(DEBUG_BREAKPOINTS_KEY, JSON.stringify(breakpoints), StorageScope.WORKSPACE); this.storageService.store(DEBUG_BREAKPOINTS_KEY, JSON.stringify(breakpoints), StorageScope.WORKSPACE);
...@@ -1001,12 +1026,6 @@ export class DebugService implements IDebugService { ...@@ -1001,12 +1026,6 @@ export class DebugService implements IDebugService {
this.storageService.remove(DEBUG_BREAKPOINTS_KEY, StorageScope.WORKSPACE); this.storageService.remove(DEBUG_BREAKPOINTS_KEY, StorageScope.WORKSPACE);
} }
if (!this.model.areBreakpointsActivated()) {
this.storageService.store(DEBUG_BREAKPOINTS_ACTIVATED_KEY, 'false', StorageScope.WORKSPACE);
} else {
this.storageService.remove(DEBUG_BREAKPOINTS_ACTIVATED_KEY, StorageScope.WORKSPACE);
}
const functionBreakpoints = this.model.getFunctionBreakpoints(); const functionBreakpoints = this.model.getFunctionBreakpoints();
if (functionBreakpoints.length) { if (functionBreakpoints.length) {
this.storageService.store(DEBUG_FUNCTION_BREAKPOINTS_KEY, JSON.stringify(functionBreakpoints), StorageScope.WORKSPACE); this.storageService.store(DEBUG_FUNCTION_BREAKPOINTS_KEY, JSON.stringify(functionBreakpoints), StorageScope.WORKSPACE);
...@@ -1020,13 +1039,6 @@ export class DebugService implements IDebugService { ...@@ -1020,13 +1039,6 @@ export class DebugService implements IDebugService {
} else { } else {
this.storageService.remove(DEBUG_EXCEPTION_BREAKPOINTS_KEY, StorageScope.WORKSPACE); this.storageService.remove(DEBUG_EXCEPTION_BREAKPOINTS_KEY, StorageScope.WORKSPACE);
} }
const watchExpressions = this.model.getWatchExpressions();
if (watchExpressions.length) {
this.storageService.store(DEBUG_WATCH_EXPRESSIONS_KEY, JSON.stringify(watchExpressions.map(we => ({ name: we.name, id: we.getId() }))), StorageScope.WORKSPACE);
} else {
this.storageService.remove(DEBUG_WATCH_EXPRESSIONS_KEY, StorageScope.WORKSPACE);
}
} }
//---- telemetry //---- telemetry
......
...@@ -722,7 +722,7 @@ export interface IDebugService { ...@@ -722,7 +722,7 @@ export interface IDebugService {
/** /**
* Updates the breakpoints. * Updates the breakpoints.
*/ */
updateBreakpoints(uri: uri, data: Map<string, IBreakpointUpdateData>, sendOnResourceSaved: boolean): void; updateBreakpoints(uri: uri, data: Map<string, IBreakpointUpdateData>, sendOnResourceSaved: boolean): Promise<void>;
/** /**
* Enables or disables all breakpoints. If breakpoint is passed only enables or disables the passed breakpoint. * Enables or disables all breakpoints. If breakpoint is passed only enables or disables the passed breakpoint.
......
...@@ -51,7 +51,9 @@ export class MockDebugService implements IDebugService { ...@@ -51,7 +51,9 @@ export class MockDebugService implements IDebugService {
throw new Error('not implemented'); throw new Error('not implemented');
} }
public updateBreakpoints(uri: uri, data: Map<string, IBreakpointUpdateData>, sendOnResourceSaved: boolean): void { } public updateBreakpoints(uri: uri, data: Map<string, IBreakpointUpdateData>, sendOnResourceSaved: boolean): Promise<void> {
throw new Error('not implemented');
}
public enableOrDisableBreakpoints(enabled: boolean): Promise<void> { public enableOrDisableBreakpoints(enabled: boolean): Promise<void> {
throw new Error('not implemented'); throw new Error('not implemented');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册