summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-25 16:04:46 -0500
committerpommicket <pommicket@gmail.com>2022-12-25 16:04:46 -0500
commit66a151badc6fb11b772c814ffcf2434e308923f2 (patch)
treede8c2f7825c96aeb591c2e6b37f33e81edb140a8
parent9ee67ef5097451705b4ae9cb28895f726843cdf3 (diff)
fix problem with jdtls by appending \n to empty files
-rw-r--r--buffer.c11
-rw-r--r--lsp.c2
-rw-r--r--main.c2
3 files changed, 9 insertions, 6 deletions
diff --git a/buffer.c b/buffer.c
index 239dda3..298e8b6 100644
--- a/buffer.c
+++ b/buffer.c
@@ -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;
}
diff --git a/lsp.c b/lsp.c
index 63a0362..b52312f 100644
--- a/lsp.c
+++ b/lsp.c
@@ -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
diff --git a/main.c b/main.c
index 03d8be5..09f12b3 100644
--- a/main.c
+++ b/main.c
@@ -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: