Init clang tidy (#195)

This commit is contained in:
Myriad-Dreamin
2025-09-06 16:23:20 +08:00
committed by GitHub
parent 0d56dbf192
commit 658c33a01f
6 changed files with 45 additions and 6 deletions

View File

@@ -13,6 +13,10 @@
# Compile commands directories to search for compile_commands.json files.
compile_commands_dirs = ["${workspace}/build"]
# Enable experimental clang-tidy diagnostics.
# This feature is tracked in https://github.com/clice-project/clice/issues/90.
clang_tidy = false
# Maximum number of active files to keep in memory. If the number of active files
# exceeds this limit, the least recently used files will be removed.
# The default value is 8. Whatever the number you set, the minimum is 1, the maximum is 512.

View File

@@ -17,6 +17,7 @@ void init(std::string_view workplace);
struct ServerOptions {
std::vector<std::string> compile_commands_dirs = {"${workspace}/build"};
bool clang_tidy = false;
size_t max_active_file = 8;
};

View File

@@ -325,6 +325,12 @@ async::Task<> Server::build_ast(std::string path, std::string content) {
co_return;
}
/// Run Clang-Tidy
if(config::server.clang_tidy) {
log::warn(
"clang-tidy is not fully supported yet. Tracked in https://github.com/clice-project/clice/issues/90.");
}
/// Send diagnostics
auto diagnostics = co_await async::submit(
[&, kind = this->kind] { return feature::diagnostics(kind, mapping, *ast); });

View File

@@ -0,0 +1,6 @@
### clice configuration
[server]
# Enable clang-tidy diagnostics.
clang_tidy = true

View File

@@ -0,0 +1,6 @@
#include <iostream>
int main() {
std::cout << "Hello World!" << std::endl;
return 0;
}

View File

@@ -7,9 +7,7 @@ from ..fixtures.client import LSPClient
@pytest.mark.asyncio
async def test_did_open(executable, test_data_dir, resource_dir):
client = LSPClient([
executable, "--mode=pipe", f"--resource-dir={resource_dir}"
])
client = LSPClient([executable, "--mode=pipe", f"--resource-dir={resource_dir}"])
await client.start()
await client.initialize(test_data_dir / "hello_world")
@@ -21,9 +19,7 @@ async def test_did_open(executable, test_data_dir, resource_dir):
@pytest.mark.asyncio
async def test_did_change(executable, test_data_dir, resource_dir):
client = LSPClient([
executable, "--mode=pipe", f"--resource-dir={resource_dir}"
])
client = LSPClient([executable, "--mode=pipe", f"--resource-dir={resource_dir}"])
await client.start()
await client.initialize(test_data_dir / "hello_world")
@@ -40,3 +36,23 @@ async def test_did_change(executable, test_data_dir, resource_dir):
await asyncio.sleep(5)
logging.info("Send exit")
await client.exit()
@pytest.mark.asyncio
async def test_clang_tidy(executable, test_data_dir, resource_dir):
config_path = test_data_dir / "clang_tidy" / "clice.toml"
client = LSPClient(
[
executable,
"--mode=pipe",
f"--resource-dir={resource_dir}",
f"--config={config_path}",
]
)
await client.start()
await client.initialize(test_data_dir / "clang_tidy")
await client.did_open("main.cpp")
await asyncio.sleep(5)
await client.exit()