MaskRay / ccls

C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting
Apache License 2.0
3.72k stars 254 forks source link

Autocompletion does not work in *.H files while works in *.C file #922

Open pBlasiak opened 1 year ago

pBlasiak commented 1 year ago

Observed behavior

I am using OpenFOAM C++ library. I followed these instructions https://openfoamwiki.net/index.php/HowTo_Use_OpenFOAM_with_Visual_Studio_Code After the running the vscode-settings I have the following setting.json file: ` { "[cpp]": { "editor.wordBasedSuggestions": true, "editor.suggest.insertMode": "replace", "editor.semanticHighlighting.enabled": true }, "ccls.cache.directory": "/home/przemek/OpenFOAM/OpenFOAM-v2106/build/linux64GccDPInt64Opt/ccls-cache",

"ccls.misc.compilationDatabaseDirectory":
"/home/przemek/OpenFOAM/OpenFOAM-v2106/build/linux64GccDPInt64Opt",

"C_Cpp.default.compileCommands":
"/home/przemek/OpenFOAM/OpenFOAM-v2106/etc/openfoam wmake -with-bear -s -j",

"C_Cpp.autocomplete": "Disabled",
"C_Cpp.errorSquiggles": "Disabled",
"C_Cpp.formatting": "Disabled",
"C_Cpp.intelliSenseEngine": "Disabled",
"files.associations": {
    "*.H": "cpp",
    "*.C": "cpp",
 }

}

`

When I open folder with my project in VSC evry file is recognized by the ccls. In the main file with .C extension autocompletion of methods after writing "object." works very well. However, in the .H files it does not see anything.

Expected behavior

Autocompletion in header files (*.H) works.

Steps to reproduce

I think it is general issue and no reproduce steps are necessary. The question is how to enable autocompletion in *.H files. I have tried to use .ccls file with such settings but it does not work: %h -x %h c++-header

System information

PandaTinker commented 1 year ago

I am having a similar issue. My problem is best described in the issue from another cpp extension here: https://github.com/microsoft/vscode-cpptools/issues/4662 The RCA seems to be that vscode does not automatically trigger completions for macro definitions. But the extension does not support manual completion either.

pBlasiak commented 1 year ago

I think in macros it is more difficult situation. OpenFOAM has specific H files. Sometimes they are typical h file as a class header, sometimes it contains frequently used code, sometimes just includes other H files. The question is if it would be typical h file or hpp, does ccls supports autocompletion in such files? Is it possible to add this feature to H files?

DuckyShine004 commented 7 months ago

Hi, try removing the key-pair value, "ccls.cache.directory". This is because for some bizarre reason, ccls will index the header files inside of the cache directory, instead of the header files inside of the includes (or wherever you put your header files) directory.