fennel-ls/test/references.fnl
Michele Campeotto 9ea6a0965b Add documentSymbol support
Implements LSP documentSymbol request to provide a list of all symbols
defined in the current document. Clients use it to show an outline and
allow to jump to the symbol's definition.
2025-10-22 09:55:55 -05:00

35 lines
1.1 KiB
Fennel

(local faith (require :faith))
(local {: create-client : location-comparator} (require :test.utils))
(local {: null} (require :dkjson))
(local {: view} (require :fennel))
(fn check [file-contents]
(let [{: client : uri : cursor : locations} (create-client file-contents)
[response] (client:references uri cursor)]
(if (not= null response.result)
(do
(table.sort locations location-comparator)
(table.sort response.result location-comparator)
(faith.= locations response.result
(view file-contents)))
(faith.= locations []))))
(fn test-references []
(check "(let [x 10] ==x==|)")
(check "(let [x| 10] ==x==)")
(check "(let [x| 10] ==x== ==x== ==x==)")
(check "(fn x []) ==x|==")
(check "(fn x []) ==|x==")
(check "(fn x| []) ==x==")
(check "(fn x [])| x")
(check "(let [x nil] ==|x.y== ==x.z==)")
(check "(let [x nil] ==x|.y== ==x.z==)")
(check "(let [x nil] x.|y x.z)")
(check "(let [x nil] x.y| x.z)")
(check "(let [x| 10]
(print ==x==)
(let [x :shadowed] x))")
nil)
{: test-references}