Basic completion support

This commit is contained in:
2026-01-06 11:39:17 +00:00
parent a905e333fc
commit e9da17eb34
15 changed files with 423 additions and 219 deletions

View File

@@ -4,38 +4,35 @@
#include "editor/decl.h"
#include "pch.h"
#include "ui/completionbox.h"
#include "ui/hover.h"
#include "utils/utils.h"
struct CompletionItem {
std::string label; // Shown in the autocomplete box
uint8_t kind; // Function, variable, class, etc.
std::optional<std::string> detail; // Shown greyed in autocomplete box
std::optional<std::string> documentation; // Hover box (can be lazy-loaded)
std::string label;
uint8_t kind;
std::optional<std::string> detail;
std::optional<std::string> documentation;
bool is_markup = false;
bool deprecated = false; // Shown with strikethrough, may push down in list
std::string sort; // Used for sorting
std::string filter; // Used for filtering (default: label)
bool deprecated = false;
std::string sort;
std::string filter;
bool snippet = false;
std::vector<TextEdit> edits;
json original;
std::vector<char> end_chars; // Ends completion session if typed
std::vector<char> end_chars;
};
struct CompletionSession {
std::shared_mutex mtx;
bool active = false;
Coord hook; // set to start of word
std::optional<std::string> prefix; // text between hook and cursor
uint8_t select = 0; // index of selected item (defualts to preselcted one
// when data requested)
Coord hook;
std::optional<std::string> prefix;
uint8_t select = 0;
std::vector<CompletionItem> items;
std::vector<uint8_t> visible;
bool complete = true; // If false, client may request more items on filter
// (but doesnt try filtering on its own)
std::optional<char> trigger_char; // Character that triggered completion sent
// to lsp for isIncomplete resolving
uint8_t trigger = 0; // Type of trigger (1: manual, 2: trigger char, 3: auto)
bool complete = true;
std::optional<char> trigger_char;
uint8_t trigger = 0;
CompletionBox box;
CompletionSession() : box(this) {}

View File

@@ -111,7 +111,7 @@ void update(uint32_t row, uint32_t col, std::string utf8, uint32_t fg,
uint32_t bg, uint8_t flags, uint32_t ul_color);
void update(uint32_t row, uint32_t col, const char *utf8, uint32_t fg,
uint32_t bg, uint8_t flags, uint32_t ul_color);
void set_cursor(uint32_t row, uint32_t col, uint32_t type,
void set_cursor(uint8_t row, uint8_t col, uint32_t type,
bool show_cursor_param);
void render();
Coord get_size();

View File

@@ -64,7 +64,9 @@ static json client_capabilities = {
{"labelDetailsSupport", true},
{"insertTextModeSupport", {{"valueSet", {1}}}},
{"deprecatedSupport", true}}},
{"completionItemKind", {{"valueSet", {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}}},
{"completionItemKind",
{{"valueSet", {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25}}}},
{"contextSupport", true},
{"insertTextMode", 1}}}}}};

View File

@@ -8,7 +8,7 @@
struct Bar {
Coord screen;
std::string command = "";
int cursor = 0;
uint32_t cursor = 0;
Bar(Coord screen) : screen(screen) {}
void render();

View File

@@ -6,6 +6,7 @@
#include "utils/utils.h"
struct CompletionBox {
std::shared_mutex mtx;
struct CompletionSession *session;
bool hidden = true;
std::vector<ScreenCell> cells;