nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects
Scope locals not correct for lua files
Nobody has claimed this yet.
- Dominant language
- Tree-sitter Query
- Stars
- 2.8k
- Forks
- 271
- Avg merge
- 8d 8h
- Merged PRs (30d)
- 1
Description
Describe the bug
When I am at line 20 of the file and I press "vas", the scope highlighted is not correct.
To Reproduce
Steps to reproduce the behavior:
- Go to 'line 20 in the attached file'
- Press "vas"
Expected behavior
Should only select the text within and including function() till end
Output of :checkhealth nvim-treesitter
==============================================================================
nvim-treesitter: require("nvim-treesitter.health").check()
Installation ~
- OK
tree-sitter found 0.20.9 (parser generator, only needed for :TSInstallFromGrammar)
- OK
node found v18.16.0 (only needed for :TSInstallFromGrammar)
- OK
git executable found.
- OK
cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
Version: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.
OS Info:
{
machine = "x86_64",
release = "5.15.133.1-microsoft-standard-WSL2",
sysname = "Linux",
version = "#1 SMP Thu Oct 5 21:02:42 UTC 2023"
} ~
Parser/Features H L F I J
- c ✓ ✓ ✓ ✓ ✓
- lua ✓ ✓ ✓ ✓ ✓
- query ✓ ✓ ✓ ✓ ✓
- vim ✓ ✓ ✓ . ✓
- vimdoc ✓ . . . ✓
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.9.5
Build type: Release
LuaJIT 2.1.1703358377
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "
/home/linuxbrew/.linuxbrew/Cellar/neovim/0.9.5/share/nvim"
Run :checkhealth for more info
Additional context
The file I am referring to:
-- Setup Lazy plugin manager
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
{
"rebelot/kanagawa.nvim",
config = function()
vim.cmd.colorscheme("kanagawa-wave")
end,
},
{
"nvim-treesitter/nvim-treesitter",
lazy = false,
dependencies = {"nvim-treesitter/nvim-treesitter-textobjects"},
config = function()
require("nvim-treesitter.configs").setup({
ensure_installed = {"c", "lua", "vim", "vimdoc", "query" },
auto_install = true,
highlight = {
enable = true,
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<Leader>ss",
node_incremental = "<Leader>si",
scope_incremental = "<Leader>sc",
node_decremental = "<Leader>sd",
},
},
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",
-- You can optionally set descriptions to the mappings (used in the desc parameter of
-- nvim_buf_set_keymap) which plugins like which-key display
["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" },
-- You can also use captures from other query groups like `locals.scm`
["as"] = { query = "@scope", query_group = "locals", desc = "Select language scope" },
},
-- You can choose the select mode (default is charwise "v")
--
-- Can also be a function which gets passed a table with the keys
-- * query_string: eg "@function.inner"
-- * method: eg "v" or "o"
-- and should return the mode ("v", "V", or "<c-v>") or a table
-- mapping query_strings to modes.
selection_modes = {
["@parameter.outer"] = "v", -- charwise
["@function.outer"] = "v", -- linewise
["@class.outer"] = "<c-v>", -- blockwise
},
-- If you set this to `true` (default is `false`) then any textobject is
-- extended to include preceding or succeeding whitespace. Succeeding
-- whitespace has priority in order to act similarly to eg the built-in
-- `ap`.
--
-- Can also be a function which gets passed a table with the keys
-- * query_string: eg "@function.inner"
-- * selection_mode: eg "v"
-- and should return true of false
include_surrounding_whitespace = true,
},
},
})
end,
},
{
"nvim-treesitter/nvim-treesitter-textobjects",
},
})
Attached images:
-
Cursor at line 20
-
Selection I got after pressing "vas"
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the Lua selection at line 20 by pressing "vas", then inspect the locals query in locals.scm and the @scope selection configured with query_group = "locals". Compare the selected range with the expected function() through end range. Done means the scope selection matches that function boundary for the provided file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100