Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix paths when running in a codespace or github.dev browser extension #93

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/activateMockDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uint8Array> {
let uri: vscode.Uri;
try {
uri = pathToUri(path);
uri = pathToUri(path, overrideUri);
} catch (e) {
return new TextEncoder().encode(`cannot read '${path}'`);
}
Expand All @@ -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);
}
}

Expand Down
24 changes: 20 additions & 4 deletions src/mockDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -276,7 +276,7 @@ export class MockDebugSession extends LoggingDebugSession {

protected async setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): Promise<void> {

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
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
}
}
2 changes: 2 additions & 0 deletions src/mockRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface FileAccessor {
isWindows: boolean;
readFile(path: string): Promise<Uint8Array>;
writeFile(path: string, contents: Uint8Array): Promise<void>;
convertDebuggerPathToClient?(path: string): string;
convertClientPathToDebugger?(path: string): string;
}

export interface IRuntimeBreakpoint {
Expand Down