You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Completion only works for packages loaded by default #44
I use languageserver via coc-r-lsp and in combination with nvim-r. Completion works fine for packages that R loads at startup: base, utils, ...
I expected getting completion for the functions provided by a package after loading it, e.g. being offered left_join as a completion option after running library(dplyr), but that doesn't work.
Hi @wngrtn, the language server should know about left_join if the text library(dplyr) appears in an R document that is opened or saved, so could you try that? If you run library(dplyr) in the R console, for example, the language server won't know about it (see #1 (comment)).
@izahn Thank you for the nice reproducible example!
The equivalent process in VSCode works without the second save. That is: open an R file, write library(stringr) at the top, save, write str, don't save, see suggestions starting with str_ from the stringr library. Perhaps this is somehow emacs-specific.
This does not work for me either in JupyterLab-lsp. I guess that this is because the notebooks as presented to the LSP server only exist as "virtual" documents (sent with with textDocumentSync) rather than actual files on the disk.
Currently, some features such as completion and caching user functions are only available via textDocument/didOpen/textDocument/didSave but not textDocument/didChange. The reason for implementing such restriction is to avoid language server being too slow. Perhaps we will need to think again if it is a reasonable tradeoff.
@krassowski Could you comment what are working and what are not working in JupyterLab-lsp?
@randy3k@izahn I think this might be an eglot issue. The README says that eglot ‘Sends textDocument/didChange for groups of edits, not one per each tiny change’. This suggests that when a completion is requested, a didChange may not have been sent and so the language server might not know what characters are at the cursor. That the completion works when the file is saved would seem to support this.
@izahn eglot mentions this in the section contesting it with lsp-model.el, so it might be worth seeing if completions work with that?
We've made didOpen, didChange, and didClose all trigger parse and package resolving (#204, #205) if needed, and we also use the text (if exists) from the requests before reading from file (#197, #198).
I have the same problem using languageserver on Sublime Text 3. I only get suggested completions for base and utils packages. I can however get the completions if I start by the package name. E.g. tidyverse::select()
The issue is not resolved by saving the file after typing the library function.
With Emacs, lsp-mode, and company, only some base package functions have completable arguments. E.g., abbreviate works but the variants of seq do not (e.g., seq.int).
With Emacs, lsp-mode, and company, only some base package functions have completable arguments. E.g., abbreviate works, but the variants of seq do not (e.g., seq.int).
We use formals() to get function arguments for completion. Unfortunately, formals() returns NULL with primitive functions like seq.int and sum. Resolved via #526.
When using quarto documentation, there is an issue with code autocompletion, which does not provide code suggestions for packages other than base r. The same code highlighting also shows only the function name of the base r
I checked completion over LSP on current master. An unsaved R file containing library(dplyr) offered left_join, and a fenced Quarto R cell containing library(stringr) offered str_squish. Closing. Feel free to reopen with the document and client trace if a package named in the document still gives no completions.
Activity
adouzzy commentedon Jul 18, 2019
It works for dplyr::left_join.
You may also consider add library(dplyr) to your .Rprofile
andycraig commentedon Jul 18, 2019
Hi @wngrtn, the language server should know about
left_joinif the textlibrary(dplyr)appears in an R document that is opened or saved, so could you try that? If you runlibrary(dplyr)in the R console, for example, the language server won't know about it (see #1 (comment)).izahn commentedon Jul 26, 2019
I also find that objects exported by packages attached via
library(<pgkname>)are not available for completion. I'm usingeglotin Emacs.andycraig commentedon Jul 27, 2019
@wngrtn @izahn Can you provide steps that can be followed to reproduce this problem?
izahn commentedon Jul 27, 2019
I don't do anything special.
Software Emacs 26.2, latest release of
languageserverfrom CRAN, latest release ofeglotfrom elpa andessfrom melpa.Reproduction steps
emacs -qeglotwithlibrary(stringr)at the top, followed bystrand pressC-M-ito trigger Emacscompletion-at-point.Expected result I should see a bunch of functions starting with
str_exported from thestringrpackage.Actual result I only see completion suggestions from
baseutilsandgraphicspackages, nothing from thestringrpackage. See screen shots below.randy3k commentedon Jul 27, 2019
You need to save the file first to allow the language server to "load" the specific packages.
izahn commentedon Jul 27, 2019
Saving the file doesn't make any difference; the behavior is still exactly as reported above.
izahn commentedon Jul 27, 2019
Oh wait, it does work if I write
strand then save before requesting completions.andycraig commentedon Jul 28, 2019
@izahn Thank you for the nice reproducible example!
The equivalent process in VSCode works without the second save. That is: open an R file, write
library(stringr)at the top, save, writestr, don't save, see suggestions starting withstr_from thestringrlibrary. Perhaps this is somehow emacs-specific.krassowski commentedon Sep 8, 2019
This does not work for me either in JupyterLab-lsp. I guess that this is because the notebooks as presented to the LSP server only exist as "virtual" documents (sent with with textDocumentSync) rather than actual files on the disk.
randy3k commentedon Sep 9, 2019
Currently, some features such as completion and caching user functions are only available via
textDocument/didOpen/textDocument/didSavebut nottextDocument/didChange. The reason for implementing such restriction is to avoid language server being too slow. Perhaps we will need to think again if it is a reasonable tradeoff.@krassowski Could you comment what are working and what are not working in JupyterLab-lsp?
krassowski commentedon Sep 9, 2019
Thanks for the quick replay! Everything works except for imported symbols, and variables & functions defined within the notebook/file.
In particular:
library(ggplot2); geom_<tab>does not work whileggplot2::geom_<tab>doesno visible global function definition "xxx"ggplot2::geom_bar()will show the documentation while hover overgeom_bar()afterlibrary(ggplot2)will not.andycraig commentedon Sep 10, 2019
@randy3k @izahn I think this might be an eglot issue. The README says that eglot ‘Sends
textDocument/didChangefor groups of edits, not one per each tiny change’. This suggests that when a completion is requested, adidChangemay not have been sent and so the language server might not know what characters are at the cursor. That the completion works when the file is saved would seem to support this.@izahn eglot mentions this in the section contesting it with lsp-model.el, so it might be worth seeing if completions work with that?
andycraig commentedon Oct 3, 2019
Open issue on eglot for allowing customisation of the time before changes are sent to the language server: joaotavora/eglot#258
renkun-ken commentedon Feb 17, 2020
Does this problem still persist?
We've made
didOpen,didChange, anddidCloseall trigger parse and package resolving (#204, #205) if needed, and we also use thetext(if exists) from the requests before reading from file (#197, #198).icecat2005 commentedon May 18, 2021
I have the same problem using languageserver on Sublime Text 3. I only get suggested completions for base and utils packages. I can however get the completions if I start by the package name. E.g. tidyverse::select()
The issue is not resolved by saving the file after typing the library function.
jkroes commentedon Feb 21, 2022
With Emacs, lsp-mode, and company, only some base package functions have completable arguments. E.g.,
abbreviateworks but the variants ofseqdo not (e.g.,seq.int).renkun-ken commentedon Feb 22, 2022
We use
formals()to get function arguments for completion. Unfortunately,formals()returnsNULLwith primitive functions likeseq.intandsum. Resolved via #526.GladioFeng commentedon Jan 18, 2024
in vscode, there are some problems.
chmzs commentedon Nov 7, 2024
When using quarto documentation, there is an issue with code autocompletion, which does not provide code suggestions for packages other than base r. The same code highlighting also shows only the function name of the base r
renkun-ken commentedon Nov 19, 2026
I checked completion over LSP on current master. An unsaved R file containing
library(dplyr)offeredleft_join, and a fenced Quarto R cell containinglibrary(stringr)offeredstr_squish. Closing. Feel free to reopen with the document and client trace if a package named in the document still gives no completions.