Replies: 3 comments 2 replies
-
This is implemented in rust-analyzer as an extension to LSP https://github.com/rust-lang/rust-analyzer/blob/a8d3c46082696b5f7dcf4b960200f2cdc2e48bd8/crates/rust-analyzer/src/lsp_ext.rs LSP extensions aren't supported currently and should most likely wait for a plugin system. So a plugin system exists and someone creates a plugin to implement rust-analyzer's LSP extensions, macro expansion will not be usable with Helix |
Beta Was this translation helpful? Give feedback.
-
This feature is one of the parts, that I'm really missing in helix. Is there a workaround for it for now? |
Beta Was this translation helpful? Give feedback.
-
I got the following to work with Steel support enabled, it calls (require "helix/editor.scm")
(require "helix/commands.scm")
(require "helix/configuration.scm")
(require "helix/misc.scm")
(require "helix/static.scm")
(require-builtin helix/core/text as text.)
(provide shell rust-analyzer-expand-macro)
(define (current-path)
(let* ([focus (editor-focus)]
[focus-doc-id (editor->doc-id focus)])
(editor-document->path focus-doc-id)))
(define (focused-document->rope)
(let* ([focus (editor-focus)]
[focus-doc-id (editor->doc-id focus)])
(editor->text focus-doc-id)))
(define (current-document-cursor-line)
(define rope (focused-document->rope))
(define pos (cursor-position))
(text.rope-char->line rope (cursor-position)))
(define (current-document-cursor-column)
(define rope (focused-document->rope))
(define pos (cursor-position))
(define line (text.rope-char->line rope (cursor-position)))
(define line-start (text.rope-line->char rope line))
(- pos line-start))
;;@doc
;; Expands the macro under the cursor
(define (rust-analyzer-expand-macro)
(send-lsp-command "rust-analyzer"
"rust-analyzer/expandMacro"
(hash
"textDocument" (hash "uri" (string-append "file://" (current-path)))
"position" (hash
"line" (current-document-cursor-line)
"character" (current-document-cursor-column)))
(lambda (result)
(cond
((void? result) (set-error! "No macro found under cursor"))
((hash? result) (begin
(define name (hash-get result 'name))
(define expansion (hash-get result 'expansion))
(vsplit-new)
(set-scratch-buffer-name! (string-append "[" name "]"))
(set-language "rust")
(insert_string expansion)
(goto_file_start))))))) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When I use vscode, I can expand a rust macro like this example.
How can I do the same things in Helix?
Beta Was this translation helpful? Give feedback.
All reactions