Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using repl with python (windows) #644

Closed
Perry3D opened this issue Aug 11, 2022 · 5 comments
Closed

Error using repl with python (windows) #644

Perry3D opened this issue Aug 11, 2022 · 5 comments
Labels

Comments

@Perry3D
Copy link

Perry3D commented Aug 11, 2022

Debug adapter definition and debug configuration

Created a python env with

python -m venv venv_depugpy
venv_depugpy/Scripts/activate.bat
pip install debugpy

Configuration in nvim:

dap.adapters.python = {
  type = 'executable';
  command = 'C:\\Users\\oli\\AppData\\Local\\nvim\\venv_debugpy\\Scripts\\python';
  args = { '-m', 'debugpy.adapter' };
  options = {
    detached = true;
  };
}

function getPythonEnv()
  local venv = os.getenv("VIRTUAL_ENV")
  if venv ~= nil then
    return string.format("%s\\bin\\python.exe", venv)
  end

  local cwd = vim.fn.getcwd()
  if vim.fn.executable(cwd .. '/venv/' .. getVenvSuffix()) == 1 then
    return cwd .. '/venv/' .. getVenvSuffix()
  elseif vim.fn.executable(cwd .. '/.venv/' .. getVenvSuffix()) == 1 then
    return cwd .. '/.venv/' .. getVenvSuffix()
  else
    if vim.loop.os_uname().sysname == 'Linux' then
      return '/usr/bin/python'
    elseif vim.loop.os_uname().sysname == 'Windows_NT' then
      return os.getenv('SCOOP') .. '/apps/python/current/python.exe'
    end
  end
end

dap.configurations.python = {
  {
    type = 'python';
    request = 'launch';
    name = "Launch file with venv";
    justMyCode = false;
    program = "${file}";
    pythonPath = getPythonEnv();
  },
}

Vim version is 0.7.2. But i also tried a nightly build

nvim-dap is from latest master branch:

commit 66d33b7585b42b7eac20559f1551524287ded353 (HEAD -> master, tag: 0.2.0, origin/master, origin/HEAD)
Author: Mathias Fussenegger <f.mathias@zignar.net>
Date:   Thu Aug 4 16:07:14 2022 +0200

    Ensure repl autocompletion doesn't trigger in other buffers

Debug adapter version

debugpy is 1.6.2, python is 3.10.4

Steps to Reproduce

  • Open python file.
  • Set breakpoint
  • Run configuration
  • Open repl buffer and insert print('hello')

Expected Result

hello should be printed in the buffer

Actual Result

Got an error message:

Error executing vim.schedule lua callback: vim/shared.lua:65: s: expected string, got nil
stack traceback:
	[C]: in function 'error'
	vim/shared.lua:662: in function 'validate'
	vim/shared.lua:65: in function 'gsplit'
	vim/shared.lua:130: in function 'split'
	...im-data\site\pack\packer\start\nvim-dap/lua/dap/repl.lua:156: in function 'callback'
	...data\site\pack\packer\start\nvim-dap/lua/dap/session.lua:834: in function <...data\site\pack\packer\start\nvim-dap/lua/dap/session.lua:830>
@mfussenegger
Copy link
Owner

This is a bug in debugpy, see microsoft/debugpy#985

@Perry3D
Copy link
Author

Perry3D commented Aug 11, 2022

I set log level to trace and executed print('hello') again:

[ DEBUG ] 2022-08-11T16:14:38Z+0200 ] ...data\site\pack\packer\start\nvim-dap/lua/dap/session.lua:1301 ]	"request"	{
  arguments = {
    context = "repl",
    expression = "print('hello')",
    frameId = 2
  },
  command = "evaluate",
  seq = 14,
  type = "request"
}
[ DEBUG ] 2022-08-11T16:14:38Z+0200 ] ...data\site\pack\packer\start\nvim-dap/lua/dap/session.lua:818 ]	{
  body = {
    category = "stdout",
    output = "hello"
  },
  event = "output",
  seq = 27,
  type = "event"
}
[ DEBUG ] 2022-08-11T16:14:38Z+0200 ] ...data\site\pack\packer\start\nvim-dap/lua/dap/session.lua:818 ]	{
  body = {
    category = "stdout",
    output = "\n"
  },
  event = "output",
  seq = 28,
  type = "event"
}
[ DEBUG ] 2022-08-11T16:14:38Z+0200 ] ...data\site\pack\packer\start\nvim-dap/lua/dap/session.lua:818 ]	{
  body = {
    category = "stdout",
    output = "hello",
    source = vim.empty_dict()
  },
  event = "output",
  seq = 29,
  type = "event"
}
[ DEBUG ] 2022-08-11T16:14:38Z+0200 ] ...data\site\pack\packer\start\nvim-dap/lua/dap/session.lua:818 ]	{
  body = {
    category = "stdout",
    output = "\n",
    source = vim.empty_dict()
  },
  event = "output",
  seq = 30,
  type = "event"
}
[ DEBUG ] 2022-08-11T16:14:38Z+0200 ] ...data\site\pack\packer\start\nvim-dap/lua/dap/session.lua:818 ]	{
  body = {
    presentationHint = vim.empty_dict(),
    variablesReference = 0
  },
  command = "evaluate",
  request_seq = 14,
  seq = 31,
  success = true,
  type = "response"
}

I am not sure if this is the same bug. If I understand correctly you executed a print(None) which should result in a string ('None').
I just do a print('hello').

@mfussenegger
Copy link
Owner

It's the same underlying problem. The result property is mandatory in the evaluate response and debugpy doesn't provide it. That's also visible in your log output:

{
  body = {
    presentationHint = vim.empty_dict(),
    variablesReference = 0
  },
  command = "evaluate",
  request_seq = 14,
  seq = 31,
  success = true,
  type = "response"
}

https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Evaluate

@mfussenegger
Copy link
Owner

I'm closing this here given that I don't indent to add a client side workaround.

@Perry3D
Copy link
Author

Perry3D commented Oct 28, 2022

Just want to mention that the upstream fix from microsoft/debugpy#1063 is working. Installing the dev version with pip install git+https://github.com/microsoft/debugpy resolves the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants