## Summary - Wire up the existing `document_format` feature to LSP via stateless workers - Add `Format` kind to stateless worker dispatch, with a lightweight `forward_format` path in `Compiler` (no compilation/deps needed — just file path + content) - Register `textDocument/formatting` and `textDocument/rangeFormatting` handlers with `scoped_pause` - Style lookup uses `clang::format::getStyle` which walks parent directories for `.clang-format`, matching clangd's behavior ## Test plan - [x] 4 unit tests: simple format, range format, idempotent (no edits), include sort - [x] 3 integration tests: full document format (verifies applied edits match expected output), range format, already-formatted no-op - [x] Capability assertions added to `test_capabilities` - [x] All existing tests pass (554 unit, 170 integration, 2 smoke) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Added document formatting and range formatting capabilities to the LSP server * Formatting can target the entire document or a specific range of code * Server now advertises formatting support to LSP clients * **Tests** * Added comprehensive test coverage for formatting functionality <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
#include "test/test.h"
|
|
#include "feature/feature.h"
|
|
|
|
namespace clice::testing {
|
|
|
|
namespace {
|
|
|
|
TEST_SUITE(Formatting) {
|
|
|
|
TEST_CASE(Simple) {
|
|
auto edits = feature::document_format("main.cpp", "int main() { return 0; }", std::nullopt);
|
|
ASSERT_NE(edits.size(), 0U);
|
|
}
|
|
|
|
TEST_CASE(RangeFormat) {
|
|
llvm::StringRef code = "int x=1;\nint y = 2 ;\nint z=3;\n";
|
|
LocalSourceRange range;
|
|
range.begin = static_cast<std::uint32_t>(code.find("int y"));
|
|
range.end = static_cast<std::uint32_t>(code.find("\nint z") + 1);
|
|
auto range_edits = feature::document_format("main.cpp", code, range);
|
|
auto full_edits = feature::document_format("main.cpp", code, std::nullopt);
|
|
ASSERT_NE(range_edits.size(), 0U);
|
|
EXPECT_LE(range_edits.size(), full_edits.size());
|
|
}
|
|
|
|
TEST_CASE(Idempotent) {
|
|
llvm::StringRef code = "int main() {\n return 0;\n}\n";
|
|
auto edits = feature::document_format("main.cpp", code, std::nullopt);
|
|
EXPECT_EQ(edits.size(), 0U);
|
|
}
|
|
|
|
TEST_CASE(IncludeSort) {
|
|
llvm::StringRef code = "#include <vector>\n#include <algorithm>\n\nint main() {}\n";
|
|
auto edits = feature::document_format("main.cpp", code, std::nullopt);
|
|
ASSERT_NE(edits.size(), 0U);
|
|
}
|
|
|
|
}; // TEST_SUITE(Formatting)
|
|
|
|
} // namespace
|
|
|
|
} // namespace clice::testing
|