emacs-lsp / emacs-ccls

Emacs client for ccls, a C/C++ language server
200 stars 29 forks source link

Help with .ccls file config: Header file correctly parsed but "file not found" error appears. #97

Open grivasgervilla opened 4 years ago

grivasgervilla commented 4 years ago

Hi everyone, I have recently configured my Doom Emacs to use ccls as my C++ server for LSP. The completion seems to work perfectly. However, in every single cpp file where I make an #include of some of my own hpp files, I got the error "file not found", and I do not know how to setup my .ccls file in my project root, so these files are found.

System Specs

Project Structure

.
├── .ccls
├── .dir-locals.el
├── .gitignore
├── include
│   ├── constants.hpp
│   ├── Context.hpp
│   ├── Graph.hpp
│   ├── Lattice.hpp
│   └── utilities.hpp
├── Makefile
├── README.md
└── src
    ├── Context.cpp
    ├── experimentation.cpp
    ├── Graph.cpp
    ├── Lattice.cpp
    ├── main.cpp
    ├── parallelism.cpp
    └── utilities.cpp

Files

I think that the following files of my project would be enough to reproduce my error. I pick the include/Context.hpp and src/Context.cpp files because the cpp file only include this hpp file from my project:

/**
* @file constants.hpp
* @author griger
*/

#ifndef __CONSTANTS__
#define __CONSTANTS__

const int TMAX = 10000;

#endif
/**
 * @file Context.hpp
 * @author griger
 * */

#include <bitset>
#include <iostream>
#include <vector>
#include <map>

#include "constants.hpp"

using namespace std;

#ifndef __CONTEXT__
#define __CONTEXT__

class Context {
        private:
                size_t nObj, nProp;
                map<int, bitset<TMAX>> Intents;
                vector<vector<bool>> table;

        public:
                Context();

                Context(vector<vector<bool>> data);

                size_t getNObjects() const {return nObj;}

                size_t getNProperties() const {return nProp;}

                bitset<TMAX>& operator[](int objID) {return Intents[objID];}
                const bitset<TMAX>& operator[](int objID) const {return Intents.at(objID);}
};

ostream& operator<<(ostream& os, Context& c);

#endif
/**
 * @file Context.cpp
 * @author griger
 * */
#include <math.h>

#include "Context.hpp"

Context::Context(){
    nObj = nProp = 0;
}

Context::Context(vector<vector<bool>> data){
    table = data;
    nObj = data.size();
    nProp = data.at(0).size();

    int objID = 0;
    for (const auto& row : data){
        Intents[objID] = bitset<TMAX>();
        int propID = 0;

        for (bool col : row){
            if (col)
                Intents[objID].set(propID);

            propID++;
        }

        objID++;
    }       
 }

ostream& operator<<(ostream& os, Context& c){
    for (size_t objID = 0; objID < c.getNObjects(); objID++)
        cout << "Objeto " << objID << " Propiedades: " << c[objID] << endl;

    return os;    
}

.ccls

I have also tried -std=c++17 flag, but the same error occurs.

clang
%cpp %hpp -std=c++2a
%cpp %hpp -Iinclude
-Iinclude

Error

prueba

As you can see a "File not found" error appears. However, there is no error about Context not being defined or something like that. In fact, the autocompletion for the Context instances methods works fine.

I have read in some similar issues for this repo or the ccls repo, that flycheck may have something to do with this problem. But I have tried to disable flycheck, but then other proper errors are not being highlighted...

Many thanks for your time :smile:.