Skip to content

Commit 4a61f33

Browse files
committed
proposed API for creating debug uri
1 parent c4a5657 commit 4a61f33

4 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/vs/vscode.proposed.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,27 @@ declare module 'vscode' {
523523

524524
//#region André: debug
525525

526+
/**
527+
* A DebugSource is an opaque stand-in type for the type [Source](https://microsoft.github.io/debug-adapter-protocol/specification#Types_Source) defined in the Debug Adapter Protocol.
528+
*/
529+
export interface DebugSource {
530+
// opaque contents
531+
}
532+
533+
export namespace debug {
534+
535+
/**
536+
* Converts a "Source" object received via the Debug Adapter Protocol into a Uri that can be used to load its contents.
537+
*
538+
* If the "Source" object has insufficient information to create a uri, an error is thrown.
539+
*
540+
* @param source An object conforming to the [Source](https://microsoft.github.io/debug-adapter-protocol/specification#Types_Source) type defined in the Debug Adapter Protocol.
541+
* @param session An optional debug session that will be used to locate the Debug Adapter Protocol.
542+
* @return A uri that can be used to load the contents of the source.
543+
*/
544+
function asDebugSourceUri(source: DebugSource, session?: DebugSession): Uri;
545+
}
546+
526547
// deprecated
527548

528549
export interface DebugConfigurationProvider {

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,14 +778,17 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
778778
if (!parentSessionOrOptions || (typeof parentSessionOrOptions === 'object' && 'configuration' in parentSessionOrOptions)) {
779779
return extHostDebugService.startDebugging(folder, nameOrConfig, { parentSession: parentSessionOrOptions });
780780
}
781-
checkProposedApiEnabled(extension);
782781
return extHostDebugService.startDebugging(folder, nameOrConfig, parentSessionOrOptions || {});
783782
},
784783
addBreakpoints(breakpoints: vscode.Breakpoint[]) {
785784
return extHostDebugService.addBreakpoints(breakpoints);
786785
},
787786
removeBreakpoints(breakpoints: vscode.Breakpoint[]) {
788787
return extHostDebugService.removeBreakpoints(breakpoints);
788+
},
789+
asDebugSourceUri(source: vscode.DebugSource, session?: vscode.DebugSession): vscode.Uri {
790+
checkProposedApiEnabled(extension);
791+
return extHostDebugService.asDebugSourceUri(source, session);
789792
}
790793
};
791794

src/vs/workbench/api/common/extHostDebugService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ export interface IExtHostDebugService extends ExtHostDebugServiceShape {
3030
registerDebugConfigurationProvider(type: string, provider: vscode.DebugConfigurationProvider): vscode.Disposable;
3131
registerDebugAdapterDescriptorFactory(extension: IExtensionDescription, type: string, factory: vscode.DebugAdapterDescriptorFactory): vscode.Disposable;
3232
registerDebugAdapterTrackerFactory(type: string, factory: vscode.DebugAdapterTrackerFactory): vscode.Disposable;
33+
asDebugSourceUri(source: vscode.DebugSource, session?: vscode.DebugSession): vscode.Uri;
3334
}
3435

src/vs/workbench/api/node/extHostDebugService.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,32 @@ export class ExtHostDebugService implements IExtHostDebugService, ExtHostDebugSe
138138
});
139139
}
140140

141+
public asDebugSourceUri(src: vscode.DebugSource, session?: vscode.DebugSession): URI {
142+
143+
const source = <any>src;
144+
145+
if (typeof source.sourceReference === 'number') {
146+
// src can be retrieved via DAP's "source" request
147+
148+
let debug = `debug:${encodeURIComponent(source.path || '')}`;
149+
let sep = '?';
150+
151+
if (session) {
152+
debug += `${sep}session=${encodeURIComponent(session.id)}`;
153+
sep = '&';
154+
}
155+
156+
debug += `${sep}ref=${source.sourceReference}`;
157+
158+
return vscode.Uri.parse(debug);
159+
} else if (source.path) {
160+
// src is just a local file path
161+
return vscode.Uri.file(source.path);
162+
} else {
163+
throw new Error(`cannot create uri from DAP 'source' object; properties 'path' and 'sourceReference' are both missing.`);
164+
}
165+
}
166+
141167
private registerAllDebugTypes(extensionRegistry: ExtensionDescriptionRegistry) {
142168

143169
const debugTypes: string[] = [];

0 commit comments

Comments
 (0)