GithubHelp home page GithubHelp logo

rrethy / nvim-treesitter-endwise Goto Github PK

View Code? Open in Web Editor NEW
313.0 5.0 17.0 60 KB

Wisely add "end" in Ruby, Vimscript, Lua, etc. Tree-sitter aware alternative to tpope's vim-endwise

License: MIT License

Lua 20.22% Scheme 15.11% Ruby 64.66%
neovim neovim-plugin treesitter tree-sitter

nvim-treesitter-endwise's People

Contributors

jasonrhansen avatar johnc219 avatar lewisacidic avatar rrethy avatar rspeicher avatar simonmandlik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nvim-treesitter-endwise's Issues

Autoclosed words not reverted back via `u` key

Within existing nesting group the plugin leaves auto-closed end's when history reverted back via u key.

  1. open an existing file, ex:
class A
  def b
   p 1
  end

  def c
    p 2
  end
end
  1. Add a nested group
class A
  module B
    def x
       |
    end  # autoclosed ๐Ÿ‘ 
  end # autoclosed ๐Ÿ‘ 
  def b
   p 1
  end

  def c
    p 2
  end
end
  1. Revert it back via 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

How to install?

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.

Plugin stop working after the first execution in Ruby files

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
}
  1. Open new or an existing Ruby file, start a new class/module. The end part added after <CR> as expected.
  2. Define new method, nothing happens after <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.

Mention nvim-treesitter as a dependency in README

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! ๐Ÿ™

The plugin is not working: somehow `end` is not being inserted

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?

Support ruby `class << self`

When I type class << self in ruby, I would like endwise to add the closing end statement like it does for regular class definitions.

Error on load: nvim-treesitter.ts_utils.is_in_node_range is deprecated: use vim.treesitter.is_in_node_range

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

Screengrab
Screenshot 2023-02-26 at 2 45 09 AM

Additional context
Add any other context about the problem here.

Elixir support

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.

Insert tab before cursor

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:

vim.fn.append(crow, indentation..end_text)

I am not sure that is the most lua-y way to solve this, but what are your thoughts on adding something like that?

Support for Julia language

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!

Lua function elseif also will insert end

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

Fails on <C-C>

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!

Language compatibility shown from TSModuleInfo?

Just a simple question.

My understanding is that this plugin supports lua, vimscript, and ruby only, but :TSModuleInfo says that it is compatible with many other languages. Is this intended or just can I simply ignore it?

image

Create comma after function in map [Lua]

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.

Endwise does not work for bash/vim with nvim-ts-rainbow and nvim-treesitter-context enabled

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:

  1. Start vim with the above init.lua only
  2. Install the plugins using :PackerSync
  3. Restart nvim
  4. Add a function to a lua file, endwise works ok
  5. Add a while loop to a shell script (either ft=sh or ft=bash), endwise does not work
  6. Disable nvim-ts-rainbow and nvim-treesitter-context and repeat, endwise now works for all 4 supported filetypes
  7. Disable only one of the above two conflicting extensions, endwise still does not work

Expected 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

Question: How to run test on this repository?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.