mirror of
https://github.com/stevearc/aerial.nvim
synced 2024-09-16 14:34:08 +02:00
feat: treesitter support for latex (#137)
This commit is contained in:
parent
45de4de76f
commit
1c666a62a2
5 changed files with 155 additions and 0 deletions
|
@ -279,6 +279,18 @@ M.typescript = {
|
|||
end,
|
||||
}
|
||||
|
||||
M.latex = {
|
||||
postprocess = function(bufnr, item, match)
|
||||
local type_node = (utils.get_at_path(match, "type") or {}).node
|
||||
local base_type = type_node:type()
|
||||
if base_type == "title_declaration" then
|
||||
item.name = "Title: " .. item.name
|
||||
elseif base_type == "author_declaration" then
|
||||
item.name = "Authors: " .. item.name
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
-- tsx needs the same transformations as typescript for now.
|
||||
-- This may not always be the case.
|
||||
M.tsx = M.typescript
|
||||
|
|
|
@ -70,6 +70,15 @@ return {
|
|||
module_definition = "Module",
|
||||
struct_definition = "Class",
|
||||
},
|
||||
latex = {
|
||||
generic_environment = "Class",
|
||||
new_command_definition = "Function",
|
||||
section = "Method",
|
||||
subsection = "Method",
|
||||
subsubsection = "Method",
|
||||
title_declaration = "Field",
|
||||
author_declaration = "Field",
|
||||
},
|
||||
lua = {
|
||||
function_declaration = "Function",
|
||||
function_definition = "Function",
|
||||
|
|
24
queries/latex/aerial.scm
Normal file
24
queries/latex/aerial.scm
Normal file
|
@ -0,0 +1,24 @@
|
|||
(section
|
||||
text: [(curly_group (text) @name) (_)] @name
|
||||
) @type
|
||||
(subsection
|
||||
text: [(curly_group (text) @name) (_)] @name
|
||||
) @type
|
||||
(subsubsection
|
||||
text: [(curly_group (text) @name) (_)] @name
|
||||
) @type
|
||||
(generic_environment
|
||||
begin: (begin
|
||||
name: [(curly_group_text text: (text) @name) (_)] @name
|
||||
)) @type
|
||||
|
||||
(new_command_definition
|
||||
declaration: [(curly_group_command_name command: (command_name) @name) (_)] @name
|
||||
) @type
|
||||
|
||||
(title_declaration
|
||||
text: [(curly_group (text) @name) (_)] @name
|
||||
) @type
|
||||
(author_declaration
|
||||
authors: [(curly_group_author_list (author) @name) (_)] @name
|
||||
) @type
|
86
tests/treesitter/latex_spec.lua
Normal file
86
tests/treesitter/latex_spec.lua
Normal file
|
@ -0,0 +1,86 @@
|
|||
local util = require("tests.test_util")
|
||||
|
||||
describe("treesitter latex", function()
|
||||
it("parses all symbols correctly", function()
|
||||
util.test_file_symbols("treesitter", "./tests/treesitter/latex_test.tex", {
|
||||
{
|
||||
kind = "Function",
|
||||
name = "\\abs",
|
||||
level = 0,
|
||||
lnum = 3,
|
||||
col = 0,
|
||||
end_lnum = 3,
|
||||
end_col = 38,
|
||||
},
|
||||
{
|
||||
kind = "Field",
|
||||
name = "Title: Lorem Ipsum",
|
||||
level = 0,
|
||||
lnum = 5,
|
||||
col = 0,
|
||||
end_lnum = 5,
|
||||
end_col = 19,
|
||||
},
|
||||
{
|
||||
kind = "Field",
|
||||
name = "Authors: John Doe",
|
||||
level = 0,
|
||||
lnum = 6,
|
||||
col = 0,
|
||||
end_lnum = 6,
|
||||
end_col = 17,
|
||||
},
|
||||
{
|
||||
kind = "Class",
|
||||
name = "document",
|
||||
level = 0,
|
||||
lnum = 8,
|
||||
col = 0,
|
||||
end_lnum = 24,
|
||||
end_col = 14,
|
||||
children = {
|
||||
{
|
||||
kind = "Method",
|
||||
name = "First section",
|
||||
level = 1,
|
||||
lnum = 10,
|
||||
col = 0,
|
||||
end_lnum = 20,
|
||||
end_col = 24,
|
||||
children = {
|
||||
{
|
||||
kind = "Method",
|
||||
name = "A subsection",
|
||||
level = 2,
|
||||
lnum = 14,
|
||||
col = 0,
|
||||
end_lnum = 20,
|
||||
end_col = 24,
|
||||
children = {
|
||||
{
|
||||
kind = "Method",
|
||||
name = "A subsubsection",
|
||||
level = 3,
|
||||
lnum = 18,
|
||||
col = 0,
|
||||
end_lnum = 20,
|
||||
end_col = 24,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "This is another subsection",
|
||||
level = 1,
|
||||
lnum = 22,
|
||||
col = 0,
|
||||
end_lnum = 22,
|
||||
end_col = 36,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
end)
|
||||
end)
|
24
tests/treesitter/latex_test.tex
Normal file
24
tests/treesitter/latex_test.tex
Normal file
|
@ -0,0 +1,24 @@
|
|||
& tex
|
||||
|
||||
\newcommand*{\abs}[1]{\left|#1\right|}
|
||||
|
||||
\title{Lorem Ipsum}
|
||||
\author{John Doe}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\section{First section}
|
||||
|
||||
This is a section.
|
||||
|
||||
\subsection{A subsection}
|
||||
|
||||
This is a subsection.
|
||||
|
||||
\subsubsection{A subsubsection}
|
||||
|
||||
This is a subsubsection.
|
||||
|
||||
\section{This is another subsection}
|
||||
|
||||
\end{document}
|
Loading…
Reference in a new issue