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

Julia support #30

Merged
merged 4 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<a href="https://github.com/RRethy/nvim-treesitter-endwise">nvim-treesitter-endwise</a>
</h1>

<h4 align="center">wisely add "end" in ruby, Lua, Vimscript, etc.</h4>
<h4 align="center">wisely add "end" in Ruby, Lua, Vimscript, etc.</h4>

https://user-images.githubusercontent.com/21000943/150613732-442589e2-6b08-4b14-b0a3-47effef0eb28.mov

Expand All @@ -18,7 +18,7 @@ require('nvim-treesitter.configs').setup {

This is a simple plugin that helps to end certain structures automatically. In Ruby, this means adding end after if, do, def, etc. This even works for languages nested inside other, such as Markdown with a Lua code block!

**Supported Languages**: *Ruby*, *Lua*, *Vimscript*, *Bash*, *Elixir*, *Fish*
**Supported Languages**: *Ruby*, *Lua*, *Vimscript*, *Bash*, *Elixir*, *Fish*, *Julia*

# Additional Language Support

Expand All @@ -28,4 +28,6 @@ Please open an issue for new languages, right now I'm open PRs but I won't be im

This is just a rewrite of https://github.com/tpope/vim-endwise to leverage Treesitter so it can be more accurate and work without having to run Neovim's slow regex based highlighting along with nvim-treesitter highlighting.

Special thanks to @jasonrhansen who added support for injected languages, Vimscript, and Julia.
Special thanks to
* [@jasonrhansen](https://www.github.com/jasonrhansen) who added support for injected languages and Vimscript.
* [@simonmandlik](https://www.github.com/simonmandlik) who added support for Julia.
113 changes: 113 additions & 0 deletions queries/julia/endwise.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
((module_definition name: (_) @cursor) @indent @endable
(#endwise! "end"))
((ERROR ["module" "baremodule"] @indent . (_) @cursor)
(#endwise! "end"))

((struct_definition
name: (_) @cursor
(type_parameter_list)? @cursor
(type_clause)? @cursor
) @indent @endable
(#endwise! "end"))

((ERROR "mutable"? "struct" @indent
. (identifier) @cursor
. (curly_expression)? @cursor
. (type_clause)? @cursor
)
(#endwise! "end"))

((quote_statement "quote" @cursor) @indent @endable
(#endwise! "end"))

((ERROR "quote" @indent @cursor)
(#endwise! "end"))

((if_statement condition: (_) @cursor) @indent @endable
(#endwise! "end"))

((ERROR "if" @indent . (_) @cursor)
(#endwise! "end"))

((try_statement "try" @cursor) @indent @endable
(#endwise! "end"))

((ERROR "try" @indent @cursor)
(#endwise! "end"))

((for_statement (for_binding) @cursor) @indent @endable
(#endwise! "end"))

((ERROR "for" (for_binding) @cursor @indent .)
(#endwise! "end"))

((while_statement condition: (_) @cursor) @indent @endable
(#endwise! "end"))

((ERROR "while" @indent . (_) @cursor)
(#endwise! "end"))

((let_statement "let" @cursor
[(identifier) (let_binding)]? @cursor
) @indent @endable
(#endwise! "end"))

((ERROR "let" @cursor @indent
[(identifier) (named_field) (let_binding)]? @cursor @indent .
)
(#endwise! "end"))

((function_definition
name: (_)? @cursor
parameters: (parameter_list)? @cursor
return_type: (identifier)? @cursor
(where_clause)? @cursor
) @indent @endable
(#endwise! "end"))

((ERROR "function" @indent
name: (_)? @cursor
parameters: (parameter_list)? @cursor
return_type: (identifier)? @cursor
(where_clause)? @cursor
)
(#endwise! "end"))

; anonymous function
((ERROR "function" @indent
(parameter_list) @cursor
(where_clause)? @cursor
)
(#endwise! "end"))

((macro_definition
name: (_) @cursor
parameters: (parameter_list)? @cursor
) @indent @endable
(#endwise! "end"))

((ERROR "macro" @indent
. (_) @cursor
. (parameter_list)? @cursor
)
(#endwise! "end"))

((do_clause ["do" (parameter_list)] @cursor) @indent @endable
(#endwise! "end"))

((ERROR ["do" (parameter_list)] @cursor @indent)
(#endwise! "end"))

((compound_statement "begin" @cursor) @endable @indent
(#endwise! "end"))

((ERROR "begin" @cursor @indent)
(#endwise! "end"))

; assignment variant
("->" @indent (identifier) @cursor
(#endwise! "end"))

; eof variant
((identifier) @cursor @indent (ERROR "\n")
(#endwise! "end"))
Loading