From 658c33a01faabb1065b71b2e2c9035f835501fc3 Mon Sep 17 00:00:00 2001 From: Myriad-Dreamin <35292584+Myriad-Dreamin@users.noreply.github.com> Date: Sat, 6 Sep 2025 16:23:20 +0800 Subject: [PATCH] Init clang tidy (#195) --- docs/clice.toml | 4 ++++ include/Server/Config.h | 1 + src/Server/Document.cpp | 6 +++++ tests/data/clang_tidy/clice.toml | 6 +++++ tests/data/clang_tidy/main.cpp | 6 +++++ tests/integration/test_file_operation.py | 28 +++++++++++++++++++----- 6 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 tests/data/clang_tidy/clice.toml create mode 100644 tests/data/clang_tidy/main.cpp diff --git a/docs/clice.toml b/docs/clice.toml index 08f58a91..f01d364b 100644 --- a/docs/clice.toml +++ b/docs/clice.toml @@ -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. diff --git a/include/Server/Config.h b/include/Server/Config.h index 5ad9068b..63b22f6d 100644 --- a/include/Server/Config.h +++ b/include/Server/Config.h @@ -17,6 +17,7 @@ void init(std::string_view workplace); struct ServerOptions { std::vector compile_commands_dirs = {"${workspace}/build"}; + bool clang_tidy = false; size_t max_active_file = 8; }; diff --git a/src/Server/Document.cpp b/src/Server/Document.cpp index b0821e23..edf36c41 100644 --- a/src/Server/Document.cpp +++ b/src/Server/Document.cpp @@ -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); }); diff --git a/tests/data/clang_tidy/clice.toml b/tests/data/clang_tidy/clice.toml new file mode 100644 index 00000000..bbb49939 --- /dev/null +++ b/tests/data/clang_tidy/clice.toml @@ -0,0 +1,6 @@ +### clice configuration + +[server] + + # Enable clang-tidy diagnostics. + clang_tidy = true diff --git a/tests/data/clang_tidy/main.cpp b/tests/data/clang_tidy/main.cpp new file mode 100644 index 00000000..ff682901 --- /dev/null +++ b/tests/data/clang_tidy/main.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + std::cout << "Hello World!" << std::endl; + return 0; +} diff --git a/tests/integration/test_file_operation.py b/tests/integration/test_file_operation.py index 1f25d85e..4b5bc65f 100644 --- a/tests/integration/test_file_operation.py +++ b/tests/integration/test_file_operation.py @@ -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()