cddesjar · 2022-10-09 18:08
I would like to use eglot with the R language server. However, eglot does not seem to work well with either RMarkdown or Quarto documents as it hangs every time entering when enter a code chunk (up to 5 seconds or so). I am guessing it does this because it disconnects when entering the markdown mode and then needs to reconnect again. I am not sure.
I have two questions.
1. How might I be able to overcome this re-connection(?) issue with quarto or rmarkdown documents and still use eglot?
2. Alternatively, how can I enable eglot just for *.r or *.R files and not just for ess-r-mode?
[deleted] · 2022-10-09 22:41
[deleted]
KaranasToll · 2022-10-10 04:52
Do RMarkdown and quarto have a different major mode than R? If they do, then only add eglot-ensure to the hook for the R major mode.
divinedominion · 2022-10-10 15:40
Do you enable eglot via a hook like `(add-hook 'r-mode-hook #'eglot-mode)`?
In that case, replace that with `(add-hook 'r-mode-hook #'my/r-eglot-mode)` and:
(defun my/r-eglot-mode ()
(pcase (file-name-extension (buffer-file-name))
("r" (eglot-mode))
;; other file extensions?
))
If you just need 1 condition, it's simpler to use:
(defun my/r-eglot-mode ()
(when (eq ("r" (file-name-extension (buffer-file-name))))
(eglot-mode)))
In other words, only conditionally enable eglot for buffers visiting files with matching extensions.
FreeAd7233 · 2022-10-18 07:37
working with rmarkdown file usually uses a `polymode` i.e multiple major mode. So when point is at normal text, it switches markdown mode, and when point is within a code block, it automatically switches to ess-r-mode
FreeAd7233 · 2022-10-18 07:42
The problem is, working with rmarkdown file typically uses a package `polymode` to allow switching major mode to markdown-mode when point is at normal text and to ess-r-mode when point is at a code block.
And when switching between major modes (i.e switching from markdown-mode to ess-r-mode), there will be significant lags.
And once you are activate `eglot`, then all `ess-r-mode` buffer will be managed by eglot. With that being said, once you have a R file in your project and you open this buffer, then eglot will also managed your rmarkdown file because it is also on ess-r-mode when point is within code block. So unless your project only contains rmd file and no r file, then it is not possible to only activate eglot in .R files (I don't find any function in eglot that allows you only activate eglot in certain buffer regardless of major mode)
Plus: eglot doesn't have a function like `eglot-mode`, there are only two relevant functions, `eglot` and `eglot-shutdown`, and as I said, it launches/shutdowns the entire language server for the whole project instead of a single buffer.
I also faces the lag problem, and I think chances are submitting an issue to eglot's repo or polymode's repo to see if there's any improvement space.
Alternative way is to just use ESS without eglot with R, ESS provides dynamic auto-completion (i.e fetches the completion sources from a running R-session instead of statically analyzing your code as lsp would do), and many other features provided by lsp, so you don't have to use lsp with R.
Another alternative is to use `lsp-bridge` instead of eglot. lsp-bridge works smoothly in rmarkdown without any lag.