3

I am trying to set up LSP with vim + cmake. I am using vim-lsc plugin as client and clangd as the server.

Folder structure:

  • Test/
  • test.cpp
  • test.h
  • CMakeLists.txt

test.h:

#ifndef TEST_H
#define TEST_H

class Apple {
  public:
    int size;
};

#endif

test.cpp:

#include <iostream>
#include "test.h"

int main() {
    Apple apple;

    return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(my_test)
add_executable(test test.cpp)
target_include_directories(test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

~/.vimrc:

let g:lsc_server_commands = {'c': 'clangd', 'cpp': 'clangd'}

I build with

mkdir build
cd build
cmake ..
make

This compiles fine with no errors and warnings.

However, while editing test.cpp in vim, vim-lsc shows errors not detecting user defined header files and types defined within them. For example, in the above project, the following two errors are shown:

test.cpp|3 col 10 error| 'test.h' file not found [pp_file_not_found]
test.cpp|6 col 5 error| Unknown type name 'Apple' [unknown_typename]

How do I set this up so that headers in the project are identified properly?

EDIT: The problem has changed somewhat. I added a compile_commands.json file to the top level directory to no avail. I suspect that it has to do with the way paths are represented in Git Bash on windows.

The compile_commands.json has the inlcude paths like so:

-IE:\\C:\\Test

If the class is defined in the same file, the lsp protocol seems to be working. Can clang not work with such paths? Could someone shed some light on this?

learning2code
  • 460
  • 4
  • 9

0 Answers0