Doom-emacs: c++ and c# autocomplete

Created on 28 Jan 2020  ·  21Comments  ·  Source: hlissner/doom-emacs

What are you trying to achieve?
Getting my emacs to work like vscode, the same as if I install the c++ and c# (for unity) vscode extensions and have autocomplete(the main one i care about). I researched a lot and only thing I got is that I need to use company mode, not sure if theres other ways, if so please educate me.

What have you tried?
I went in .doom.d/init.el and uncommented cc and csharp and did a 'bin/doom refresh' but am only getting syntax highlighting(colors on the text).

System information


emacs version 26.3
features XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS GLIB NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD LCMS2
build Aug 29, 2019
buildopts (--prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib --localstatedir=/var --with-x-toolkit=gtk3 --with-xft --with-modules 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt' CPPFLAGS=-D_FORTIFY_SOURCE=2 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now)
windowsys x
daemonp server-running
doom version 2.0.9
build HEAD -> develop c6518498b 2020-01-28 14:07:08 -0500
dir ~/.doom.d/
system type gnu/linux
config x86_64-pc-linux-gnu
shell /bin/bash
uname Linux 5.4.14-arch1-1 #1 SMP PREEMPT Thu, 23 Jan 2020 10:07:05 +0000 x86_64
path (/usr/local/bin /usr/local/sbin /usr/bin /usr/bin/site_perl /usr/bin/vendor_perl /usr/bin/core_perl /usr/lib/emacs/26.3/x86_64-pc-linux-gnu/)
config envfile envvar-file
elc-files 0
modules (:completion company ivy :ui doom doom-dashboard doom-quit hl-todo modeline nav-flash ophints (popup +all +defaults) vc-gutter vi-tilde-fringe window-select workspaces :editor (evil +everywhere) file-templates fold multiple-cursors rotate-text snippets :emacs dired electric ibuffer vc :checkers syntax :tools (eval +overlay) (lookup +docsets) lsp magit :lang cc csharp data emacs-lisp markdown (org +dragndrop +present) sh :config (default +bindings +smartparens))
packages (n/a)
elpa (s popup pkg-info flycheck f epl dash csharp-mode auto-complete)
unpin (n/a)
```

:lang cc :lang csharp :tools lsp question elisp

All 21 comments

Why not stick with VS code?

because I want to use doom emacs and dont want to use vscode..

Try enabling :lang (cc +lsp) and installing ccls on your system. It uses the same backend as vscode. I am not at a PC to check but I believe the csharp module also supports +lsp (with omnisharp).

this is working but only for c++, it says theres no lsp for csharpmode.

:lang (csharp +lsp) expects https://github.com/OmniSharp/omnisharp-roslyn to be installed.

Without +lsp, we use https://github.com/OmniSharp/omnisharp-emacs, which also ends up using omnisharp.

In any case, have you installed omnisharp?

yep, on arch linux what I did:

  1. clone omnisharp-roslyn from AUR
  2. cd into dir and makepkg -si
    (its the same method for ccls)

when open .cs file, log is saying "LSP :: No LSP server for csharp-mode(check lsp-log)"

Does that install the server into your PATH?

Try activating debug mode: SPC h d d then open the *lsp-log* buffer (with SPC b B lsp-log) and see what it says.

strangely theres no lsp log buffer, any ideas?

Try to check error or message buffers.
try to run which OmniSharp

@LarryLeb Did you open a C# buffer after activating debug mode, but before you checked for *lsp-log*?

Was there any LSP output in *Messages*? (SPC h e)

'@myrgy running commands in linux terminal:
which omnisharp returns "which: no omnisharp in (/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)"

which omnisharp-roslyn returns "which: no omnisharp-roslyn in (/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)"

Although I can see that omnisharp-roslyn is installed with pacman -Qet

@hlissner yes, I opened doom emacs in main screen with no buffers and then went in debug mode and then opened the csharp file and theres no lsplog to be found with SPC-b-B. Here is Messages buffer.
https://pastebin.com/DrwK7SFd

You may try to put symbolic link into one of bin folders.

Hi @LarryLeb ,have you managed to fix the problem?

@myrgy nope

just to be sure, can you confirm that it is working on your machine. Because ive tried both arch linux and windows 10, both have same problem.

Sorry for the late reply. But I don't use OmniSharp. But ccls and python completion works fine for me.

would appreciate if you could try it and let me know if it works

@LarryLeb

You may have better luck installing omnisharp-roselyn via LSP mode using lsp-install-server. I did this, and I could see the lsp-log buffer--but, I ran into the same issues mentioned in the thread below.

But, LSP support hasn't quite been perfected yet. Check out this issue: https://github.com/emacs-lsp/lsp-mode/issues/1125

And more specifically, check out this PR mentioned in the above issue thread: https://github.com/emacs-lsp/lsp-mode/issues/1125#issuecomment-607412250

_Looks like razzmatazz managed to get most features working for him._

The good news is that it appears that MS developers from OmniSharp are actively working on LSP improvements (per commits to the master branch at https://github.com/OmniSharp/csharp-language-server-protocol).


In the mean time, omnisharp-emacs is the best alternative.

@coltoneakins

Weird, lsp-csharp just works sometimes. Not always, though!

Waiting for @razzmatazz commits to be accepted! :D

@coltoneakins

Weird, lsp-csharp just works sometimes. Not always, though!

Waiting for @razzmatazz commits to be accepted! :D

Oh, that PR still needs some work and -- hopefully -- some help from maintainers of omnisharp-roslyn too, as I am not sure how to fix that issue with PollingFileChangeToken that pops in CI:

I have this issue.

Steps:

  1. Uncomment lsp.
  2. Set (csharp +lsp) to :lang
  3. Install omnisharp-roslyn: brew install omnisharp/omnisharp-roslyn/omnisharp
  4. Run: doom sync
  5. Run: doom env
  6. Open a .cs file and the log says "LSP :: No LSP server for csharp-mode(check *lsp-log*)."

Try to check error or message buffers.
try to run which OmniSharp

~bash
$ which omnisharp
/usr/local/bin/omnisharp
~

@LarryLeb Did you open a C# buffer after activating debug mode, but before you checked for lsp-log?

Was there any LSP output in Messages? (SPC h e)

The same as @LarryLeb , there is no buffer *lsp-log*.

@LarryLeb Did you open a C# buffer after activating debug mode, but before you checked for lsp-log?

Was there any LSP output in Messages? (SPC h e)

Debug mode on Note: standard-indent, tab-width, evil-shift-width adjusted to 4 DOOM Running doom hook: lsp! DOOM [ui/doom-dashboard] Changed dashboard’s PWD to <path-to-project-instead> LSP :: No LSP server for csharp-mode(check *lsp-log*). Garbage collecting...done (0.089s)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

idoo picture idoo  ·  3Comments

gilbertw1 picture gilbertw1  ·  3Comments

luisenrike picture luisenrike  ·  3Comments

nasoundead picture nasoundead  ·  3Comments

laishulu picture laishulu  ·  3Comments