From b01c7b595cabce4704b6e5e6ead61bdebdedc923 Mon Sep 17 00:00:00 2001 From: pommicket Date: Wed, 11 Jan 2023 22:39:00 -0500 Subject: strip ../ in go-to-error if file is not found --- build.c | 21 +++++++++++++++++---- main.c | 2 +- ted.h | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/build.c b/build.c index 0adf0af..dc15144 100644 --- a/build.c +++ b/build.c @@ -9,7 +9,7 @@ void build_stop(Ted *ted) { ted->building = false; ted->build_shown = false; arr_foreach_ptr(ted->build_errors, BuildError, err) { - free(err->filename); + free(err->path); } arr_clear(ted->build_errors); arr_foreach_ptr(ted->build_queue, char *, cmd) { @@ -112,7 +112,7 @@ static void build_go_to_error(Ted *ted) { if (ted->build_error < arr_len(ted->build_errors)) { BuildError error = ted->build_errors[ted->build_error]; // open the file where the error happened - if (ted_open_file(ted, error.filename)) { + if (ted_open_file(ted, error.path)) { TextBuffer *buffer = ted->active_buffer; assert(buffer); // move cursor to error @@ -226,9 +226,22 @@ void build_check_for_errors(Ted *ted) { char *filename = str32_to_utf8_cstr(str32(filename_start, filename_len)); if (filename) { char full_path[TED_PATH_MAX]; - path_full(ted->build_dir, filename, full_path, sizeof full_path); + const char *pfilename = filename; + path_full(ted->build_dir, pfilename, full_path, sizeof full_path); + // if the file does not exist, try stripping ../ + // this can solve "file not found" problems if your build command involves + // cd'ing to a directory inside build_dir + while (fs_path_type(full_path) == FS_NON_EXISTENT + && (str_has_prefix(pfilename, "../") + #if _WIN32 + || str_has_prefix(pfilename, "..\\") + #endif + )) { + pfilename += 3; + path_full(ted->build_dir, pfilename, full_path, sizeof full_path); + } BuildError error = { - .filename = str_dup(full_path), + .path = str_dup(full_path), .pos = {.line = (u32)line_number, .index = (u32)column_number}, .build_output_line = line_idx }; diff --git a/main.c b/main.c index 3342b11..878b0a5 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,6 @@ /* @TODO: -- strip ../ if file is not found (go to error) +- build-command - rust-analyzer bug reports: - bad json can give "Unexpected error: client exited without proper shutdown sequence" - containerName not always given in workspace/symbols diff --git a/ted.h b/ted.h index 6300c0b..f6e8ae4 100644 --- a/ted.h +++ b/ted.h @@ -329,7 +329,7 @@ typedef struct { } FindResult; typedef struct { - char *filename; + char *path; BufferPos pos; u32 build_output_line; // which line in the build output corresponds to this error } BuildError; -- cgit v1.2.3