summaryrefslogtreecommitdiff
path: root/lsp-write.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-09-08 19:16:37 -0400
committerpommicket <pommicket@gmail.com>2023-09-08 19:16:37 -0400
commitf86b0aa1e843646056c08a91fcc759aa0d8a57ba (patch)
tree49a48c14c167df8614996d0c5b8d026fc99fc627 /lsp-write.c
parent100859239a28c2709bb3e2cdce347300a2b763e2 (diff)
better LSP over TCP
Diffstat (limited to 'lsp-write.c')
-rw-r--r--lsp-write.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/lsp-write.c b/lsp-write.c
index 9722a7b..17aef7f 100644
--- a/lsp-write.c
+++ b/lsp-write.c
@@ -334,10 +334,18 @@ static void message_writer_write_and_free(LSP *lsp, JSONWriter *o) {
fprintf(lsp->log, "LSP MESSAGE FROM CLIENT TO SERVER\n%s\n\n", content + header_size);
}
- if (lsp->socket)
- socket_write(lsp->socket, content, strlen(content));
- else
- process_write(lsp->process, content, strlen(content));
+ long long bytes_written = lsp->socket
+ ? socket_write(lsp->socket, content, strlen(content))
+ : process_write(lsp->process, content, strlen(content));
+
+ if (bytes_written == -1) {
+ // we'll handle this properly next time we do a read.
+ if (lsp->log) fprintf(lsp->log, "LSP server closed connection unexpectedly\n");
+ } else if (bytes_written < 0) {
+ if (lsp->log) fprintf(lsp->log, "Error writing to LSP server (errno = %d)\n", errno);
+ } else {
+ assert((size_t)bytes_written == strlen(content));
+ }
str_builder_free(&builder);
}