Skip to content

Copilot doesn't know about files loaded at RStudio launch time until you make changes to them #15895

Closed

Description

@gtritchie

System details

RStudio Edition : Desktop or Server
RStudio Version : 2024.12.1+563 up through latest Mariposa Orchid `main`
OS Version      : any
R Version       : any

Steps to reproduce the problem

  • add COPILOT_LOG_LEVEL=3 to ~/.Renviron
  • launch RStudio
  • open an existing script (e.g. "foo.R")
  • close RStudio
  • launch RStudio

Describe the problem in detail

  • RStudio loads "foo.R" when it launches, as it should
  • in the various Copilot messages spewed into the Console will be:
RESPONSE
------------------
{"jsonrpc":"2.0","id":"060b3e35-108c-4ab5-805d-65ae72226c35","error":{"code":-32602,"message":"Document for URI could not be found: file:///Users/gary/foo/foo.R, URIs of the known document are: "}}
------------------
  • no completions will show in that file until you make an edit to it

Describe the behavior you expected

  • no error, and completions work without making an edit

The problem is we aren't notifying Copilot (via textDocument/didOpen) about files that get opened automatically at RStudio launch time; once changes are made to the file it will start working and show completions.

Here's the code that currently suppresses this error:

// Handle 'document could not be found' errors up-front. These errors
// will normally self-resolve after the user starts editing the document,
// so it should suffice just to indicate that no completions are available.
int code = error.code;
if (code == CopilotConstants.ErrorCodes.DOCUMENT_NOT_FOUND)
{
events_.fireEvent(new CopilotEvent(CopilotEventType.COMPLETION_RECEIVED_NONE));

QA Notes

Once you have opened a PR, add additional information for QA on how to validate the change, paying special attention to the level of risk, adjacent areas that could be affected by the change, and any important contextual information not present in the original description.

  • I have read the guide for submitting good bug reports.
  • I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting an RStudio crash, I have included a diagnostics report.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

Activity

  1. added
    new
    copilot
    on Apr 9, 2025
  2. added theissue type on Apr 9, 2025
  3. removed
    new
    on Apr 9, 2025
  4. added this to the Backlog milestone on Apr 14, 2025
  5. self-assigned this
    on May 20, 2025
  6. gtritchie commented on May 27, 2025

    @gtritchie
    MemberAuthor

    Note to self, the documents are loaded during session startup at

    private void restoreDocuments(final Session session)
    .

  7. ronblum commented on Jun 17, 2025

    @ronblum
    Contributor

    Verified in RStudio Desktop 2025.08.0-daily+214 on Windows 11. Also confirmed that requests/responses are made when clicking or moving the mouse in the file without making any edits.

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

Metadata

Metadata

Assignees

Labels

bugcopilot

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions