Skip to content

DAP: support the locations request (jump to a variable's declaration or value) #2115

Done

Description

@lagergren

What

  • The locations request was added in DAP 1.68 ("Add locationReferences to Variable-related data types to allow navigation to declarations, and a corresponding locations request").
  • References: Variable.declarationLocationReference and Variable.valueLocationReference, plus valueLocationReference on EvaluateResponse, SetVariableResponse and SetExpressionResponse. They share the lifetime of variablesReference.
  • There is no capability flag. The spec (debugAdapterProtocol.json at 1b52c20, version 1.71) has no supportsLocationsRequest; the client calls locations for a reference the adapter returned.

Why

  • lldb-dap: a locations handler (Handler/LocationsRequestHandler.cpp, registered at DAP.cpp:1502). It sets declarationLocationReference when the declaration is valid, and valueLocationReference when 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 sets valueLocationReference for function objects only (variableStore.ts:1129, threads.ts:681), and never declarationLocationReference.
  • 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. computeSourcePosition uses stackFrame.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.
  • DAPDebuggerEvaluator drops valueLocationReference.

How it could be done

Turning a reference into a position:

  • Add DAPClient.locations(int).
  • Turn the answer into an XSourcePosition with the logic of DAPStackFrame.doGetSourcePosition, moved into a shared helper (it is private today). A path gives a local or deferred file position, and a sourceReference gives DAPSourceReferencePosition.
  • 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) asks locations and calls navigatable.setSourcePosition in a read action, as setSourcePosition does 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 a valueLocationReference.
  • 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:

Test

  • Session test: the server returns a variable with declarationLocationReference: 5 and valueLocationReference: 6, and answers locations.
    • computeSourcePosition gives the answered file and line.
    • Without the reference, the search is used, in the style of DAPValueSourcePositionTest.
    • A failed locations falls back to the search.
  • Unit test: answer to position, for a path, a sourceReference and a missing line.

Effort and risk

Small to medium, low risk. Open question: a new action, or reuse "Jump to Type Source"?

Related: #2005, #2006.

Activity

  1. added
    enhancement
    dap
    on Nov 22, 2026
  2. added this to the 0.30.2 milestone on Nov 23, 2026
  3. added a commit that references this issue on Nov 24, 2026
    1112a7d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dapenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions