[PR #11579] fix(lsp): Improve LSP for c/c++ project. #13846

Open
opened 2026-02-16 18:18:40 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11579

State: open
Merged: No


What does this PR do?

Fixes #11617 #9521

LSP server of clangd was started with incorrect working directory and arguments.

clangd should run in root project directory and it will find .clangd and compile_flags.txt automatically.

Directory of compile_commands.json should be passed to clangd as argument in case that it is not in the up directories of active file. It is quite normal when project is built out of source tree.

Todo:
In this patch, we try to find compile_commands.json in the first level sub directories of root project and root project itself. In case of opencode is running on the subdirectory of git repository, it first search current working directory and then top directory of git repository.

If multiply build directories exist, or it is not in above location, it will fail to find or choose one which is not expected. It would be better to find a way to detect working directory more AI way. #7780

If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!

How did you verify your code works?

Test cases added to cover above chagnes.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11579 **State:** open **Merged:** No --- ### What does this PR do? Fixes #11617 #9521 LSP server of clangd was started with incorrect working directory and arguments. clangd should run in root project directory and it will find `.clangd` and `compile_flags.txt` automatically. Directory of `compile_commands.json` should be passed to clangd as argument in case that it is not in the up directories of active file. It is quite normal when project is built out of source tree. Todo: In this patch, we try to find `compile_commands.json` in the first level sub directories of root project and root project itself. In case of opencode is running on the subdirectory of git repository, it first search current working directory and then top directory of git repository. If multiply build directories exist, or it is not in above location, it will fail to find or choose one which is not expected. It would be better to find a way to detect working directory more AI way. #7780 **If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!** ### How did you verify your code works? Test cases added to cover above chagnes.
yindo added the pull-request label 2026-02-16 18:18:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13846