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+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
3+
Symbol: TEST_VARIABLE
4+
/TEST_OUTPUT/workspace/clangd/src/helper.cpp
5+
Range: L5:C1 - L5:C24
6+
7+
5|int TEST_VARIABLE = 100; // A test variable used for integration testing purposes.
8+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/TEST_OUTPUT/workspace/src/clean.cpp
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/TEST_OUTPUT/workspace/src/main.cpp
2+
Diagnostics in File: 1
3+
WARNING at L14:C3: Code will never be executed (Source: clang, Code: -Wunreachable-code)
4+
5+
10|int main() {
6+
...
7+
12| return 0;
8+
13|
9+
14| foo_bar();
10+
15|
11+
16| // Intentional error: unreachable code
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
instance-method method
2+
3+
void
4+
Parameters:
5+
- int param
6+
@brief A method that takes an integer parameter.
7+
@param param The integer parameter to be processed.
8+
9+
// In TestClass
10+
public: void method(int param)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class TestClass
2+
3+
Size: 1 byte
4+
5+
class TestClass {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function helperFunction
2+
3+
→ void
4+
5+
void helperFunction()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function foo_bar
2+
3+
→ void
4+
FooBar is a simple function for testing
5+
6+
void foo_bar()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
No hover information available for this position on the following line:
2+
// FooBar is a simple function for testing
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No hover information available for this position on the following line:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
variable TEST_VARIABLE
2+
3+
Type: int
4+
Value = 100 (0x64)
5+
A test variable used for integration testing purposes.
6+
7+
int TEST_VARIABLE = 100
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
3+
/TEST_OUTPUT/workspace/clangd/src/main.cpp
4+
References in File: 1
5+
At: L14:C3
6+
7+
10|int main() {
8+
11| helperFunction();
9+
12| return 0;
10+
13|
11+
14| foo_bar();
12+
15|
13+
16| // Intentional error: unreachable code
14+
17| std::cout << "This is unreachable" << std::endl;
15+
18|}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
3+
/TEST_OUTPUT/workspace/clangd/src/consumer.cpp
4+
References in File: 1
5+
At: L14:C28
6+
7+
9| /**
8+
10| * @brief A method that takes an integer parameter.
9+
11| *
10+
12| * @param param The integer parameter to be processed.
11+
13| */
12+
14| void method(int param) { helperFunction(); }
13+
15|};
14+
15+
---
16+
17+
/TEST_OUTPUT/workspace/clangd/src/main.cpp
18+
References in File: 1
19+
At: L11:C3
20+
21+
6| std::cout << "Hello, World!" << std::endl;
22+
7| return;
23+
8|}
24+
9|
25+
10|int main() {
26+
11| helperFunction();
27+
12| return 0;
28+
13|
29+
14| foo_bar();
30+
15|
31+
16| // Intentional error: unreachable code
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
\
2+
# Clangd Integration Tests
3+
4+
This directory contains integration tests for `clangd`, the C/C++ language server.
5+
6+
## Prerequisites
7+
8+
Before running these tests, you must generate the `compile_commands.json` file in the `integrationtests/workspaces/clangd` directory. This can typically be done by navigating to that directory and running a tool like `bear` with your build command (e.g., `bear -- make`).
9+
10+
The GitHub Actions workflow for these tests uses the following command from the root of the repository:
11+
```bash
12+
cd integrationtests/workspaces/clangd
13+
bear -- make
14+
cd ../../../..
15+
```
16+
17+
## Clangd Version
18+
19+
These tests are currently run against **clangd version 16**. While they may pass with other versions of clangd, compatibility is not guaranteed.

0 commit comments

Comments
 (0)