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

Tree sitter highlighting breaks buffer content during search/replace (reproducible example within) #235

Open
jacksonludwig opened this issue Aug 1, 2022 · 0 comments

Comments

@jacksonludwig
Copy link

Ran into an interesting issue. When using evil mode's smart-case search/replace, buffer content's are "corrupted"/out of date if tree-sitter highlighting is enabled.

Here is reproducible example (tested on emacs 28 with native comp, same result on linux and macos):

init.el:

;;; Straight-el boostrap
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

;;; Evil
(straight-use-package 'evil)
(straight-use-package 'evil-collection)
(straight-use-package 'evil-surround)
(straight-use-package 'evil-commentary)

(customize-set-variable 'evil-want-integration t)
(customize-set-variable 'evil-want-keybinding nil)
(customize-set-variable 'evil-respect-visual-line-mode t)
(customize-set-variable 'evil-undo-system 'undo-redo)
(customize-set-variable 'evil-split-window-below t)
(customize-set-variable 'evil-vsplit-window-right t)
(customize-set-variable 'evil-want-C-u-scroll t)

(require 'evil)
(evil-mode 1)
(require 'evil-surround)
(global-evil-surround-mode 1)
(require 'evil-commentary)
(evil-commentary-mode)

(require 'evil-collection)
(evil-collection-init)

;;; Treesitter
(straight-use-package 'tree-sitter)
(straight-use-package 'tree-sitter-langs)
(require 'tree-sitter)
(require 'tree-sitter-langs)

;;; Typescript
(straight-use-package 'typescript-mode)
(require 'typescript-mode)

Example file to see issue (example.ts):

import * as SomeQueries from '../../queries/queries';

export const main = async (): void => {
  try {
    const result = await SomeQueries.query();
  } catch (err) {
    console.log('wowo err');
  }
};

Steps:

  1. emacs -nw example.ts
  2. enable tree-sitter highlighting (e.g. tree-sitter-hl-mode)
  3. execute search and replace utilizing smart case (e.g. :%s/some/other/g)
  4. observe corrupt buffer contents (incorrect highlighting, incomplete replace, etc).
  5. (optional) perform same steps without activating tree-sitter-hl-mode and observe no issue.
@jacksonludwig jacksonludwig changed the title Tree sitter highlighting breaks buffer content during search/replace Tree sitter highlighting breaks buffer content during search/replace (reproducible example within) Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant