fennel-ls/test/document-highlight.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

50 lines
1.6 KiB
Fennel

(local faith (require :faith))
(local {: create-client : range-comparator} (require :test.utils))
(local {: null} (require :dkjson))
(local {: view} (require :fennel))
(fn check [file-contents]
(let [{: client : uri : cursor : highlights} (create-client file-contents)
[response] (client:document-highlight uri cursor)]
(if (not= null response.result)
(do
(table.sort highlights range-comparator)
(table.sort response.result range-comparator)
;; Override kind in the result because utils.parse-markup doesn't have
;; a way to express it. The ranges are more important.
(each [_ v (ipairs response.result)]
(set v.kind 1))
(faith.= highlights response.result
(view file-contents)))
(faith.= highlights []))))
(fn test-document-highlights []
(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)
(fn test-multiple-files []
(check
{:foo.fnl "(fn target []
nil)
{: target}"
:main.fnl "(local foo (require :foo))
(foo.targe|t)"})
nil)
{: test-document-highlights
: test-multiple-files}