diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index b89290d05fa..d139918f061 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -523,6 +523,27 @@ declare module 'vscode' { //#region André: debug + /** + * 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. + */ + export interface DebugSource { + // opaque contents + } + + export namespace debug { + + /** + * Converts a "Source" object received via the Debug Adapter Protocol into a Uri that can be used to load its contents. + * + * If the "Source" object has insufficient information to create a uri, an error is thrown. + * + * @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. + * @param session An optional debug session that will be used to locate the Debug Adapter Protocol. + * @return A uri that can be used to load the contents of the source. + */ + function asDebugSourceUri(source: DebugSource, session?: DebugSession): Uri; + } + // deprecated export interface DebugConfigurationProvider { diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index c872655f012..448923b1044 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -778,7 +778,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I if (!parentSessionOrOptions || (typeof parentSessionOrOptions === 'object' && 'configuration' in parentSessionOrOptions)) { return extHostDebugService.startDebugging(folder, nameOrConfig, { parentSession: parentSessionOrOptions }); } - checkProposedApiEnabled(extension); return extHostDebugService.startDebugging(folder, nameOrConfig, parentSessionOrOptions || {}); }, addBreakpoints(breakpoints: vscode.Breakpoint[]) { @@ -786,6 +785,10 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I }, removeBreakpoints(breakpoints: vscode.Breakpoint[]) { return extHostDebugService.removeBreakpoints(breakpoints); + }, + asDebugSourceUri(source: vscode.DebugSource, session?: vscode.DebugSession): vscode.Uri { + checkProposedApiEnabled(extension); + return extHostDebugService.asDebugSourceUri(source, session); } }; diff --git a/src/vs/workbench/api/common/extHostDebugService.ts b/src/vs/workbench/api/common/extHostDebugService.ts index f079be622ee..a80504d6c0f 100644 --- a/src/vs/workbench/api/common/extHostDebugService.ts +++ b/src/vs/workbench/api/common/extHostDebugService.ts @@ -30,5 +30,6 @@ export interface IExtHostDebugService extends ExtHostDebugServiceShape { registerDebugConfigurationProvider(type: string, provider: vscode.DebugConfigurationProvider): vscode.Disposable; registerDebugAdapterDescriptorFactory(extension: IExtensionDescription, type: string, factory: vscode.DebugAdapterDescriptorFactory): vscode.Disposable; registerDebugAdapterTrackerFactory(type: string, factory: vscode.DebugAdapterTrackerFactory): vscode.Disposable; + asDebugSourceUri(source: vscode.DebugSource, session?: vscode.DebugSession): vscode.Uri; } diff --git a/src/vs/workbench/api/node/extHostDebugService.ts b/src/vs/workbench/api/node/extHostDebugService.ts index 1b9b233961a..82d87ead799 100644 --- a/src/vs/workbench/api/node/extHostDebugService.ts +++ b/src/vs/workbench/api/node/extHostDebugService.ts @@ -138,6 +138,32 @@ export class ExtHostDebugService implements IExtHostDebugService, ExtHostDebugSe }); } + public asDebugSourceUri(src: vscode.DebugSource, session?: vscode.DebugSession): URI { + + const source = src; + + if (typeof source.sourceReference === 'number') { + // src can be retrieved via DAP's "source" request + + let debug = `debug:${encodeURIComponent(source.path || '')}`; + let sep = '?'; + + if (session) { + debug += `${sep}session=${encodeURIComponent(session.id)}`; + sep = '&'; + } + + debug += `${sep}ref=${source.sourceReference}`; + + return vscode.Uri.parse(debug); + } else if (source.path) { + // src is just a local file path + return vscode.Uri.file(source.path); + } else { + throw new Error(`cannot create uri from DAP 'source' object; properties 'path' and 'sourceReference' are both missing.`); + } + } + private registerAllDebugTypes(extensionRegistry: ExtensionDescriptionRegistry) { const debugTypes: string[] = [];