Skip to content

fix: clear closed editor file context#280

Open
nanookclaw wants to merge 2 commits into
microsoft:mainfrom
nanookclaw:fix/clear-closed-file-context
Open

fix: clear closed editor file context#280
nanookclaw wants to merge 2 commits into
microsoft:mainfrom
nanookclaw:fix/clear-closed-file-context

Conversation

@nanookclaw

Copy link
Copy Markdown

Summary

Fixes #277.

When an editor closes, ReferencedFileService now checks whether the closed editor is the file currently represented in Copilot Chat. If it is, the service clears both the current-file observable and current-selection observable immediately. This keeps the existing fallback behavior for the final-editor-close case, but no longer depends only on the workbench editor reference count, which can still include an editor while focus has moved to a non-editor view.

The regression test captures the part listener registered by ReferencedFileService, seeds the current file observable, simulates closing that same editor while another editor reference is still reported by the active page, and asserts the chat current file is cleared.

Testing

  • git diff --check
  • ./mvnw -pl com.microsoft.copilot.eclipse.terminal.api,com.microsoft.copilot.eclipse.core,com.microsoft.copilot.eclipse.ui,com.microsoft.copilot.eclipse.ui.test -am -Dtest=ReferencedFileServiceTest test

I also tried the same module set with verify, but it stops in packaging because com.microsoft.copilot.eclipse.core/build.properties expects copilot-agent/dist/, which is not present in this checkout.

Copilot AI review requested due to automatic review settings June 5, 2026 20:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors ReferencedFileService editor-close handling to clear the “current referenced file” more reliably, and adds a unit test covering the new behavior.

Changes:

  • Update partClosed logic to clear the current referenced file when either the current file is closed or there are no open editors.
  • Extract helper methods (isCurrentReferencedFile, hasNoOpenEditors, clearCurrentReferencedFile) for reuse and readability.
  • Add a JUnit/Mockito test validating that closing the current referenced file clears service state.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/services/ReferencedFileService.java Refactors close-handling and adds helper methods to decide when to clear current referenced file/selection.
com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ReferencedFileServiceTest.java Adds a regression test for clearing current file when the closed editor matches the current referenced file.

@jdneo

jdneo commented Jun 25, 2026

Copy link
Copy Markdown
Member

Hi @nanookclaw

Thank you for your contribution, there are some copilot review comments, could you first check if they are valid?

@nanookclaw

Copy link
Copy Markdown
Author

Checked the Copilot review comments and they were valid. I pushed 122edf0 with the fixes:

  • Resolve the closed-editor false negative by reading the file from IEditorReference.getEditorInput() before falling back to the editor part.
  • Avoid active-page-only clearing by checking editor references across all workbench windows/pages.
  • Replace the test reflection against currentFileObservable with a small protected test seam and local test subclass.

Verification:

  • git diff --check
  • ./mvnw -pl com.microsoft.copilot.eclipse.core,com.microsoft.copilot.eclipse.terminal.api,com.microsoft.copilot.eclipse.ui,com.microsoft.copilot.eclipse.ui.test -Dtest=ReferencedFileServiceTest test

@jdneo

jdneo commented Jun 25, 2026

Copy link
Copy Markdown
Member

Thank you. Please mark those comments as resolved once you addressed them

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

Successfully merging this pull request may close these issues.

The Copilot Chat view retains file context even after the file is closed

3 participants