onivim / oni

Oni: Modern Modal Editing - powered by Neovim
https://www.onivim.io
MIT License
11.35k stars 299 forks source link

cpp language server configuration #1074

Open dpriedel opened 6 years ago

dpriedel commented 6 years ago

Is there a way to pass run-time, project specific configuration options to the clangd cpp languagage server? atom ide-cpp uses an 'unofficial' method using the .clang_complete file which seems to work.

Thanks

TalAmuyal commented 6 years ago

As far as I know, the latest clangd should be able to read your compile_commands.json (can be generated by CMake). IDK of other methods of feeding clangd with relevant arguments, but on the other hand, I'm not on the mailing list so maybe there is a way.

On the Oni side, I think there is still no such mechanism (@bryphe surly knows for sure). Also, I believe that a PR that implements that will be accepted swiftly.

bryphe commented 6 years ago

I just checked out the documentation here: https://atom.io/packages/autocomplete-clang

It looks like the entries in that file are passed as parameters to clang. We don't look for that file per-se, but we do have a way to pass arguments to the language server process, via configuration:

https://github.com/onivim/oni/blob/45f51c59b40dab399f96f2476e9040ee75ee725e/browser/src/Services/Configuration/DefaultConfiguration.ts#L134

Although for clangd looks like they'd be more in-depth. The big gap we have with this approach is the 'project-specific' configuration - unfortunately we don't currently have that today (that is tracked by #68

Another option is to return to having a C/C++ plugin on the Oni side, which gives us more options programmatically than the default configuration, and would make it easier to support scenarios like this. A good place to look at is this code here, which creates the language client based on the configuration: https://github.com/onivim/oni/blob/45f51c59b40dab399f96f2476e9040ee75ee725e/browser/src/Services/Language/LanguageConfiguration.ts#L99

dpriedel commented 6 years ago

Hi

I tried adding this to my oni.config:

  "language.cpp.languageServer.arguments": ["-std=c++17"]

but this causes an error in starting clangd:

[LANGUAGE CLIENT - STDERR]: clangd: Unknown command line argument '-std=c++17'.  Try: 'clangd -help' clangd: Did you mean '-stats=c++17'?

I believe what needs to be done is to somehow tell clangd what compilation options to use but I don't see any way to do that.

The atom ide-cpp module (NOT the autocomplete-clang) extracts this information from the .clang_complete file and somehow passes it to clangd.

I'll try and look some more to see how it does it.

Thanks !!

On 12/05/2017 02:36 PM, Bryan Phelps wrote:

I just checked out the documentation here: https://atom.io/packages/autocomplete-clang

It looks like the entries in that file are passed as parameters to |clang|. We don't look for that file per-se, but we do have a way to pass arguments to the language server process, via configuration:

https://github.com/onivim/oni/blob/45f51c59b40dab399f96f2476e9040ee75ee725e/browser/src/Services/Configuration/DefaultConfiguration.ts#L134

Although for |clangd| looks like they'd be more in-depth. The big gap we have with this approach is the 'project-specific' configuration - unfortunately we don't currently have that today (that is tracked by

68 https://github.com/onivim/oni/issues/68

Another option is to return to having a C/C++ plugin on the Oni side, which gives us more options programmatically than the default configuration, and would make it easier to support scenarios like this. A good place to look at is this code here, which creates the language client based on the configuration: https://github.com/onivim/oni/blob/45f51c59b40dab399f96f2476e9040ee75ee725e/browser/src/Services/Language/LanguageConfiguration.ts#L99

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/onivim/oni/issues/1074#issuecomment-349416440, or mute the thread https://github.com/notifications/unsubscribe-auth/AGjjyjXy-Ict3USOuSzYKo98E5xBwo97ks5s9ZtBgaJpZM4Q2YDX.

dpriedel commented 6 years ago

Browsing through the clangd project, it seems there is work underway to look for a file called 'compile_flags.txt' (which seems to look like .clang_complete for syntax) and use that for 'simple' builds instead of compile_commands.json. There are commits from early November related to this.

Miszo97 commented 6 years ago

@dpriedel Have you found out how to pass args to clangd yet? I mean: language.cpp.languageServer.arguments": ["-std=c++17"] does not work.

dpriedel commented 6 years ago

On 01/18/2018 05:10 PM, Miszo wrote:

@dpriedel https://github.com/dpriedel Have you found out how to pass args to clangd yet? I mean: |language.cpp.languageServer.arguments": ["-std=c++17"]| does not work.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/onivim/oni/issues/1074#issuecomment-358798589, or mute the thread https://github.com/notifications/unsubscribe-auth/AGjjykTlzlRo4hlIW5gVTa292QBud7QTks5tL8FqgaJpZM4Q2YDX.

The only thing I have found which works with clangd 5.0.1 or before and ONI is to use a compile_commands.json file. But, the easiest way to create this is with CMake which I don't run.  I did cobble together a simple json file for one source file and verified that it appears to work -- once.  After one syntax check or one completion try the clangd server crashes.  I don't know why (it could be my cobbled together json file)

Dave

MaskRay commented 6 years ago

There is also an older thread https://github.com/onivim/oni/issues/1074 for another language server cquery. Hope you guys can make the two C++ language servers customizable.

Sorry for pasting an Emacs related wiki page :) But the Emacs plugin is most full-blown and you can get a quick overview of what features it provides. https://github.com/cquery-project/cquery/wiki/Emacs

LucaWolf commented 6 years ago

Just wanted to share a partial success setup for clangd on Win64 for C projects, perhaps will be useful to others:

1) using Onivm 0.3.3 with included neovim

2) LLVM installed and added to the Windows' environment path

3) onivim configuration edited to export "configuration" section before "activate". This is because will add to configration, so it needs being declared already.

4) add to the configuration section the path to the current project as: oni.configuration.setValues({"language.cpp.languageServer.arguments": "-j=4 -compile-commands-dir=" + oni.workspace.activeWorkspace})

4) declare a project basic "compile_flags.txt" or compilation database file as required by clangd to the root of your project. I have an embedded project where cmake is not an option, so I don't have the luxury of a compilation database file (don't want to manually generate). So my compile_flags.txt is: -IC:/toolchain/arm-none-eabi/include -IC:/projects/demo/proj1/include -IC:/projects/demo/proj1/src -IC:/projects/demo/proj1/inc -Wall -etc, whatever flags you might have

5) done (restart onivom to make sure?). Place the cursor on a symbol and press F12 (jumpt to definition) or Ctrl-F12 (window split jump to definition)

6) I've noticed that not all the files will work. I don't understand why, perhaps because clang will fail to compile particular sources (don't know if it actually attempts full compilation or does just the AST parsing...)? On error, the developer tool console will read: Error -32602: findDefinitions called on non-added file

7) At least is a step forward for me. Please update this thread with your postive findings, if any.

Towerism commented 5 years ago

Simply symlink the final location of build_commands.json to your project root and you will be all set.