iabdelkareem / csharp.nvim

Neovim plugin written in Lua, powered by omnisharp-roslyn, that aims to enhance the development experience for .NET developers.
MIT License
213 stars 9 forks source link

Debugging not working #4

Open nathanjcollins opened 7 months ago

nathanjcollins commented 7 months ago

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.

iabdelkareem commented 7 months ago

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

VladimirBeliakov commented 7 months ago

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.

ryanseipp commented 6 months ago

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

Skaanning commented 5 months ago

Same issue here

iabdelkareem commented 5 months ago

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.

Skaanning commented 5 months ago

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

Skaanning commented 5 months ago

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.

NF-DomenicoDUva commented 5 months ago

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:

Skaanning commented 5 months ago

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

Tantol commented 5 months ago

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

iabdelkareem commented 3 months ago

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:

thomasbecker commented 3 months ago

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.

Skaanning commented 3 months ago
b3b00 commented 2 months ago

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

lispercat commented 2 months ago

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