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

"replace-match-maybe-edit: Match data clobbered by buffer modification hooks" with lsp-clangd #2241

Open
svenpanne opened this issue Oct 9, 2020 · 16 comments

Comments

@svenpanne
Copy link
Contributor

This is basically the same issue as #1293 and #2081, this time when using query-replace in a C++ buffer with the lsp-clangd backend enabled. To reproduce: Use (c-c++ :variables c-c++-backend 'lsp-clangd) in Spacemacs' dotspacemacs-configuration-layers and do a query-replace. (lsp-mode-20201008.1601)

Probably yet another missing save-match-data, but I've got no clue where to add this...

@yyoncho
Copy link
Member

yyoncho commented Oct 9, 2020

can you provide callstack?

@svenpanne
Copy link
Contributor Author

can you provide callstack?

How can I produce one? The *Messages* buffer contains only a one-line message as seen in the topic of this issue.

@yyoncho
Copy link
Member

yyoncho commented Oct 9, 2020

In the Report bug template there is an instruction on how to do that: https://github.com/emacs-lsp/lsp-mode/blob/master/.github/ISSUE_TEMPLATE/bug_report.md

@svenpanne
Copy link
Contributor Author

Debugger entered--Lisp error: (error "Match data clobbered by buffer modification hooks")
  replace-match("main_reply_queue_" nil t)
  replace-match-maybe-edit("main_reply_queue_" nil t nil (5915 5921 #<buffer main.cc>) nil)
  perform-replace(#("queue_" 0 5 (face font-lock-variable-name-face) 5 6 (rear-nonsticky t face font-lock-variable-name-face)) "main_reply_queue_" t nil nil nil nil nil nil nil nil)
  query-replace(#("queue_" 0 5 (face font-lock-variable-name-face) 5 6 (rear-nonsticky t face font-lock-variable-name-face)) "main_reply_queue_" nil nil nil nil nil)
  funcall-interactively(query-replace #("queue_" 0 5 (face font-lock-variable-name-face) 5 6 (rear-nonsticky t face font-lock-variable-name-face)) "main_reply_queue_" nil nil nil nil nil)
  call-interactively(query-replace nil nil)
  command-execute(query-replace)

@svenpanne
Copy link
Contributor Author

Is any info still missing? I don't think so, but I can't remove the need-info label, because I'm not a project owner...

@svenpanne
Copy link
Contributor Author

The issue is still there with the latest lsp-mode-20201027.850. Is there anything else I can do to help debugging this? A broken query-replace is quite annoying in day-to-day work. 😢 Everything else is very usable, so this is a pity...

@yyoncho
Copy link
Member

yyoncho commented Oct 31, 2020

I am unable to reproduce with the provided info. Also, I do not see lsp-mode in the error callstack. Are you able to reproduce with lsp-start-plain.el?

@svenpanne
Copy link
Contributor Author

I am unable to reproduce with the provided info. Also, I do not see lsp-mode in the error callstack.

Neither do I, but nevertheless I am relatively sure that lsp-mode is the culprit: My current workaround is to switch to any non-lsp-mode (e.g. fundamental), do the query-replace, and switch back to c/c++-mode.

I am using Spacemacs (development branch, updating almost daily) with Emacs 27.1. The relevant snippet from my .spacemacs in the dotspacemacs-configuration-layers part:

     (c-c++ :variables
            c-c++-backend 'lsp-clangd
            c-c++-default-mode-for-headers 'c++-mode
            lsp-clients-clangd-executable "clangd-11"
            company-clang-executable "clang-11"
            clang-format-executable "clang-format-11")

Are you able to reproduce with lsp-start-plain.el?

How can I do that? I'm happy to try, but I've never heard of lsp-start-plain.el...

It really looks like another save-match-data is missing somewhere in lsp-mode, but I can't really guess where. Can you give me some hints/places where I can try to add this?

@yyoncho
Copy link
Member

yyoncho commented Oct 31, 2020

How can I do that? I'm happy to try, but I've never heard of lsp-start-plain.el...

The instructions are in the bug template.

It really looks like another save-match-data is missing somewhere in lsp-mode, but I can't really guess where. Can you give me some hints/places where I can try to add this?

I have no clue.

My current workaround is to switch to any non-lsp-mode (e.g. fundamental), do the query-replace, and switch back to c/c++-mode.

Try lsp-disconnect

The relevant snippet from my .spacemacs in the dotspacemacs-configuration-layers part:

I am using spacemacs as well. The issue might be from a different layer/setting.

@svenpanne
Copy link
Contributor Author

I am quite sure by now that the culprit is the "info box" (don't know what it is called in lsp-mode) popping up in the upper right, showing information like the signature/comments/... of the C++ entity below the cursor:

  • If this pops up during query-replace, the match data is clobbered.
  • If it pops up during repeatedly pressing M-d (kill-word), the kill ring is somehow broken (it did not accumulate the consecutive kills anymore).
  • If it pops up during incremental search (isearch-forward, C-s), it breaks the "search again" functionality of C-s, i.e. you have to press C-s an additional time.

All of this seems to imply that the "info box" incorrectly modifies various global state which should better be left untouched.

To see all those bugs you need a working C++ project where the "info box" actually pops up all the time when the cursor is over a C++ entity. This means that you need a compile-commands.json file, have set the project root correctly etc. This might explain why you don't see the bugs I am describing. But setting up such a project should not be a problem for someone who has written lsp-clangd.el. 😉 I am a bit clueless how to give more hints with a simpler setup, but given the amount of bugs associated with the "info box", it shouldn't be too hard to reproduce on your side. 🤔

One final thing: I update my Spacemacs packages almost every day, so the problem should be reproducible in lsp-mode's HEAD, I guess. Currently my Spacemacs uses .emacs.d/elpa/27.1/develop/lsp-mode-20201103.2013.

@wkenyon
Copy link

wkenyon commented Apr 7, 2021

Still an issue for me on lsp-mode-20210330.1510

@wkenyon
Copy link

wkenyon commented Apr 7, 2021

It seems to be due to the "info box" that svenpanne mentioned.
My workaround is to use these functions to disable the info box (lsp-ui-doc-mode) for all buffers before doing a rename,
and then reenable when I'm done renaming.

(defun w/disable-doc ()
(interactive)
  (setq lsp-ui-doc-enable nil)
  (dolist (buffer (buffer-list))
    (with-current-buffer buffer
      (lsp-ui-doc-mode -1))))

(defun w/enable-doc ()
(interactive)
  (setq lsp-ui-doc-enable 1)
  (dolist (buffer (buffer-list))
    (with-current-buffer buffer
      (lsp-ui-doc-mode 1))))

Hope it's useful to someone. p.s. lsp-mode is amazing, don't know how I lived without it. Thanks for all your hard work on it.

@squiter
Copy link

squiter commented Dec 10, 2021

Just to bring more evidence to the problem, I'm having this exact same problem using lsp-mode for elixir.

I tried this last snippet from @wkenyon but didn't work to me, the only workaround that was working is to change the major mode to something else, do a query-replace and then go back to the elixir-mode.

@squiter
Copy link

squiter commented Apr 29, 2022

Still an issue to me on LSP :: lsp-mode 20220429.647, Emacs 27.2, gnu/linux

@squiter
Copy link

squiter commented May 4, 2022

Hey folks, just to give you some feedback, my problem wasn't related to lsp-mode, was related to the auto-highlight-symbol package.

@ianyepan
Copy link

ianyepan commented Jun 7, 2023

Any updates on this issue? I'm still seeing errors despite disabling lsp-mode (clangd) and highlight-symbol-mode (similar to auto highlight symbol).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants