jacobdufault / cquery

C/C++ language server supporting multi-million line code base, powered by libclang. Emacs, Vim, VSCode, and others with language server protocol support. Cross references, completion, diagnostics, semantic highlighting and more
MIT License
2.35k stars 162 forks source link

[feature-request] A global ~/.config/cquery/settings file #648

Open skywind3000 opened 6 years ago

skywind3000 commented 6 years ago

I have to copy same .cquery every where, it contains only few lines:

%clang
%c -std=gnu11
%cpp -std=gnu++14
-pthread

# Includes
-ID:/dev/mingw/include

Can I have a global .cquery file like C:\Users\MyName\.config\cquery\settings to setup include paths ?? YouCompleteMe can allow me have a global config.

jacobdufault commented 6 years ago

Sure, this sounds reasonable.

nick96 commented 6 years ago

I'm interested in implementing this feature. I've been looking over the code base and am struggling to find where the .cquery file is loaded. Could someone point me in the right direction?

jacobdufault commented 6 years ago

This function handles loading from .cquery: https://github.com/cquery-project/cquery/blob/1fa36852b5dbe0d8e8207b1362a150c722a077c7/src/project.cc#L456-L514

nick96 commented 6 years ago

Great! Thank you :smile:

A couple things:

  1. On *nix it is probably best to get the .cquery file from $HOME/.config/cquery as opposed to just putting it at $HOME
  2. On Windows what is the convention for config files? Looking here it seems that C:\Users\<user>\AppData\Roaming\cquery would be the best spot.

What I plan to do:

jacobdufault commented 6 years ago

For linux, what about reading $XDG_CONFIG_HOME and defaulting to $HOME/.cquery if not present?

A single global config SGTM.

Adding a function GetGlobalConfigDir to platform.h is one potential approach.

ambihelical commented 6 years ago

FYI, per XDG basedir convention, config dir should be at $HOME/.config/cquery/ when XDG_CONFIG_HOME is not defined and $XDG_CONFIG_HOME/cquery/ when it is. So if it is desired to be consistent with this generally spottily-followed specification, this isn't really doing it right. However, this is an improvement over only $HOME/.cquery, IMO.

I've done a few XDG basedir retrofits, and I've usually checked for the original config file in $HOME, and if it doesn't exist there follow the basedir spec. This way no one's existing config breaks and the basedir spec is followed for new installs.

liushapku commented 5 years ago

Is it possible to have environment variables in the .cqeury file?

I use conda and installed my gcc compilers inside conda environment. The include path should look like -I$CONDA_PREFIX/include/c++/6.1.0

nick96 commented 5 years ago

I don't know. I think most of the config file stuff is just passed on to clang and a quick google doesn't suggest anything. I did a quick test on my machine and it didn't seem to effect code completion. Does it work for you?