From 14c5751f3813590ffcbaa4997a7fcbff0af0b4d3 Mon Sep 17 00:00:00 2001 From: Noah Pederson Date: Mon, 15 Jul 2024 22:52:01 -0500 Subject: [PATCH 1/3] Fixes line encoding for strict clients (neovim) The line ending is *always* \r\n as far as neovim is concerned. Futher, these values are effectively constants, no reason to wrap them in function calls. --- src/main.janet | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main.janet b/src/main.janet index ff7f09b..65830f2 100644 --- a/src/main.janet +++ b/src/main.janet @@ -213,19 +213,15 @@ "exit" (on-exit state params) [:noresponse state]))) -(defn line-ending [] - (case (os/which) - :windows "\r\n\r\n" - "\n\n")) - -(defn read-offset [] +(def line-ending "\r\n\r\n") +(def read-offset (case (os/which) :windows 1 2)) (defn write-response [file response] # Write headers - (file/write file (string "Content-Length: " (length response) (line-ending))) + (file/write file (string "Content-Length: " (length response) line-ending)) # Write response (file/write file response) From 71df200073f7193597879919e1b3a4c8cc0ac6ea Mon Sep 17 00:00:00 2001 From: Noah Pederson Date: Sun, 21 Jul 2024 16:47:35 -0500 Subject: [PATCH 2/3] Fix line ending in tests --- test/test-integration.janet | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/test-integration.janet b/test/test-integration.janet index 50b6038..8a55704 100644 --- a/test/test-integration.janet +++ b/test/test-integration.janet @@ -2,14 +2,11 @@ (use judge) -(defn line-ending [] - (case (os/which) - :windows "\r\n\r\n" - "\n\n")) +(def line-ending "\r\n\r\n") (defn write-output [handle response] # Write headers - (:write handle (string "Content-Length: " (length response) (line-ending))) + (:write handle (string "Content-Length: " (length response) line-ending)) # Write response (:write handle (string response (if (string/has-suffix? "\n" response) "" "\n"))) From d2f6e8331a3394d9189e0f2538e525068077e091 Mon Sep 17 00:00:00 2001 From: Noah Pederson Date: Sun, 21 Jul 2024 19:24:24 -0500 Subject: [PATCH 3/3] Fix incorrect missed invocation of read-offset --- src/main.janet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.janet b/src/main.janet index 65830f2..0f21a05 100644 --- a/src/main.janet +++ b/src/main.janet @@ -231,7 +231,7 @@ (defn read-message [] (let [input (file/read stdin :line) - content-length (+ (parse-content-length input) (read-offset)) + content-length (+ (parse-content-length input) read-offset) input (file/read stdin content-length)] (json/decode input)))