How to implement lsp extension using steel ? #416
-
|
Hi, As per the FAQ. Lsp extensions will not be implemented in helix core. I want to implement dart Lsp extension called closingLabels. How to do it using steel ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 31 replies
-
|
So you'll want to use the From the docs: Send an lsp command. The Example(define (view-crate-graph)
(send-lsp-command "rust-analyzer"
"rust-analyzer/viewCrateGraph"
(hash "full" #f)
;; Callback to run with the result
(lambda (result) (displayln result))))Specifically for this, I don't know what the result will look like, but then it'll be the responsibility of the client to render those labels. In this case, you could try using the |
Beta Was this translation helpful? Give feedback.
-
|
thanks @mattwparas. now all the closing labels show in the first file (at least). I marked the question as complete because I can't spend more time on it. and this is the last version of my code about the dart lsp closing labels extension: (require-builtin helix/core/text as text.)
(require "helix/misc.scm")
(require "helix/editor.scm")
(require "helix/configuration.scm")
(require "helix/ext.scm")
(require-builtin steel/time)
;; @doc
;; Get the currently focused document as a rope
(define (focused-document->rope)
(let* ([focus (editor-focus)]
[focus-doc-id (editor->doc-id focus)])
(editor->text focus-doc-id)))
;;@doc
;; Converts the currently focused document row and column
;; coordinates to a character offset
(define (current-document-row-col->offset row col)
(define rope (focused-document->rope))
(+ (text.rope-line->char rope row) col))
;;@doc
;; label-info: hashmap label info
;; get end line, end char and label info
;; add some prefix
;; set to inlay
(define (set-label-to-inlay label_info)
(define end_info (hash-get (hash-get label_info 'range) 'end))
(define line (exact (hash-get end_info 'line)))
(define char (exact (hash-get end_info 'character)))
(define label (hash-get label_info 'label))
(log::info! (to-string label_info))
(add-inlay-hint (current-document-row-col->offset line (+ char 1)) (string-append " // " label)))
;;@doc
;; listen for dart lsp event for closingLabels
;; extract labels from the response
;; and run set-label-to-inlay in loop
(define (closing-labels)
(register-lsp-notification-handler "dart"
"dart/textDocument/publishClosingLabels"
(lambda (args)
(define labels (hash-get args 'labels))
(map set-label-to-inlay (reverse labels)))))
(provide closing-labels)
thank you @mattwparas for answering all my questions. and adding the needed functionality. |
Beta Was this translation helpful? Give feedback.
So when you asked this question it wasn't possible, but I've just pushed some additions that let you subscribe to notifications from the lsp:
If you're willing to be on the bleeding edge a bit, you could help me experiment with this since I haven't had a chance to fully test it out. The docs:
Register a callback to be called on LSP notifications sent from the server -> client
that aren't currently handled by Helix as a built in.
Examples