Skip to content

Commit

Permalink
tree traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
grierson committed Aug 11, 2023
1 parent 2200893 commit 557513e
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 90 deletions.
2 changes: 2 additions & 0 deletions docs/sample.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(defn foo [x y]
(+ x (+ y 1)))
3 changes: 0 additions & 3 deletions fnl/formedit/api/motion.fnl

This file was deleted.

12 changes: 0 additions & 12 deletions fnl/formedit/init.fnl

This file was deleted.

13 changes: 13 additions & 0 deletions fnl/formedit/tree.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(local forms {:list_lit true
:vec_lit true
:map_lit true
:set_lit true
:anon_fn_lit true})

(fn form? [node]
(if (. forms (node:type))
node
(let [child (node:named_child 0)]
(when child (form? child)))))

{: form?}
20 changes: 0 additions & 20 deletions fnl/spec/nfnl/api/motion/motion_spec.fnl

This file was deleted.

5 changes: 3 additions & 2 deletions fnl/spec/nfnl/helper.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
(fn setup [{: cursor : content}]
(vim.api.nvim_buf_set_option 0 :filetype :clojure)
(vim.api.nvim_buf_set_lines 0 0 -1 true [content])
(vim.api.nvim_win_set_cursor 0 cursor))
(vim.api.nvim_win_set_cursor 0 cursor)
(: (vim.treesitter.get_parser 0) :parse))

(fn expect [{: cursor : content}]
(when content
Expand All @@ -13,4 +14,4 @@
(when cursor
(assert.are.same cursor (vim.api.nvim_win_get_cursor 0))))

{: setup : expect}
{: setup : expect : feedkeys}
14 changes: 14 additions & 0 deletions fnl/spec/nfnl/tree/tree_spec.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(local {: describe : it} (require :plenary.busted))
(local h (require :spec.nfnl.helper))
(local tree (require :formedit.tree))
(local assert (require :luassert.assert))
(local ts (require :nvim-treesitter.ts_utils))

(describe "node under cursor"
(fn []
(it "cursor on start of form"
(fn []
(h.setup {:content "(a)" :cursor [1 2]})
(let [node (ts.get_node_at_cursor)
actual (tree.form? node)]
(assert.equals :list_lit (actual:type)))))))
5 changes: 0 additions & 5 deletions lua/formedit/api/motion.lua

This file was deleted.

15 changes: 15 additions & 0 deletions lua/formedit/tree.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 0 additions & 26 deletions lua/spec/nfnl/api/motion/motion_spec.lua

This file was deleted.

20 changes: 0 additions & 20 deletions lua/spec/nfnl/cursor_spec.lua

This file was deleted.

5 changes: 3 additions & 2 deletions lua/spec/nfnl/helper.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions lua/spec/nfnl/tree/tree_spec.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 557513e

Please sign in to comment.