-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ccls c++ header completion on osx #191
Comments
I try the ccls installed by "brew install --HEAD ccls" and build ccls from source code(master), same problem happened. |
By "solutions in wiki didn't work" do you mean, you verified that the clang resource directory is available and in the correct place based on the log output? Also I should point out that your compile_commands.json is not being used here. If the .ccls file exists then it will be used and compile_commands.json will not be used. You can use both, but to do so you need to (a) remove the %clang from your .ccls file and (b) add %compile_commands.json to your .ccls file. Note this likely won't work with the homebrew version (I have no idea how old it is but this feature is just weeks old). More info is available in https://github.com/madscientist/ccls/wiki/Customization#ccls-file and https://github.com/madscientist/ccls/wiki/Project-Setup (I reworked the wiki but @MaskRay is taking a well-earned break: he pulled some but not all of my changes so there are broken links in his version of the wiki--I'm sure he'll resolve this quickly once he's back online). I don't really understand why you're hardcoding a path to /usr/local in your CMakeLists.txt if you're using clang (the default compiler) on MacOS but I don't know much about either one so maybe it's needed. |
Thanks to @madscientist !
When the line is https://github.com/maskray/ccls/blob/master/src/messages/textDocument_completion.cc#L476
CCOpts.IncludeCodePatterns = StringRef(buffer_line).ltrim().startswith("#"); You'll get a list of filenames (what you might expect) if the line is If you use company-lsp, there is an option
GCC 6/Clang 6 default to
#125 is irrelevant to ccls (completion feature missing in the client) #160 is related. Have you read #160 (comment) ? I don't have a Mac OS X to verify, but can you set
|
I now use the ccls build from source using the command "cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DSYSTEM_CLANG=ON -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm" |
@MaskRay I try #include <, but still got nothing. I notice that the command "clang++ -fsyntax-only -v -xc++ /dev/null -stdlib=libc++" output is Is it correct? |
I don't use Mac OS X so I'm not sure. libc++ search directory looks like On Linux, clang is typically installed at Can you print some variables related to |
Does ccls support clang 10.0.0? When I build ccls using command "cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DSYSTEM_CLANG=ON" , the cmake report error: I explored the directory of "/Library/Developer/CommandLineTools/usr", the include directory have "FlexLexer.h c++ swift", while in clang+llvm 7.0.0 the include directory contains "c++ clang clang-c lld llvm llvm-c polly". And the lib directory in /Library/Developer/CommandLineTools/usr(maybe the clang 10.0.0 root directory) and the clang+llvm 7.0.0 is very different. |
I modified the source code of ccls as #160 and rebuild ccls. But nothing is output, no file is generated in the path I used to initilized fstream f, why? |
Take a look at https://en.wikipedia.org/wiki/Xcode#Latest_versions and https://trac.macports.org/wiki/XcodeVersionInfo Your llvm version is BTW, does c header file work and what's your |
I have tried use the llvm 7.0.0 downloaded by CMake but problem still happened. |
I use cquery for the lsp-backend and things work well. |
The next major release of clang+llvm (8.0) will support builtin header file completion. There are two header completion backends in ccls:
Can you check the value of the macro
It is not compatible. I'm very confused as you use both 7.0.0 and 10.0.0 . For
Did you mean Can you dump the values of |
Yes, it will download and extract clang+llvm7.0 to the Release directory. Config/llvm-config.h CMakeCache.txt CMakeCache.txt |
@FirstLoveLife |
@DL-85 Hi, I have the same problem with you. Finally I found a solution which cost me almost one day. Environment :
Final solution:
The position could be near the CommandLineTools, maybe it is in Xcode.app (
some tips here:
In my case, the root cause is My debug steps: I add insert some code in HeaderOpts.AddPath("/Users/leadroyal/pllvm/r/include/c++/v1/", clang::frontend::IncludeDirGroup::System, false, false); or HeaderOpts.AddPath("/Library/Developer/CommandLineTools/usr/include/c++/v1", clang::frontend::IncludeDirGroup::System, false, false); Then compile ccls, clean cache, restart software. Both of the modifications is effective. |
I use ArchLinux and it cant complete header file too but when I switch to OS: test in docker container, using My coc.nvim config showen as below: "ccls": {
"command": "ccls",
"filetypes": ["c", "cpp", "cuda", "objc", "objcpp"],
"rootPatterns": [".ccls", "compile_commands.json", ".vim/", ".git/", ".hg/"],
"trace.server": "verbose",
"initializationOptions": {
"cacheDirectory": "/tmp/ccls"
}
}, are there any possible to recur this problem or need any more details? |
This was always an issue with clang < 8 on Mac OS X. The work around is to pass It was actually a clangDriver issue (fixed in clang 8), but the ccls 0.20181225.* release was also at fault (the "Extend .ccls ..." commit ( To make header completion work with clang < 8 on Mac OS X, use a shell script wrapper: #!/bin/sh
exec /path/to/ccls/Release/ccls -init='{"clang":{"extraArgs":["-isystem", "/Library/Developer/CommandLineTools/usr/include/c++/v1"]}}' "$@" When clang < 8 (I use clang trunk personally so this configuration gets less testing), the header completion backends is Before rC348365 (will be included in clang 8 but not in clang 7) the libc++ directory ( rC348365
--- a/lib/Frontend/InitHeaderSearch.cpp
+++ b/lib/Frontend/InitHeaderSearch.cpp
@@ -476,22 +476,6 @@ void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
if (Lang.CPlusPlus && !Lang.AsmPreprocessor &&
HSOpts.UseStandardCXXIncludes && HSOpts.UseStandardSystemIncludes) {
if (HSOpts.UseLibcxx) {
- if (triple.isOSDarwin()) {
- // On Darwin, libc++ may be installed alongside the compiler in
- // include/c++/v1.
- if (!HSOpts.ResourceDir.empty()) {
- // Remove version from foo/lib/clang/version
- StringRef NoVer = llvm::sys::path::parent_path(HSOpts.ResourceDir);
- // Remove clang from foo/lib/clang
- StringRef Lib = llvm::sys::path::parent_path(NoVer);
- // Remove lib from foo/lib
- SmallString<128> P = llvm::sys::path::parent_path(Lib);
-
- // Get foo/include/c++/v1
- llvm::sys::path::append(P, "include", "c++", "v1");
- AddUnmappedPath(P, CXXSystem, false);
- }
- } Thanks to @LeadroyaL for letting me explore his environment. Recorded here for future reference:
|
If I understand correctly, the above implies that the workaround cc: @MaskRay |
(randyimac)-~$ clang -print-resource-dir
/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0
(randyimac)-~$ clang -v -fsyntax-only -x c++ /dev/null
Apple clang version 11.0.0 (clang-1100.0.33.8)
Target: x86_64-apple-darwin19.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
"/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -fsyntax-only -disable-free -disable-llvm-verifier -discard-value-names -main-file-name null -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 512.4 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/11.0.0 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1 -Wno-framework-include-private-from-public -Wno-atimport-in-framework-header -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdeprecated-macro -fdebug-compilation-dir /Users/Randy -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.15.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -x c++ /dev/null
clang -cc1 version 11.0.0 (clang-1100.0.33.8) default target x86_64-apple-darwin19.0.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include
/Library/Developer/CommandLineTools/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list. |
@randy3k I have encountered the same issue (also Catalina), Also got the exact same result from So do you specify this in a Also do we need to specify this for every project root? Any nicer to way to work around? thanks! |
I didn't use
as initialization option. Check https://github.com/MaskRay/ccls/wiki/Customization#initialization-options
|
@randy3k I've tried the following and doesn't solve the issue
Any idea why? |
Did you install the CommandLineTools at the first place? |
yes I did, I saw all the necessary header files at those two paths already, |
I didn't pass the settings to ccls via |
@randy3k thanks for your reply, I have resolve my issue, for future reference, I use emacs, thus the following config:
(after! ccls
(setq ccls-initialization-options
'(:clang (:extraArgs ["-isystem/Library/Developer/CommandLineTools/usr/include/c++/v1"
"-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
"-isystem/usr/local/include"
"-isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include"
"-isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include"
"-isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include"
"-isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"]
:resourceDir "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0")))
)
🥂 |
I'm glad that you've figured it out. I know how frustrated it could be. |
The header completion does not work on my Mac. My
I am on Please help. |
@alxiong thanks for your comment, it works. I am using neovim with coc.nvim on macOS Catalina, here is my {
"languageserver": {
"ccls": {
"command": "ccls",
"filetypes": ["c", "cpp", "objc", "objcpp"],
"rootPatterns": [".ccls", "compile_commands.json", ".vim/", ".git/", ".hg/"],
"initializationOptions": {
"cache": {
"directory": "/tmp/ccls"
},
// see https://github.com/MaskRay/ccls/issues/191
"clang": {
// from clang -v -fsyntax-only -x c++ /dev/null
"extraArgs": [
"-isystem/usr/local/include",
"-isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1",
"-isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include",
"-isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
"-isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
"-isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
//From clang -print-resource-dir
"resourceDir": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0"
}
}
}
}
} |
@phphong EDIT: Resolved! I just had to configure vim ALE to use CCLS, all is well now :) I tried to follow your recommendations and headers now autocomplete just fine. But for some reason vim is complaining about not being able to find header files... Here are the results of the commands you described:
So from this output, I set my CocConfig to the following:
Any ideas? |
maybe you can try {
"clang": {
"extraArgs": [
"-isystem",
"/usr/local/opt/llvm/include/c++/v1",
],
"resourceDir": "/usr/local/opt/llvm/lib/clang/9.0.1"
},
} |
hey, could u pls post your vim ale ccls configurations here? |
Sure! Here's the relevant part of my vimcrc on my dotfiles rep: https://github.com/neiljohari/dotfiles/blob/2770fb1a211141ecbdf30b7c5f89603ab440b774/vimrc.local#L91 |
mark same issue |
edit: resolved by workaround in #622 (comment) (hopefully we can find a more reasonable solution though!) Somehow, this issue has randomly come back up. I've been investigating for a bit now, very surprised. The output of Any ideas on debugging this? The only changes have been brew upgrades, which I'm not sure but maybe node and npm had version changes? They still fit the requirements, and I think they are linked into my path so CCLS should be able to find it. Very strange issue to randomly appear. I'll post findings here:
|
Same issue occurs for me as well. Frustrating. |
@krishnakumarg1984 have you tried those solutions above? It works for me |
Oh god! Finally, that works!!!!!! thx |
OS: macOS Mojave 10.14.2
emacs: 26.1
Spacemacs: develop
Problem: header file can't be completed correctly
And ccls reported error on string and vector even if the correct header file is included
.ccls content:
%clang
-Wall
%c -std=gnu11
%cpp -std=c++11
%cpp -stdlib=libc++
CMakeLists.txt:
cmake_minimum_required(VERSION 3.13)
project(test_ccls)
set(CMAKE_CXX_STANDARD 11)
include_directories(/usr/local/Cellar/llvm/7.0.0_1/include/c++/v1)
add_executable(test_ccls main.cpp)
I have generated and linked the compile_commands.json file.
Solutions mentioned in #125 and #160 seem not work here.
Solutions in wiki https://github.com/MaskRay/ccls/wiki/FAQ#some-cc-headers-are-not-recognized also don't work.
The text was updated successfully, but these errors were encountered: