Skip to content

Commit 73afcfb

Browse files
16bit-ykikoclaude
andauthored
refactor: introduce syntax/scan module with DependencyDirectivesGetter (#357)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ce2f355 commit 73afcfb

File tree

18 files changed

+1282
-1633
lines changed

18 files changed

+1282
-1633
lines changed

.github/workflows/check-format.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ jobs:
2424
args: --lint ./docs
2525
continue-on-error: true
2626

27-
- name: Suggest changes
28-
if: github.event_name == 'pull_request'
29-
uses: reviewdog/action-suggester@v1.24.0
30-
with:
31-
tool_name: "fmt"
32-
fail_level: any
33-
filter_mode: nofilter
27+
- name: Check diff
28+
run: |
29+
if ! git diff --quiet; then
30+
echo "::error::Formatting changes detected. Please run 'pixi run format' and commit the result."
31+
git --no-pager diff --stat
32+
git --no-pager diff
33+
exit 1
34+
fi

.github/workflows/main.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ jobs:
5656
5757
format:
5858
needs: changes
59-
permissions:
60-
contents: read
61-
checks: write
62-
issues: write
63-
pull-requests: write
6459
if: ${{ needs.changes.outputs.format == 'true' }}
6560
uses: ./.github/workflows/check-format.yml
6661

.github/workflows/test-cmake.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
include:
12-
- os: windows-2025
13-
build_type: RelWithDebInfo
14-
- os: ubuntu-24.04
15-
build_type: Debug
16-
- os: macos-15
17-
build_type: Debug
11+
os: [windows-2025, ubuntu-24.04, macos-15]
12+
build_type: [Debug, RelWithDebInfo]
1813
runs-on: ${{ matrix.os }}
1914
steps:
2015
- name: Checkout repository

CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,20 @@ add_custom_target(generate_flatbuffers_schema DEPENDS "${GENERATED_HEADER}")
131131

132132
# Temporary migration-only build graph.
133133
add_library(clice-core STATIC
134-
"${PROJECT_SOURCE_DIR}/src/server/server.cpp"
135-
"${PROJECT_SOURCE_DIR}/src/server/worker.cpp"
136134
"${PROJECT_SOURCE_DIR}/src/compile/command.cpp"
137135
"${PROJECT_SOURCE_DIR}/src/compile/toolchain.cpp"
138136
"${PROJECT_SOURCE_DIR}/src/compile/compilation.cpp"
139137
"${PROJECT_SOURCE_DIR}/src/compile/compilation_unit.cpp"
140138
"${PROJECT_SOURCE_DIR}/src/compile/diagnostic.cpp"
141139
"${PROJECT_SOURCE_DIR}/src/compile/directive.cpp"
142-
"${PROJECT_SOURCE_DIR}/src/compile/preamble.cpp"
143140
"${PROJECT_SOURCE_DIR}/src/compile/tidy.cpp"
144141
"${PROJECT_SOURCE_DIR}/src/support/doxygen.cpp"
145142
"${PROJECT_SOURCE_DIR}/src/support/structed_text.cpp"
146143
"${PROJECT_SOURCE_DIR}/src/support/fuzzy_matcher.cpp"
147144
"${PROJECT_SOURCE_DIR}/src/support/glob_pattern.cpp"
148145
"${PROJECT_SOURCE_DIR}/src/support/logging.cpp"
149146
"${PROJECT_SOURCE_DIR}/src/syntax/lexer.cpp"
147+
"${PROJECT_SOURCE_DIR}/src/syntax/scan.cpp"
150148
"${PROJECT_SOURCE_DIR}/src/feature/semantic_tokens.cpp"
151149
"${PROJECT_SOURCE_DIR}/src/feature/document_links.cpp"
152150
"${PROJECT_SOURCE_DIR}/src/feature/document_symbols.cpp"
@@ -185,7 +183,7 @@ target_link_libraries(clice-core PUBLIC
185183
)
186184

187185
add_executable(clice "${PROJECT_SOURCE_DIR}/src/clice.cc")
188-
target_link_libraries(clice PRIVATE clice::core eventide::deco)
186+
target_link_libraries(clice PRIVATE clice::core)
189187
install(TARGETS clice RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
190188

191189
message(STATUS "Copying resource directory for development build")

src/clice.cc

Lines changed: 1 addition & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -1,186 +1,3 @@
1-
#include <cstdio>
2-
#include <expected>
3-
#include <filesystem>
4-
#include <iostream>
5-
#include <optional>
6-
#include <string>
7-
#include <string_view>
8-
#include <vector>
9-
10-
#include "eventide/deco/macro.h"
11-
#include "eventide/deco/runtime.h"
12-
#include "eventide/serde/config.h"
13-
#include "server/protocol.h"
14-
#include "server/runtime.h"
15-
16-
namespace {
17-
18-
using clice::server::Mode;
19-
using clice::server::Options;
20-
21-
struct ModeOption {
22-
Mode value = Mode::Pipe;
23-
24-
auto into(std::string_view text) -> std::optional<std::string_view> {
25-
if(text == "pipe") {
26-
value = Mode::Pipe;
27-
return std::nullopt;
28-
}
29-
if(text == "socket") {
30-
value = Mode::Socket;
31-
return std::nullopt;
32-
}
33-
if(text == "worker") {
34-
value = Mode::Worker;
35-
return std::nullopt;
36-
}
37-
return "invalid --mode, expected: pipe|socket|worker";
38-
}
39-
};
40-
41-
struct CliOptions {
42-
DECO_CFG_START(required = false;);
43-
44-
DecoFlag(names = {"-h", "--help"}; help = "Show this help message and exit"; required = false;)
45-
help = false;
46-
47-
DecoFlag(names = {std::string_view(clice::server::k_worker_mode)};
48-
help = "Run as worker process";
49-
required = false;)
50-
worker_mode = false;
51-
52-
DecoKVStyled(deco::decl::KVStyle::Joined, names = {"--mode=", "--mode"}; meta_var = "MODE";
53-
help = "Server mode: pipe|socket|worker";
54-
required = false;)
55-
<ModeOption> mode;
56-
57-
DecoKVStyled(deco::decl::KVStyle::Joined, names = {"--host=", "--host"}; meta_var = "HOST";
58-
help = "Socket host (default: 127.0.0.1)";
59-
required = false;)
60-
<std::string> host;
61-
62-
DecoKVStyled(deco::decl::KVStyle::Joined, names = {"--port=", "--port"}; meta_var = "PORT";
63-
help = "Socket port (default: 50051)";
64-
required = false)
65-
<int> port;
66-
67-
DecoKVStyled(deco::decl::KVStyle::Joined, names = {"--worker-count=", "--worker-count"};
68-
meta_var = "N";
69-
help = "Worker process count (default: 2)";
70-
required = false)
71-
<std::size_t> worker_count;
72-
73-
DecoKVStyled(deco::decl::KVStyle::Joined,
74-
names = {"--worker-doc-capacity=", "--worker-doc-capacity"};
75-
meta_var = "N";
76-
help = "Per-worker AST cache capacity (default: 32)";
77-
required = false;)
78-
<std::size_t> worker_document_capacity;
79-
80-
DecoKVStyled(deco::decl::KVStyle::Joined,
81-
names = {"--master-doc-capacity=", "--master-doc-capacity"};
82-
meta_var = "N";
83-
help = "Master ownership cache capacity (default: 256)";
84-
required = false;)
85-
<std::size_t> master_document_capacity;
86-
87-
DECO_CFG_END();
88-
};
89-
90-
auto resolve_self_path(int argc, const char** argv) -> std::string {
91-
if(argc <= 0 || argv == nullptr || argv[0] == nullptr) {
92-
return "clice";
93-
}
94-
95-
std::error_code ec;
96-
auto absolute = std::filesystem::absolute(argv[0], ec);
97-
if(ec) {
98-
return std::string(argv[0]);
99-
}
100-
return absolute.string();
101-
}
102-
103-
auto build_options(const CliOptions& cli_options, int argc, const char** argv)
104-
-> std::expected<Options, std::string> {
105-
Options options;
106-
options.self_path = resolve_self_path(argc, argv);
107-
108-
if(cli_options.mode.value.has_value()) {
109-
options.mode = cli_options.mode->value;
110-
} else if(cli_options.worker_mode.value.value_or(false)) {
111-
options.mode = Mode::Worker;
112-
}
113-
114-
if(cli_options.host.value.has_value()) {
115-
options.host = *cli_options.host;
116-
}
117-
if(cli_options.port.value.has_value()) {
118-
if(*cli_options.port <= 0) {
119-
return std::unexpected("--port must be a positive integer");
120-
}
121-
options.port = *cli_options.port;
122-
}
123-
if(cli_options.worker_count.value.has_value()) {
124-
if(*cli_options.worker_count == 0) {
125-
return std::unexpected("--worker-count must be a positive integer");
126-
}
127-
options.worker_count = *cli_options.worker_count;
128-
}
129-
if(cli_options.worker_document_capacity.value.has_value()) {
130-
if(*cli_options.worker_document_capacity == 0) {
131-
return std::unexpected("--worker-doc-capacity must be a positive integer");
132-
}
133-
options.worker_document_capacity = *cli_options.worker_document_capacity;
134-
}
135-
if(cli_options.master_document_capacity.value.has_value()) {
136-
if(*cli_options.master_document_capacity == 0) {
137-
return std::unexpected("--master-doc-capacity must be a positive integer");
138-
}
139-
options.master_document_capacity = *cli_options.master_document_capacity;
140-
}
141-
142-
return options;
143-
}
144-
145-
auto print_usage() -> void {
146-
deco::cli::Dispatcher<CliOptions> dispatcher("clice [OPTIONS]");
147-
dispatcher.usage(std::cerr, true);
148-
}
149-
150-
auto run_with_options(const Options& options) -> int {
151-
switch(options.mode) {
152-
case Mode::Pipe: return clice::server::run_pipe_mode(options);
153-
case Mode::Socket: return clice::server::run_socket_mode(options);
154-
case Mode::Worker: return clice::server::run_worker_mode(options);
155-
}
156-
return 1;
157-
}
158-
159-
} // namespace
160-
1611
int main(int argc, const char** argv) {
162-
eventide::serde::config::set_field_rename_policy<eventide::serde::rename_policy::lower_camel>();
163-
164-
auto args = deco::util::argvify(argc, argv);
165-
auto parsed = deco::cli::parse<CliOptions>(args);
166-
if(!parsed) {
167-
std::fprintf(stderr, "%s\n", parsed.error().message.c_str());
168-
print_usage();
169-
return 1;
170-
}
171-
172-
const auto& cli_options = parsed->options;
173-
if(cli_options.help.value.value_or(false)) {
174-
print_usage();
175-
return 0;
176-
}
177-
178-
auto options = build_options(cli_options, argc, argv);
179-
if(!options) {
180-
std::fprintf(stderr, "%s\n", options.error().c_str());
181-
print_usage();
182-
return 1;
183-
}
184-
185-
return run_with_options(*options);
2+
return 0;
1863
}

src/compile/compilation.h

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include <vector>
1111

1212
#include "compile/compilation_unit.h"
13-
#include "compile/module.h"
14-
#include "compile/preamble.h"
1513
#include "support/filesystem.h"
1614

1715
#include "llvm/ADT/StringMap.h"
@@ -25,6 +23,46 @@ class CodeCompleteConsumer;
2523

2624
namespace clice {
2725

26+
struct PCHInfo {
27+
/// The path of the output PCH file.
28+
std::string path;
29+
30+
/// The building time of this PCH.
31+
std::int64_t mtime;
32+
33+
/// The content used to build this PCH.
34+
std::string preamble;
35+
36+
/// All files involved in building this PCH.
37+
std::vector<std::string> deps;
38+
39+
/// The command arguments used to build this PCH.
40+
std::vector<const char*> arguments;
41+
};
42+
43+
struct ModuleInfo {
44+
/// Whether this module is an interface unit.
45+
/// i.e. has export module declaration.
46+
bool isInterfaceUnit = false;
47+
48+
/// Module name.
49+
std::string name;
50+
51+
/// Dependent modules of this module.
52+
std::vector<std::string> mods;
53+
};
54+
55+
struct PCMInfo : ModuleInfo {
56+
/// PCM file path.
57+
std::string path;
58+
59+
/// Source file path.
60+
std::string srcPath;
61+
62+
/// Files involved in building this PCM(not include module).
63+
std::vector<std::string> deps;
64+
};
65+
2866
struct CompilationParams {
2967
/// The kind of this compilation.
3068
CompilationKind kind;

src/compile/module.h

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)