fennel-ls/test/utils/client.fnl
Michele Campeotto 627a02e2c0 Implement basic signatureHelp feature.
This implements the simple form of the signatureHelp feature, which only
displays the signature of the function being typed, without indication
of the active argument.

Active argument detection, while accounting for destructuring to support
each and for special forms turned out to be more involved than expected
and is left for a follow up patch.
2025-03-21 10:42:13 -07:00

103 lines
2.8 KiB
Fennel

(local dispatch (require :fennel-ls.dispatch))
(local message (require :fennel-ls.message))
(local ROOT-PATH "/path/to/test/project")
(local ROOT-URI
(.. "file://" ROOT-PATH))
(local default-encoding :utf-8)
(fn next-id! [self]
(set self.prev-id (+ self.prev-id 1))
self.prev-id)
(fn open-file! [self name text]
(dispatch.handle* self.server
(message.create-notification :textDocument/didOpen
{:textDocument
{:uri name
:languageId "fennel"
:version 1
: text}})))
(fn pretend-this-file-exists! [self name text]
(tset self.server.preload name text))
(fn completion [self file position]
(dispatch.handle* self.server
(message.create-request (next-id! self) :textDocument/completion
{: position
:textDocument {:uri file}})))
(fn definition [self file position]
(dispatch.handle* self.server
(message.create-request (next-id! self) :textDocument/definition
{: position
:textDocument {:uri file}})))
(fn hover [self file position]
(dispatch.handle* self.server
(message.create-request (next-id! self) :textDocument/hover
{: position
:textDocument {:uri file}})))
(fn references [self file position ?includeDeclaration]
(dispatch.handle* self.server
(message.create-request (next-id! self) :textDocument/references
{: position
:textDocument {:uri file}
:context {:includeDeclaration (not (not ?includeDeclaration))}})))
(fn document-highlight [self file position]
(dispatch.handle* self.server
(message.create-request (next-id! self) :textDocument/documentHighlight
{: position
:textDocument {:uri file}})))
(fn signature-help [self file position]
(dispatch.handle*
self.server
(message.create-request (next-id! self)
:textDocument/signatureHelp
{: position
:textDocument {:uri file}})))
(fn rename [self file position newName]
(dispatch.handle* self.server
(message.create-request (next-id! self) :textDocument/rename
{: position
:textDocument {:uri file}
: newName})))
(fn code-action [self file range]
(dispatch.handle* self.server
(message.create-request (next-id! self) :textDocument/codeAction
{: range
:textDocument {:uri file}
:context {:diagnostics []}})))
(fn did-save [self file]
(dispatch.handle* self.server
(message.create-notification :textDocument/didSave
{:textDocument {:uri file}})))
(local client-mt
{:__index {: open-file!
: pretend-this-file-exists!
: completion
: definition
: hover
: references
: document-highlight
: signature-help
: rename
: code-action
: did-save}})
{: client-mt
: default-encoding
: ROOT-URI
: ROOT-PATH}