dgkf / debugadapter

Debug Adapter Protocol implementation for R
GNU General Public License v3.0
18 stars 2 forks source link

Configuration on Neovim (thread to find the right recipe) #20

Closed PMassicotte closed 2 months ago

PMassicotte commented 3 months ago

Opening a new separate issue.

@jalvesaq fixed the issue with missing symbols in nvimcom. I was able to correctly install nvimcom, debugadapter on my system. Here is what I am getting now. I am posting this GIF that show how I proceeded.

Peek 2024-07-02 12-22

I am not sure which steps I am missing, but could not get it working.

I am pasting .cache/nvim/dap.log as it might have additional information. Note that DAP is able to communicate with debugadater. It might be related to the message = "No source refs found.", message?

[ DEBUG ] 2024-07-02T12:22:14Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1319 ]    "Connecting to debug adapter"   {
  host = "localhost",
  options = {
    source_filetype = "r"
  },
  port = 18721,
  type = "server"
}
[ DEBUG ] 2024-07-02T12:22:14Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1711 ]    "request"   {
  arguments = {
    adapterID = "nvim-dap",
    clientID = "neovim",
    clientName = "neovim",
    columnsStartAt1 = true,
    linesStartAt1 = true,
    locale = "en_CA.UTF-8",
    pathFormat = "path",
    supportsProgressReporting = true,
    supportsRunInTerminalRequest = true,
    supportsStartDebuggingRequest = true,
    supportsVariableType = true
  },
  command = "initialize",
  seq = 1,
  type = "request"
}
[ DEBUG ] 2024-07-02T12:22:14Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:966 ] 1   {
  body = {
    additionalModuleColumns = {},
    completionTriggerCharacters = {},
    exceptionBreakpointFilters = {},
    supportSuspendDebuggee = false,
    supportTerminateDebuggee = true,
    supportedChecksumAlgorithms = {},
    supportsBreakpointLocationsRequest = false,
    supportsCancelRequest = false,
    supportsClipboardContext = false,
    supportsCompletionsRequest = false,
    supportsConditionalBreakpoints = false,
    supportsConfigurationDoneRequest = true,
    supportsDataBreakpoints = false,
    supportsDelayedStackTraceLoading = false,
    supportsDisassembleRequest = false,
    supportsEvaluateForHovers = false,
    supportsExceptionFilterOptions = false,
    supportsExceptionInfoRequest = false,
    supportsExceptionOptions = false,
    supportsFunctionBreakpoints = true,
    supportsGotoTargetsRequest = false,
    supportsHitConditionalBreakpoints = false,
    supportsInstructionBreakpoints = false,
    supportsLoadedSourcesRequest = false,
    supportsLogPoints = false,
    supportsModulesRequest = false,
    supportsReadMemoryRequest = false,
    supportsRestartFrame = false,
    supportsRestartRequest = false,
    supportsSetExpression = false,
    supportsSetVariable = true,
    supportsSingleThreadExecutionRequests = false,
    supportsStepBack = false,
    supportsStepInTargetsRequest = false,
    supportsSteppingGranularity = false,
    supportsTerminateRequest = false,
    supportsTerminateThreadsRequest = false,
    supportsValueFormattingOptions = false,
    supportsWriteMemoryRequest = false
  },
  command = "initialize",
  request_seq = 1,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-07-02T12:22:14Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1711 ]    "request"   {
  arguments = {
    host = "localhost",
    name = "Attach to R process",
    port = 18721,
    request = "attach",
    type = "r"
  },
  command = "attach",
  seq = 2,
  type = "request"
}
[ DEBUG ] 2024-07-02T12:22:14Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:966 ] 1   {
  event = "initialized",
  type = "event"
}
[ DEBUG ] 2024-07-02T12:22:14Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1711 ]    "request"   {
  arguments = {
    breakpoints = { {
        line = 3
      } },
    lines = { 3 },
    source = {
      name = "debug.R",
      path = "/home/filoche/Desktop/debug.R"
    },
    sourceModified = false
  },
  command = "setBreakpoints",
  seq = 3,
  type = "request"
}
[ DEBUG ] 2024-07-02T12:22:14Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:966 ] 1   {
  command = "attach",
  request_seq = 2,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-07-02T12:22:14Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:966 ] 1   {
  body = {
    breakpoints = { {
        id = 1,
        message = "No source refs found.",
        verified = false
      } }
  },
  command = "setBreakpoints",
  request_seq = 3,
  success = true,
  type = "response"
}
[ INFO ] 2024-07-02T12:22:14Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:904 ]  "Breakpoint unverified" {
  id = 1,
  message = "No source refs found.",
  verified = false
}
[ DEBUG ] 2024-07-02T12:22:14Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1711 ]    "request"   {
  arguments = {
    filters = {}
  },
  command = "setExceptionBreakpoints",
  seq = 4,
  type = "request"
}
[ DEBUG ] 2024-07-02T12:22:14Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:966 ] 1   {
  body = {
    breakpoints = {}
  },
  command = "setExceptionBreakpoints",
  request_seq = 4,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-07-02T12:22:14Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1711 ]    "request"   {
  command = "configurationDone",
  seq = 5,
  type = "request"
}
[ DEBUG ] 2024-07-02T12:22:14Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:966 ] 1   {}
[ WARN ] 2024-07-02T12:22:14Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1027 ] "Received unexpected message"   {}
[ DEBUG ] 2024-07-02T12:22:33Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1711 ]    "request"   {
  arguments = {
    restart = false,
    terminateDebuggee = true
  },
  command = "disconnect",
  seq = 6,
  type = "request"
}
[ DEBUG ] 2024-07-02T12:22:33Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:966 ] 1   {}
[ WARN ] 2024-07-02T12:22:33Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1027 ] "Received unexpected message"   {}
[ INFO ] 2024-07-02T12:22:36Z-0400 ] ...oche/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1823 ] "Session closed due to disconnect"
PMassicotte commented 3 months ago

Additional information provided when using options(debugadapter.log = 2).

Do you know what this is referring to?

[BG<pid1697136>][DEBUG] Cannot find capability 'runInTerminal'

Complete log:

[BG<pid1697136>][DEBUG] sent (60)
Content-Length: 38
{"type":"event","event":"initialized"}

[BG<pid1697136>][DEBUG] recieved (150)
{"arguments":{"host":"localhost","name":"Attach to R process","request":"attach","port":18721,"type":"r"},"command":"attach","type":"request","seq":2}

[BG<pid1697136>][DEBUG] sent (91)
Content-Length: 69
{"type":"response","request_seq":2,"success":true,"command":"attach"}

[BG<pid1697136>][DEBUG] sent (91)
Content-Length: 69
{"type":"response","request_seq":2,"success":true,"command":"attach"}

[BG<pid1697136>][DEBUG] recieved (200)
{"arguments":{"breakpoints":[{"line":3}],"sourceModified":false,"lines":[3],"source":{"name":"debug.R","path":"\/home\/filoche\/Desktop\/debug.R"}},"command":"setBreakpoints","type":"request","seq":3}

[BG<pid1697136>][DEBUG] sent (185)
Content-Length: 162
{"type":"response","request_seq":3,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"verified":false,"message":"No source refs found.","id":1}]}}

[BG<pid1697136>][DEBUG] sent (185)
Content-Length: 162
{"type":"response","request_seq":3,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"verified":false,"message":"No source refs found.","id":1}]}}

[BG<pid1697136>][DEBUG] recieved (89)
{"arguments":{"filters":[]},"command":"setExceptionBreakpoints","type":"request","seq":4}

[BG<pid1697136>][DEBUG] sent (135)
Content-Length: 112
{"type":"response","request_seq":4,"success":true,"command":"setExceptionBreakpoints","body":{"breakpoints":[]}}

[BG<pid1697136>][DEBUG] sent (135)
Content-Length: 112
{"type":"response","request_seq":4,"success":true,"command":"setExceptionBreakpoints","body":{"breakpoints":[]}}

[BG<pid1697136>][DEBUG] recieved (56)
{"command":"configurationDone","type":"request","seq":5}

[BG<pid1697136>][DEBUG] sent (23)
Content-Length: 2
[]
[DEBUG] recieved (69)
{"type":"response","request_seq":2,"success":true,"command":"attach"}

[DEBUG] recieved (162)
{"type":"response","request_seq":3,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"verified":false,"message":"No source refs found.","id":1}]}}

Error in srcfile(srcfile) : is.character(filename) is not TRUE
dgkf commented 3 months ago

Awesome that you got it set up! To be honest, I think I would classify this as "working as intended implemented". We can see that it's successfully doing the handshake to connect to the R process and attempting to verify breakpoints in the R process, which is about all I really expect of the implementation right now.

As far as ensuring it can work in neovim, this looks like your configuration is correct. Just to address a few of the issues you're encountering:

Error in srcfile(srcfile) : is.character(filename) is not TRUE

Since I quickly moved to using sockets, a bit of the message handling was broken for a bit. Definitely a bug and I think I've already fixed it in a branch.

[BG<pid1697136>][DEBUG] Cannot find capability 'runInTerminal'

I'll need to investigate this one. The client sends its capabilities and it looks like I'm not handling the capability name properly. This is effectively how the client tells the DAP that the DAP can send back code that the neovim debugger will run in a neovim-managed terminal pane. This is where I enumerate available capabilities and I think the spec may have changed since I first drafted this a couple years ago.

breakpoints = { {
  id = 1,
  message = "No source refs found.",
  verified = false
} }

Currently, breakpoints will only be able to be set in package files (and specifically, only when you have the package installed). For the DAP to be able to debug this script, we would first need to source("debug.R", keep.source = TRUE) in order to load the code with source references to the file. This exact scenario is what I'm hoping to tackle in #18, but admittedly I'll probably only start tackling user-experience issues once the protocol implementation is a bit more mature.


In closing, I'm sorry that it's not living up to your expectations yet. I really appreciate you going through all this effort to test it against your setup. Even if it's not useful, it's super encouraging to me that you were able to get things "working". I'm much more hopeful about the current direction of the project, so I hope it soon gets to a state where it's more useful to you. I'd greatly appreciate your continued testing and bug reports!

PMassicotte commented 3 months ago

That is me who should be thanking you for this :) This is super nice to see reviving and really looking forward. I will try to do more test during the weekend and see if I can come back with more information!

dgkf commented 2 months ago

Sharing some progress since yesterday!

asciicast

You'll notice:

Tons more to still be improved, but just wanted to share how things are coming along. It's been a huge weight off my shoulders not to have to pull so many tricks to work with the browser, so development pace has been much faster!

PMassicotte commented 2 months ago

wow that is very nice! I will try that tomorrow (I have to rebuild R-dev). One quick question. at ~25 sec, it looks like the connection is occurring, even if the :DapContinue has not been called yet?

PMassicotte commented 2 months ago

Just looked the video 3–4 times in a row and that is indeed very nice work :ok_hand:

dgkf commented 2 months ago

at ~25 sec, it looks like the connection is occurring, even if the :DapContinue has not been called yet?

The connection that’s formed at that point is between the R session and the DAP running as a sub-process.

Once :DapContinue is called in neovim, a second connection is formed, but we don’t see this in R until we execute some arbitrary code (I just run 1) to run the top level task callback that echos debug from the subprocess.

dgkf commented 2 months ago

Going to close this since this is working as much as we can expect at this point. Please do continue to open issues as you encounter problems 🙏