Skip to content

Commit 3ea0bd9

Browse files
authored
Merge pull request #25 from CFiggers:dev
v0.0.6
2 parents 52dc61f + 2587cec commit 3ea0bd9

9 files changed

+377
-367
lines changed

CHANGELOG.md

+40
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,46 @@
22
All notable changes to this project will be documented in this file.
33
Format for entires is <version-string> - release date.
44

5+
## 0.0.6 - 2024-07-31
6+
7+
- Core Functionality
8+
- Factored out `line-ending` and `read-offset` functions/values by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/25
9+
- Fix bug with line endings (communication over `stdio` was broken on Widows) by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/25
10+
- Logging
11+
- Now fail gracefully when unable to write to `janetlsp.log.txt` by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/25
12+
- Jump to Definition
13+
- Preliminary work (not completed yet) by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/25
14+
15+
## 0.0.5 - 2024-06-14
16+
17+
- Diagnostics
18+
- Only syntax highlight function signatures in pop-up hover definitions by @CFiggers in [#23](https://github.com/CFiggers/janet-lsp/pull/23)
19+
- Fix bug with publishing diagnostics (was causing last diagnostic warning to not clear when using for e.g. nvim-lsp) by @CFiggers in [#23](https://github.com/CFiggers/janet-lsp/pull/23)
20+
- Tests
21+
- Additional tests and reorganization by @CFiggers in [#23](https://github.com/CFiggers/janet-lsp/pull/23)
22+
23+
## 0.0.4 - 2024-01-26
24+
25+
- Project
26+
- We now install `janet-lsp` as a binscript instead of building an executable at all by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/19
27+
- Formatting
28+
- Tweak to vendored copy of `spork/fmt` by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/19
29+
- Diagnostics
30+
- `eval-buffer` now starts with a clean environment on every evaluation (resolving many consistency issues) by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/19
31+
- Can now push diagnostics to clients that prefer not to request by issuing `testDocument/publishDiagnostics` RPC notifications by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/18
32+
- Completion and Hover Definitions
33+
- Bugs with jpm definitions resolved by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/19
34+
- Signature helps
35+
- Fix bugs in `sexp-at` (off-by-one and crash on unparenthesized top-level forms) by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/19
36+
- RPC
37+
- Can now send properly formatted LSP notifications (in addition to responses, needed for publishing diagnostics)by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/19
38+
- Testing
39+
- Migrated Judge tests from main.janet into a separate fileby @CFiggers in https://github.com/CFiggers/janet-lsp/pull/19
40+
- CLI
41+
- `--debug` flag now works correctlyby @CFiggers in https://github.com/CFiggers/janet-lsp/pull/19
42+
- Misc
43+
- Source code formatting and comment cleanup by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/17
44+
545
## 0.0.3 - 2024-01-09
646

747
- Completion

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ Desirable, but possibly more complicated/difficult features include:
3636

3737
## Clients (i.e. Editors)
3838

39-
Currently, the only editor tested and known working with Janet LSP is [Visual Studio Code](https://code.visualstudio.com/), which you can try/take advantage of by installing the [Janet++](https://github.com/CFiggers/vscode-janet-plus-plus) extension [from the VS Code marketplace](https://marketplace.visualstudio.com/items?itemName=CalebFiggers.vscode-janet-plus-plus).
39+
Currently, Janet LSP is being regularly tested and is expected to work out of the box with two major editors:
40+
41+
- [Visual Studio Code](https://code.visualstudio.com/), which you can try/take advantage of by installing the [Janet++](https://github.com/CFiggers/vscode-janet-plus-plus) extension [from the VS Code marketplace](https://marketplace.visualstudio.com/items?itemName=CalebFiggers.vscode-janet-plus-plus), and
42+
- [Neovim](https://neovim.io/), which ships with support for LSP servers.
4043

4144
Other editors that implement LSP client protocols, either built-in or through editor extensions, include:
4245

4346
- Emacs
44-
- vim/neovim
47+
- Vim
4548
- Sublime Text
4649
- Helix
4750
- Kakoune

project.janet

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(declare-project
22
:name "janet-lsp"
33
:description "A Language Server (LSP) for the Janet Programming Language"
4-
:version "0.0.5"
4+
:version "0.0.6"
55
:dependencies ["https://github.com/janet-lang/spork.git"
66
"https://github.com/CFiggers/jayson.git"
77
"https://github.com/ianthehenry/judge.git"

src/logging.janet

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
(print (:print (dyn :client) output)))
2121

2222
(when (dyn :debug)
23-
(spit "janetlsp.log.txt" (string output "\n") :a)
23+
(try (spit "janetlsp.log.txt" (string output "\n") :a)
24+
([_]))
2425
(file/write stderr (string output "\n"))))

src/main.janet

+34-18
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
(use judge)
1515

16-
(def version "0.0.5")
16+
(def version "0.0.6")
1717

1818
(def jpm-defs (require "../libs/jpm-defs"))
1919

@@ -147,7 +147,7 @@
147147
that this server provides so the client knows what it can request.
148148
``
149149
[state params]
150-
(logging/log (string/format "on-initialize called with these params: %m" params))
150+
(comment (logging/log (string/format "on-initialize called with these params: %m" params)))
151151

152152
(if-let [diagnostic? (get-in params ["capabilities" "textDocument" "diagnostic"])]
153153
(setdyn :push-diagnostics false)
@@ -161,7 +161,9 @@
161161
:workspaceDiagnostics false}
162162
:hoverProvider true
163163
:signatureHelpProvider {:triggerCharacters [" "]}
164-
:documentFormattingProvider true}
164+
:documentFormattingProvider true
165+
# :definitionProvider true
166+
}
165167
:serverInfo {:name "janet-lsp"
166168
:version version}}])
167169

@@ -190,6 +192,21 @@
190192
[state params]
191193
[:ok state :json/null])
192194

195+
# (defn on-document-definition
196+
# ``
197+
# Called by the LSP client to request the location of a symbol's definition.
198+
# ``
199+
# [state params]
200+
# (let [uri (get-in params ["textDocument" "uri"])
201+
# content (get-in state [:documents uri :content])
202+
# {"line" line "character" character} (get params "position")
203+
# {:word define-word :range [start end]} (lookup/word-at {:line line :character character} content)]
204+
# (if-let [[uri line col] ((dyn (symbol define-word) :source-map))]
205+
# [:ok state {:uri uri
206+
# :range {:start {:line (max 0 (dec line)) :character col}
207+
# :end {:line (max 0 (dec line)) :character col}}}]
208+
# [:ok state :json/null])))
209+
193210
(defn handle-message [message state]
194211
(let [id (get message "id")
195212
method (get message "method")
@@ -208,41 +225,38 @@
208225
"textDocument/signatureHelp" (on-document-signature-help state params)
209226
# "textDocument/references" (on-document-references state params) TODO: Implement this? See src/lsp/api.ts:103
210227
# "textDocument/documentSymbol" (on-document-symbols state params) TODO: Implement this? See src/lsp/api.ts:121
228+
# "textDocument/definition" (on-document-definition state params)
211229
"janet/serverInfo" (on-janet-serverinfo state params)
212230
"shutdown" (on-shutdown state params)
213231
"exit" (on-exit state params)
214232
[:noresponse state])))
215233

216-
(def line-ending "\r\n\r\n")
217-
(def read-offset
218-
(case (os/which)
219-
:windows 1
220-
2))
221-
222234
(defn write-response [file response]
223235
# Write headers
224-
(file/write file (string "Content-Length: " (length response) line-ending))
236+
(file/write file (string "Content-Length: " (length response) (case (os/which)
237+
:windows "\n\n" "\r\n\r\n")))
225238

226239
# Write response
227240
(file/write file response)
228241

229242
# Flush response
230-
(file/flush file))
243+
(file/flush file))
231244

232245
(defn read-message []
233-
(let [input (file/read stdin :line)
234-
content-length (+ (parse-content-length input) read-offset)
235-
input (file/read stdin content-length)]
246+
(let [content-length-line (file/read stdin :line)
247+
_ (file/read stdin :line)
248+
input (file/read stdin (parse-content-length content-length-line))]
236249
(json/decode input)))
237250

238251
(defn message-loop [&named state]
252+
(logging/log "Loop enter")
239253
(let [message (read-message)]
240254
(logging/log (string/format "got: %q" message))
241255
(match (handle-message message state)
242256
[:ok new-state & response] (do
243-
(logging/log "successful rpc")
244-
(write-response stdout (rpc/success-response (get message "id") ;response))
245-
(message-loop :state new-state))
257+
(logging/log "successful rpc")
258+
(write-response stdout (rpc/success-response (get message "id") ;response))
259+
(message-loop :state new-state))
246260
[:noresponse new-state] (message-loop :state new-state)
247261

248262
[:error new-state err] (printf "unhandled error response: %m" err)
@@ -280,7 +294,9 @@
280294

281295
(defn start-language-server []
282296
(print "Starting LSP")
283-
(when (dyn :debug) (spit "janetlsp.log.txt" ""))
297+
(when (dyn :debug)
298+
(try (spit "janetlsp.log.txt" "")
299+
([_] (logging/log "Tried to write to janetlsp.log txt, but couldn't"))))
284300

285301
(merge-module root-env jpm-defs nil true)
286302
(setdyn :eval-env (make-env root-env))

0 commit comments

Comments
 (0)