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

Bug when typing in Markdown after using ESS with LSP #34

Open
shirdekel opened this issue Mar 21, 2022 · 13 comments
Open

Bug when typing in Markdown after using ESS with LSP #34

shirdekel opened this issue Mar 21, 2022 · 13 comments

Comments

@shirdekel
Copy link

When I write in an rmd file everything is normal when editing the markdown parts. After I enter an ESS code chunk, subsequent typing in markdown leads to weird things, including jumping to the end of the buffer and typing in reverse. Editing is fine within the code chunk. The issue persists even after deleting the code chunk but "resets" after I close and reopen the buffer. Also the bug doesn't happen when I don't load the lsp layer in spacemacs so I assume it has something to do with that. I usually have (ess :variables ess-r-backend 'lsp) in the layer config but the issue happens even when I just load ess. Everything is fine in a normal ESS buffer. See below for a demonstration:

poly-r-bug.mov

Setup

  • M1 Pro Macbook
  • macOS 12.0.1
  • emacs-plus@28
@shirdekel shirdekel changed the title Bug when typing after using ESS with LSP Bug when typing in Markdown after using ESS with LSP Mar 21, 2022
@vspinu
Copy link
Contributor

vspinu commented Mar 22, 2022

There is a half backed lsp integration in polymode since recently but I got interrupted and it's not yet fully tested. That might be an issue.

With the most recent polymode you should be able to set polymode-lsp-integration to nil in order to disable it.

I will have a closer look at this issue some time later. Do I understand correctly that R lsp server does understand markdown documents, thus no special integration is needed on polymode side?

@vspinu
Copy link
Contributor

vspinu commented Mar 22, 2022

polymode-lsp-integration should be set before polymode is loaded though

@bryce-carson
Copy link

I experience the same issue, so it's reproducible. 😞

For now I'll disable it as @vspinu suggests.

@shirdekel
Copy link
Author

Thanks @vspinu! I'm not sure how to answer your question about the R lsp server understanding markdown documents unfortunately.

Also, can you clarify how I should set polymode-lsp-integration before polymode is loaded? At the moment I'm loading poly-r in my dotspacemacs-additional-packages list and then using (setq polymode-lsp-integration nil) in my user config.

@bryce-carson
Copy link

bryce-carson commented Mar 28, 2022

Thanks @vspinu! I'm not sure how to answer your question about the R lsp server understanding markdown documents unfortunately.

Also, can you clarify how I should set polymode-lsp-integration before polymode is loaded? At the moment I'm loading poly-r in my dotspacemacs-additional-packages list and then using (setq polymode-lsp-integration nil) in my user config.

As far as I am aware, if you're not using the ESS layer (you're specifying polymode [not poly-r; you need to configure this for polymode - poly-r is dependent on Polymode's configuration]), then the way to set the variable's value before the package is loaded is with the :init property.

You should double-check the documentation, but the way I am doing it is with this line in my user-config; I am not sure it is working, however, because I am using the ESS layer. The layer does not include Polymode, however, so it should be working.

I do still have the lsp layer enabled, and an LSP server is not being started when I enter an R code block in an Rmd document just now, so I can at least say that it is disabled, yes.

  (use-package eglot)

  (use-package polymode
    :init (setq polymode-lsp-integration nil))

I changed the backend to eglot two days ago, and that may have had a fuller effect. I'm not sure. Spacemacs is going through a period of change right now and many layers and core functionality needs code review and refactoring. I'll be contributing to that this summer.

For clarity, this is what I have in my dotspacemacs/layers:

     (;; TODO: configure `lsp', `company', `company-box', etc.
      ess :variables
          ess-r-backend 'eglot
          ess-use-company 't
          markdown-code-block-braces t
          polymode-lsp-integration nil
          :config (add-to-list 'auto-mode-alist '("\\.[rR]md\\'" . poly-markdown+r-mode)))

and this is what I have in my additional-packages list:

                                      ;; Language server
                                      eglot

                                      ;;; Multi-language buffers, incl. Rmd
                                      (polymode :location (recipe :fetcher github :repo "polymode/polymode"))
                                      poly-R
                                      poly-markdown
                                      poly-noweb
                                      poly-org

@shirdekel
Copy link
Author

Thanks! Unfortunately it's still not selectively disabling it in Rmd code chunks even after I load polymode in addition to poly-R as you have, and set polymode-lsp-integration to nil in both the ess variables and using use-package in user-config.

@bryce-carson
Copy link

Thanks! Unfortunately it's still not selectively disabling it in Rmd code chunks even after I load polymode in addition to poly-R as you have, and set polymode-lsp-integration to nil in both the ess variables and using use-package in user-config.

If I recall, you said you're using Spacemacs. In that case, the best place to put the setting of that variable is in dotspacemacs/user-init, which will execute before layers and packages are loaded and initialized, so the variable will have the proper setting at the proper time with this location.

@shirdekel
Copy link
Author

That doesn't seem to work for me either :(
I added the below to dotspacemacs/user-init:

  (require 'use-package)
  (use-package polymode
    :init (setq polymode-lsp-integration nil))

And got (Spacemacs) Error in dotspacemacs/user-init: Cannot open load file: No such file or directory, use-package. I had to require use-pacakge because otherwise I get (Spacemacs) Error in dotspacemacs/user-init: Symbol’s function definition is void: use-package.

@shirdekel
Copy link
Author

Update: I successfully disabled polymode-lsp-integration.

The solution: updating my packages.

I didn't take the "recent" part of what @vspinu said earlier seriously enough:

With the most recent polymode you should be able to set polymode-lsp-integration to nil in order to disable it.

Now for everything to work as expected (and still use LSP within Rmd R code chunks) I just need to do the following:

  1. Disable polymode-lsp-integration in the ess layer config:
     (ess :variables
          ess-r-backend 'lsp
          polymode-lsp-integration nil)
  1. Add poly-R to dotspacemacs-additional-packages

No need to load polymode separately or to use dotspacemacs/user-init.

@maikol-solis
Copy link

maikol-solis commented Apr 29, 2022

I wasn't aware of this issue when I opened this polymode/polymode#316

Setting (setq polymode-lsp-integration nil) solves the issue for me.

shirdekel added a commit to shirdekel/dotfiles that referenced this issue May 12, 2022
@atanasj
Copy link

atanasj commented May 23, 2022

I am getting this too using doomemacs. Setting (setq polymode-lsp-integration nil) worked for me too.

@milanglacier
Copy link

It seems that polymode-lsp-integration only works with lsp-mode? I am using eglot, and editing rmarkdown file is extremely slow, when typing in the code block, emacs frequently hangs for 2-3 seconds to respond to input characters.

@rromoli
Copy link

rromoli commented Jan 22, 2024

I do have the same problem. Using the suggestion of @vspinu I solved it and I'm able to work with Rmd files. I still have issues fontifyng the script. All is white (dark background) and some colored word randomly appear. Any suggestion?

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

7 participants