diff options
author | pommicket <pommicket@gmail.com> | 2022-12-25 16:04:46 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-25 16:04:46 -0500 |
commit | 66a151badc6fb11b772c814ffcf2434e308923f2 (patch) | |
tree | de8c2f7825c96aeb591c2e6b37f33e81edb140a8 | |
parent | 9ee67ef5097451705b4ae9cb28895f726843cdf3 (diff) |
fix problem with jdtls by appending \n to empty files
-rw-r--r-- | buffer.c | 11 | ||||
-rw-r--r-- | lsp.c | 2 | ||||
-rw-r--r-- | main.c | 2 |
3 files changed, 9 insertions, 6 deletions
@@ -2142,12 +2142,18 @@ Status buffer_load_file(TextBuffer *buffer, char const *filename) { buffer_seterr(buffer, "File too big (size: %zu).", file_size); success = false; } else { - u8 *file_contents = buffer_calloc(buffer, 1, file_size + 1); + u8 *file_contents = buffer_calloc(buffer, 1, file_size + 2); lines_capacity = 4; lines = buffer_calloc(buffer, lines_capacity, sizeof *buffer->lines); // initial lines nlines = 1; size_t bytes_read = fread(file_contents, 1, file_size, fp); if (bytes_read == file_size) { + // append a newline if there's no newline + if (file_contents[file_size - 1] != '\n') { + file_contents[file_size] = '\n'; + ++file_size; + } + char32_t c = 0; for (u8 *p = file_contents, *end = p + file_size; p != end; ) { if (*p == '\r' && p != end-1 && p[1] == '\n') { @@ -2178,8 +2184,7 @@ Status buffer_load_file(TextBuffer *buffer, char const *filename) { buffer_line_append_char(buffer, line, c); } } - } - if (ferror(fp)) { + } else { buffer_seterr(buffer, "Error reading from file."); success = false; } @@ -1,7 +1,7 @@ // print server-to-client communication #define LSP_SHOW_S2C 0 // print client-to-server communication -#define LSP_SHOW_C2S 0 +#define LSP_SHOW_C2S 1 #define write_bool lsp_write_bool @@ -1,7 +1,5 @@ /* @TODO: -- 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 (might be fixed now) - what's wrong with gopls? - make sure "save as" works - more LSP stuff: |