rust-lang / rust-lang/rust-mode
rust-mode-treesitter-derive with lsp-mode breaks electric-pair-mode
Nobody has claimed this yet.
- Dominant language
- Emacs Lisp
- Stars
- 1.3k
- Forks
- 198
- PR merge metrics
- No merged PRs in 30d
Description
I noticed that electric-pair-mode stopped working in rust files.
After a few hours of investigation, I was able to narrow it down to using treesitter with rust-mode-treesitter-derive.
The difficulty was, that it breaks it only after the second emacs start (after a fresh install).
Here is a minimal example to reproduce the issue:
(require 'package)
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("gnu" . "https://elpa.gnu.org/packages/")))
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(require 'use-package)
(setq use-package-always-ensure t)
(electric-pair-mode 1) ;; this stops working after the second emacs start
(use-package rust-mode
:hook (rust-mode . lsp-deferred)
:init
(setq rust-mode-treesitter-derive t) ;; this causes the bug
:config
(setq rust-format-on-save nil))
(use-package lsp-mode)
My test protocol was:
- delete
.config/emacs/elpaand.config/emacs/eln-cachefolder (i didn't delete the.config/emacs/treesitterfolder) - Save the above init.el in
.config/emacs/init.el - Open a rust file
emacs main.rs - Wait for the packages to get installed
- Write a few brackets in the rust file to ensure electric-pair is working.
- Close emacs
- Open the same rust file again
- Write a few brackets in the rust file. electric-pair is no more working. 🐛
ls ~/.config/emacs/elpa
lv-20200507.1518 s-20220902.1511
dash-20240510.1327 ht-20230703.558 markdown-mode-20240829.324 spinner-1.7.4
f-20241003.1131 lsp-mode-20241015.1503 rust-mode-20240903.1233 spinner-1.7.4.signed
emacs --version
GNU Emacs 29.4
I'm using Kubuntu 24.04
Contributor guide
No contributing guide indexed for this repository
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
Start with the minimal init.el configuration and reproduce the difference between the first and second Emacs startup, using electric-pair-mode with rust-mode-treesitter-derive and lsp-mode. Then inspect the rust-mode treesitter setup and the electric-pair behavior in the Rust buffer. Done means electric pairing still works after restarting Emacs with the reported configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- emacs, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100