Skip to content

Conversation

AmadeusW
Copy link
Contributor

@AmadeusW AmadeusW commented Jul 25, 2024

There was an edge case in code that gets context (references, definitions) for copilot rename suggestions.
When a reference/definition touched the end of file (because there was no empty line at the end of file), ArgumentOutOfRangeException was thrown from within GetRenameContextAsync, and Roslyn ended up not making the rename request at all.

The solution is twofold:

  1. Gracefully handle errors. If context cannot be obtained, make a request without context
  2. Fix the code that gets context span. It was incorrectly attempting to get an extra trailing character, which was typically \r on Windows machines (and therefore not visible in logs).

Fixes #74545 and DevDiv 2173894

@AmadeusW AmadeusW requested a review from a team as a code owner July 25, 2024 23:50
@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 25, 2024
@dotnet-policy-service dotnet-policy-service bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Jul 25, 2024
startPosition = documentText.Lines[startLine].Start;
endPosition = documentText.Lines[endLine].End;
var length = endPosition - startPosition + 1;
var length = endPosition - startPosition;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔Do you feel it needs to be covered by a test?
either integration test(is querying copilot in CI allowed?)/unit test (might be lighter, and assert GetRenameContextAsync directly, but we might need to hard-code the result in test)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely. We synced over message, @Cosifne is helping set up the test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copilot Rename Suggestions: No suggestions for identifiers referenced in methods that touch the end of file
3 participants