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
5 changes: 4 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
BreakAdjacentStringLiterals: false
BreakAdjacentStringLiterals: true
BreakStringLiterals: false
CompactNamespaces: false
Cpp11BracedListStyle: true
Expand Down Expand Up @@ -141,6 +141,9 @@ KeepEmptyLines:
AtStartOfFile: false

StatementMacros:
# Field-position annotation: always break between the macro and the
# annotated declaration, so `<T> name;` gets its own line.
- KOTATSU_ANNOTATE
- DECO_CFG_START
- DECO_CFG
- DECO_CFG_END
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/scan_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void export_graph_json(const PathPool& path_pool,
export_data.files.push_back(std::move(node));
}

auto json = kota::codec::json::to_json(export_data);
auto json = kota::codec::json::to_string(export_data);
if(!json) {
std::println(stderr, "Failed to serialize dependency graph");
return;
Expand Down
2 changes: 1 addition & 1 deletion cmake/package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ set(ENABLE_ROARING_MICROBENCHMARKS OFF CACHE INTERNAL "" FORCE)
FetchContent_Declare(
kotatsu
GIT_REPOSITORY https://github.com/clice-io/kotatsu
GIT_TAG c516e3ae0ca3c7d7fb35fdcfdc7c6a111adef764
GIT_TAG af2b6d1c2bf19d5b9cd643e7dfa43739bfffb361
)

set(KOTA_ENABLE_ZEST ON)
Expand Down
12 changes: 8 additions & 4 deletions src/command/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ std::optional<std::size_t> CompilationDatabase::load(llvm::StringRef path) {
simdjson::ondemand::object obj;
if(element.get_object().get(obj)) {
LOG_ERROR(
"Invalid compilation database in {}. Skipping item at index {}: " "item is not an object.",
"Invalid compilation database in {}. Skipping item at index {}: "
"item is not an object.",
path,
index);
++index;
Expand All @@ -255,7 +256,8 @@ std::optional<std::size_t> CompilationDatabase::load(llvm::StringRef path) {
std::string_view dir_sv, file_sv;
if(obj["directory"].get_string().get(dir_sv)) {
LOG_ERROR(
"Invalid compilation database in {}. Skipping item at index {}: " "'directory' key is missing.",
"Invalid compilation database in {}. Skipping item at index {}: "
"'directory' key is missing.",
path,
index);
++index;
Expand All @@ -264,7 +266,8 @@ std::optional<std::size_t> CompilationDatabase::load(llvm::StringRef path) {

if(obj["file"].get_string().get(file_sv)) {
LOG_ERROR(
"Invalid compilation database in {}. Skipping item at index {}: " "'file' key is missing.",
"Invalid compilation database in {}. Skipping item at index {}: "
"'file' key is missing.",
path,
index);
++index;
Expand Down Expand Up @@ -316,7 +319,8 @@ std::optional<std::size_t> CompilationDatabase::load(llvm::StringRef path) {
std::string_view cmd_sv;
if(obj["command"].get_string().get(cmd_sv)) {
LOG_ERROR(
"Invalid compilation database in {}. Skipping item at index {}: " "neither 'arguments' nor 'command' key is present.",
"Invalid compilation database in {}. Skipping item at index {}: "
"neither 'arguments' nor 'command' key is present.",
path,
index);
++index;
Expand Down
55 changes: 28 additions & 27 deletions src/driver/inspect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,35 @@ struct InspectOptions {
DecoFlag(names = {"-h", "--help"}, help = "Show help", required = false)
help;

DecoInput(
meta_var = "<FEATURE> <PATH>",
help =
"Feature to run (code_completion, document_links, document_symbol, " "folding_range, hover, inlay_hint, semantic_tokens, signature_help, " "tu_index) and a source file or directory",
required = false)
DecoInput(meta_var = "<FEATURE> <PATH>",
help =
"Feature to run (code_completion, document_links, document_symbol, "
"folding_range, hover, inlay_hint, semantic_tokens, signature_help, "
"tu_index) and a source file or directory",
required = false)
<std::vector<std::string>> inputs;

DecoFlag(
names = {"--annotations"},
help =
"Treat inputs as annotated fixture sources: strip inline " "§-markers before compiling (the snap-test grammar)",
required = false)
DecoFlag(names = {"--annotations"},
help =
"Treat inputs as annotated fixture sources: strip inline "
"§-markers before compiling (the snap-test grammar)",
required = false)
annotations;

DecoKVStyled(
kota::deco::decl::KVStyle::JoinedOrSeparate,
names = {"--flags", "--flags="},
help =
"Compile flags for the inputs as a JSON string array; " "replaces the compile_commands.json lookup",
required = false)
DecoKVStyled(kota::deco::decl::KVStyle::JoinedOrSeparate,
names = {"--flags", "--flags="},
help =
"Compile flags for the inputs as a JSON string array; "
"replaces the compile_commands.json lookup",
required = false)
<std::string> flags;

DecoKVStyled(
kota::deco::decl::KVStyle::JoinedOrSeparate,
names = {"--config", "--config="},
help =
"Feature options overlay as a JSON object " "(only features that take options accept it)",
required = false)
DecoKVStyled(kota::deco::decl::KVStyle::JoinedOrSeparate,
names = {"--config", "--config="},
help =
"Feature options overlay as a JSON object "
"(only features that take options accept it)",
required = false)
<std::string> config;

DecoKVStyled(kota::deco::decl::KVStyle::JoinedOrSeparate,
Expand Down Expand Up @@ -142,17 +143,17 @@ struct StrictJson {

/// The fixture's --config JSON overlaid on the feature's default options.
/// 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 config
/// sections. Runners re-parse on each call; --config was validated up
/// `defaulted = true`), so decoding onto a fresh value IS the overlay:
/// missing keys keep the field initializers, exactly like the server's
/// config sections. Runners re-parse on each call; --config was validated up
/// front in run_inspect, so their parse cannot fail.
template <typename Options>
std::optional<Options> parse_feature_config(llvm::StringRef config) {
Options options;
if(config.empty()) {
return options;
}
if(auto result = kota::codec::json::from_json<StrictJson>(config, options); !result) {
if(auto result = kota::codec::json::from_string<StrictJson>(config, options); !result) {
LOG_ERROR("invalid --config: {}", result.error().message);
return std::nullopt;
}
Expand Down Expand Up @@ -789,7 +790,7 @@ int run_inspect(const InspectOptions& opts) {

std::vector<std::string> flags;
if(opts.flags.has_value()) {
if(auto result = kota::codec::json::from_json(*opts.flags, flags); !result) {
if(auto result = kota::codec::json::from_string(*opts.flags, flags); !result) {
LOG_ERROR("--flags is not a JSON string array: {}", result.error().message);
return 1;
}
Expand Down
91 changes: 67 additions & 24 deletions src/feature/feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "support/filesystem.h"
#include "support/markup.h"

#include "kota/codec/macro.h"
#include "kota/ipc/lsp/position.h"
#include "kota/ipc/lsp/protocol.h"
#include "kota/ipc/lsp/uri.h"
Expand All @@ -24,11 +25,10 @@ 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;
// Feature options double as their clice.toml/initializationOptions config
// sections: `defaulted = true` lets a decode leave unmentioned fields at
// their initializers, so those are the single source of every default and a
// config source only ever overlays what it names.

using kota::ipc::lsp::LineMap;
using kota::ipc::lsp::PositionEncoding;
Expand Down Expand Up @@ -86,22 +86,46 @@ inline auto to_range(const LineMap& map, LocalSourceRange range) -> std::optiona

/// Corresponds to the `[code_completion]` section in clice.toml.
struct CodeCompletionOptions {
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;
KOTATSU_ANNOTATE(defaulted = true,
description = "Complete keywords as snippets (not yet implemented).")
<bool> enable_keyword_snippet = false;

KOTATSU_ANNOTATE(defaulted = true,
description = "Insert function arguments as a snippet on completion.")
<bool> enable_function_arguments_snippet = false;

KOTATSU_ANNOTATE(defaulted = true,
description =
"Insert template arguments as a snippet on completion "
"(not yet implemented).")
<bool> enable_template_arguments_snippet = false;

KOTATSU_ANNOTATE(defaulted = true,
description =
"Insert parentheses when completing a function call "
"(not yet implemented).")
<bool> insert_paren_in_function_call = false;

KOTATSU_ANNOTATE(defaulted = true,
description = "Collapse an overload set into a single completion item.")
<bool> bundle_overloads = true;

KOTATSU_ANNOTATE(defaulted = true,
description = "Maximum number of completion items (not yet implemented).")
<std::uint32_t> limit = 0;
};

/// Corresponds to the `[hover]` section in clice.toml.
struct HoverOptions {
/// Render the hover card as markdown rather than plain text.
defaulted<bool> parse_comment_as_markdown = true;

/// Show the desugared form of a type, e.g. `vector<int>::size_type (aka
/// unsigned long)`.
defaulted<bool> show_aka = true;
KOTATSU_ANNOTATE(defaulted = true,
description = "Render the hover card as markdown rather than plain text.")
<bool> parse_comment_as_markdown = true;

KOTATSU_ANNOTATE(defaulted = true,
description =
"Show the desugared form of a type, e.g. "
"`vector<int>::size_type (aka unsigned long)`.")
<bool> show_aka = true;
};

/// Contains detailed information about a symbol. Especially useful when
Expand Down Expand Up @@ -206,13 +230,32 @@ void parse_documentation(llvm::StringRef input, markup::Document& output);

/// Corresponds to the `[inlay_hints]` section in clice.toml.
struct InlayHintsOptions {
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;
KOTATSU_ANNOTATE(defaulted = true, description = "Master switch for inlay hints.")
<bool> enabled = true;

KOTATSU_ANNOTATE(defaulted = true, description = "Show parameter name hints at call sites.")
<bool> parameters = true;

KOTATSU_ANNOTATE(defaulted = true,
description = "Show deduced types for `auto` and templated declarations.")
<bool> deduced_types = true;

KOTATSU_ANNOTATE(defaulted = true,
description = "Show designators in aggregate initialization.")
<bool> designators = true;

KOTATSU_ANNOTATE(defaulted = true,
description = "Show a hint naming the construct after a closing brace.")
<bool> block_end = false;

KOTATSU_ANNOTATE(defaulted = true, description = "Show omitted default arguments.")
<bool> default_arguments = false;

KOTATSU_ANNOTATE(defaulted = true,
description =
"Character budget for a rendered type name; longer names "
"are truncated; 0 means no limit.")
<std::uint32_t> type_name_limit = 32;
};

struct SignatureHelpOptions {};
Expand Down
Loading
Loading