socketsupply / socket

A cross-platform runtime for Web developers to build desktop & mobile apps for any OS using any frontend library.
https://socketsupply.co/guides
Other
1.63k stars 78 forks source link

[Guide] C++ language server for local development in VS Code #651

Open aleclarson opened 1 year ago

aleclarson commented 1 year ago

There's probably a better place for this, but I'll put it here so anyone who is looking can find it.

Note: Android, Windows, and Linux targets have not been added yet.

1. Download the CMakeLists.txt file

wget -O src/CMakeLists.txt https://gist.github.com/aleclarson/361ccb9aaf7540d91630b42e0ae580de/raw/CMakeLists.txt

2. Install compdb

This lets us generate a compile_commands.json file that contains header files, which are missing from the cmake output.

pip install compdb

2. Run cmake and compdb

cd src
cmake -S . -B ../build
compdb -p ../build list > compile_commands.json

After running this, the src/compile_commands.json file should have been generated, which the Clangd language server needs for finding header files and other validation stuff.

3. VS Code extensions

I use VS Code, so I can only help with getting that set up.

In most cases, you'll only need the clangd language server extension. It should work out of the box.

If you plan to add to the CMakeLists.txt file you downloaded earlier, you'll want the CMake extension for syntax highlighting and cmake-format for automatic formatting.

lamiazar commented 1 year ago

These steps will be added to the repo wiki https://discord.com/channels/775715380089716778/1092667624237846528/1163515772744773823 cc @chicoxyzzy