reddit / emacs

How in the world do I setup C# in Doom Emacs?

XNovaViperX · 2022-01-27 15:07
Hey guys, im trying to setup C# with LSP in Doom Emacs but I don't see anywhere how exactly you set it up. I have the plugin installed but I can't seem to get it to run my cs files. I try to run `csharp-mode-menu` but it says I need to have it mount to an event with parameters.. but I have no idea what that means. Also can't find anywhere how I can compile my cs files too. Anyone know what Im missing? ​ \--Edit-- I managed to get dap-mode setup with `(debugger +lsp)` which enables dap-mode and the necessary integrations for lsp, `(c# + lsp)` which enables the C# language packages and lsp integrations and `lsp` for enabling LSP, but I have no idea how to setup the debugger for C#. I haven't been able to find much information for setting up the dap debugger for C#.
LuciferTowers · 2022-01-27 20:07
Step 1: Stop using Doom Emacs. Step 2: Write your own config. Slowly add what you need for C# Step 3: Rinse and repeat for everything else.
FrozenOnPluto · 2022-01-28 00:29
Perhaps there is a language server and you can set up lsp-mode or eglot?
XNovaViperX · 2022-01-28 00:31
I actually did get LSP and omnisharp up! But I still can't figure out the debugger part.. and there's hardly anything online about Emacs and C# debugging sadly <\_>
FrozenOnPluto · 2022-01-28 00:32
dap-mode? I’ve been getting by on elpy for Python; only fiddled with lsp, dap and eglot for various languages so not much help I’m afraid :)
XNovaViperX · 2022-01-28 00:55
D: Sadly I don't think C# works with eglot.. I don't see it listed
[deleted] · 2022-01-28 02:50
[removed]
Vince_Vice · 2022-01-28 08:25
Youmight also want to ask here: r/doomemacs
sebhoagie · 2022-01-28 16:30
It does work, this was my Eglot setup for it (I don't use Doom Emacs, though): (use-package eglot :commands (eglot eglot-ensure) :hook ((python-mode-hook . eglot-ensure) (csharp-mode-hook . eglot-ensure)) :bind (:map eglot-mode-map (("C-c C-e r" . eglot-rename) ("C-c C-e f" . eglot-format) ("C-c C-e h" . eldoc))) :config (add-to-list 'eglot-server-programs `(csharp-mode . ("/home/hoagie/.omnisharp/1.37.15/run" "-lsp"))) ;; patch the argument. When nil, use "" instead. (defun eglot--format-markup-patch (args) (list (or (car args) ""))) (advice-add 'eglot--format-markup :filter-args #'eglot--format-markup-patch))
sebhoagie · 2022-01-28 16:33
On top of the dap-mode configuration, I also had to `(require 'dap-netcore)` in my config for it to work. Again, not a Doom Emacs user, but that should get you started, maybe? Then it was a matter of `M-x dap-debug`. You can trigger a stop for debugger in code using the tools in the System.Diagnostics namespace.
XNovaViperX · 2022-01-28 17:37
O.o oo I'm gonna have to give a try when I get home from my classes!
XNovaViperX · 2022-01-28 17:38
~~Oddly I can't get dap-netcore imported, it just gives me an error saying the package is unavailable. From what I could tell tho it seems like net ore is built into dap~~ Just realized that `required` enables features xD Alright, so I have dap-netcore enabled, what do I do now?
XNovaViperX · 2022-01-28 18:41
Alright.. I got eglot added, but I still can't find how to actually launch the debugger, I ran `dap-debug` but it says there's no templates made. How do I make a template for it?
collapsing_spacetime · 2022-01-29 12:13
did any of [this](https://emacs-lsp.github.io/dap-mode/) help?
XNovaViperX · 2022-01-29 18:07
Unfortunately, no. There's nothing about setting up the debugger for C# with netcoredbg
sebhoagie · 2022-01-30 05:13
Be warned though, if you want debugger support, you will need lsp-mode :)
sebhoagie · 2022-01-30 05:19
If you try to start a session with `dap-debug` now, you should see two options, to attach or launch. Launching is like F5 in Visual Studio, where it launches the solution with the debugger attached. The "Attach" option, will prompt you for a running process, and then you can control what happens via code. For example if you `dotnet run` a website, attach the debugger, and then in a controller you have a call to `System.Diagnostics.Debugger.Break()`, dap will show you the code stopped in that point. I hope that helped!
XNovaViperX · 2022-01-30 06:41
That's what I have, I have emacs lsp enabled with dap-mode netcore enabled too.. but I have no idea how to make dap-mode specifically run my cs files. keep on getting error 127 when I run it <\_>
XNovaViperX · 2022-01-30 06:41
Ah, so I need to create a solution file too? I just have the cs file from a template I got from Microsoft's Visual Studio tutorial
sebhoagie · 2022-01-30 07:37
Apologies, I was imprecise. You need something that you can `dotnet run` on. Usually that is a project (not a solution), but I guess I am just too old and stuck in my VS days LOL
sebhoagie · 2022-01-30 07:40
It seems you are the author of the GH issue about this in the dap-mode project (#555), we can continue the conversation other there.
XNovaViperX · 2022-02-21 15:41
Final update: Hey guys! I finally managed to get it working, I had to change up the program location to point to the dll files for C# and also install netcoredbg. Here's how I have my debug parameters setup for C# [https://github.com/emacs-lsp/dap-mode/issues/555#issuecomment-1043114294](https://github.com/emacs-lsp/dap-mode/issues/555#issuecomment-1043114294) &#x200B; Also this [PR](https://github.com/emacs-lsp/dap-mode/pull/564) adds in the parameters I'm using currently so it should be out and ready in the latest builds now :D