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

Roll back debugger call stack improvement #1236

Merged
merged 2 commits into from
Jul 14, 2021
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changes to Calva.

## [Unreleased]
- [Use new custom LSP method for server info command and print info in "Calva says" output channel ](https://github.com/BetterThanTomorrow/calva/issues/1211)
- [Roll back debugger call stack improvement](https://github.com/BetterThanTomorrow/calva/pull/1236)

## [2.0.204] - 2021-07-11
- [Put closing paren of rich comments on separate line](https://github.com/BetterThanTomorrow/calva/issues/1224)
Expand Down
48 changes: 20 additions & 28 deletions src/debugger/calva-debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import annotations from '../providers/annotations';
import { NReplSession } from '../nrepl';
import debugDecorations from './decorations';
import { setStateValue, getStateValue } from '../../out/cljs-lib/cljs-lib';
import * as util from '../utilities';
import * as replSession from '../nrepl/repl-session';

const CALVA_DEBUG_CONFIGURATION: DebugConfiguration = {
Expand Down Expand Up @@ -56,9 +57,9 @@ class CalvaDebugSession extends LoggingDebugSession {
}

/**
* The 'initialize' request is the first request called by the frontend
* to interrogate the features the debug adapter provides.
*/
* The 'initialize' request is the first request called by the frontend
* to interrogate the features the debug adapter provides.
*/
protected async initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): Promise<void> {

this.setDebuggerLinesStartAt1(args.linesStartAt1);
Expand All @@ -74,6 +75,8 @@ class CalvaDebugSession extends LoggingDebugSession {
}

protected async attachRequest(response: DebugProtocol.AttachResponse, args: DebugProtocol.AttachRequestArguments): Promise<void> {
const cljSession = replSession.getSession(CLOJURE_SESSION_NAME);

this.sendResponse(response);
state.analytics().logEvent(DEBUG_ANALYTICS.CATEGORY, DEBUG_ANALYTICS.EVENT_ACTIONS.ATTACH).send();
}
Expand Down Expand Up @@ -175,8 +178,6 @@ class CalvaDebugSession extends LoggingDebugSession {
protected async stackTraceRequest(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments, request?: DebugProtocol.Request): Promise<void> {

const debugResponse = getStateValue(DEBUG_RESPONSE_KEY);
const cljSession = replSession.getSession(CLOJURE_SESSION_NAME);
const { id, key } = getStateValue(DEBUG_RESPONSE_KEY);
const uri = debugResponse.file.startsWith('jar:') ? vscode.Uri.parse(debugResponse.file) : vscode.Uri.file(debugResponse.file);
const document = await vscode.workspace.openTextDocument(uri);
const positionLine = convertOneBasedToZeroBased(debugResponse.line);
Expand All @@ -195,39 +196,28 @@ class CalvaDebugSession extends LoggingDebugSession {
}

const [line, column] = tokenCursor.rowCol;
const stackTraceResponse = await cljSession.sendDebugInput(':stacktrace', id, key);
const allStackFrames = stackTraceResponse.causes[0].stacktrace;
const projectStackFrames = allStackFrames.filter(frame => {
return ['project', 'repl', 'clj'].some(f => frame.flags.includes(f)) &&
!['dup', 'tooling'].some(f => frame.flags.includes(f));
});
const mostRecentProjectReplFrame = allStackFrames.filter(frame => frame.flags.includes('project') && frame.flags.includes('repl'))[0];
const breakpointFrameName = `${mostRecentProjectReplFrame.ns}/${mostRecentProjectReplFrame.fn.split('/')[1]}`;

// Pass scheme in path argument to Source contructor so that if it's a jar file it's handled correctly
const source = new Source(basename(debugResponse.file), debugResponse.file);
const breakPointStackFrame = new StackFrame(0, breakpointFrameName, source, line + 1, column + 1);
const stackFrames = [breakPointStackFrame, ...projectStackFrames.map((frame, index) => {
const name = `${frame.ns}/${frame.fn}`;
const fileUrl = frame['file-url'];
const source = (typeof fileUrl === 'string') ? new Source(basename(fileUrl), fileUrl) : undefined;
return new StackFrame(index + 1, name, source, frame.line);
})];
const name = tokenCursor.getFunctionName();
const stackFrames = [new StackFrame(0, name, source, line + 1, column + 1)];

response.body = {
stackFrames,
totalFrames: stackFrames.length
};

this.sendResponse(response);

this._showDebugAnnotation(debugResponse['debug-value'], document, line, column);
}

protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments, request?: DebugProtocol.Request): void {
// If not frame 0, return empty scopes array because we cannot get the variables and values for other frames, as far as I know
const scopes = args.frameId && args.frameId !== 0 ? [] :
[new Scope("Locals", this._variableHandles.create('locals'), false)];

response.body = {
scopes
scopes: [
new Scope("Locals", this._variableHandles.create('locals'), false)
]
};

this.sendResponse(response);
Expand Down Expand Up @@ -257,10 +247,12 @@ class CalvaDebugSession extends LoggingDebugSession {
protected async disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments, request?: DebugProtocol.Request): Promise<void> {

const cljSession = replSession.getSession(CLOJURE_SESSION_NAME);

if (cljSession) {
const { id, key } = getStateValue(DEBUG_RESPONSE_KEY);
cljSession.sendDebugInput(':quit', id, key);
}

this.sendResponse(response);
}

Expand Down Expand Up @@ -290,10 +282,10 @@ CalvaDebugSession.run(CalvaDebugSession);

class CalvaDebugConfigurationProvider implements DebugConfigurationProvider {

/**
* Massage a debug configuration just before a debug session is being launched,
* e.g. add all missing attributes to the debug configuration.
*/
/**
* Massage a debug configuration just before a debug session is being launched,
* e.g. add all missing attributes to the debug configuration.
*/
resolveDebugConfiguration(folder: WorkspaceFolder | undefined, config: DebugConfiguration, token?: CancellationToken): ProviderResult<DebugConfiguration> {

// If launch.json is missing or empty
Expand Down