Skip to content

Commit

Permalink
Support fish shell (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisacidic authored Jun 28, 2023
1 parent 944b0d8 commit 9298b3a
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
**Supported Languages**: *Ruby*, *Lua*, *Vimscript*, *Bash*, *Elixir*, *Fish*

# Additional Language Support

Expand Down
15 changes: 15 additions & 0 deletions queries/fish/endwise.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
((function_definition name: (_) option: (_) @cursor) @endable @indent (#endwise! "end" ))
((function_definition name: (_) @cursor) @endable @indent (#endwise! "end" ))
((while_statement condition: (_) @cursor) @endable @indent (#endwise! "end"))
((for_statement variable: (_) value: (_) @cursor) @endable @indent (#endwise! "end"))
((begin_statement (_) @cursor) @endable @indent (#endwise! "end"))
((switch_statement (_) @cursor) @endable @indent (#endwise! "end"))
((if_statement condition: (_) @cursor) @endable @indent (#endwise! "end"))

((ERROR ("function" . (_)+ @cursor) @indent) (#endwise! "end" ))
((ERROR ("while" . (_) @cursor) @indent) (#endwise! "end"))
((ERROR ("for" . (_) . "in" . (_) @cursor) @indent) (#endwise! "end"))
((ERROR ("begin" @cursor) @indent) (#endwise! "end"))
((ERROR ("switch" . (_) @cursor) @indent) (#endwise! "end"))
((ERROR ("if" . (_) @cursor) @indent) (#endwise! "end"))

98 changes: 98 additions & 0 deletions tests/endwise/fish.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
config({
extension: "fish",
overrides: <<~INIT_LUA
vim.opt.expandtab = true
vim.opt.shiftwidth = 2
INIT_LUA
})

test "fish, global function", <<~END
-function foo█
+function foo
+
+end
END

test "fish, global function with options", <<~END
-function foo --on-signal WINCH█
+function foo --on-signal WINCH
+
+end
END

test "fish, while loop", <<~END
-while true█
+while true
+
+end
END

test "fish, for loop generic clause", <<~END
-for i in (seq 1 5)█
+for i in (seq 1 5)
+
+end
END

test "fish, if stmt", <<~END
-if foo█
+if foo
+
+end
END

test "fish, nested global function", <<~END
-function foobarbaz
- function foo█
-end
+function foobarbaz
+ function foo
+
+ end
+end
END

test "fish, nested global function with options", <<~END
-function foobarbaz --on-signal WINCH
- function foo█
-end
+function foobarbaz --on-signal WINCH
+ function foo
+
+ end
+end
END

test "fish, nested global function with inner options", <<~END
-function foobarbaz
- function foo --on-signal WINCH█
-end
+function foobarbaz
+ function foo --on-signal WINCH
+
+ end
+end
END

test "fish, nested while loop", <<~END
-function foobarbaz
- while true█
-end
+function foobarbaz
+ while true
+
+ end
+end
END

test "fish, nested for loop loop", <<~END
-function foobarbaz
- for i in (seq 1 5)█
-end
+function foobarbaz
+ for i in (seq 1 5)
+
+ end
+end
END

0 comments on commit 9298b3a

Please sign in to comment.