Skip to content

Commit

Permalink
Limit debugging variable resolve recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Jun 9, 2024
1 parent a68cafc commit e412b38
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/text/language/debugger.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import std/[strutils, options, json, tables, sugar]
import std/[strutils, options, json, tables, sugar, strtabs]
import misc/[id, custom_async, custom_logger, util, connection, myjsonutils, event, response]
import scripting/expose
import dap_client, dispatch_tables, app_interface, config_provider, selector_popup_builder
Expand Down Expand Up @@ -215,18 +215,20 @@ proc updateStackTrace(self: Debugger, threadId: Option[ThreadId]): Future[Option

return threadId.some

proc updateVariables(self: Debugger, variablesReference: VariablesReference) {.async.} =
proc updateVariables(self: Debugger, variablesReference: VariablesReference, maxDepth: int) {.async.} =
if self.client.getSome(client):
let variables = await client.variables(variablesReference)
if variables.isError:
return

self.variables[variablesReference] = variables.result
if maxDepth == 0:
return

let futures = collect:
for variable in variables.result.variables:
if variable.variablesReference != 0.VariablesReference:
self.updateVariables(variable.variablesReference)
self.updateVariables(variable.variablesReference, maxDepth - 1)

await futures.all

Expand All @@ -241,7 +243,7 @@ proc updateScopes(self: Debugger, threadId: ThreadId) {.async.} =
self.scopes = scopes.result
let futures = collect:
for scope in self.scopes.scopes:
self.updateVariables(scope.variablesReference)
self.updateVariables(scope.variablesReference, 2)

await futures.all

Expand Down

0 comments on commit e412b38

Please sign in to comment.