diff --git a/src/activateMockDebug.ts b/src/activateMockDebug.ts index f451e444..9e4bd30f 100644 --- a/src/activateMockDebug.ts +++ b/src/activateMockDebug.ts @@ -182,12 +182,20 @@ class MockConfigurationProvider implements vscode.DebugConfigurationProvider { } } +// Fix up URI on remote systems +const overrideUri: { scheme?: string, authority?: string } = {}; +if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length) { + const root = vscode.workspace.workspaceFolders[0].uri; + overrideUri.scheme = root.scheme; + overrideUri.authority = root.authority; +} + export const workspaceFileAccessor: FileAccessor = { isWindows: typeof process !== 'undefined' && process.platform === 'win32', async readFile(path: string): Promise { let uri: vscode.Uri; try { - uri = pathToUri(path); + uri = pathToUri(path, overrideUri); } catch (e) { return new TextEncoder().encode(`cannot read '${path}'`); } @@ -196,14 +204,23 @@ export const workspaceFileAccessor: FileAccessor = { }, async writeFile(path: string, contents: Uint8Array) { await vscode.workspace.fs.writeFile(pathToUri(path), contents); + }, + convertDebuggerPathToClient(path: string): string { + // Add overrides + const uri = pathToUri(path, overrideUri); + return uri.toString(); + }, + convertClientPathToDebugger(path: string): string { + // Remove scheme + return vscode.Uri.parse(path).fsPath; } }; -function pathToUri(path: string) { +function pathToUri(path: string, change: typeof overrideUri = {}) { try { - return vscode.Uri.file(path); + return vscode.Uri.file(path).with(change); } catch (e) { - return vscode.Uri.parse(path); + return vscode.Uri.parse(path).with(change); } } diff --git a/src/mockDebug.ts b/src/mockDebug.ts index b02f49ed..f9d09f07 100644 --- a/src/mockDebug.ts +++ b/src/mockDebug.ts @@ -73,7 +73,7 @@ export class MockDebugSession extends LoggingDebugSession { * Creates a new debug adapter that is used for one debug session. * We configure the default implementation of a debug adapter here. */ - public constructor(fileAccessor: FileAccessor) { + public constructor(protected fileAccessor: FileAccessor) { super("mock-debug.txt"); // this debugger uses zero-based lines and columns @@ -276,7 +276,7 @@ export class MockDebugSession extends LoggingDebugSession { protected async setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): Promise { - const path = args.source.path as string; + const path = this.convertClientPathToDebugger(args.source.path as string); const clientLines = args.lines || []; // clear all breakpoints for this file @@ -301,7 +301,8 @@ export class MockDebugSession extends LoggingDebugSession { protected breakpointLocationsRequest(response: DebugProtocol.BreakpointLocationsResponse, args: DebugProtocol.BreakpointLocationsArguments, request?: DebugProtocol.Request): void { if (args.source.path) { - const bps = this._runtime.getBreakpoints(args.source.path, this.convertClientLineToDebugger(args.line)); + const path = this.convertClientPathToDebugger(args.source.path as string); + const bps = this._runtime.getBreakpoints(path, this.convertClientLineToDebugger(args.line)); response.body = { breakpoints: bps.map(col => { return { @@ -908,5 +909,20 @@ export class MockDebugSession extends LoggingDebugSession { private createSource(filePath: string): Source { return new Source(basename(filePath), this.convertDebuggerPathToClient(filePath), undefined, undefined, 'mock-adapter-data'); } -} + protected convertDebuggerPathToClient(debuggerPath: string): string { + if (this.fileAccessor.convertDebuggerPathToClient) { + return this.fileAccessor.convertDebuggerPathToClient(debuggerPath); + } + + return super.convertDebuggerPathToClient(debuggerPath); + } + + protected convertClientPathToDebugger(clientPath: string): string { + if (this.fileAccessor.convertClientPathToDebugger) { + return this.fileAccessor.convertClientPathToDebugger(clientPath); + } + + return super.convertClientPathToDebugger(clientPath); + } +} diff --git a/src/mockRuntime.ts b/src/mockRuntime.ts index 87858a68..584a4634 100644 --- a/src/mockRuntime.ts +++ b/src/mockRuntime.ts @@ -8,6 +8,8 @@ export interface FileAccessor { isWindows: boolean; readFile(path: string): Promise; writeFile(path: string, contents: Uint8Array): Promise; + convertDebuggerPathToClient?(path: string): string; + convertClientPathToDebugger?(path: string): string; } export interface IRuntimeBreakpoint {