Skip to content

Commit 59e3c95

Browse files
committed
fixed #237
1 parent c9d65ef commit 59e3c95

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

src/client/debugger/Common/Utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
import {IPythonProcess, IPythonThread, IPythonModule, IPythonEvaluationResult} from "./Contracts";
44
import * as path from "path";
5+
import * as fs from 'fs';
6+
7+
const PathValidity: Map<string, boolean> = new Map<string, boolean>();
8+
export function validatePath(filePath: string): Promise<string> {
9+
if (filePath.length === 0) {
10+
return Promise.resolve('');
11+
}
12+
if (PathValidity.has(filePath)) {
13+
return Promise.resolve(PathValidity.get(filePath) ? filePath : '');
14+
}
15+
return new Promise<string>(resolve => {
16+
fs.exists(filePath, exists => {
17+
PathValidity.set(filePath, exists);
18+
return resolve(exists ? filePath : '');
19+
});
20+
});
21+
}
522

623
export function CreatePythonThread(id: number, isWorker: boolean, process: IPythonProcess, name: string = ""): IPythonThread {
724
return {

src/client/debugger/Main.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {DebugClient, DebugType} from "./DebugClients/DebugClient";
1919
import {CreateAttachDebugClient, CreateLaunchDebugClient} from "./DebugClients/DebugFactory";
2020
import {DjangoApp, LaunchRequestArguments, AttachRequestArguments, DebugFlags, DebugOptions, TelemetryEvent} from "./Common/Contracts";
2121
import * as telemetryContracts from "../common/telemetryContracts";
22+
import {validatePath} from './Common/Utils';
2223

2324
const CHILD_ENUMEARATION_TIMEOUT = 5000;
2425

@@ -380,21 +381,27 @@ export class PythonDebugger extends DebugSession {
380381
let maxFrames = typeof args.levels === "number" && args.levels > 0 ? args.levels : pyThread.Frames.length - 1;
381382
maxFrames = maxFrames < pyThread.Frames.length ? maxFrames : pyThread.Frames.length;
382383

383-
let frames = [];
384-
for (let counter = 0; counter < maxFrames; counter++) {
385-
let frame = pyThread.Frames[counter];
386-
let frameId = this._pythonStackFrames.create(frame);
387-
frames.push(new StackFrame(frameId, frame.FunctionName,
388-
new Source(path.basename(frame.FileName), this.convertDebuggerPathToClient(frame.FileName)),
389-
this.convertDebuggerLineToClient(frame.LineNo - 1),
390-
0));
391-
}
392-
393-
response.body = {
394-
stackFrames: frames
395-
};
384+
let frames = pyThread.Frames.map(frame => {
385+
return validatePath(this.convertDebuggerPathToClient(frame.FileName)).then(fileName => {
386+
let frameId = this._pythonStackFrames.create(frame);
387+
if (fileName.length === 0) {
388+
return new StackFrame(frameId, frame.FunctionName);
389+
}
390+
else {
391+
return new StackFrame(frameId, frame.FunctionName,
392+
new Source(path.basename(frame.FileName), fileName),
393+
this.convertDebuggerLineToClient(frame.LineNo - 1),
394+
0);
395+
}
396+
});
397+
});
398+
Promise.all<StackFrame>(frames).then(resolvedFrames => {
399+
response.body = {
400+
stackFrames: resolvedFrames
401+
};
396402

397-
this.sendResponse(response);
403+
this.sendResponse(response);
404+
});
398405
});
399406
}
400407
protected stepInRequest(response: DebugProtocol.StepInResponse): void {

0 commit comments

Comments
 (0)