Skip to content

Commit

Permalink
Merge pull request #25 from CFiggers:dev
Browse files Browse the repository at this point in the history
v0.0.6
  • Loading branch information
CFiggers authored Aug 1, 2024
2 parents 52dc61f + 2587cec commit 3ea0bd9
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 367 deletions.
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,46 @@
All notable changes to this project will be documented in this file.
Format for entires is <version-string> - release date.

## 0.0.6 - 2024-07-31

- Core Functionality
- Factored out `line-ending` and `read-offset` functions/values by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/25
- Fix bug with line endings (communication over `stdio` was broken on Widows) by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/25
- Logging
- Now fail gracefully when unable to write to `janetlsp.log.txt` by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/25
- Jump to Definition
- Preliminary work (not completed yet) by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/25

## 0.0.5 - 2024-06-14

- Diagnostics
- Only syntax highlight function signatures in pop-up hover definitions by @CFiggers in [#23](https://github.com/CFiggers/janet-lsp/pull/23)
- 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)
- Tests
- Additional tests and reorganization by @CFiggers in [#23](https://github.com/CFiggers/janet-lsp/pull/23)

## 0.0.4 - 2024-01-26

- Project
- 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
- Formatting
- Tweak to vendored copy of `spork/fmt` by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/19
- Diagnostics
- `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
- 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
- Completion and Hover Definitions
- Bugs with jpm definitions resolved by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/19
- Signature helps
- 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
- RPC
- 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
- Testing
- Migrated Judge tests from main.janet into a separate fileby @CFiggers in https://github.com/CFiggers/janet-lsp/pull/19
- CLI
- `--debug` flag now works correctlyby @CFiggers in https://github.com/CFiggers/janet-lsp/pull/19
- Misc
- Source code formatting and comment cleanup by @CFiggers in https://github.com/CFiggers/janet-lsp/pull/17

## 0.0.3 - 2024-01-09

- Completion
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ Desirable, but possibly more complicated/difficult features include:

## Clients (i.e. Editors)

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).
Currently, Janet LSP is being regularly tested and is expected to work out of the box with two major editors:

- [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
- [Neovim](https://neovim.io/), which ships with support for LSP servers.

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

- Emacs
- vim/neovim
- Vim
- Sublime Text
- Helix
- Kakoune
Expand Down
2 changes: 1 addition & 1 deletion project.janet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(declare-project
:name "janet-lsp"
:description "A Language Server (LSP) for the Janet Programming Language"
:version "0.0.5"
:version "0.0.6"
:dependencies ["https://github.com/janet-lang/spork.git"
"https://github.com/CFiggers/jayson.git"
"https://github.com/ianthehenry/judge.git"
Expand Down
3 changes: 2 additions & 1 deletion src/logging.janet
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
(print (:print (dyn :client) output)))

(when (dyn :debug)
(spit "janetlsp.log.txt" (string output "\n") :a)
(try (spit "janetlsp.log.txt" (string output "\n") :a)
([_]))
(file/write stderr (string output "\n"))))
52 changes: 34 additions & 18 deletions src/main.janet
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

(use judge)

(def version "0.0.5")
(def version "0.0.6")

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

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

(if-let [diagnostic? (get-in params ["capabilities" "textDocument" "diagnostic"])]
(setdyn :push-diagnostics false)
Expand All @@ -161,7 +161,9 @@
:workspaceDiagnostics false}
:hoverProvider true
:signatureHelpProvider {:triggerCharacters [" "]}
:documentFormattingProvider true}
:documentFormattingProvider true
# :definitionProvider true
}
:serverInfo {:name "janet-lsp"
:version version}}])

Expand Down Expand Up @@ -190,6 +192,21 @@
[state params]
[:ok state :json/null])

# (defn on-document-definition
# ``
# Called by the LSP client to request the location of a symbol's definition.
# ``
# [state params]
# (let [uri (get-in params ["textDocument" "uri"])
# content (get-in state [:documents uri :content])
# {"line" line "character" character} (get params "position")
# {:word define-word :range [start end]} (lookup/word-at {:line line :character character} content)]
# (if-let [[uri line col] ((dyn (symbol define-word) :source-map))]
# [:ok state {:uri uri
# :range {:start {:line (max 0 (dec line)) :character col}
# :end {:line (max 0 (dec line)) :character col}}}]
# [:ok state :json/null])))

(defn handle-message [message state]
(let [id (get message "id")
method (get message "method")
Expand All @@ -208,41 +225,38 @@
"textDocument/signatureHelp" (on-document-signature-help state params)
# "textDocument/references" (on-document-references state params) TODO: Implement this? See src/lsp/api.ts:103
# "textDocument/documentSymbol" (on-document-symbols state params) TODO: Implement this? See src/lsp/api.ts:121
# "textDocument/definition" (on-document-definition state params)
"janet/serverInfo" (on-janet-serverinfo state params)
"shutdown" (on-shutdown state params)
"exit" (on-exit state params)
[:noresponse state])))

(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) (case (os/which)
:windows "\n\n" "\r\n\r\n")))

# Write response
(file/write file response)

# Flush response
(file/flush file))
(file/flush file))

(defn read-message []
(let [input (file/read stdin :line)
content-length (+ (parse-content-length input) read-offset)
input (file/read stdin content-length)]
(let [content-length-line (file/read stdin :line)
_ (file/read stdin :line)
input (file/read stdin (parse-content-length content-length-line))]
(json/decode input)))

(defn message-loop [&named state]
(logging/log "Loop enter")
(let [message (read-message)]
(logging/log (string/format "got: %q" message))
(match (handle-message message state)
[:ok new-state & response] (do
(logging/log "successful rpc")
(write-response stdout (rpc/success-response (get message "id") ;response))
(message-loop :state new-state))
(logging/log "successful rpc")
(write-response stdout (rpc/success-response (get message "id") ;response))
(message-loop :state new-state))
[:noresponse new-state] (message-loop :state new-state)

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

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

(merge-module root-env jpm-defs nil true)
(setdyn :eval-env (make-env root-env))
Expand Down
Loading

0 comments on commit 3ea0bd9

Please sign in to comment.