nvim-treesitter / nvim-treesitter-textobjects

Apache License 2.0
2.21k stars 200 forks source link

Text Objects are not being set at all #96

Closed kvietcong closed 1 year ago

kvietcong commented 3 years ago

Describe the bug The text objects I set are non-existent. When I try the bindings within the configuration (at the bottom), nothing happens. There's no error messages or anything like that. It is as if they weren't set. Thanks for any help

Expected behavior I was expecting the text objects to be selected, cleared, etc when I acted upon them

Output of :checkhealth nvim_treesitter

health#nvim_treesitter#check ======================================================================== ## Installation - WARNING: `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall) - OK: `node` found v16.4.1 (only needed for :TSInstallFromGrammar) - OK: `git` executable found. - OK: `gcc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" } - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI. ## Parser/Features H L F I J - python ✓ ✓ ✓ ✓ ✓ - haskell ✓ . . . ✓ - yaml ✓ ✓ ✓ ✓ ✓ - javascript ✓ ✓ ✓ ✓ ✓ - commonlisp ✓ ✓ ✓ . . - json ✓ ✓ ✓ ✓ . - rust ✓ ✓ ✓ ✓ ✓ - c ✓ ✓ ✓ ✓ ✓ - html ✓ ✓ ✓ ✓ ✓ - css ✓ . ✓ ✓ ✓ - lua ✓ ✓ ✓ ✓ ✓ Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections +) multiple parsers found, only one will be used x) errors found in the query, try to run :TSUpdate {lang}

Output of nvim --version

NVIM v0.6.0-dev+98-ga5c25e4f3
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe /DWIN32 /D_WINDOWS /W3 -DNVIM_TS_HAS_SET_MATCH_LIMIT /MD /Zi /O2 /Ob1 /DNDEBUG /W3 -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -DWIN32 -D_WIN32_WINNT=0x0600 -DINCLUDE_GENERATED_DECLARATIONS -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -ID:/a/neovim/neovim/build/config -ID:/a/neovim/neovim/src -ID:/a/neovim/neovim/nvim-deps/usr/include -ID:/a/neovim/neovim/build/src/nvim/auto -ID:/a/neovim/neovim/build/include
Compiled by runneradmin@fv-az152-272

Features: -acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM\sysinit.vim"
  fall-back for $VIM: "C:/Program Files/nvim/share/nvim"

Run :checkhealth for more info

Additional context My Text Objects Configuration

-- ...
textobjects = {
    lsp_interop = { enable = true },
    select = {
        enable = true,
        keymaps = {
            ["al"] = "@loop.outer",
            ["il"] = "@loop.inner",
            ["ab"] = "@block.outer",
            ["ib"] = "@block.inner",
            ["ac"] = "@class.outer",
            ["ic"] = "@class.inner",
            ["af"] = "@function.outer",
            ["if"] = "@function.inner",
            ["ap"] = "@parameter.outer",
            ["ip"] = "@parameter.inner",
            ["ak"] = "@comment.outer"
        },
    },
    swap = {
        enable = true,
        swap_next = {
            ["<Leader>cs"] = "@parameter.inner",
        },
        swap_previous = {
            ["<Leader>cs"] = "@parameter.inner",
        },
    },
    move = {
        enable = true,
        set_jumps = true,
        goto_next_start = { ["]]"] = "@function.outer" },
        goto_next_end = { ["]}"] = "@function.outer" },
        goto_previous_start = { ["[["] = "@function.outer" },
        goto_previous_end = { ["[{"] = "@function.outer" },
    }
}
-- ...
theHamsta commented 3 years ago

So none of the combinations daf (delete a function) vaf (select a function) would work for? Not even the go-to commands?

kvietcong commented 3 years ago

Yes, none of those work. It just puts me into visual mode (no cursor movement) or waits for a text object. The go tos dont work either

dmatos2012 commented 3 years ago

@kvietcong did you fix this? It happens to me as well sometimes, although for me swap doenst work, but move does. I dont think I changed anything.

kvietcong commented 3 years ago

@dmatos2012 Sadly I have not been able to fix this. I haven't tested this yet but this might be a Windows problem. I'll have to test it out on Linux later

johnybx commented 3 years ago

I have same problem. I defined mapping with config below but swap and lsp_interop are not defined at all - cannot see it in mappings. select and Only move seem to work fine :thinking:

    textobjects = {
        select = {
            enable = true,

            -- Automatically jump forward to textobj, similar to targets.vim
            lookahead = true,

            keymaps = {
                -- You can use the capture groups defined in textobjects.scm
                ["af"] = "@function.outer",
                ["if"] = "@function.inner",
                ["ac"] = "@class.outer",
                ["ic"] = "@class.inner",
            },
        },
        move = {
            enable = true,
            set_jumps = true, -- whether to set jumps in the jumplist
            goto_next_start = {
                ["]m"] = "@function.outer",
                ["]]"] = "@class.outer",
            },
            goto_next_end = {
                ["]M"] = "@function.outer",
                ["]["] = "@class.outer",
            },
            goto_previous_start = {
                ["[m"] = "@function.outer",
                ["[["] = "@class.outer",
            },
            goto_previous_end = {
                ["[M"] = "@function.outer",
                ["[]"] = "@class.outer",
            },
        },
        swap = {
            enable = true,
            swap_next = { ["<leader>z"] = "@parameter.inner" },
            swap_previous = { ["<leader>Z"] = "@parameter.inner" },
        },
        lsp_interop = {
            enable = true,
            border = "none",
            peek_definition_code = {
                ["<leader>df"] = "@function.outer",
                ["<leader>dF"] = "@class.outer",
            },
        },
}
kvietcong commented 3 years ago

Yeah even after removing swap and lsp_interop, it sadly doesn't work

n3wborn commented 3 years ago

Same for me, lsp_interop peek_definition doesn't work since many days now :/ selection is ok though

--- https://github.com/nvim-treesitter/nvim-treesitter

require('nvim-treesitter.configs').setup({
    ensure_installed = 'maintained',
    highlight = {
        enable = true,
    },
    playground = {
        enable = false,
    },
    indent = {
        enable = true,
    },
    textobjects = {
        lsp_interop = {
            enable = true,
            border = 'rounded',
            peek_definition_code = {
                ['df'] = '@function.outer',
                ['dF'] = '@class.outer',
            },
        },
        select = {
            enable = true,
            lookahead = true,
            keymaps = {
                ['af'] = '@function.outer',
                ['if'] = '@function.inner',
                ['ac'] = '@class.outer',
                ['ic'] = '@class.inner',
            },
        },
        move = {
            enable = true,
            set_jumps = true,
            goto_next_start = {
                [']m'] = '@function.outer',
                [']]'] = '@class.outer',
            },
            goto_next_end = {
                [']M'] = '@function.outer',
                [']['] = '@class.outer',
            },
            goto_previous_start = {
                ['[m'] = '@function.outer',
                ['[['] = '@class.outer',
            },
            goto_previous_end = {
                ['[M'] = '@function.outer',
                ['[]'] = '@class.outer',
            },
        },
    },
    autopairs = {
        enable = true, -- check for autopairs (see nvim-autopairs)
    },
    -- https://github.com/nvim-treesitter/nvim-treesitter-refactor
    refactor = {
        highlight_definitions = {
            enable = true,
        },
        smart_rename = {
            enable = true,
            keymaps = {
                smart_rename = 'R',
            },
        },
        navigation = {
            enable = true,
            keymaps = {
                goto_definition_lsp_fallback = 'gnd',
                list_definitions = 'gnD',
                list_definitions_toc = 'gO',
                goto_next_usage = '<a-*>',
                goto_previous_usage = '<a-µ>',
            },
        },
    },
})
artemrakov commented 2 years ago

Did anyone manage to solve this bug? Select does not work for me as well

theHamsta commented 2 years ago

@artemrakov Even, :TSTextobjectSelect @function.outer wouldn't work for you?

artemrakov commented 2 years ago

Sorry, my bad. Didn't install TreeSitter parser (TSIntall) :D. After installation, it worked.

:TSTextobjectSelect @function.outer actually showed me the error. Thanks @theHamsta

Nimmidev commented 2 years ago

I have the same problem. With the defaullt config taken from the README neither daf, dif, vaf or any other binding works. Running :TSTextobjectSelect @function.outer directly does work as intended.

SollyCB commented 2 years ago

^^ Yep, same issue. Command works. But binds from the readme are broke.

Nimmidev commented 2 years ago

@sozomon i had the problem because i put the config in the lua/plugin directory instead of after/plugin. Now everything works.

SollyCB commented 2 years ago

@Nimmidev Fixed after reinstalling treesitter cargo cli. Idk why it did not work on last reinstall

kiyoon commented 1 year ago

Closing as many people resolved the issue. Feel free to reopen

itse4elhaam commented 1 day ago

I came across this issue too, following this guide helped me install it correctly for lazy.nvim.