Skip to content

Commit e8c4b03

Browse files
Fix selection tree, add some unit tests (#154)
Co-authored-by: ykiko <ykikoykikoykiko@gmail.com>
1 parent 741f70a commit e8c4b03

File tree

14 files changed

+203
-55
lines changed

14 files changed

+203
-55
lines changed

.github/workflows/check-format.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: format
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
check:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Install clang-format
17+
run: |
18+
wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/llvm.asc
19+
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-20 main" | sudo tee /etc/apt/sources.list.d/llvm20.list
20+
echo "deb-src http://apt.llvm.org/noble/ llvm-toolchain-noble-20 main" | sudo tee -a /etc/apt/sources.list.d/llvm20.list
21+
sudo apt-get update && sudo apt-get install -y clang-format-20
22+
clang-format-20 --version
23+
24+
- name: Run clang-format check
25+
run: |
26+
FILES=$(find ./ -type f | grep -P '^\.\/(src|include)(\/[^\/]+)*\/[^\/]+\.(h|cpp|cc)$')
27+
28+
UNFORMATTED=$(clang-format-20 --dry-run --Werror $FILES)
29+
30+
if [ $? -ne 0 ]; then
31+
echo "× Some files are not properly formatted. Run clang-format to fix them."
32+
exit 1
33+
else
34+
echo "✓ All files are properly formatted."
35+
fi

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
files: '^(src|include)(/[^/]+)*/[^/]+\.(h|cpp)$'
1+
files: '^(src|include)(/[^/]+)*/[^/]+\.(h|cpp|cc)$'
22
repos:
33
- repo: https://github.com/pre-commit/mirrors-clang-format
44
rev: "v20.1.0"

include/AST/SourceCode.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ struct LocalSourceRange {
2828
}
2929
};
3030

31-
3231
/// Get the content of the file with the given file ID.
3332
llvm::StringRef getFileContent(const clang::SourceManager& SM, clang::FileID fid);
3433

include/Async/Task.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ class Task {
290290
promise_base* handle = core;
291291
while(handle) {
292292
clice::println("{}:{}:{}",
293-
handle->location.file_name(),
294-
handle->location.line(),
295-
handle->location.function_name());
293+
handle->location.file_name(),
294+
handle->location.line(),
295+
handle->location.function_name());
296296
handle = handle->continuation;
297297
}
298298
}

include/Async/libuv.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ T* uv_cast(U& u) {
5959
return reinterpret_cast<T*>(&u);
6060
}
6161

62-
void uv_check_result(const int result, const std::source_location location = std::source_location::current());
62+
void uv_check_result(const int result,
63+
const std::source_location location = std::source_location::current());
6364

6465
template <typename T>
6566
class Task;

include/Compiler/Command.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ class CompilationDatabase {
7979
auto load_commands(this Self& self, llvm::StringRef json_content)
8080
-> std::expected<std::vector<UpdateInfo>, std::string>;
8181

82-
auto get_command(this Self& self, llvm::StringRef file, bool resource_dir = false) -> LookupInfo;
82+
auto get_command(this Self& self, llvm::StringRef file, bool resource_dir = false)
83+
-> LookupInfo;
8384

8485
private:
8586
/// The memory pool to hold all cstring and command list.

include/Test/CTest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct Tester {
8080

8181
Tester& compile(llvm::StringRef standard = "-std=c++20") {
8282
auto command = std::format("clang++ {} {} -fms-extensions", standard, src_path);
83+
8384
database.update_command("fake", src_path, command);
8485
params.arguments = database.get_command(src_path).arguments;
8586

src/AST/Selection.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ struct SelectionBuilder {
7979

8080
template <typename Node, typename Callback>
8181
bool hook(const Node* node, const Callback& callback) {
82+
83+
if(!node) {
84+
return true;
85+
}
86+
8287
if constexpr(requires { node->isImplicit(); })
8388
if(node->isImplicit())
8489
return true;

src/Async/Async.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace clice::async {
66

7-
87
/// The default event loop.
98
uv_loop_t* loop = nullptr;
109

src/Async/libuv.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ const std::error_category& category() {
3030
void uv_check_result(const int result, const std::source_location location) {
3131
if(result < 0) {
3232
log::warn("libuv error: {}", uv_strerror(result));
33-
log::warn("At {}:{}:{}",
34-
location.file_name(),
35-
location.line(),
36-
location.function_name());
33+
log::warn("At {}:{}:{}", location.file_name(), location.line(), location.function_name());
3734
}
3835
}
3936

0 commit comments

Comments
 (0)