Files
clice/docs/design/design.md
2024-09-29 21:21:48 +08:00

6.3 KiB

"architectural issue" here actually means the issue which can be solved but need to make a lot of modification to clangd. Currently, such big modification can be hard to push because of lack resource in clangd as mentioned here. I am a university student, also a c++ enthusiast and a vscode user. So I have a lot of time that I can dedicate to things I am interested in.. At first, I just want to wonder whether I can make some efforts to clangd. But gradually, I found it could be better to rewrite a new LSP. After evaluating the project scale, I think it's possible to complete for just one person (about 4w~ lines and ccls is also written by one person). Then I start to dive into clangd source code and learn the clang base. So far, I have known how to build preamble, how to build AST, how to traverse AST and so on. All of them are done with clang's C++ API. Next step is putting them together into final program. However, before the actual implementation, I need to plan out its structure.

At first, how to manage message? LSP is also a type of server, and the common event-driven model is sufficient. I plan to use libuv as the event library, with the main thread handling requests and distributing tasks, while the thread pool executes the actual tasks. This is slightly different from clangd's current model; clangd doesn't use a thread pool, but rather creates a new thread for each file and uses semaphore to limit the number of active threads.

Then we need to handle TU. I decided to use a different policy with clangd, which is not to build the preamble for the file until the first edit, and headers will reuse the AST in the source file by default, also until first edit. In this way, we can reduce a lot of memory usage, speed up the loading (building preamble always needs more time compared to normal AST building) and support non self contained header. This can be very useful, people actually only need to modify a few files in big projects like LLVM. And today I found Sam also reported this issue. Another important problem is how to interact with C++20 modules, I am still exploring this.

Next is about indexing, current indexer in clangd seems to be efficient enough, so I think I would reuse it and make only some small modifications to record more information. Also, I am wondering whether we can modify the absolute path to relative path in the index, so issue like support offline background index preparation。It shouldn't be hard to implement.

Following is discussion on some specific LSP features:

Semantic Highlight

There are several issues around it.

Mainly about wrong or not enough information in the semantic highlight. I would like to support detail information for each token, then we can solve all of them.

Hint

Most of these problems are about hint. Providing options to allow users to configure them will be fine.

Action

Providing more actions will be helpful.

Code Completion

These issues around code completion could be hardest to resolve. We need to modify the Parser and SemaComplete in clang to support them. Some are about templates, improving HeuristicResolver will resolve them.