Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getSource(filename: string) {
if (this._filenameToPath.has(filename)) {
return new Source(filename, this._filenameToPath.get(filename));
}
let index = this._filenames.indexOf(filename);
if (index === -1) {
index = this._filenames.length;
this._filenames.push(filename);
}
let sourcePath = null;
let testPath = path.resolve(path.dirname(this._launchArgs.program), filename);
// TODO: check against list command.
if (fs.existsSync(testPath)) {
sourcePath = testPath;
}
return new Source(filename, sourcePath, index + 1, 'source');
}
let sourcePath = this.convertVMUriToSourcePath(uri);
let canShowSource = sourcePath && fs.existsSync(sourcePath);
// Download the source if from a "dart:" uri.
let sourceReference: number | undefined;
if (uri.startsWith("dart:")) {
sourcePath = undefined;
sourceReference = thread.storeData(location.script);
canShowSource = true;
}
const shortName = this.formatUriForShortDisplay(uri);
const stackFrame: DebugProtocol.StackFrame = new StackFrame(
frameId,
frameName,
canShowSource ? new Source(shortName, sourcePath, sourceReference, undefined, location.script) : undefined,
0, 0,
);
// The top frame is only allowed to be deemphasized when it's an exception (so the editor walks
// up the stack to user code). If the reson for stopping was a breakpoint, step, etc., then we
// should always leave the frame focusable.
const isTopFrame = stackFrames.length === 0;
const isStoppedAtException = thread.exceptionReference !== 0;
const allowDeemphasizingFrame = !isTopFrame || isStoppedAtException;
// If we wouldn't debug this source, then deemphasize in the stack.
if (stackFrame.source && allowDeemphasizingFrame) {
if (!this.isValidToDebug(uri) || (this.isSdkLibrary(uri) && !this.debugSdkLibraries)) {
stackFrame.source.origin = "from the Dart SDK";
stackFrame.source.presentationHint = "deemphasize";
} else if (this.isExternalLibrary(uri) && !this.debugExternalLibraries) {
stackFrame.source.origin = uri.startsWith("package:flutter/") ? "from the Flutter framework" : "from Pub packages";
stackFrame.source.presentationHint = "deemphasize";
if (this._filenameToPath.has(filename)) {
return new Source(filename, this._filenameToPath.get(filename));
}
let index = this._filenames.indexOf(filename);
if (index === -1) {
index = this._filenames.length;
this._filenames.push(filename);
}
let sourcePath = null;
let testPath = path.resolve(path.dirname(this._launchArgs.program), filename);
// TODO: check against list command.
if (fs.existsSync(testPath)) {
sourcePath = testPath;
}
return new Source(filename, sourcePath, index + 1, 'source');
}
stackFrames: xdebugResponse.stack.map(stackFrame => {
// XDebug paths are URIs, VS Code file paths
const filePath = this.convertDebuggerPathToClient(stackFrame.fileUri);
// "Name" of the source and the actual file path
const source = new vscode.Source(path.basename(filePath), filePath);
// a new, unique ID for scopeRequests
const stackFrameId = this._stackFrameIdCounter++;
// save the connection this stackframe belongs to and the level of the stackframe under the stacktrace id
this._stackFrames.set(stackFrameId, stackFrame);
// prepare response for VS Code (column is always 1 since XDebug doesn't tell us the column)
return new vscode.StackFrame(stackFrameId, stackFrame.name, source, stackFrame.line, 1);
})
}
if (fs.existsSync(source)) {
fs.unlinkSync(source)
}
let json = JSON.stringify(info)
fs.writeFileSync(source, json)
} catch (e) { }
} else {
if (source.indexOf(this.fileExtname) == -1) {
source = source + this.fileExtname
}
source = this.convertToServerPath(source)
}
if (source != null && source != "") {
let tname = source.substring(source.lastIndexOf("/") + 1)
let line = info.currentline
frames.push(new StackFrame(i, info.scoreName, new Source(tname, source), line))
}
}
response.body = {
stackFrames: frames,
totalFrames: frames.length
}
this.sendResponse(response)
}
stackFrames: []
};
this.currentStackThread = null;
this.sendResponse(response);
}
var pyThread = this.pythonProcess.Threads.get(args.threadId);
this.currentStackThread = pyThread;
var maxFrames = typeof args.levels === "number" && args.levels > 0 ? args.levels : pyThread.Frames.length - 1;
maxFrames = maxFrames < pyThread.Frames.length ? maxFrames : pyThread.Frames.length;
var frames = [];
for (var counter = 0; counter < maxFrames; counter++) {
var frame = pyThread.Frames[counter];
frames.push(new StackFrame(counter, frame.FunctionName,
new Source(path.basename(frame.FileName), this.convertDebuggerPathToClient(frame.FileName)),
this.convertDebuggerLineToClient(frame.LineNo - 1),
0));
}
response.body = {
stackFrames: frames
};
this.sendResponse(response);
}
stateRespObj.stateResponse.state.references &&
stateRespObj.stateResponse.state.references.references
) {
this.populateReferences(
stateRespObj.stateResponse.state.references.references,
frameInfo.requestId
);
}
}
clientFrames.push(
new StackFrame(
frameId,
serverFrames[i].fullName,
sourcePath
? new Source(
basename(sourcePath),
this.convertDebuggerPathToClient(sourcePath)
)
: undefined,
this.convertDebuggerLineToClient(serverFrames[i].lineNumber),
0
)
);
}
}
response.body = { stackFrames: clientFrames };
response.success = true;
} catch (error) {
response.message = error;
}
this.sendResponse(response);