Code completion (from Sema) (#144)

This commit is contained in:
ykiko
2025-07-07 11:32:16 +08:00
committed by GitHub
parent bfd6bbadbb
commit cce576dfdd
12 changed files with 1216 additions and 271 deletions

View File

@@ -12,7 +12,23 @@ struct CompilationParams;
namespace config {
struct CodeCompletionOption {};
struct CodeCompletionOption {
/// Insert placeholder for keywords? function call parameters? template arguments?
bool enable_keyword_snippet = false;
/// Also apply for lambda ...
bool enable_function_arguments_snippet = false;
bool enable_template_arguments_snippet = false;
bool insert_paren_in_function_call = false;
/// TODO: Add more detailed option, see
/// https://github.com/llvm/llvm-project/issues/63565
bool bundle_overloads = true;
/// The limits of code completion, 0 is non limit.
std::uint32_t limit = 0;
};
}; // namespace config
@@ -47,30 +63,43 @@ enum class CompletionItemKind {
TypeParameter
};
/// Represents a single code completion item to be presented to the user.
struct CompletionItem {
/// The label displayed when user select the item.
/// The primary label displayed in the completion list.
std::string label;
/// Additional details, like a function signature, shown next to the label.
std::string detail;
/// TODO:
/// std::string sortText;
/// A short description of the item, typically its type or namespace.
std::string description;
/// Full documentation for the item, shown on selection or hover.
std::string document;
/// The kind of item (function, class, etc.), used for an icon.
CompletionItemKind kind;
/// A score for ranking this item against others. Higher is better.
float score;
/// Whether this item is deprecated (often rendered with a strikethrough).
bool deprecated;
/// The text edit to be applied when this item is accepted.
struct Edit {
/// The new text to insert, which may be a snippet.
std::string text;
/// The source range to be replaced by the new text.
LocalSourceRange range;
} edit;
};
using CodeCompletionResult = std::vector<CompletionItem>;
CodeCompletionResult codeCompletion(CompilationParams& params,
const config::CodeCompletionOption& option);
std::vector<CompletionItem> code_complete(CompilationParams& params,
const config::CodeCompletionOption& option);
} // namespace feature