Skip to content

Commit

Permalink
Use scopes from response without copy
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Jun 1, 2024
1 parent c187677 commit 936ade9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lua/dap/ext/vscode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function M._load_json(jsonstr)
end

---@param path string?
---@return Configuration[]
---@return dap.Configuration[]
function M.getconfigs(path)
local resolved_path = path or (vim.fn.getcwd() .. '/.vscode/launch.json')
if not vim.loop.fs_stat(resolved_path) then
Expand Down
6 changes: 6 additions & 0 deletions lua/dap/protocol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
---@field stackFrames dap.StackFrame[]
---@field totalFrames? number


---@class dap.Scope
---@field name string
---@field presentationHint? "arguments"|"locals"|"registers"|string
Expand All @@ -79,6 +80,11 @@
---@field endColumn? number
---@field variables? table<string, dap.Variable> by variable name. Not part of spec


---@class dap.ScopesResponse
---@field scopes dap.Scope[]


---@class dap.ValueFormat
---@field hex? boolean Display the value in hex

Expand Down
37 changes: 22 additions & 15 deletions lua/dap/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -760,27 +760,34 @@ end

---@param current_frame dap.StackFrame
function Session:_request_scopes(current_frame)
self:request('scopes', { frameId = current_frame.id }, function(_, scopes_resp)
if not scopes_resp or not scopes_resp.scopes then
local params = {
frameId = current_frame.id
}
---@param scope_resp dap.ScopesResponse?
local function on_scopes(_, scope_resp)
if not scope_resp then
return
end
current_frame.scopes = {}
for _, scope in pairs(scopes_resp.scopes) do
table.insert(current_frame.scopes, scope)
local scopes = scope_resp.scopes
current_frame.scopes = scopes
local function toname(var)
return var.name
end
for _, scope in ipairs(scopes) do
if not scope.expensive then
local params = { variablesReference = scope.variablesReference }
self:request('variables', params, function(_, variables_resp)
if not variables_resp then
return

---@param resp dap.VariableResponse?
local function on_variables(_, resp)
if resp then
scope.variables = utils.to_dict(resp.variables, toname)
end
scope.variables = utils.to_dict(
variables_resp.variables,
function(v) return v.name end
)
end)
end
local varparams = { variablesReference = scope.variablesReference }
self:request('variables', varparams, on_variables)
end
end
end)
end
self:request('scopes', params, on_scopes)
end


Expand Down

0 comments on commit 936ade9

Please sign in to comment.