Skip to content

Commit 4f895b5

Browse files
authored
feat: Add clangd integration tests and documentation (#29)
1 parent 1677c8a commit 4f895b5

38 files changed

+1047
-1
lines changed

.github/workflows/go.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,39 @@ jobs:
131131

132132
- name: Run TypeScript integration tests
133133
run: go test ./integrationtests/tests/typescript/...
134+
135+
clangd-integration-tests:
136+
name: Clangd Integration Tests
137+
runs-on: ubuntu-latest
138+
steps:
139+
- uses: actions/checkout@v4
140+
141+
- name: Set up Go
142+
uses: actions/setup-go@v5
143+
with:
144+
go-version: "1.24"
145+
check-latest: true
146+
cache: true
147+
148+
- name: Install LLVM, Clang and bear
149+
run: |
150+
sudo apt-get update
151+
sudo apt-get install -y clang-16 llvm-16 clangd-16 bear
152+
153+
- name: Verify Clangd Installation
154+
run: |
155+
sudo ln -s /usr/bin/clangd-16 /usr/bin/clangd
156+
clangd-16 --version
157+
clangd --version
158+
159+
- name: Create compile commands
160+
run: |
161+
cd integrationtests/workspaces/clangd
162+
bear -- make
163+
cd ../../../..
164+
165+
- name: Run Clangd definition tests
166+
run: go test ./integrationtests/tests/clangd/definition...
167+
168+
- name: Run Clangd diagnostics tests
169+
run: go test ./integrationtests/tests/clangd/diagnostics...

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ mcp-language-server
44
# Test output
55
test-output/
66
*.diff
7+
integrationtests/workspaces/clangd/compile_commands.json
8+
integrationtests/workspaces/clangd/src/*.o
9+
integrationtests/workspaces/clangd/clean_program
10+
integrationtests/workspaces/clangd/program
11+
integrationtests/workspaces/clangd/.cache
12+
713

814
# Temporary files
915
*~

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,37 @@ This is an [MCP](https://modelcontextprotocol.io/introduction) server that runs
124124
</pre>
125125
</div>
126126
</details>
127+
<details>
128+
<summary>C/C++ (clangd)</summary>
129+
<div>
130+
<p><strong>Install clangd</strong>: Download prebuilt binaries from the <a href="https://github.com/clangd/clangd/releases">official LLVM releases page</a> or install via your system's package manager (e.g., <code>apt install clangd</code>, <code>brew install clangd</code>).</p>
131+
<p><strong>Configure your MCP client</strong>: This will be different but similar for each client. For Claude Desktop, add the following to <code>~/Library/Application\\ Support/Claude/claude_desktop_config.json</code></p>
132+
133+
<pre>
134+
{
135+
"mcpServers": {
136+
"language-server": {
137+
"command": "mcp-language-server",
138+
"args": [
139+
"--workspace",
140+
"/Users/you/dev/yourproject/",
141+
"--lsp",
142+
"/path/to/your/clangd_binary",
143+
"--",
144+
"--compile-commands-dir=/path/to/yourproject/build_or_compile_commands_dir"
145+
]
146+
}
147+
}
148+
}
149+
</pre>
150+
<p><strong>Note</strong>:</p>
151+
<ul>
152+
<li>Replace <code>/path/to/your/clangd_binary</code> with the actual path to your clangd executable.</li>
153+
<li><code>--compile-commands-dir</code> should point to the directory containing your <code>compile_commands.json</code> file (e.g., <code>./build</code>, <code>./cmake-build-debug</code>).</li>
154+
<li>Ensure <code>compile_commands.json</code> is generated for your project for clangd to work effectively.</li>
155+
</ul>
156+
</div>
157+
</details>
127158
<details>
128159
<summary>Other</summary>
129160
<div>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
3+
Symbol: TestClass
4+
/TEST_OUTPUT/workspace/clangd/src/consumer.cpp
5+
Range: L7:C1 - L15:C2
6+
7+
7|class TestClass {
8+
8| public:
9+
9| /**
10+
10| * @brief A method that takes an integer parameter.
11+
11| *
12+
12| * @param param The integer parameter to be processed.
13+
13| */
14+
14| void method(int param) { helperFunction(); }
15+
15|};
16+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
3+
Symbol: TEST_CONSTANT
4+
/TEST_OUTPUT/workspace/clangd/src/helper.cpp
5+
Range: L4:C1 - L4:C29
6+
7+
4|const int TEST_CONSTANT = 42;
8+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
3+
Symbol: foo_bar
4+
/TEST_OUTPUT/workspace/src/main.cpp
5+
Range: L5:C1 - L8:C2
6+
7+
5|void foo_bar() {
8+
6| std::cout << "Hello, World!" << std::endl;
9+
7| return;
10+
8|}
11+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
3+
Symbol: helperFunction
4+
/TEST_OUTPUT/workspace/clangd/src/helper.cpp
5+
Range: L7:C1 - L7:C71
6+
7+
7|void helperFunction() { std::cout << "Helper function" << std::endl; }
8+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
3+
Symbol: method
4+
/TEST_OUTPUT/workspace/clangd/src/consumer.cpp
5+
Range: L7:C1 - L15:C2
6+
7+
7|class TestClass {
8+
8| public:
9+
9| /**
10+
10| * @brief A method that takes an integer parameter.
11+
11| *
12+
12| * @param param The integer parameter to be processed.
13+
13| */
14+
14| void method(int param) { helperFunction(); }
15+
15|};
16+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
3+
Symbol: TestStruct
4+
/TEST_OUTPUT/workspace/clangd/src/types.cpp
5+
Range: L6:C1 - L8:C2
6+
7+
6|struct TestStruct {
8+
7| int value;
9+
8|};
10+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
3+
Symbol: TestType
4+
/TEST_OUTPUT/workspace/clangd/src/types.cpp
5+
Range: L10:C1 - L10:C21
6+
7+
10|using TestType = int;
8+

0 commit comments

Comments
 (0)