Repository navigation
Done
Labels
Milestone
Description
What
- The
locationsrequest was added in DAP 1.68 ("AddlocationReferences to Variable-related data types to allow navigation to declarations, and a correspondinglocationsrequest"). - References:
Variable.declarationLocationReferenceandVariable.valueLocationReference, plusvalueLocationReferenceon EvaluateResponse, SetVariableResponse and SetExpressionResponse. They share the lifetime ofvariablesReference. - There is no capability flag. The spec (
debugAdapterProtocol.jsonat 1b52c20, version 1.71) has nosupportsLocationsRequest; the client callslocationsfor a reference the adapter returned.
Why
- lldb-dap: a
locationshandler (Handler/LocationsRequestHandler.cpp, registered atDAP.cpp:1502). It setsdeclarationLocationReferencewhen the declaration is valid, andvalueLocationReferencewhen the value points to code (Variables.cpp:166-170). It also sets the latter on evaluate and setVariable. - vscode-js-debug: a handler (
debugAdapter.ts:114,:453). It setsvalueLocationReferencefor function objects only (variableStore.ts:1129,threads.ts:681), and neverdeclarationLocationReference. - Others: no. CodeLLDB has the fields in its protocol types but sets none.
What users miss:
- "Jump to Source" on a variable goes to a guess.
- A function value (a JS callback, a C function pointer) can't be opened at its definition.
VS Code shows a value that has valueLocationReference as a link (debugExpressionRenderer.ts:182-187, resolved in debugSession.ts:933-938). It keeps declarationLocationReference, but no UI uses it at the commit read.
Today
DAPValue.canNavigateToSource()is true.computeSourcePositionusesstackFrame.getSourcePositionFor(variable): a search for the variable's name in the current frame's file, through the TextMate or LSP variable registrars.- The same method feeds the inline values (
computeInlineDebuggerData, DAPValue.java:161). canNavigateToTypeSource()is false.DAPDebuggerEvaluatordropsvalueLocationReference.
How it could be done
Turning a reference into a position:
- Add
DAPClient.locations(int). - Turn the answer into an
XSourcePositionwith the logic ofDAPStackFrame.doGetSourcePosition, moved into a shared helper (it is private today). A path gives a local or deferred file position, and asourceReferencegivesDAPSourceReferencePosition. - Use line − 1. For a local file, use the column through
XDebuggerUtil.createPosition(VirtualFile, int, int)(both versions).
Declaration:
- With a
declarationLocationReference,computeSourcePosition(Jump to Source) askslocationsand callsnavigatable.setSourcePositionin a read action, assetSourcePositiondoes today. - Without one, or on failure, it falls back to today's search.
Inline values: computeInlineDebuggerData keeps calling the search directly. A locations request per variable shown inline would cost too much, and would move the values to their declarations.
Value:
- The proposal is a new action, "Jump to Value Source", in
XDebugger.ValueGroup, enabled when the shown variable has avalueLocationReference. - The alternative is "Jump to Type Source" (
canNavigateToTypeSource,computeTypeSourcePosition,canNavigateToTypeSourceAsync, all in both versions). Its name doesn't fit a function value; this is open. - A link inside the value, as in VS Code, would need
XValueNodeEx.addAdditionalHyperlink. That is impl API and doesn't exist in 2024.2, so I don't propose it.
Other points:
- Copy
valueLocationReferencefrom the evaluate, setVariable and setExpression answers. - Lifetime: values are rebuilt at each stop, so an old reference is never reused.
- Threading: requests run off the EDT, and the navigatable is called in a read action (DAP: inline values report "Read access is allowed from inside read-action only" from
DAPValue.computeSourcePosition#2005, fix(dap): give the source position of a DAP value in a read action #2006). - Compatibility: without references, nothing changes.
- Docs: mark Locations as supported in DAPSupport.md.
Test
- Session test: the server returns a variable with
declarationLocationReference: 5andvalueLocationReference: 6, and answerslocations.computeSourcePositiongives the answered file and line.- Without the reference, the search is used, in the style of
DAPValueSourcePositionTest. - A failed
locationsfalls back to the search.
- Unit test: answer to position, for a path, a
sourceReferenceand a missing line.
Effort and risk
Small to medium, low risk. Open question: a new action, or reuse "Jump to Type Source"?
Activity
feat: jump from a DAP variable to the source of its value, with the l…
feat: jump from a DAP variable to its declaration, with the locations…
feat: the debug console of a DAP session shows a link after an output…