nvim-treesitter-textobjects icon indicating copy to clipboard operation
nvim-treesitter-textobjects copied to clipboard

Text Objects are not being set at all

Open kvietcong opened this issue 3 years ago • 10 comments

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" },
    }
}
-- ...

kvietcong avatar Aug 01 '21 23:08 kvietcong

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

theHamsta avatar Aug 02 '21 05:08 theHamsta

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

kvietcong avatar Aug 02 '21 06:08 kvietcong

@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.

dmatos2012 avatar Aug 05 '21 13:08 dmatos2012

@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

kvietcong avatar Aug 05 '21 17:08 kvietcong

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",
			},
		},
}

johnybx avatar Aug 10 '21 17:08 johnybx

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

kvietcong avatar Aug 12 '21 08:08 kvietcong

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-µ>',
            },
        },
    },
})

n3wborn avatar Sep 14 '21 21:09 n3wborn

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

artemrakov avatar Jan 03 '22 19:01 artemrakov

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

theHamsta avatar Jan 03 '22 19:01 theHamsta

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

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

artemrakov avatar Jan 03 '22 20:01 artemrakov

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.

Nimmidev avatar Sep 25 '22 16:09 Nimmidev

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

SollyCB avatar Nov 20 '22 19:11 SollyCB

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

Nimmidev avatar Nov 20 '22 19:11 Nimmidev

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

SollyCB avatar Nov 20 '22 19:11 SollyCB

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

kiyoon avatar Feb 14 '23 18:02 kiyoon