Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@comment.inner not working as expected #628

Open
SamuelBorn opened this issue May 31, 2024 · 2 comments
Open

@comment.inner not working as expected #628

SamuelBorn opened this issue May 31, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@SamuelBorn
Copy link

SamuelBorn commented May 31, 2024

Describe the bug
When using the @comment.inner text object, nothing gets selected.
@comment.outer works fine.

To Reproduce

  1. Add this to your treesitter config.
            textobjects = {
                select = {
                    enable = true,
                    lookahead = true,
                    include_surrounding_whitespace = true,
                    keymaps = {
                        ["ac"] = "@comment.outer",
                        ["ic"] = "@comment.inner",
                    },
                },
            },
  1. open cpp file
  2. go to line with comment "// ..."
  3. use command "cic"
  4. nothing happens

Expected behavior

Line in beginning:
// Change<cursor> this comment

Line after cic:
// <cursor>

Output of :checkhealth nvim-treesitter

nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~
- OK `tree-sitter` found 0.22.5 (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v20.12.2 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
  Version: cc (GCC) 14.1.1 20240522 (Red Hat 14.1.1-4)
- 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 = "6.8.9-300.fc40.x86_64",
  sysname = "Linux",
  version = "#1 SMP PREEMPT_DYNAMIC Thu May  2 18:59:06 UTC 2024"
} ~

Parser/Features         H L F I J
  - bash                ✓ ✓ ✓ . ✓
  - c                   ✓ ✓ ✓ ✓ ✓
  - cmake               ✓ . ✓ ✓ .
  - cpp                 ✓ ✓ ✓ ✓ ✓
  - csv                 ✓ . . . .
  - gitignore           ✓ . . . .
  - glsl                ✓ ✓ ✓ ✓ ✓
  - html                ✓ ✓ ✓ ✓ ✓
  - lua                 ✓ ✓ ✓ ✓ ✓
  - markdown            ✓ . ✓ ✓ ✓
  - python              ✓ ✓ ✓ ✓ ✓
  - rust                ✓ ✓ ✓ ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓
  - yaml                ✓ ✓ ✓ ✓ ✓

  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.10.0
Build type: RelWithDebInfo
LuaJIT 2.1.1707061634
Run "nvim -V1 -v" for more info

Additional context

@comment.outer works fine and like expected:

Line in beginning:
// Change<cursor> this comment

Line after cac:
<cursor>

@SamuelBorn SamuelBorn added the bug Something isn't working label May 31, 2024
@ribru17
Copy link
Member

ribru17 commented Jun 7, 2024

This is a limitation with the parser, right now block and line comments are parsed as the same node, and there is no distinction exposed between // and comment content

@kiyoon
Copy link
Collaborator

kiyoon commented Jun 8, 2024

@comment.inner is just not defined for C and it can be added for more languages.

Currently the implementation is simple without a comment parser. It selects comment.outer with an offset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants