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
4 changes: 0 additions & 4 deletions docs/clice.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
# Enable experimental clang-tidy diagnostics.
# This feature is tracked in https://github.com/clice-io/clice/issues/90.
clang_tidy = false
# Maximum number of active files to keep in memory. If the number of active files
# exceeds this limit, the least recently used files will be removed.
# The default value is 8.
max_active_file = 8
# Directory for storing on-disk caches (PCH, PCM and index files) and logs.
# When unset, clice defaults to a per-workspace directory under the XDG
# cache: ~/.cache/clice/<workspace>-<hash>, with logs in its logs/
Expand Down
2 changes: 1 addition & 1 deletion docs/en/dev/contribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Please refer to [build](./build.md) to build clice, and [test and debug](./test-

| Entity | Convention | Example |
| ---------------------------- | ------------ | --------------------------------- |
| Variables, fields, functions | `snake_case` | `file_path`, `apply_defaults` |
| Variables, fields, functions | `snake_case` | `file_path` |
| Classes, enums, concepts | `PascalCase` | `CompileGraph`, `SymbolKind` |
| Enum values | `PascalCase` | `GoToDefinition`, `IncludeAngled` |
| Template parameters | `PascalCase` | `typename Result` |
Expand Down
9 changes: 0 additions & 9 deletions docs/en/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ The following variable is supported in string values:

Enable experimental clang-tidy diagnostics. **Not yet wired** — the option is parsed but has no effect currently.

### `project.max_active_file`

| Type | Default |
| ----- | ------- |
| `int` | `8` |

Maximum number of active files to keep in memory. **Not yet wired** — the option is parsed but the worker still uses a hardcoded limit.

### `project.cache_dir`

| Type | Default |
Expand Down Expand Up @@ -229,7 +221,6 @@ Flags to remove from the compilation command. Example: `["-Wall", "-Werror"]`.

```toml
[project]
max_active_file = 16
compile_commands_paths = ["${workspace}/build", "${workspace}/cmake-build-debug"]
clang_tidy = true

Expand Down
2 changes: 1 addition & 1 deletion docs/zh/dev/contribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

| 实体 | 规范 | 示例 |
| ---------------- | ------------ | --------------------------------- |
| 变量、字段、函数 | `snake_case` | `file_path`、`apply_defaults` |
| 变量、字段、函数 | `snake_case` | `file_path` |
| 类、枚举、概念 | `PascalCase` | `CompileGraph`、`SymbolKind` |
| 枚举值 | `PascalCase` | `GoToDefinition`、`IncludeAngled` |
| 模板参数 | `PascalCase` | `typename Result` |
Expand Down
9 changes: 0 additions & 9 deletions docs/zh/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ clice 从工作区根目录的 `clice.toml` 中读取配置;若该文件不存

启用实验性的 clang-tidy 诊断。**尚未接线**——该选项会被解析,但当前没有任何效果。

### `project.max_active_file`

| 类型 | 默认值 |
| ----- | ------ |
| `int` | `8` |

内存中保持的最大活跃文件数。**尚未接线**——该选项会被解析,但工作进程仍使用硬编码的上限。

### `project.cache_dir`

| 类型 | 默认值 |
Expand Down Expand Up @@ -169,7 +161,6 @@ clice 从工作区根目录的 `clice.toml` 中读取配置;若该文件不存

```toml
[project]
max_active_file = 16
compile_commands_paths = ["${workspace}/build", "${workspace}/cmake-build-debug"]
clang_tidy = true

Expand Down
21 changes: 5 additions & 16 deletions src/driver/inspect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "compile/compilation.h"
#include "driver/driver.h"
#include "feature/feature.h"
#include "server/state/config.h"
#include "support/filesystem.h"
#include "syntax/annotation.h"

Expand Down Expand Up @@ -161,29 +160,19 @@ struct StrictJson {
};

/// The fixture's --config JSON overlaid on default completion options.
/// Decoded through the same all-optional mirror the server's
/// [code_completion] section uses, so missing keys keep the feature
/// struct's own defaults — a partial overlay, not a full options value.
/// The options struct doubles as its config section (all fields
/// `defaulted`), so decoding onto a fresh value IS the overlay: missing
/// keys keep the field initializers, exactly like the server's
/// [code_completion] section.
std::optional<feature::CodeCompletionOptions> parse_completion_config(llvm::StringRef config) {
feature::CodeCompletionOptions options;
if(config.empty()) {
return options;
}
CodeCompletionConfig overlay;
if(auto result = kota::codec::json::from_json<StrictJson>(config, overlay); !result) {
if(auto result = kota::codec::json::from_json<StrictJson>(config, options); !result) {
LOG_ERROR("invalid --config: {}", result.error().message);
return std::nullopt;
}
options.enable_keyword_snippet =
overlay.enable_keyword_snippet.value_or(options.enable_keyword_snippet);
options.enable_function_arguments_snippet = overlay.enable_function_arguments_snippet.value_or(
options.enable_function_arguments_snippet);
options.enable_template_arguments_snippet = overlay.enable_template_arguments_snippet.value_or(
options.enable_template_arguments_snippet);
options.insert_paren_in_function_call =
overlay.insert_paren_in_function_call.value_or(options.insert_paren_in_function_call);
options.bundle_overloads = overlay.bundle_overloads.value_or(options.bundle_overloads);
options.limit = overlay.limit.value_or(options.limit);
return options;
}

Expand Down
19 changes: 0 additions & 19 deletions src/feature/document_link.h

This file was deleted.

71 changes: 57 additions & 14 deletions src/feature/feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "compile/compilation.h"
#include "compile/compilation_unit.h"
#include "feature/document_link.h"
#include "semantic/display.h"
#include "semantic/symbol.h"
#include "support/anomaly.h"
Expand All @@ -17,12 +16,20 @@
#include "kota/ipc/lsp/position.h"
#include "kota/ipc/lsp/protocol.h"
#include "kota/ipc/lsp/uri.h"
#include "kota/meta/annotation.h"
#include "llvm/ADT/ArrayRef.h"

namespace clice::feature {

namespace lsp = kota::ipc::lsp;
namespace protocol = kota::ipc::protocol;

/// Feature options double as their clice.toml/initializationOptions config
/// sections: `defaulted` lets a decode leave unmentioned fields at the
/// values below, so the field initializers are the single source of every
/// default and a config source only ever overlays what it names.
using kota::meta::defaulted;

using kota::ipc::lsp::LineMap;
using kota::ipc::lsp::PositionEncoding;

Expand Down Expand Up @@ -77,13 +84,14 @@ inline auto to_range(const LineMap& map, LocalSourceRange range) -> std::optiona
return protocol::Range{.start = *start, .end = *end};
}

/// Corresponds to the `[code_completion]` section in clice.toml.
struct CodeCompletionOptions {
bool enable_keyword_snippet = false;
bool enable_function_arguments_snippet = false;
bool enable_template_arguments_snippet = false;
bool insert_paren_in_function_call = false;
bool bundle_overloads = true;
std::uint32_t limit = 0;
defaulted<bool> enable_keyword_snippet = false;
defaulted<bool> enable_function_arguments_snippet = false;
defaulted<bool> enable_template_arguments_snippet = false;
defaulted<bool> insert_paren_in_function_call = false;
defaulted<bool> bundle_overloads = true;
defaulted<std::uint32_t> limit = 0;
};

struct HoverOptions {
Expand Down Expand Up @@ -195,14 +203,15 @@ struct HoverInfo {
/// Try to infer structure of a documentation comment (e.g. line breaks).
void parse_documentation(llvm::StringRef input, markup::Document& output);

/// Corresponds to the `[inlay_hints]` section in clice.toml.
struct InlayHintsOptions {
bool enabled = true;
bool parameters = true;
bool deduced_types = true;
bool designators = true;
bool block_end = false;
bool default_arguments = false;
std::uint32_t type_name_limit = 32;
defaulted<bool> enabled = true;
defaulted<bool> parameters = true;
defaulted<bool> deduced_types = true;
defaulted<bool> designators = true;
defaulted<bool> block_end = false;
defaulted<bool> default_arguments = false;
defaulted<std::uint32_t> type_name_limit = 32;
};

struct SignatureHelpOptions {};
Expand All @@ -219,6 +228,30 @@ struct FoldingRange {
std::string collapsed_text;
};

/// A resolved document link: the argument range of an include-like
/// directive (byte offsets in the containing file) and the absolute path
/// of the target file. Plain data — it serializes over the worker RPC and
/// the PCH's PreambleState blob as-is and becomes an LSP DocumentLink only
/// at the reply edge, where the session's line map does the conversion.
struct DocumentLink {
LocalSourceRange range;
std::string target;
};

/// Result of scanning a unit for preprocessor-inactive regions.
struct InactiveScan {
/// Byte-offset ranges [begin0, end0, begin1, end1, ...] of inactive
/// branch bodies in the interested file; directive lines excluded.
std::vector<std::uint32_t> regions;

/// Conditional levels still open at the end of the scanned content,
/// outermost first. Bit 0: the level's current branch is inactive.
/// Bit 1: an earlier branch of the level was already taken (decides a
/// later #else). Preamble/PCH builds end mid-#if when the bound cuts
/// inside a block; the AST compile resumes from this stack.
std::vector<std::uint8_t> open_stack;
};

struct DocumentSymbol {
std::string name;
std::string detail;
Expand Down Expand Up @@ -274,6 +307,16 @@ auto document_links(CompilationUnitRef unit) -> std::vector<DocumentLink>;
auto include_definition(CompilationUnitRef unit, std::uint32_t offset)
-> std::vector<protocol::Location>;

/// Scan the interested file's condition directives. `open_stack` seeds the
/// nesting state (from a preceding preamble scan) and `resume_offset` is
/// where the scanned content starts — pending inactive levels from the
/// seed begin there. A scan that ends with open levels closes their
/// pending regions at `end_offset` (the content bound).
InactiveScan inactive_regions(CompilationUnitRef unit,
llvm::ArrayRef<std::uint8_t> open_stack = {},
std::uint32_t resume_offset = 0,
std::uint32_t end_offset = UINT32_MAX);
Comment thread
16bit-ykiko marked this conversation as resolved.

auto diagnostics(CompilationUnitRef unit, PositionEncoding encoding = PositionEncoding::UTF16)
-> std::vector<protocol::Diagnostic>;

Expand Down
3 changes: 1 addition & 2 deletions src/feature/inactive_regions.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "feature/inactive_regions.h"

#include "compile/directive.h"
#include "feature/feature.h"

#include "llvm/ADT/SmallVector.h"

Expand Down
36 changes: 0 additions & 36 deletions src/feature/inactive_regions.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/index/preamble_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string>
#include <vector>

#include "feature/document_link.h"
#include "feature/feature.h"
#include "index/tu_index.h"

#include "llvm/ADT/ArrayRef.h"
Expand Down
29 changes: 2 additions & 27 deletions src/server/compiler/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,20 +1391,7 @@ Compiler::RawResult Compiler::forward_query(worker::QueryKind kind,
worker::QueryParams wp;
wp.kind = kind;
wp.path = path;

if(kind == worker::QueryKind::InlayHints) {
// apply_defaults() has filled every field of the config section.
auto& ih = workspace.config.inlay_hints;
wp.inlay_options = {
.enabled = *ih.enabled,
.parameters = *ih.parameters,
.deduced_types = *ih.deduced_types,
.designators = *ih.designators,
.block_end = *ih.block_end,
.default_arguments = *ih.default_arguments,
.type_name_limit = *ih.type_name_limit,
};
}
wp.config = workspace.config;

if(position) {
wp.offset = clamped_offset(map, *position);
Expand Down Expand Up @@ -1572,19 +1559,7 @@ Compiler::RawResult Compiler::forward_build(worker::BuildKind kind,
wp.text = session->text;
contexts.resolve_command(path, wp.directory, wp.arguments, session.get());
contexts.append_suffix_include(*session, wp.text);

if(kind == worker::BuildKind::Completion) {
// apply_defaults() has filled every field of the config section.
auto& cc = workspace.config.code_completion;
wp.completion_options = {
.enable_keyword_snippet = *cc.enable_keyword_snippet,
.enable_function_arguments_snippet = *cc.enable_function_arguments_snippet,
.enable_template_arguments_snippet = *cc.enable_template_arguments_snippet,
.insert_paren_in_function_call = *cc.insert_paren_in_function_call,
.bundle_overloads = *cc.bundle_overloads,
.limit = *cc.limit,
};
}
wp.config = workspace.config;

ScopedTimer timer;
if(!co_await ensure_deps(*session, gen, epoch, wp.directory, wp.arguments, wp.pch, wp.pcms)) {
Expand Down
5 changes: 3 additions & 2 deletions src/server/compiler/indexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,15 @@ kota::task<> Indexer::stop() {
}

void Indexer::schedule() {
if(!*workspace.config.project.enable_indexing || indexing_active || indexing_scheduled)
if(!workspace.config.project.enable_indexing.value || indexing_active || indexing_scheduled)
return;
indexing_scheduled = true;

if(!index_idle_timer) {
index_idle_timer = std::make_shared<kota::timer>(kota::timer::create(loop));
}
index_idle_timer->start(std::chrono::milliseconds(*workspace.config.project.idle_timeout_ms));
index_idle_timer->start(
std::chrono::milliseconds(workspace.config.project.idle_timeout_ms.value));

if(!bg_tasks.spawn(run_background_indexing())) {
indexing_scheduled = false;
Expand Down
Loading
Loading