Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .github/workflows/check-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ jobs:
args: --lint ./docs
continue-on-error: true

- name: Suggest changes
if: github.event_name == 'pull_request'
uses: reviewdog/action-suggester@v1.24.0
with:
tool_name: "fmt"
fail_level: any
filter_mode: nofilter
- name: Check diff
run: |
if ! git diff --quiet; then
echo "::error::Formatting changes detected. Please run 'pixi run format' and commit the result."
git --no-pager diff --stat
git --no-pager diff
exit 1
fi
5 changes: 0 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ jobs:

format:
needs: changes
permissions:
contents: read
checks: write
issues: write
pull-requests: write
if: ${{ needs.changes.outputs.format == 'true' }}
uses: ./.github/workflows/check-format.yml

Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/test-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
- os: windows-2025
build_type: RelWithDebInfo
- os: ubuntu-24.04
build_type: Debug
- os: macos-15
build_type: Debug
os: [windows-2025, ubuntu-24.04, macos-15]
build_type: [Debug, RelWithDebInfo]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
Expand Down
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,20 @@ add_custom_target(generate_flatbuffers_schema DEPENDS "${GENERATED_HEADER}")

# Temporary migration-only build graph.
add_library(clice-core STATIC
"${PROJECT_SOURCE_DIR}/src/server/server.cpp"
"${PROJECT_SOURCE_DIR}/src/server/worker.cpp"
"${PROJECT_SOURCE_DIR}/src/compile/command.cpp"
"${PROJECT_SOURCE_DIR}/src/compile/toolchain.cpp"
"${PROJECT_SOURCE_DIR}/src/compile/compilation.cpp"
"${PROJECT_SOURCE_DIR}/src/compile/compilation_unit.cpp"
"${PROJECT_SOURCE_DIR}/src/compile/diagnostic.cpp"
"${PROJECT_SOURCE_DIR}/src/compile/directive.cpp"
"${PROJECT_SOURCE_DIR}/src/compile/preamble.cpp"
"${PROJECT_SOURCE_DIR}/src/compile/tidy.cpp"
"${PROJECT_SOURCE_DIR}/src/support/doxygen.cpp"
"${PROJECT_SOURCE_DIR}/src/support/structed_text.cpp"
"${PROJECT_SOURCE_DIR}/src/support/fuzzy_matcher.cpp"
"${PROJECT_SOURCE_DIR}/src/support/glob_pattern.cpp"
"${PROJECT_SOURCE_DIR}/src/support/logging.cpp"
"${PROJECT_SOURCE_DIR}/src/syntax/lexer.cpp"
"${PROJECT_SOURCE_DIR}/src/syntax/scan.cpp"
"${PROJECT_SOURCE_DIR}/src/feature/semantic_tokens.cpp"
"${PROJECT_SOURCE_DIR}/src/feature/document_links.cpp"
"${PROJECT_SOURCE_DIR}/src/feature/document_symbols.cpp"
Expand Down Expand Up @@ -185,7 +183,7 @@ target_link_libraries(clice-core PUBLIC
)

add_executable(clice "${PROJECT_SOURCE_DIR}/src/clice.cc")
target_link_libraries(clice PRIVATE clice::core eventide::deco)
target_link_libraries(clice PRIVATE clice::core)
install(TARGETS clice RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

message(STATUS "Copying resource directory for development build")
Expand Down
185 changes: 1 addition & 184 deletions src/clice.cc
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;
Comment thread
16bit-ykiko marked this conversation as resolved.
}
42 changes: 40 additions & 2 deletions src/compile/compilation.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <vector>

#include "compile/compilation_unit.h"
#include "compile/module.h"
#include "compile/preamble.h"
#include "support/filesystem.h"

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

namespace clice {

struct PCHInfo {
/// The path of the output PCH file.
std::string path;

/// The building time of this PCH.
std::int64_t mtime;

/// The content used to build this PCH.
std::string preamble;

/// All files involved in building this PCH.
std::vector<std::string> deps;

/// The command arguments used to build this PCH.
std::vector<const char*> arguments;
Comment thread
16bit-ykiko marked this conversation as resolved.
};

struct ModuleInfo {
/// Whether this module is an interface unit.
/// i.e. has export module declaration.
bool isInterfaceUnit = false;

/// Module name.
std::string name;

/// Dependent modules of this module.
std::vector<std::string> mods;
};

struct PCMInfo : ModuleInfo {
/// PCM file path.
std::string path;

/// Source file path.
std::string srcPath;

/// Files involved in building this PCM(not include module).
std::vector<std::string> deps;
};

struct CompilationParams {
/// The kind of this compilation.
CompilationKind kind;
Expand Down
44 changes: 0 additions & 44 deletions src/compile/module.h

This file was deleted.

Loading