rrethy / nvim-treesitter-endwise Goto Github PK
View Code? Open in Web Editor NEWWisely add "end" in Ruby, Vimscript, Lua, etc. Tree-sitter aware alternative to tpope's vim-endwise
License: MIT License
Wisely add "end" in Ruby, Vimscript, Lua, etc. Tree-sitter aware alternative to tpope's vim-endwise
License: MIT License
Describe the bug
In ruby:
def f(<cursor>)
Pressing <CR>
gives me:
def f(
end
)
Expected behavior
def f(
)
Within existing nesting group the plugin leaves auto-closed end
's when history reverted back via u
key.
class A
def b
p 1
end
def c
p 2
end
end
class A
module B
def x
|
end # autoclosed ๐
end # autoclosed ๐
def b
p 1
end
def c
p 2
end
end
u
key multiple times. It stops in this state:class A
end # left ๐
def b
p 1
end
def c
p 2
end
end
Please notice the end
left behind. I would expect it reverts back into initial state instead.
Here is short video example: https://user-images.githubusercontent.com/526022/232875662-89ecbd07-6fe1-4c65-8b98-cefd6bafd3c1.mov
Hi! Sorry for the dumb question but I've been trying to install this and I'm not sure how.
I'm using Neovim, and I'm testing LunarVim right now.
Should I install this plugin? Like Plug "RRethy/nvim-treesitter-endwise"
or similar?
I'm asking because I configured it as documented but seems that It's not working.
Hi, long time endwise
user here, poking the nvim
alternatives. Thanks for the plugin!
Describe the bug
Plugin stop execution after the first successful completion.
To Reproduce
Minimal config:
{
'nvim-treesitter/nvim-treesitter',
build = ':TSUpdate',
dependencies = { 'RRethy/nvim-treesitter-endwise' },
config = function()
require('nvim-treesitter.configs').setup({
endwise = {
enable = true,
},
})
end
}
:TSConfigInfo output
{
auto_install = false,
ensure_installed = {},
ignore_install = {},
modules = {
endwise = {
disable = {},
enable = true,
loaded = true,
module_path = "nvim-treesitter.endwise"
},
highlight = {
additional_vim_regex_highlighting = false,
custom_captures = {},
disable = {},
enable = false,
module_path = "nvim-treesitter.highlight"
},
incremental_selection = {
disable = {},
enable = false,
keymaps = {
init_selection = "gnn",
node_decremental = "grm",
node_incremental = "grn",
scope_incremental = "grc"
},
module_path = "nvim-treesitter.incremental_selection"
},
indent = {
disable = {},
enable = false,
module_path = "nvim-treesitter.indent"
}
},
sync_install = false
}
end
part added after <CR>
as expected.<CR>
class A
def test
|
end
Expected behavior
It shoud continue working for all following input.
Additional context
$ nvim --version
NVIM v0.8.3
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by [email protected]
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.8.3/share/nvim"
:checkhealth
nvim-treesitter: require("nvim-treesitter.health").check()
========================================================================
## Installation
- OK: `tree-sitter` found 0.20.7 (parser generator, only needed for :TSInstallFromGrammar)
- OK: `node` found v18.15.0 (only needed for :TSInstallFromGrammar)
- OK: `git` executable found.
- OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
Version: Apple clang version 14.0.3 (clang-1403.0.22.14.1)
- OK: Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.
Installation of additional treesitter-syntax for Ruby doesn't help either.
I am using Lazy as package manager and have trouble figuring out what goes wrong.
I call
require('nvim-treesitter.configs').setup {
endwise = {
enable = true,
},
}
in my init.lua
, leading to the following errors
Error detected while processing /Users/felixwolfsteller/.config/nvim/init.lua:
E5113: Error while calling lua chunk: /Users/felixwolfsteller/.config/nvim/init.lua:235: module 'nvim-treesitter.configs' not found:
no field package.preload['nvim-treesitter.configs']
cache_loader: module nvim-treesitter.configs not found
cache_loader_lib: module nvim-treesitter.configs not found
#[...]
on startup.
Sorry for being somewhat ignorant; I assume that it has to do with the load order. A config example specific for lazy users (coughcough) would be great! ๐
I am having a hard time making this plugin working. :TSModuleInfo
shows endwise is loaded and active for the current filetype (lua, ruby, etc.), but it is not inserting end
automatically for me. What am I doing wrong or how can I troubleshoot?
I am on neovim 0.7.0 nightly, NVIM v0.7.0-dev+953-gd0493d110 (tried on 0.6.2 but it's the same).
In my treesitter config, I have endwise enabled:
require'nvim-treesitter.configs'.setup {
-- one of "all", "maintained" (parsers with maintainers), or a list of languages
ensure_installed = "maintained",
-- List of parsers to ignore installing
ignore_install = { },
highlight = {
enable = false,
},
playground = {
...
},
-- nvim-treesitter-endwise
endwise = {
enable = true,
},
}
I have ruby, lua, vimscript parser for treesitter installed, and confirm that TS is working fine from :TSPlaygroundToggle
.
Given the plugin/module activated, however, I never see this working: on a new ruby file, I type module Foo
and then hit <CR>
. I expect end
would be inserted, but nothing happened.
module Foo
|
Any hints or insight on how I could troubleshoot/debug the plugin?
When I type class << self
in ruby, I would like endwise to add the closing end
statement like it does for regular class definitions.
Seeing this deprecation message on load, also not getting it to function as shown in the demo
nvim-treesitter.ts_utils.is_in_node_range is deprecated: use vim.treesitter.is_in_node_range
I'm using Lazy.nvim and have added the configs:
endwise = {
enable = true,
},
Expected behavior
endwise loads without errors and works
Additional context
Add any other context about the problem here.
I was looking into adding Elixir support for this plugin, however I'm not very familiar with Treesitter query syntax.
Looking at an Elixir file in Treesitter playground, it doesn't look to me like there's a difference between an unclosed def foo do
node and a closed one:
An already-closed node (def foo do \n end
)
call [16, 4] - [17, 7]
target: identifier [16, 4] - [16, 6]
arguments [16, 7] - [16, 10]
identifier [16, 7] - [16, 10]
do_block [16, 11] - [17, 7]
while an unclosed node (def foo do
) shows:
call [19, 4] - [20, 5]
target: identifier [19, 4] - [19, 6]
arguments [19, 7] - [19, 10]
identifier [19, 7] - [19, 10]
do_block [19, 11] - [20, 5]
I'd appreciate knowing if this is even possible before pursuing it further.
This is not a software bug, but a request to improve the documentation.
I thought this plugin was a replacement for tpope/vim-endwise
, and was wondering why (when I followed the quick-start instructions) I was not getting any functionality.
If you are not using tree-sitter, when you press after a ruby class/if/def etc. will indent the cursor (|
):
it "works" do
|
end
Currently with tree-sitter, that does not work. However, I think we could make it work with this plugin.
I was able to get it to work by adding:
vim.api.nvim_put({ string.rep(' ', vim.api.nvim_buf_get_option(0, 'tabstop')) }, 'c', true, true)
Right after this line:
I am not sure that is the most lua-y way to solve this, but what are your thoughts on adding something like that?
Hi,
This seems a great plugin. Could it be implemented for Julia as well? The syntax is very similar to the Ruby one.
Thank you!
nvim-treesitter-endwise is causing a segfault using Neovim @ HEAD. See: neovim/neovim#18079 for the details.
I have <CR>
mapped to <Plug>delimitMateCR
in insert mode, which somehow causes the end
block to be inserted twice (tested w/ Lua files).
Here's a video. Can you reproduce the behaviour?
Before:
if true then
print('true')
elseif true then |
else
print('false')
end
Input :
if true then
print('true')
elseif true then
|
end
else
print('false')
end
For better or worse, I use <C-C>
instead of escape most of the time. Using that produced this error:
Error executing vim.on_key Lua callback: vim.lua:498: Error executing 'on_key' with ns_ids '2'
Messages: Keyboard interrupt
stack traceback:
[C]: in function 'error'
vim.lua:498: in function <vim.lua:485>
Let me know if I can do anything to help debug!
Is your feature request related to a problem? Please describe.
I would like to jump to matching do
/end
pairs with %
in neovim.
Describe the solution you'd like
There is prior art for this concept: https://www.vim.org/scripts/script.php?script_id=290, I think powering this functionality on treesitter would be killer.
Describe the bug
When inside a map in Lua and adding another key, no comma is inserted after the def ... end
Expected behavior
I'd expect a comma to be inserted as otherwise I need to manually go to behind the function I created and insert it which is cumbersome.
Describe the bug
When I have nvim-treesitter-endwise, nvim-treesitter-context and nvim-ts-rainbow enabled, then endwise does not work for the filetypes sh
and vim
. It works for ruby and lua.
I have traced down the behavior to this init.lua:
-- Vim Plug Installation {{{
local packer_path = os.getenv('HOME') .. '/.local/share/nvim/site/pack/packer/start/packer.nvim/'
local f = io.open(packer_path .. "lua/packer.lua", "r")
if f == nil then
local result = os.execute("git clone --depth 1 https://github.com/wbthomason/packer.nvim " ..
"~/.local/share/nvim/site/pack/packer/start/packer.nvim")
end
function run_packer()
require("packer").sync()
end
vim.api.nvim_create_augroup("PackerAutoInstall", {clear=true})
vim.api.nvim_create_autocmd("VimEnter", {group="PackerAutoInstall", callback=run_packer})
-- }}}
plugins = {
{url='https://github.com/wbthomason/packer.nvim', enable=true},
{
description = 'Nvim Treesitter configurations and abstraction layer',
url = 'https://github.com/nvim-treesitter/nvim-treesitter',
enabled = true,
on_update = ":TSUpdate",
config = function() require('nvim-treesitter.configs').setup ({
ensure_installed = {"bash", "bibtex", "c", "comment", "cpp", "css", "commonlisp", "dockerfile",
"html", "http", "java", "javascript", "json", "latex", "lua", "make", "markdown",
"php", "phpdoc", "python", "r", "regex", "rst", "scss", "toml", "vim", "yaml"},
rainbow = {
enable = true,
extended_mode = true, -- Also highlight non-bracket delimiters like html tags
},
endwise = {
enable = true,
},
}) end,
},
{
description = 'Rainbow parentheses for neovim using tree-sitter',
url = 'https://github.com/romgrk/nvim-treesitter-context',
enabled = true,
config = function() require'treesitter-context'.setup({
patterns = {
default = {
'class',
'function',
'method',
'for',
'while',
'if',
'switch',
'case',
},
},
}) end
},
{
description = 'Rainbow parentheses for neovim using tree-sitter',
url = 'https://github.com/p00f/nvim-ts-rainbow',
enabled = true,
},
{
description = 'Wisely add "end" in Ruby, Vimscript, Lua, etc. Tree-sitter aware',
url = 'https://github.com/RRethy/nvim-treesitter-endwise',
enabled = true,
},
-- }}}
}
function install_plugins(plugins)
for i, plugin in ipairs(plugins) do
require("packer").use({
plugin.url,
branch=plugin.branch,
disable=not plugin.enabled,
requires=plugin.dependencies,
run=plugin.on_update,
config=plugin.config,
})
end
end
packer = require("packer")
packer.reset()
packer.init({compile_path = packer_db})
install_plugins(plugins)
To Reproduce
Steps to reproduce the behavior with a minimal init.lua:
nvim-ts-rainbow
and nvim-treesitter-context
and repeat, endwise now works for all 4 supported filetypesExpected behavior
Endwise should work.
Screengrab
If applicable, add screengrabs which record any weird behaviour.
Additional context
neovim --version
:
NVIM v0.7.0-dev+1186-g83fc91433 Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/yaourt-tmp-nikos/aur-neovim-git/src/build/config -I/tmp/yaourt-tmp-nikos/aur-neovim-git/src/neovim-git/src -I/usr/include -I/tmp/yaourt-tmp-nikos/aur-neovim-git/src/build/src/nvim/auto -I/tmp/yaourt-tmp-nikos/aur-neovim-git/src/build/include
Compiled by my-machine
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/share/nvim"
Run :checkhealth for more info
Describe the bug
nvim-treesiter module support will be removed
Hi there. It's not a bug. I have a question and need guidance on how to run tests in this repository.
I tried running ruby tests/runner.rb
, but encountered an error related to a missing module nvim-treesitter
. The error message indicates that the module cannot be found.
...
nvim-treesitter-endwise/tests/init.lua:5: module 'nvim-treesitter.configs' not found
...
Could someone please provide instructions if possible? Thank you!
I tried running the command on both Linux (Manjaro) and macOS.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.