csharp.nvim icon indicating copy to clipboard operation
csharp.nvim copied to clipboard

Debugging not working

Open nathanjcollins opened this issue 1 year ago • 15 comments

So it seems like debugging is not working. If I use the debug_project() -> Launch -> Choose my project, nothing happens and it stops there. When I use run_project(), I can select my project and then it gives me the option of 2 profiles (http, https) - it's a minimal API. This works great.

So I try to use debug_project() to attach to the running process and I get the following:

image

Where can I find logs for this - as I realise the above isn't a great level of detail! My project has multiple projects in a .NET 8 solution.

nathanjcollins avatar Feb 20 '24 07:02 nathanjcollins

Hi, Thank you for reporting the issue. Please set the plugin log level to TRACE and send attach the logs to help me identify the problem.

The logs can be found in $XDG_STATE_HOME/nvim/csharp.log or $HOME/.local/state/nvim/csharp.log

iabdelkareem avatar Feb 26 '24 11:02 iabdelkareem

I run

require("csharp").debug_project()

then choose

1. Launch - .NET

and nothing happens.

Here's my logs (log level TRACE):

09:57:02 [DEBUG] csharp_logger: Selected debug config factory  buffer=3 feature="debugger", file="structlog.nvim/lua/structlog/logger.lua", line=80
09:57:30 [INFO] csharp_logger: Registering csharp commands to buffer 3 buffer=3 file="structlog.nvim/lua/structlog/logger.lua", line=80
09:57:37 [DEBUG] csharp_logger: Selected debug config factory  buffer=3 debug_config_factory={  create_config=<function 1>,  name="Launch - .NET",  request="launch" }, feature="debugger", file="structlog.nvim/lua/structlog/logger.lua", line=80
09:57:37 [DEBUG] csharp_logger: Sending request to LSP Server  buffer=3 feature="get-workspace-information", file="structlog.nvim/lua/structlog/logger.lua", line=80, method="o#/projects", request={  ExcludeSourceFiles=true }
09:57:37 [DEBUG] csharp_logger: Found only one executable project buffer=3 feature="select-project", file="structlog.nvim/lua/structlog/logger.lua", line=80, project=<1>{  AssemblyName="repositories",  Configuration="Debug",  IntermediateOutputPath="obj/Debug/net8.0/",  IsExe=true,  IsUnityProject=false,  OutputPath="bin/Debug/net8.0/",  Path="/home/vlad/repositories/repositories.csproj",  Platform="AnyCPU",  ProjectGuid="00000000-0000-0000-0000-000000000000",  TargetFramework=".NETCoreApp,Version=v8.0",  TargetFrameworks={ {    FriendlyName=".NETCoreApp",    Name=".NETCoreApp",    ShortName="net8.0"   } },  TargetPath="/home/vlad/repositories/bin/Debug/net8.0/repositories.dll" }, workspace_information={  MsBuild={   Projects={ <table 1> },   SolutionPath="/home/vlad/repositories/repositories.sln"  },  Script={   Projects={}  } }
09:57:37 [DEBUG] csharp_logger: Executing: dotnet build /home/vlad/repositories/repositories.csproj -c Debug buffer=3 feature="dotnet-cli", file="structlog.nvim/lua/structlog/logger.lua", line=80
09:57:38 [DEBUG] csharp_logger: Build failed                   buffer=3 feature="dotnet-cli", file="structlog.nvim/lua/structlog/logger.lua", line=80

However, if I just run

dotnet build /home/vlad/repositories/repositories.csproj -c Debug

everything is building ok.

VladimirBeliakov avatar Mar 01 '24 06:03 VladimirBeliakov

Having the same issue here. Plugin thinks the build fails, but running the command myself and everything is successful.

ryanseipp avatar Apr 04 '24 13:04 ryanseipp

Same issue here

Skaanning avatar Apr 16 '24 13:04 Skaanning

Thank you for reporting. Unfortunately, I don't have time at the moment to look into it :( I appreciate any contribution if you can, otherwise, I'll start looking into it once I get the chance.

iabdelkareem avatar Apr 16 '24 13:04 iabdelkareem

I would like to help, but I have no idea where to begin - I am new to all this nvim stuff.

Skaanning avatar Apr 16 '24 13:04 Skaanning

I added logger.debug("testout:::" .. output) between the two lines here - https://github.com/iabdelkareem/csharp.nvim/blob/main/lua/csharp/modules/dotnet-cli.lua#L6-L7

and got the following output

16:00:07 [DEBUG] csharp_logger: Selected debug config factory  buffer=1 debug_config_factory={  create_config=<function 1>,  name="Launch - .NET",  request="launch" }, feature="debugger", file="structlog.nvim/lua/structlog/logger.lua", line=80
16:00:07 [DEBUG] csharp_logger: Sending request to LSP Server  buffer=1 feature="get-workspace-information", file="structlog.nvim/lua/structlog/logger.lua", line=80, method="o#/projects", request={  ExcludeSourceFiles=true }
16:00:07 [DEBUG] csharp_logger: Found multiple projects! Selecting one buffer=1 executable_projects={ ............... } },  TargetPath="C:\\projects\\testprojectxxxxxx\\src\\testcli\\bin\\Debug\\net8.0\\testcli.dll" }
16:00:08 [DEBUG] csharp_logger: Executing: dotnet build C:\projects\testprojectxxxxxx\src\testcli\testcli.csproj -c Debug buffer=1 feature="dotnet-cli", file="structlog.nvim/lua/structlog/logger.lua", line=80
16:00:09 [DEBUG] csharp_logger: testout:::MSBuild version 17.8.5+b5265ef37 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  testcli.Models -> C:\projects\testprojectxxxxxx\src\testcli.Models\bin\Debug\net8.0\testcli.Models.dll
  testcli -> C:\projects\testprojectxxxxxx\src\testcli\bin\Debug\net8.0\testcli.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.70
 buffer=1 file="structlog.nvim/lua/structlog/logger.lua", line=80
16:00:09 [DEBUG] csharp_logger: Build failed                   buffer=1 feature="dotnet-cli", file="structlog.nvim/lua/structlog/logger.lua", line=80

So file:close() gives an non 0 exit_code on that output. Why that is I dont know.

Skaanning avatar Apr 16 '24 14:04 Skaanning

I added logger.debug("testout:::" .. output) between the two lines here - https://github.com/iabdelkareem/csharp.nvim/blob/main/lua/csharp/modules/dotnet-cli.lua#L6-L7

and got the following output

16:00:07 [DEBUG] csharp_logger: Selected debug config factory  buffer=1 debug_config_factory={  create_config=<function 1>,  name="Launch - .NET",  request="launch" }, feature="debugger", file="structlog.nvim/lua/structlog/logger.lua", line=80
16:00:07 [DEBUG] csharp_logger: Sending request to LSP Server  buffer=1 feature="get-workspace-information", file="structlog.nvim/lua/structlog/logger.lua", line=80, method="o#/projects", request={  ExcludeSourceFiles=true }
16:00:07 [DEBUG] csharp_logger: Found multiple projects! Selecting one buffer=1 executable_projects={ ............... } },  TargetPath="C:\\projects\\testprojectxxxxxx\\src\\testcli\\bin\\Debug\\net8.0\\testcli.dll" }
16:00:08 [DEBUG] csharp_logger: Executing: dotnet build C:\projects\testprojectxxxxxx\src\testcli\testcli.csproj -c Debug buffer=1 feature="dotnet-cli", file="structlog.nvim/lua/structlog/logger.lua", line=80
16:00:09 [DEBUG] csharp_logger: testout:::MSBuild version 17.8.5+b5265ef37 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  testcli.Models -> C:\projects\testprojectxxxxxx\src\testcli.Models\bin\Debug\net8.0\testcli.Models.dll
  testcli -> C:\projects\testprojectxxxxxx\src\testcli\bin\Debug\net8.0\testcli.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.70
 buffer=1 file="structlog.nvim/lua/structlog/logger.lua", line=80
16:00:09 [DEBUG] csharp_logger: Build failed                   buffer=1 feature="dotnet-cli", file="structlog.nvim/lua/structlog/logger.lua", line=80

So file:close() gives an non 0 exit_code on that output. Why that is I dont know.

How did you make the change without getting an error in Lazy? I get this after changing the file as suggested

You have local changes in /home/*****/.local/share/nvim/lazy/csharp.nvim: * lua/csharp/modules/dotnet-cli.lua Please remove them to update. You can also press x to remove the plugin and then I to install it again.

NF-DomenicoDUva avatar Apr 17 '24 17:04 NF-DomenicoDUva

Sorry, I don't know - lazy didn't complain when I did it

Skaanning avatar Apr 17 '24 18:04 Skaanning

I run

require("csharp").debug_project()

then choose

1. Launch - .NET

and nothing happens.

Here's my logs (log level TRACE):

09:57:02 [DEBUG] csharp_logger: Selected debug config factory  buffer=3 feature="debugger", file="structlog.nvim/lua/structlog/logger.lua", line=80
09:57:30 [INFO] csharp_logger: Registering csharp commands to buffer 3 buffer=3 file="structlog.nvim/lua/structlog/logger.lua", line=80
09:57:37 [DEBUG] csharp_logger: Selected debug config factory  buffer=3 debug_config_factory={  create_config=<function 1>,  name="Launch - .NET",  request="launch" }, feature="debugger", file="structlog.nvim/lua/structlog/logger.lua", line=80
09:57:37 [DEBUG] csharp_logger: Sending request to LSP Server  buffer=3 feature="get-workspace-information", file="structlog.nvim/lua/structlog/logger.lua", line=80, method="o#/projects", request={  ExcludeSourceFiles=true }
09:57:37 [DEBUG] csharp_logger: Found only one executable project buffer=3 feature="select-project", file="structlog.nvim/lua/structlog/logger.lua", line=80, project=<1>{  AssemblyName="repositories",  Configuration="Debug",  IntermediateOutputPath="obj/Debug/net8.0/",  IsExe=true,  IsUnityProject=false,  OutputPath="bin/Debug/net8.0/",  Path="/home/vlad/repositories/repositories.csproj",  Platform="AnyCPU",  ProjectGuid="00000000-0000-0000-0000-000000000000",  TargetFramework=".NETCoreApp,Version=v8.0",  TargetFrameworks={ {    FriendlyName=".NETCoreApp",    Name=".NETCoreApp",    ShortName="net8.0"   } },  TargetPath="/home/vlad/repositories/bin/Debug/net8.0/repositories.dll" }, workspace_information={  MsBuild={   Projects={ <table 1> },   SolutionPath="/home/vlad/repositories/repositories.sln"  },  Script={   Projects={}  } }
09:57:37 [DEBUG] csharp_logger: Executing: dotnet build /home/vlad/repositories/repositories.csproj -c Debug buffer=3 feature="dotnet-cli", file="structlog.nvim/lua/structlog/logger.lua", line=80
09:57:38 [DEBUG] csharp_logger: Build failed                   buffer=3 feature="dotnet-cli", file="structlog.nvim/lua/structlog/logger.lua", line=80

However, if I just run

dotnet build /home/vlad/repositories/repositories.csproj -c Debug

everything is building ok.

Same issue. Maybe it is something related to structlog?

[DEBUG] csharp_logger: Build failed buffer=3 feature="dotnet-cli", file="structlog.nvim/lua/structlog/logger.lua", line=80

Tantol avatar May 01 '24 17:05 Tantol

Thank you for your patience while I investigated this issue. I can't reproduce the. It might be an environment-specific issue. Could you please confirm if you are running Windows or share details of your environment if you're experiencing this bug?

Example:

  • OS: Fedora 40
  • Nvim: 10.0
  • Dotnet CLI: 8.0.203

iabdelkareem avatar Jun 10 '24 13:06 iabdelkareem

Are you guys by any chance running on macOS? I've the same problem and I think it's due to the fact that netcoredbg is not build for Mac.

thomasbecker avatar Jun 12 '24 06:06 thomasbecker

  • OS: Windows 11 Pro
  • NVIM v0.9.5
  • dotnet: 8.0.106

Skaanning avatar Jun 12 '24 07:06 Skaanning

I added logger.debug("testout:::" .. output) between the two lines here - https://github.com/iabdelkareem/csharp.nvim/blob/main/lua/csharp/modules/dotnet-cli.lua#L6-L7

and got the following output

16:00:07 [DEBUG] csharp_logger: Selected debug config factory  buffer=1 debug_config_factory={  create_config=<function 1>,  name="Launch - .NET",  request="launch" }, feature="debugger", file="structlog.nvim/lua/structlog/logger.lua", line=80
16:00:07 [DEBUG] csharp_logger: Sending request to LSP Server  buffer=1 feature="get-workspace-information", file="structlog.nvim/lua/structlog/logger.lua", line=80, method="o#/projects", request={  ExcludeSourceFiles=true }
16:00:07 [DEBUG] csharp_logger: Found multiple projects! Selecting one buffer=1 executable_projects={ ............... } },  TargetPath="C:\\projects\\testprojectxxxxxx\\src\\testcli\\bin\\Debug\\net8.0\\testcli.dll" }
16:00:08 [DEBUG] csharp_logger: Executing: dotnet build C:\projects\testprojectxxxxxx\src\testcli\testcli.csproj -c Debug buffer=1 feature="dotnet-cli", file="structlog.nvim/lua/structlog/logger.lua", line=80
16:00:09 [DEBUG] csharp_logger: testout:::MSBuild version 17.8.5+b5265ef37 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  testcli.Models -> C:\projects\testprojectxxxxxx\src\testcli.Models\bin\Debug\net8.0\testcli.Models.dll
  testcli -> C:\projects\testprojectxxxxxx\src\testcli\bin\Debug\net8.0\testcli.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.70
 buffer=1 file="structlog.nvim/lua/structlog/logger.lua", line=80
16:00:09 [DEBUG] csharp_logger: Build failed                   buffer=1 feature="dotnet-cli", file="structlog.nvim/lua/structlog/logger.lua", line=80

So file:close() gives an non 0 exit_code on that output. Why that is I dont know.

Indeed file:close does not always return a 3 items values (see f:close)

so the code in dotnet-cli.luashould be something like

local output = file:read("*all")
  logger.debug("[DBG CLI] output",{output=output})
-- ok is a boolean stating if the file is correctly closed (in our case if the command exits with a succes (0) code)
-- exit_code is only valued when ok == false 
  local ok, _, exit_code = file:close()  
  if (ok) then
    return output, 0
  else
    return output, exit_code
  end

I've tried it on a fork and it seems to work but still the debugger does not start 😢 For who is interested here is my fork : https://github.com/b3b00/csharp.nvim. I've also merged the roslyn PR #11

b3b00 avatar Jul 25 '24 12:07 b3b00

Same issue. BTW, how do you set up a breakpoint?

lispercat avatar Jul 28 '24 20:07 lispercat