Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add treesitter queries and tests for commonlisp #76

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ paredit.setup({
-- for new filetypes.
--
-- Defaults to all supported filetypes.
filetypes = { "clojure", "fennel", "scheme" },
filetypes = { "clojure", "fennel", "scheme", "lisp" },

-- This is some language specific configuration. Right now this is just used for
-- setting character lists that are considered whitespace.
Expand Down Expand Up @@ -288,8 +288,13 @@ understand the AST.
Right now `nvim-paredit` has built-in support for:

- `clojure`
- `fennel`
- `scheme`
- `fennel` *
- `scheme` *
- `commonlisp` *

> [!NOTE]
>
> Items marked with `*` only have partial test coverage. Not all language syntax is guaranteed to work.

Take a look at the [Language Queries Spec](./docs/language-queries.md) if you are wanting to add support for languages
not built-in to nvim-paredit, or you want to develop on the existing queries.
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-paredit/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ M.defaults = {
enabled = false,
indentor = require("nvim-paredit.indentation.native").indentor,
},
filetypes = { "clojure", "fennel", "scheme" },
filetypes = { "clojure", "fennel", "scheme", "lisp" },
languages = {
clojure = {
whitespace_chars = { " ", "," },
Expand Down
5 changes: 4 additions & 1 deletion lua/nvim-paredit/treesitter/forms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ end
-- (list_lit
-- (kw_lit)) @form.inner) @form.outer
-- ```
--
--
-- Given the above AST we would want to extract the `list_lit` annotated in
-- this example with @form.inner.
function M.get_form_inner(form_node, opts)
Expand Down Expand Up @@ -140,6 +140,9 @@ local function get_last_anon_child_of_form_head(node)
return current
end
local child = node:child(i)
if not child then
return
end
if child:named() then
return current
end
Expand Down
13 changes: 13 additions & 0 deletions queries/commonlisp/paredit/forms.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
;; We only consider a list_lit a form if it starts with a "(" anonymous node.
;; Some constructs like `(defun)` or `(loop)` are constructed as:
;;
;; (list_lit
;; (defun ...))
;;
;; And in these cases we want to consider the `(defun)` the form inner and
;; 'ignore' the `list_lit` node
(list_lit
open: "(") @form

(loop_macro) @form
(defun) @form
2 changes: 1 addition & 1 deletion tests/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ vim.bo.swapfile = false

require("nvim-treesitter.configs").setup({
parser_install_dir = vim.fn.getcwd() .. "/.build/parsers",
ensure_installed = { "clojure", "fennel", "scheme" },
ensure_installed = { "clojure", "fennel", "scheme", "commonlisp" },
sync_install = true,
})
Loading
Loading