summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-22 22:56:18 -0500
committerpommicket <pommicket@gmail.com>2022-12-22 22:56:18 -0500
commitb9ac4215ef8d02ad6da257315891c408bc395165 (patch)
tree3b7297102da65890944989f730dd1217c6931f7c
parent266af5ed551765ca22cb90819f570ff9371e279b (diff)
start capabilities
-rw-r--r--autocomplete.c8
-rw-r--r--colors.h2
-rw-r--r--lsp-write.c56
-rw-r--r--lsp.c4
-rw-r--r--main.c4
-rw-r--r--ted.cfg5
6 files changed, 72 insertions, 7 deletions
diff --git a/autocomplete.c b/autocomplete.c
index db7a045..514c9a5 100644
--- a/autocomplete.c
+++ b/autocomplete.c
@@ -138,9 +138,11 @@ static void autocomplete_process_lsp_response(Ted *ted, const LSPResponse *respo
for (size_t i = 0; i < ncompletions; ++i) {
const LSPCompletionItem *lsp_completion = &completion->items[i];
Autocompletion *ted_completion = &ac->completions[i];
- // @TODO: deal with fancier textEdits
ted_completion->label = str_dup(lsp_response_string(response, lsp_completion->label));
ted_completion->filter = str_dup(lsp_response_string(response, lsp_completion->filter_text));
+ // NOTE: here we don't deal with snippets.
+ // right now we are sending "snippetSupport: false" in the capabilities,
+ // so this should be okay.
ted_completion->text = str_dup(lsp_response_string(response, lsp_completion->text_edit.new_text));
const char *detail = lsp_response_string(response, lsp_completion->detail);
ted_completion->detail = *detail ? str_dup(detail) : NULL;
@@ -265,14 +267,14 @@ static void autocomplete_frame(Ted *ted) {
if (cursor_entry < ncompletions) {
// highlight moused over entry
Rect r = rect(V2(x, start_y + cursor_entry * char_height), V2(menu_width, char_height));
- gl_geometry_rect(r, colors[COLOR_MENU_HL]);
+ gl_geometry_rect(r, colors[COLOR_AUTOCOMPLETE_HL]);
ted->cursor = ted->cursor_hand;
}
if (!ac->waiting_for_lsp) {
// highlight cursor entry
Rect r = rect(V2(x, start_y + (float)ac->cursor * char_height), V2(menu_width, char_height));
- gl_geometry_rect(r, colors[COLOR_MENU_HL]);
+ gl_geometry_rect(r, colors[COLOR_AUTOCOMPLETE_HL]);
}
for (uint i = 0; i < ted->nmouse_clicks[SDL_BUTTON_LEFT]; ++i) {
diff --git a/colors.h b/colors.h
index 247261d..92c8858 100644
--- a/colors.h
+++ b/colors.h
@@ -26,6 +26,7 @@ typedef enum {
COLOR_FIND_HL,
COLOR_AUTOCOMPLETE_BG,
+ COLOR_AUTOCOMPLETE_HL,
COLOR_AUTOCOMPLETE_BORDER,
COLOR_AUTOCOMPLETE_FUNCTION,
COLOR_AUTOCOMPLETE_VARIABLE,
@@ -89,6 +90,7 @@ static ColorName const color_names[] = {
{COLOR_CHARACTER, "character"},
{COLOR_CONSTANT, "constant"},
{COLOR_AUTOCOMPLETE_BG, "autocomplete-bg"},
+ {COLOR_AUTOCOMPLETE_HL, "autocomplete-hl"},
{COLOR_AUTOCOMPLETE_BORDER, "autocomplete-border"},
{COLOR_AUTOCOMPLETE_VARIABLE, "autocomplete-variable"},
{COLOR_AUTOCOMPLETE_FUNCTION, "autocomplete-function"},
diff --git a/lsp-write.c b/lsp-write.c
index 28b19d3..51f638f 100644
--- a/lsp-write.c
+++ b/lsp-write.c
@@ -1,4 +1,5 @@
+
static const char *lsp_language_id(Language lang) {
switch (lang) {
case LANG_CONFIG:
@@ -109,6 +110,16 @@ static void write_key_arr_start(JSONWriter *o, const char *key) {
write_arr_start(o);
}
+static void write_arr_elem_obj_start(JSONWriter *o) {
+ write_arr_elem(o);
+ write_obj_start(o);
+}
+
+static void write_arr_elem_arr_start(JSONWriter *o) {
+ write_arr_elem(o);
+ write_arr_start(o);
+}
+
static void write_number(JSONWriter *o, double number) {
str_builder_appendf(&o->builder, "%g", number);
}
@@ -118,6 +129,11 @@ static void write_key_number(JSONWriter *o, const char *key, double number) {
write_number(o, number);
}
+static void write_arr_elem_number(JSONWriter *o, double number) {
+ write_arr_elem(o);
+ write_number(o, number);
+}
+
static void write_null(JSONWriter *o) {
str_builder_append(&o->builder, "null");
}
@@ -127,11 +143,30 @@ static void write_key_null(JSONWriter *o, const char *key) {
write_null(o);
}
+static void write_bool(JSONWriter *o, bool b) {
+ str_builder_append(&o->builder, b ? "true" : "false");
+}
+
+static void write_key_bool(JSONWriter *o, const char *key, bool b) {
+ write_key(o, key);
+ write_bool(o, b);
+}
+
+static void write_arr_elem_null(JSONWriter *o) {
+ write_arr_elem(o);
+ write_null(o);
+}
+
static void write_key_string(JSONWriter *o, const char *key, const char *s) {
write_key(o, key);
write_string(o, s);
}
+static void write_arr_elem_string(JSONWriter *o, const char *s) {
+ write_arr_elem(o);
+ write_string(o, s);
+}
+
static void write_file_uri(JSONWriter *o, DocumentID document) {
const char *path = o->lsp->document_paths[document];
str_builder_append(&o->builder, "\"file:///");
@@ -251,9 +286,30 @@ static void write_request(LSP *lsp, LSPRequest *request) {
write_key_obj_start(o, "params");
write_key_number(o, "processId", process_get_id());
write_key_obj_start(o, "capabilities");
+ write_key_obj_start(o, "textDocument");
+ write_key_obj_start(o, "completion");
+ // completion capabilities
+ write_key_obj_start(o, "completionItem");
+ write_key_bool(o, "snippetSupport", false);
+ write_obj_end(o);
+ // "completion item kinds" supported by ted
+ // (these are the little icons displayed for function/variable/etc.)
+ write_key_obj_start(o, "completionItemKind");
+ write_key_arr_start(o, "valueSet");
+ for (int i = LSP_COMPLETION_KIND_MIN;
+ i <= LSP_COMPLETION_KIND_MAX; ++i) {
+ write_arr_elem_number(o, i);
+ }
+ write_arr_end(o);
+ write_obj_end(o);
+ write_obj_end(o);
+ write_obj_end(o);
write_obj_end(o);
write_key_null(o, "rootUri");
write_key_null(o, "workspaceFolders");
+ write_key_obj_start(o, "clientInfo");
+ write_key_string(o, "name", "ted");
+ write_obj_end(o);
write_obj_end(o);
} break;
case LSP_REQUEST_DID_OPEN: {
diff --git a/lsp.c b/lsp.c
index 9d02d34..c6b0215 100644
--- a/lsp.c
+++ b/lsp.c
@@ -1,3 +1,5 @@
+#define write_bool lsp_write_bool
+
static void lsp_request_free(LSPRequest *r);
static void lsp_response_free(LSPResponse *r);
@@ -411,3 +413,5 @@ SymbolKind lsp_completion_kind_to_ted(LSPCompletionKind kind) {
return SYMBOL_KEYWORD;
}
}
+
+#undef write_bool
diff --git a/main.c b/main.c
index ce40db1..198609d 100644
--- a/main.c
+++ b/main.c
@@ -1,8 +1,6 @@
/*
@TODO:
-- kind (icon/color)
- - improve color_for_symbol_kind
-- send textDocument.completion.completionItemKind capability
+- trigger characters (with setting)
- only show "Loading..." if it's taking some time (prevent flash)
- LSP setting
- scroll through completions
diff --git a/ted.cfg b/ted.cfg
index 5bab390..0e823bd 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -195,6 +195,8 @@ Ctrl+Shift+tab = :split-swap
Escape = :escape
[colors]
+# below, bg is short for background and hl is short for highlight
+
border = #a77
active-tab-hl = #a77a
# this color is used for tabs which are selected, but not active (because you are on the other side of a split, perhaps)
@@ -235,7 +237,8 @@ cancel = #ffa
# autocomplete
autocomplete-bg = #000
-autocomplete-border = #fff
+autocomplete-border = #999
+autocomplete-hl = #0a0
autocomplete-variable = #bfb
autocomplete-function = #aaf
autocomplete-type = #fac