Repository navigation
refactor: introduce syntax/scan module with DependencyDirectivesGetter #357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1ab8908
refactor: add syntax/scan module and remove server code
16bit-ykiko 201b834
refactor: replace IncludeOnlyVFS with DependencyDirectivesGetter in s…
16bit-ykiko 501d5c4
ci: expand cmake test matrix to 6 combinations
16bit-ykiko 8614275
test: add preamble bound computation tests
16bit-ykiko 14e1178
ci: replace reviewdog suggester with diff check in format workflow
16bit-ykiko 4efd177
fix: use CreateFromArgs in scan tests to fix Windows failures
16bit-ykiko 2b28e4f
fix: use platform-appropriate absolute paths in VFS tests
16bit-ykiko b02e89b
refactor: extract TestVFS helper class to simplify VFS test setup
16bit-ykiko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,186 +1,3 @@ | ||
| #include <cstdio> | ||
| #include <expected> | ||
| #include <filesystem> | ||
| #include <iostream> | ||
| #include <optional> | ||
| #include <string> | ||
| #include <string_view> | ||
| #include <vector> | ||
|
|
||
| #include "eventide/deco/macro.h" | ||
| #include "eventide/deco/runtime.h" | ||
| #include "eventide/serde/config.h" | ||
| #include "server/protocol.h" | ||
| #include "server/runtime.h" | ||
|
|
||
| namespace { | ||
|
|
||
| using clice::server::Mode; | ||
| using clice::server::Options; | ||
|
|
||
| struct ModeOption { | ||
| Mode value = Mode::Pipe; | ||
|
|
||
| auto into(std::string_view text) -> std::optional<std::string_view> { | ||
| if(text == "pipe") { | ||
| value = Mode::Pipe; | ||
| return std::nullopt; | ||
| } | ||
| if(text == "socket") { | ||
| value = Mode::Socket; | ||
| return std::nullopt; | ||
| } | ||
| if(text == "worker") { | ||
| value = Mode::Worker; | ||
| return std::nullopt; | ||
| } | ||
| return "invalid --mode, expected: pipe|socket|worker"; | ||
| } | ||
| }; | ||
|
|
||
| struct CliOptions { | ||
| DECO_CFG_START(required = false;); | ||
|
|
||
| DecoFlag(names = {"-h", "--help"}; help = "Show this help message and exit"; required = false;) | ||
| help = false; | ||
|
|
||
| DecoFlag(names = {std::string_view(clice::server::k_worker_mode)}; | ||
| help = "Run as worker process"; | ||
| required = false;) | ||
| worker_mode = false; | ||
|
|
||
| DecoKVStyled(deco::decl::KVStyle::Joined, names = {"--mode=", "--mode"}; meta_var = "MODE"; | ||
| help = "Server mode: pipe|socket|worker"; | ||
| required = false;) | ||
| <ModeOption> mode; | ||
|
|
||
| DecoKVStyled(deco::decl::KVStyle::Joined, names = {"--host=", "--host"}; meta_var = "HOST"; | ||
| help = "Socket host (default: 127.0.0.1)"; | ||
| required = false;) | ||
| <std::string> host; | ||
|
|
||
| DecoKVStyled(deco::decl::KVStyle::Joined, names = {"--port=", "--port"}; meta_var = "PORT"; | ||
| help = "Socket port (default: 50051)"; | ||
| required = false) | ||
| <int> port; | ||
|
|
||
| DecoKVStyled(deco::decl::KVStyle::Joined, names = {"--worker-count=", "--worker-count"}; | ||
| meta_var = "N"; | ||
| help = "Worker process count (default: 2)"; | ||
| required = false) | ||
| <std::size_t> worker_count; | ||
|
|
||
| DecoKVStyled(deco::decl::KVStyle::Joined, | ||
| names = {"--worker-doc-capacity=", "--worker-doc-capacity"}; | ||
| meta_var = "N"; | ||
| help = "Per-worker AST cache capacity (default: 32)"; | ||
| required = false;) | ||
| <std::size_t> worker_document_capacity; | ||
|
|
||
| DecoKVStyled(deco::decl::KVStyle::Joined, | ||
| names = {"--master-doc-capacity=", "--master-doc-capacity"}; | ||
| meta_var = "N"; | ||
| help = "Master ownership cache capacity (default: 256)"; | ||
| required = false;) | ||
| <std::size_t> master_document_capacity; | ||
|
|
||
| DECO_CFG_END(); | ||
| }; | ||
|
|
||
| auto resolve_self_path(int argc, const char** argv) -> std::string { | ||
| if(argc <= 0 || argv == nullptr || argv[0] == nullptr) { | ||
| return "clice"; | ||
| } | ||
|
|
||
| std::error_code ec; | ||
| auto absolute = std::filesystem::absolute(argv[0], ec); | ||
| if(ec) { | ||
| return std::string(argv[0]); | ||
| } | ||
| return absolute.string(); | ||
| } | ||
|
|
||
| auto build_options(const CliOptions& cli_options, int argc, const char** argv) | ||
| -> std::expected<Options, std::string> { | ||
| Options options; | ||
| options.self_path = resolve_self_path(argc, argv); | ||
|
|
||
| if(cli_options.mode.value.has_value()) { | ||
| options.mode = cli_options.mode->value; | ||
| } else if(cli_options.worker_mode.value.value_or(false)) { | ||
| options.mode = Mode::Worker; | ||
| } | ||
|
|
||
| if(cli_options.host.value.has_value()) { | ||
| options.host = *cli_options.host; | ||
| } | ||
| if(cli_options.port.value.has_value()) { | ||
| if(*cli_options.port <= 0) { | ||
| return std::unexpected("--port must be a positive integer"); | ||
| } | ||
| options.port = *cli_options.port; | ||
| } | ||
| if(cli_options.worker_count.value.has_value()) { | ||
| if(*cli_options.worker_count == 0) { | ||
| return std::unexpected("--worker-count must be a positive integer"); | ||
| } | ||
| options.worker_count = *cli_options.worker_count; | ||
| } | ||
| if(cli_options.worker_document_capacity.value.has_value()) { | ||
| if(*cli_options.worker_document_capacity == 0) { | ||
| return std::unexpected("--worker-doc-capacity must be a positive integer"); | ||
| } | ||
| options.worker_document_capacity = *cli_options.worker_document_capacity; | ||
| } | ||
| if(cli_options.master_document_capacity.value.has_value()) { | ||
| if(*cli_options.master_document_capacity == 0) { | ||
| return std::unexpected("--master-doc-capacity must be a positive integer"); | ||
| } | ||
| options.master_document_capacity = *cli_options.master_document_capacity; | ||
| } | ||
|
|
||
| return options; | ||
| } | ||
|
|
||
| auto print_usage() -> void { | ||
| deco::cli::Dispatcher<CliOptions> dispatcher("clice [OPTIONS]"); | ||
| dispatcher.usage(std::cerr, true); | ||
| } | ||
|
|
||
| auto run_with_options(const Options& options) -> int { | ||
| switch(options.mode) { | ||
| case Mode::Pipe: return clice::server::run_pipe_mode(options); | ||
| case Mode::Socket: return clice::server::run_socket_mode(options); | ||
| case Mode::Worker: return clice::server::run_worker_mode(options); | ||
| } | ||
| return 1; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| int main(int argc, const char** argv) { | ||
| eventide::serde::config::set_field_rename_policy<eventide::serde::rename_policy::lower_camel>(); | ||
|
|
||
| auto args = deco::util::argvify(argc, argv); | ||
| auto parsed = deco::cli::parse<CliOptions>(args); | ||
| if(!parsed) { | ||
| std::fprintf(stderr, "%s\n", parsed.error().message.c_str()); | ||
| print_usage(); | ||
| return 1; | ||
| } | ||
|
|
||
| const auto& cli_options = parsed->options; | ||
| if(cli_options.help.value.value_or(false)) { | ||
| print_usage(); | ||
| return 0; | ||
| } | ||
|
|
||
| auto options = build_options(cli_options, argc, argv); | ||
| if(!options) { | ||
| std::fprintf(stderr, "%s\n", options.error().c_str()); | ||
| print_usage(); | ||
| return 1; | ||
| } | ||
|
|
||
| return run_with_options(*options); | ||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.