DEV Community

Harry Tanama
Harry Tanama

Posted on

LSP Server and Clangd Face Challenges Dealing With Very Large Codebases

When you want to jump to function definition in Linux, you need to use Ctags or Cscope. Or you can use LSP server and clangd to jump to function definition in Linux when you are programming with C or C++.

Apparently LSP server and clangd face challenges and its limitation when it comes to managing source code navigation to jump into function definition because of large codebase, LSP server and clangd cannot read millions of lines of code inside the compile_commands.json file itself.

In large projects with millions of lines of code, the compile_commands.json file itself can become huge. clangd has to parse this and then index the entire codebase in the background. This can be memory-intensive and time-consuming.

LSP servers like clangd can struggle with "jump to definition" due to a number of factors, with the primary one being the difficulty in correctly and efficiently indexing a massive codebase, even with the help of BEAR (Bear is a tool that generates a compilation database for clang tooling). When clangd fails, my best approach is to use a more simpler tool like Ctags or Cscope.

ctags generates a tags file that allows you to quickly jump to definitions. It's a simple, low-overhead solution that works on almost any codebase. I love using ctags (Universal Ctags).

cscope is more powerful than ctags, it can perform cross-reference searches (e.g., finding all functions that call a specific function). It's an excellent choice for navigating complex codebases where understanding dependencies is key.

I can combine both ctags and cscope for source code navigation system in a large codebase project for example I am using them when compiling Godot Game Engine from the source code and enable debugging code when compiling Godot with Scons.

I am able to use cscope and ctags to navigate Godot's source code using these to navigate with jump to definition or jump to declaration.

Top comments (0)