Skip to content

Commit

Permalink
Merge pull request #24 from chiefnoah/master
Browse files Browse the repository at this point in the history
Fixes line encoding to match LSP spec (always `\r\n\r\n`, never `\n\n`)
  • Loading branch information
CFiggers authored Jul 22, 2024
2 parents d3e51d9 + d2f6e83 commit 52dc61f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
12 changes: 4 additions & 8 deletions src/main.janet
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -235,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)))

Expand Down
7 changes: 2 additions & 5 deletions test/test-integration.janet
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down

0 comments on commit 52dc61f

Please sign in to comment.