diff options
author | pommicket <pommicket@gmail.com> | 2022-12-25 13:35:36 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-25 13:35:36 -0500 |
commit | f67094bce357a76334a717ed669b377d3b93d18e (patch) | |
tree | 6721170920a8d78d31a16a532e1e75c740d377d0 | |
parent | 1793fa40528295306d1d790074fdd8f382e8bef3 (diff) |
fix various problems from texlab test
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | autocomplete.c | 9 | ||||
-rw-r--r-- | lsp-parse.c | 3 | ||||
-rw-r--r-- | lsp-write.c | 4 | ||||
-rw-r--r-- | lsp.c | 12 | ||||
-rw-r--r-- | main.c | 5 | ||||
-rw-r--r-- | util.c | 26 |
7 files changed, 47 insertions, 13 deletions
@@ -23,4 +23,5 @@ pcre2* SDL2 *.deb test.txt +log.txt UpgradeLog.htm diff --git a/autocomplete.c b/autocomplete.c index cc1bf41..8f3df10 100644 --- a/autocomplete.c +++ b/autocomplete.c @@ -131,8 +131,7 @@ static void autocomplete_find_completions(Ted *ted, char32_t trigger_char) { }; unicode_utf32_to_utf8(request.data.completion.context.trigger_character, ac->trigger_char); lsp_send_request(lsp, &request); - if (!ac->completions) - ac->waiting_for_lsp = true; + ac->waiting_for_lsp = true; } else { // tag completion autocomplete_clear_completions(ted); @@ -184,7 +183,7 @@ static void autocomplete_process_lsp_response(Ted *ted, const LSPResponse *respo ted_completion->kind = lsp_completion_kind_to_ted(lsp_completion->kind); ted_completion->deprecated = lsp_completion->deprecated; const char *documentation = lsp_response_string(response, lsp_completion->documentation); - ted_completion->documentation = documentation ? str_dup(documentation) : NULL; + ted_completion->documentation = *documentation ? str_dup(documentation) : NULL; } } @@ -288,7 +287,7 @@ static void autocomplete_frame(Ted *ted) { float menu_width = 400, menu_height = (float)ncompletions_visible * char_height; - if (ac->waiting_for_lsp) { + if (ac->waiting_for_lsp && ncompletions == 0) { menu_height = 200.f; } @@ -332,7 +331,7 @@ static void autocomplete_frame(Ted *ted) { float border_thickness = settings->border_thickness; - if (document) { + if (document && document->documentation) { // document that entry!! // we've got some wacky calculations to figure out the diff --git a/lsp-parse.c b/lsp-parse.c index 86a223d..84b44e2 100644 --- a/lsp-parse.c +++ b/lsp-parse.c @@ -337,6 +337,9 @@ static void process_message(LSP *lsp, JSON *json) { LSPResponse response = {0}; bool add_to_messages = false; response.request = response_to; + // make sure (LSPString){0} gets treated as an empty string + arr_add(response.string_data, '\0'); + switch (response_to.type) { case LSP_REQUEST_COMPLETION: add_to_messages = parse_completion(lsp, json, &response); diff --git a/lsp-write.c b/lsp-write.c index 808f479..ef524d9 100644 --- a/lsp-write.c +++ b/lsp-write.c @@ -414,8 +414,8 @@ static void write_request(LSP *lsp, LSPRequest *request) { memcpy(header + strlen(header), "\r\n\r\n", 4); char *content = header; - #if 0 - printf("\x1b[1m%s\x1b[0m\n",content); + #if LSP_SHOW_C2S + printf("%s%s%s\n",term_bold(stdout),content,term_clear(stdout)); #endif // @TODO: does write always write the full amount? probably not. this should be fixed. @@ -1,3 +1,9 @@ +// print server-to-client communication +#define LSP_SHOW_S2C 0 +// print client-to-server communication +#define LSP_SHOW_C2S 0 + + #define write_bool lsp_write_bool static void lsp_request_free(LSPRequest *r); @@ -146,7 +152,7 @@ static void lsp_receive(LSP *lsp, size_t max_size) { if (nstderr > 0) { // uh oh stderr_buf[nstderr] = '\0'; - eprint("\x1b[1m\x1b[93m%s\x1b[0m", stderr_buf); + eprint("%s%s%s%s", term_bold(stderr), term_yellow(stderr), stderr_buf, term_clear(stderr)); } else { break; } @@ -164,8 +170,8 @@ static void lsp_receive(LSP *lsp, size_t max_size) { // kind of a hack. this is needed because arr_set_len zeroes the data. arr_hdr_(lsp->received_data)->len = (u32)received_so_far; lsp->received_data[received_so_far] = '\0';// null terminate - #if 0 - printf("\x1b[3m%s\x1b[0m\n",lsp->received_data); + #if LSP_SHOW_S2C + printf("%s%s%s\n",term_italics(stdout),lsp->received_data,term_clear(stdout)); #endif u64 response_offset=0, response_size=0; @@ -1,9 +1,8 @@ /* @TODO: -- in texlab, when typing "\something" why does the autocomplete menu close on 's'? - - is the weird documentation really what we're getting? +- stop typing from completing when there's only one copmletion left - in jdtls, opening an empty java file gives an exception. is this my fault? -- what's wrong with pylsp (try "f.w") in generate.py +- what's wrong with pylsp (try "f.w") in generate.py (might be fixed now) - what's wrong with gopls? - make sure "save as" works - more LSP stuff: @@ -21,6 +21,32 @@ static bool is_space(char32_t c) { return c < WCHAR_MAX && iswspace((wint_t)c); } +static bool is_a_tty(FILE *out) { + return + #if __unix__ + isatty(fileno(out)) + #else + false + #endif + ; +} + +static const char *term_italics(FILE *out) { + return is_a_tty(out) ? "\x1b[3m" : ""; +} + +static const char *term_bold(FILE *out) { + return is_a_tty(out) ? "\x1b[1m" : ""; +} + +static const char *term_yellow(FILE *out) { + return is_a_tty(out) ? "\x1b[93m" : ""; +} + +static const char *term_clear(FILE *out) { + return is_a_tty(out) ? "\x1b[0m" : ""; +} + static u8 util_popcount(u64 x) { #ifdef __GNUC__ |