dap-mode icon indicating copy to clipboard operation
dap-mode copied to clipboard

[golang] Expanding map only shows len() not content.

Open emilhjd opened this issue 2 years ago • 3 comments

Trying to look into local map variables when doing local debugging. Can see the variables but when I try to expand to see more the only information is the length. VS Code with the same code and tools (as far as I can tell) does not have this issue.

Included screenshots, message output after setting dap-print-io to true, and the example code.

Actual

Screenshot 2023-08-30 at 16 52 40

Expected (VS code)

Screenshot 2023-08-30 at 17 14 43

Output after setting `(setq dap-print-io t)`

Sending:

{
  "command": "variables",
  "arguments": {
    "variablesReference": 1000
  },
  "type": "request",
  "seq": 8
}

Received:

{
  "seq": 0,
  "type": "response",
  "request_seq": 8,
  "success": true,
  "command": "variables",
  "body": {
    "variables": [
      {
        "name": "~r0",
        "value": "example.com/debugissue.M nil",
        "type": "example.com/debugissue.M",
        "variablesReference": 0
      },
      {
        "name": "m",
        "value": "map[string][]string [\"a\": [\"b\",\"c\"], ]",
        "type": "map[string][]string",
        "evaluateName": "m",
        "variablesReference": 1001,
        "namedVariables": 1,
        "indexedVariables": 1
      }
    ]
  }
}

Sending:

{
  "command": "variables",
  "arguments": {
    "variablesReference": 1001,
    "start": 0,
    "filter": "indexed",
    "count": 0,
    "start": 0,
    "filter": "named",
    "count": 0
  },
  "type": "request",
  "seq": 9
}

Received:

{
  "seq": 0,
  "type": "response",
  "request_seq": 9,
  "success": true,
  "command": "variables",
  "body": {
    "variables": [
      {
        "name": "len()",
        "value": "1",
        "type": "int",
        "evaluateName": "len(m)",
        "variablesReference": 0
      }
    ]
  }
}
Minimal example code

main.go

package main

import "fmt"

func main() {
	fmt.Println(foo())
}

type M map[string][]string

func foo() M {
	m := map[string][]string{
		"a": {"b", "c"},
	}
	return m // Debug point here.
}

main_test.go

package main

import "testing"

func TestFoo(t *testing.T) {
	foo()
}

emilhjd avatar Aug 30 '23 15:08 emilhjd

Try adjusting dap-ui-variable-length ?

yyoncho avatar Aug 31 '23 07:08 yyoncho

I set it to 100 and no difference.

(setq dap-ui-variable-length 100)

Doing rgrep though dap-mode folder it looks to be at 20 by default.

(defcustom dap-ui-variable-length 30
  "Default number of variables to load in inspect variables view for
array variables."
  :group 'dap-ui
  :type 'number)

emilhjd avatar Aug 31 '23 13:08 emilhjd

Getting closer to fixing the issue. If i remove the duplicated start, filter, and count arguments I get the expected behavior.

I have no idea what other consequences this will have but with this patch it works as expected.

diff --git a/dap-ui.el b/dap-ui.el
index 51e010e..8fd4e7c 100644
--- a/dap-ui.el
+++ b/dap-ui.el
@@ -843,16 +843,7 @@ issue requests.
 VARIABLES-REFERENCE specifies the handle returned by the debug
 adapter for acquiring nested variables and must not be 0."
   (when (dap--session-running debug-session)
-    (->> (apply #'dap-request debug-session "variables"
-                :variablesReference  variables-reference
-                (append (when (and indexed-variables (< 0 indexed-variables))
-                          (list :start 0
-                                :filter "indexed"
-                                :count (1- (min indexed-variables dap-ui-default-fetch-count))))
-                        (when (and named-variables (< 0 named-variables))
-                          (list :start 0
-                                :filter "named"
-                                :count (1- (min named-variables dap-ui-default-fetch-count))))))
+    (->> (dap-request debug-session "variables" :variablesReference  variables-reference)
          (gethash "variables")
          (-map (-lambda ((&hash "value"
                                 "name"

Sending:

{
  "command": "variables",
  "arguments": {
    "variablesReference": 1002
  },
  "type": "request",
  "seq": 11
}

Received:

{
  "seq": 0,
  "type": "response",
  "request_seq": 11,
  "success": true,
  "command": "variables",
  "body": {
    "variables": [
      {
        "name": "len()",
        "value": "2",
        "type": "int",
        "evaluateName": "len(m)",
        "variablesReference": 0
      },
      {
        "name": "\"1\"",
        "value": "1",
        "type": "string: int",
        "evaluateName": "m[\"1\"]",
        "variablesReference": 0
      },
      {
        "name": "\"2\"",
        "value": "2",
        "type": "string: int",
        "evaluateName": "m[\"2\"]",
        "variablesReference": 0
      }
    ]
  }
}

Screenshot 2023-09-01 at 09 56 49

emilhjd avatar Sep 01 '23 08:09 emilhjd