nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects

Incorrect `swap_previous` behavior with Rust code

Open
#889 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Tree-sitter Query
Stars
2.8k
Forks
271
Avg merge
8d 8h
Merged PRs (30d)
1

Description

Describe the bug
swap_previous on Rust snippet results in malformed syntax

To Reproduce
Steps to reproduce the behavior:

  1. Place the cursor on test parameter:
fn main() {
    if let Some(foo) = bar(baz, test, 100) {
                             // ^ here
    }
}
  1. Issue swap_previous
  2. Results in:
fn main() {
    if let , test(foo) = bar(bazSome, 100) {
    }
}

Expected behavior

fn main() {
    if let Some(foo) = bar(test, baz, 100) {
    }
}

Output of :checkhealth nvim-treesitter

Paste the output here

Output of nvim --version

==============================================================================
nvim-treesitter:                                                            ✅

Requirements ~
- ✅ OK Neovim was compiled with tree-sitter runtime ABI version 15 (required >=13).
- ✅ OK tree-sitter-cli 0.26.8 (/opt/homebrew/bin/tree-sitter)
- ✅ OK tar 3.5.3 (/usr/bin/tar)
- ✅ OK curl 8.7.1 (/usr/bin/curl)
  curl 8.7.1 (x86_64-apple-darwin25.0) libcurl/8.7.1 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.12 nghttp2/1.68.1
  Release-Date: 2024-03-27
  Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
  Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM SPNEGO SSL threadsafe UnixSockets

OS Info ~
- machine: arm64
- sysname: Darwin
- release: 25.5.0
- version: Darwin Kernel Version 25.5.0: Mon Apr 27 20:38:56 PDT 2026; root:xnu-12377.121.6~2/RELEASE_ARM64_T6000

Install directory for parsers and queries ~
- /Users/adaszko/.local/share/nvim/site
- ✅ OK is writable.
- ✅ OK is in runtimepath.

Installed languages     H L F I J ~
- ecma
- go                    ✓ ✓ ✓ ✓ ✓
- javascript            ✓ ✓ ✓ ✓ ✓
- jsx
- markdown              ✓ . ✓ ✓ ✓
- markdown_inline       ✓ . . . ✓
- python                ✓ ✓ ✓ ✓ ✓
- rust                  ✓ ✓ ✓ ✓ ✓
- zig                   ✓ ✓ ✓ ✓ ✓

  Legend: [H]ighlights, [L]ocals, [F]olds, [I]ndents, In[J]ections ~

Additional context
Add any other context about the problem here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the malformed result with the Rust snippet and the swap_previous entry point. Trace how swap_previous identifies and rearranges the surrounding Rust syntax, then verify that the result matches the expected argument order without corrupting the if-let expression.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.