Skip to content

Commit

Permalink
debug session: add breakpointLocations
Browse files Browse the repository at this point in the history
  • Loading branch information
isidorn committed Sep 17, 2019
1 parent 9e3d285 commit 50a0bd9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
34 changes: 24 additions & 10 deletions src/vs/workbench/contrib/debug/browser/debugSession.ts
Expand Up @@ -10,7 +10,7 @@ import * as platform from 'vs/base/common/platform';
import severity from 'vs/base/common/severity';
import { Event, Emitter } from 'vs/base/common/event';
import { CompletionItem, completionKindFromString } from 'vs/editor/common/modes';
import { Position } from 'vs/editor/common/core/position';
import { Position, IPosition } from 'vs/editor/common/core/position';
import * as aria from 'vs/base/browser/ui/aria/aria';
import { IDebugSession, IConfig, IThread, IRawModelUpdate, IDebugService, IRawStoppedDetails, State, LoadedSourceEvent, IFunctionBreakpoint, IExceptionBreakpoint, IBreakpoint, IExceptionInfo, AdapterEndEvent, IDebugger, VIEWLET_ID, IDebugConfiguration, IReplElement, IStackFrame, IExpression, IReplElementSource, IDataBreakpoint } from 'vs/workbench/contrib/debug/common/debug';
import { Source } from 'vs/workbench/contrib/debug/common/debugSource';
Expand All @@ -34,6 +34,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { variableSetEmitter } from 'vs/workbench/contrib/debug/browser/variablesView';
import { CancellationTokenSource, CancellationToken } from 'vs/base/common/cancellation';
import { distinct } from 'vs/base/common/arrays';

export class DebugSession implements IDebugSession {

Expand Down Expand Up @@ -284,15 +285,7 @@ export class DebugSession implements IDebugSession {
return Promise.resolve(undefined);
}

const source = this.getSourceForUri(modelUri);
let rawSource: DebugProtocol.Source;
if (source) {
rawSource = source.raw;
} else {
const data = Source.getEncodedDebugData(modelUri);
rawSource = { name: data.name, path: data.path, sourceReference: data.sourceReference };
}

const rawSource = this.getRawSource(modelUri);
if (breakpointsToSend.length && !rawSource.adapterData) {
rawSource.adapterData = breakpointsToSend[0].adapterData;
}
Expand Down Expand Up @@ -376,6 +369,17 @@ export class DebugSession implements IDebugSession {
return Promise.reject(new Error('no debug adapter'));
}

async breakpointsLocations(uri: URI, lineNumber: number): Promise<IPosition[]> {
if (this.raw) {
const source = this.getRawSource(uri);
const response = await this.raw.breakpointLocations({ source, line: lineNumber });
const positions = response.body.breakpoints.map(bp => ({ lineNumber: bp.line, column: bp.column || 1 }));

return distinct(positions, p => p.toString());
}
return Promise.reject(new Error('no debug adapter'));
}

customRequest(request: string, args: any): Promise<DebugProtocol.Response> {
if (this.raw) {
return this.raw.custom(request, args);
Expand Down Expand Up @@ -914,6 +918,16 @@ export class DebugSession implements IDebugSession {
return source;
}

private getRawSource(uri: URI): DebugProtocol.Source {
const source = this.getSourceForUri(uri);
if (source) {
return source.raw;
} else {
const data = Source.getEncodedDebugData(uri);
return { name: data.name, path: data.path, sourceReference: data.sourceReference };
}
}

private getNewCancellationToken(threadId: number): CancellationToken {
const tokenSource = new CancellationTokenSource();
const tokens = this.cancellationMap.get(threadId) || [];
Expand Down
7 changes: 7 additions & 0 deletions src/vs/workbench/contrib/debug/browser/rawDebugSession.ts
Expand Up @@ -381,6 +381,13 @@ export class RawDebugSession implements IDisposable {
return this.send<DebugProtocol.SetExceptionBreakpointsResponse>('setExceptionBreakpoints', args);
}

breakpointLocations(args: DebugProtocol.BreakpointLocationsArguments): Promise<DebugProtocol.BreakpointLocationsResponse> {
if (this.capabilities.supportsBreakpointLocationsRequest) {
return this.send('breakpointLocations', args);
}
return Promise.reject(new Error('breakpointLocations is not supported'));
}

configurationDone(): Promise<DebugProtocol.ConfigurationDoneResponse> {
if (this.capabilities.supportsConfigurationDoneRequest) {
return this.send('configurationDone', null);
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/contrib/debug/common/debug.ts
Expand Up @@ -12,7 +12,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
import { IEditorContribution } from 'vs/editor/common/editorCommon';
import { ITextModel as EditorIModel } from 'vs/editor/common/model';
import { IEditor, ITextEditor } from 'vs/workbench/common/editor';
import { Position } from 'vs/editor/common/core/position';
import { Position, IPosition } from 'vs/editor/common/core/position';
import { CompletionItem } from 'vs/editor/common/modes';
import { Source } from 'vs/workbench/contrib/debug/common/debugSource';
import { Range, IRange } from 'vs/editor/common/core/range';
Expand Down Expand Up @@ -208,6 +208,7 @@ export interface IDebugSession extends ITreeElement {
dataBreakpointInfo(name: string, variablesReference?: number): Promise<{ dataId: string | null, description: string, canPersist?: boolean }>;
sendDataBreakpoints(dbps: IDataBreakpoint[]): Promise<void>;
sendExceptionBreakpoints(exbpts: IExceptionBreakpoint[]): Promise<void>;
breakpointsLocations(uri: uri, lineNumber: number): Promise<IPosition[]>;

stackTrace(threadId: number, startFrame: number, levels: number): Promise<DebugProtocol.StackTraceResponse>;
exceptionInfo(threadId: number): Promise<IExceptionInfo | undefined>;
Expand Down
7 changes: 6 additions & 1 deletion src/vs/workbench/contrib/debug/test/common/mockDebug.ts
Expand Up @@ -6,7 +6,7 @@
import { URI as uri } from 'vs/base/common/uri';
import { Event } from 'vs/base/common/event';
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { Position } from 'vs/editor/common/core/position';
import { Position, IPosition } from 'vs/editor/common/core/position';
import { ILaunch, IDebugService, State, IDebugSession, IConfigurationManager, IStackFrame, IBreakpointData, IBreakpointUpdateData, IConfig, IDebugModel, IViewModel, IBreakpoint, LoadedSourceEvent, IThread, IRawModelUpdate, IFunctionBreakpoint, IExceptionBreakpoint, IDebugger, IExceptionInfo, AdapterEndEvent, IReplElement, IExpression, IReplElementSource, IDataBreakpoint } from 'vs/workbench/contrib/debug/common/debug';
import { Source } from 'vs/workbench/contrib/debug/common/debugSource';
import { CompletionItem } from 'vs/editor/common/modes';
Expand Down Expand Up @@ -132,6 +132,11 @@ export class MockDebugService implements IDebugService {
}

export class MockSession implements IDebugSession {

breakpointsLocations(uri: uri, lineNumber: number): Promise<IPosition[]> {
throw new Error('Method not implemented.');
}

dataBreakpointInfo(name: string, variablesReference?: number | undefined): Promise<{ dataId: string | null; description: string; canPersist?: boolean | undefined; }> {
throw new Error('Method not implemented.');
}
Expand Down

0 comments on commit 50a0bd9

Please sign in to comment.