diff options
author | pommicket <pommicket@gmail.com> | 2023-01-03 17:10:40 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-01-03 17:10:40 -0500 |
commit | 0d92c03f3998fe4d16f3ba928d3a94583755e1ce (patch) | |
tree | a2afad849822433ea795ce6bc216321722e754f2 | |
parent | baae904ed2c97ba5c701442ec5ef6900715f785d (diff) |
rename ted_seterr to ted_error
-rw-r--r-- | build.c | 4 | ||||
-rw-r--r-- | config.c | 10 | ||||
-rw-r--r-- | find.c | 10 | ||||
-rw-r--r-- | lsp-parse.c | 5 | ||||
-rw-r--r-- | main.c | 10 | ||||
-rw-r--r-- | tags.c | 6 | ||||
-rw-r--r-- | ted.c | 23 | ||||
-rw-r--r-- | ted.h | 4 | ||||
-rw-r--r-- | ui.c | 6 |
9 files changed, 40 insertions, 38 deletions
@@ -52,7 +52,7 @@ static bool build_run_next_command_in_queue(Ted *ted) { free(command); return true; } else { - ted_seterr(ted, "Couldn't start build: %s", error); + ted_error(ted, "Couldn't start build: %s", error); build_stop(ted); return false; } @@ -253,7 +253,7 @@ void build_frame(Ted *ted, float x1, float y1, float x2, float y2) { i64 bytes_read = (i64)process_read(process, buf + 3, sizeof buf - 3); if (bytes_read == -2) { - ted_seterr(ted, "Error reading command output: %s.", process_geterr(process)); + ted_error(ted, "Error reading command output: %s.", process_geterr(process)); build_stop(ted); break; } else if (bytes_read == -1) { @@ -162,7 +162,7 @@ static void config_err(ConfigReader *cfg, const char *fmt, ...) { va_start(args, fmt); vsnprintf(error + strlen(error), sizeof error - strlen(error) - 1, fmt, args); va_end(args); - ted_seterr(cfg->ted, "%s", error); + ted_error(cfg->ted, "%s", error); } static void context_copy(SettingsContext *dest, const SettingsContext *src) { @@ -424,7 +424,7 @@ static void config_init_settings(void) { void config_read(Ted *ted, ConfigPart **parts, const char *filename) { FILE *fp = fopen(filename, "rb"); if (!fp) { - ted_seterr(ted, "Couldn't open config file %s: %s.", filename, strerror(errno)); + ted_error(ted, "Couldn't open config file %s: %s.", filename, strerror(errno)); return; } @@ -475,7 +475,7 @@ void config_read(Ted *ted, ConfigPart **parts, const char *filename) { } if (ferror(fp)) - ted_seterr(ted, "Error reading %s.", filename); + ted_error(ted, "Error reading %s.", filename); fclose(fp); } @@ -604,7 +604,7 @@ uniform sampler2D t_texture;\n\ char error[512] = {0}; GLuint shader = gl_compile_and_link_shaders(error, vshader, fshader); if (*error) - ted_seterr(ted, "%s", error); + ted_error(ted, "%s", error); if (shader) { GLuint buffer = 0, array = 0; glGenBuffers(1, &buffer); @@ -649,7 +649,7 @@ static void settings_load_bg_texture(Ted *ted, Settings *s) { if (texture) { s->bg_texture = gl_rc_texture_new(texture); } else { - ted_seterr(ted, "Couldn't load image %s", path); + ted_error(ted, "Couldn't load image %s", path); } } @@ -22,12 +22,12 @@ TextBuffer *find_search_buffer(Ted *ted) { } -static void ted_seterr_to_pcre2_err(Ted *ted, int err) { +static void ted_error_from_pcre2_error(Ted *ted, int err) { char32_t buf[256] = {0}; size_t len = (size_t)pcre2_get_error_message(err, buf, arr_count(buf) - 1); char *error_cstr = str32_to_utf8_cstr(str32(buf, len)); if (error_cstr) { - ted_seterr(ted, "Search error: %s.", error_cstr); + ted_error(ted, "Search error: %s.", error_cstr); free(error_cstr); } } @@ -51,7 +51,7 @@ static bool find_compile_pattern(Ted *ted) { } pcre2_match_data_free(match_data); } else { - ted_seterr(ted, "Out of memory."); + ted_error(ted, "Out of memory."); } } else { ted->find_invalid_pattern = false; @@ -256,11 +256,11 @@ static bool find_replace_match(Ted *ted, u32 match_idx) { } success = true; } else if (ret < 0) { - ted_seterr_to_pcre2_err(ted, ret); + ted_error_from_pcre2_error(ted, ret); } free(output_buffer); } else { - ted_seterr(ted, "Out of memory."); + ted_error(ted, "Out of memory."); } return success; } diff --git a/lsp-parse.c b/lsp-parse.c index 7b5849f..14db651 100644 --- a/lsp-parse.c +++ b/lsp-parse.c @@ -869,8 +869,9 @@ void process_message(LSP *lsp, JSON *json) { response.error = json_string_get_alloc(json, error.val.string); } - if (response.error && error_code != LSP_ERROR_REQUEST_CANCELLED) { - add_to_messages = true; + if (response.error) { + if (error_code != LSP_ERROR_REQUEST_CANCELLED) + add_to_messages = true; } else switch (response_to.type) { case LSP_REQUEST_COMPLETION: add_to_messages = parse_completion(lsp, json, &response); @@ -1,6 +1,5 @@ /* @TODO: -- rename ted_seterr to ted_error - go to declaration with LSP - ted.h documentation - handle multiple symbols with same name in go-to-definition menu @@ -29,6 +28,7 @@ - bad json can give "Unexpected error: client exited without proper shutdown sequence" FUTURE FEATURES: - add numlock as a key modifier? (but make sure "Ctrl+S" handles both "No NumLock+Ctrl+S" and "NumLock+Ctrl+S") +- return to previous location in buffer - font setting & support for multiple fonts to cover more characters - comment-start & comment-end settings - robust find (results shouldn't move around when you type things) @@ -846,7 +846,7 @@ int main(int argc, char **argv) { if (r->error) { // not displaying this right now // idk it might be spammy - //ted_seterr(ted, "%s", r->error); + //ted_error(ted, "%s", r->error); } // it's important that we send error responses here too. // we don't want to be waiting around for a response that's never coming. @@ -982,12 +982,12 @@ int main(int argc, char **argv) { } if (text_has_err()) { - ted_seterr(ted, "Couldn't render text: %s", text_get_err()); + ted_error(ted, "Couldn't render text: %s", text_get_err()); } for (u16 i = 0; i < TED_MAX_BUFFERS; ++i) { TextBuffer *buffer = &ted->buffers[i]; if (buffer_haserr(buffer)) { - ted_seterr_to_buferr(ted, buffer); + ted_error_from_buffer(ted, buffer); buffer_clearerr(buffer); } } @@ -995,7 +995,7 @@ int main(int argc, char **argv) { LSP *lsp = ted->lsps[i]; char error[512] = {0}; if (lsp_get_error(lsp, error, sizeof error, true)) { - ted_seterr(ted, "%s", error); + ted_error(ted, "%s", error); } } @@ -13,7 +13,7 @@ static const char *tags_filename(Ted *ted, bool error_if_does_not_exist) { ted_path_full(ted, "../..", ted->tags_dir, sizeof ted->tags_dir); if (!fs_file_exists(filename)) { if (error_if_does_not_exist) - ted_seterr(ted, "No tags file. Try running ctags."); + ted_error(ted, "No tags file. Try running ctags."); filename = NULL; } } @@ -325,7 +325,7 @@ top:; } str32_free(&pattern32); } else { - ted_seterr(ted, "Unrecognized tag address: %s", address); + ted_error(ted, "Unrecognized tag address: %s", address); } } break; @@ -340,7 +340,7 @@ top:; already_regenerated_tags = true; goto top; } else { - ted_seterr(ted, "No such tag: %s", tag); + ted_error(ted, "No such tag: %s", tag); } } fclose(file); @@ -40,7 +40,7 @@ void ted_set_message(Ted *ted, MessageType type, const char *fmt, ...) { va_end(args); } -void ted_seterr(Ted *ted, const char *fmt, ...) { +void ted_error(Ted *ted, const char *fmt, ...) { va_list args; va_start(args, fmt); ted_vset_message(ted, MESSAGE_ERROR, fmt, args); @@ -71,12 +71,13 @@ void ted_log(Ted *ted, const char *fmt, ...) { } -void ted_seterr_to_buferr(Ted *ted, TextBuffer *buffer) { - ted_seterr(ted, "%s", buffer->error); +void ted_error_from_buffer(Ted *ted, TextBuffer *buffer) { + if (*buffer->error) + ted_error(ted, "%s", buffer->error); } void ted_out_of_mem(Ted *ted) { - ted_seterr(ted, "Out of memory."); + ted_error(ted, "Out of memory."); } void *ted_malloc(Ted *ted, size_t size) { @@ -353,7 +354,7 @@ i32 ted_new_node(Ted *ted) { return i; } } - ted_seterr(ted, "Too many nodes."); + ted_error(ted, "Too many nodes."); return -1; } @@ -394,7 +395,7 @@ static Status ted_open_buffer(Ted *ted, u16 *buffer_idx, u16 *tab) { ted_switch_to_buffer(ted, new_buffer); return true; } else { - ted_seterr(ted, "Too many tabs."); + ted_error(ted, "Too many tabs."); ted_delete_buffer(ted, (u16)new_buffer_index); return false; } @@ -437,7 +438,7 @@ bool ted_open_file(Ted *ted, const char *filename) { if (buffer_load_file(buffer, path)) { return true; } else { - ted_seterr_to_buferr(ted, buffer); + ted_error_from_buffer(ted, buffer); node_tab_close(ted, ted->active_node, tab_idx); ted_delete_buffer(ted, (u16)buffer_idx); return false; @@ -460,7 +461,7 @@ bool ted_new_file(Ted *ted, const char *filename) { if (!buffer_haserr(buffer)) { return true; } else { - ted_seterr_to_buferr(ted, buffer); + ted_error_from_buffer(ted, buffer); node_tab_close(ted, ted->active_node, tab_idx); ted_delete_buffer(ted, (u16)buffer_idx); return false; @@ -486,7 +487,7 @@ bool ted_save_all(Ted *ted) { } else { if (!buffer_save(buffer)) { success = false; - ted_seterr_to_buferr(ted, buffer); + ted_error_from_buffer(ted, buffer); } } } @@ -632,7 +633,7 @@ void ted_cancel_lsp_request(Ted *ted, LSPID lsp, LSPRequestID request) { static void mark_node_reachable(Ted *ted, u16 node, bool reachable[TED_MAX_NODES]) { if (reachable[node]) { - ted_seterr(ted, "Node %u reachable in 2 different ways\nThis should never happen.", node); + ted_error(ted, "Node %u reachable in 2 different ways\nThis should never happen.", node); ted_log(ted, "Node %u reachable in 2 different ways\n", node); node_close(ted, node); return; @@ -651,7 +652,7 @@ void ted_check_for_node_problems(Ted *ted) { mark_node_reachable(ted, 0, reachable); for (u16 i = 0; i < TED_MAX_NODES; ++i) { if (ted->nodes_used[i] && !reachable[i]) { - ted_seterr(ted, "ORPHANED NODE %u\nThis should never happen.", i); + ted_error(ted, "ORPHANED NODE %u\nThis should never happen.", i); ted_log(ted, "ORPHANED NODE %u\n", i); node_close(ted, i); } @@ -1052,7 +1052,7 @@ void die(PRINTF_FORMAT_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2); // display a message to the user void ted_set_message(Ted *ted, MessageType type, PRINTF_FORMAT_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(3, 4); // display an error to the user -void ted_seterr(Ted *ted, PRINTF_FORMAT_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3); +void ted_error(Ted *ted, PRINTF_FORMAT_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3); // display a warning to the user void ted_warn(Ted *ted, PRINTF_FORMAT_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3); // display information to the user @@ -1068,7 +1068,7 @@ Status ted_get_file(Ted const *ted, const char *name, char *out, size_t outsz); // get full path relative to ted->cwd. void ted_path_full(Ted *ted, const char *relpath, char *abspath, size_t abspath_size); void ted_reset_active_buffer(Ted *ted); -void ted_seterr_to_buferr(Ted *ted, TextBuffer *buffer); +void ted_error_from_buffer(Ted *ted, TextBuffer *buffer); // Returns the buffer containing the file at `path`, or NULL if there is none. TextBuffer *ted_get_buffer_with_file(Ted *ted, const char *path); bool ted_save_all(Ted *ted); @@ -418,9 +418,9 @@ char *file_selector_update(Ted *ted, FileSelector *fs) { if (files) break; else if (i == 0) { if (fs_path_type(cwd) == FS_NON_EXISTENT) - ted_seterr(ted, "%s is not a directory.", cwd); + ted_error(ted, "%s is not a directory.", cwd); else - ted_seterr(ted, "Can't list directory %s.", cwd); + ted_error(ted, "Can't list directory %s.", cwd); } file_selector_cd(ted, fs, ".."); } @@ -478,7 +478,7 @@ char *file_selector_update(Ted *ted, FileSelector *fs) { // set cwd to this (if no buffers are open, the "open" menu should use the last file selector's cwd) strbuf_cpy(ted->cwd, cwd); } else { - ted_seterr(ted, "Couldn't list directory '%s'.", cwd); + ted_error(ted, "Couldn't list directory '%s'.", cwd); } free(search_term); |