Skip to content

Add Copilot preference for a chat's custom instructions loading (from all projects or from referenced projects only)#136

Open
travkin79 wants to merge 1 commit intomicrosoft:mainfrom
travkin79:feature/select-custom-instructions
Open

Add Copilot preference for a chat's custom instructions loading (from all projects or from referenced projects only)#136
travkin79 wants to merge 1 commit intomicrosoft:mainfrom
travkin79:feature/select-custom-instructions

Conversation

@travkin79
Copy link
Copy Markdown

@travkin79 travkin79 commented May 5, 2026

This PR fixes issue #62 according to the comment #62 (comment)

The PR

  • introduces a new setting in the Copilot preferences with currently two options for loading custom instructions in Copilot chats:
    • Load instructions from all projects in the Eclipse workspace
    • Load only instructions from projects derived from files / folders selected in the chat window (from the resources' parent projects) new default
  • if activated, derives projects only from given resources and passes the corresponding workspace folders to the language server (CopilotLanguageServerConnection), i.e.
    • if no files / folders are selected => no custom instructions are loaded at all
    • if a set of files / folders is selected in the chat window, only these resources' parent projects are checked for custom instructions. Custom instructions from other projects are ignored.
  • adds some unit tests

Preference page preview (new group highlighted):
image

@travkin79 travkin79 force-pushed the feature/select-custom-instructions branch from 7c28fcc to 8c9cc48 Compare May 5, 2026 14:14
@travkin79 travkin79 marked this pull request as ready for review May 5, 2026 16:06
Copilot AI review requested due to automatic review settings May 5, 2026 16:06
@travkin79
Copy link
Copy Markdown
Author

Hi @iloveeclipse,
I'm not sure, if it's OK if the custom copilot instructions are only loaded when starting a new chat. The set of loaded custom instructions doesn't change in an open chat window when the set of files in the context changes. I think, as a user, I would expect the set of custom instructions to change with the file selection in the chat. WDYT?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new chat preference to control how project-level Copilot custom instructions are scoped when starting a chat, so Eclipse can avoid loading unrelated projects’ instruction files and reduce the prompt bloat behind issue #62.

Changes:

  • Added a persisted CustomInstructionsChatLoadScope preference with UI labels/defaults for chat instruction loading.
  • Derived workspace folders from selected/current resources in ChatView and threaded that list into conversation creation.
  • Added enum/helper tests and ResourceUtils coverage for workspace-folder derivation.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/utils/ResourceUtils.java Adds helper to derive distinct accessible workspace folders from selected resources.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/messages.properties Adds user-facing labels for the new chat instruction scope preference.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/Messages.java Exposes new NLS message keys.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/CustomInstructionPreferencePage.java Adds the new combo box to the preferences UI and persists the selection.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/CopilotPreferenceInitializer.java Sets the default chat instruction scope preference.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/ChatView.java Derives scoped workspace folders before creating a new conversation.
com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/utils/ResourceUtilsTest.java Adds tests for workspace-folder derivation behavior.
com.microsoft.copilot.eclipse.ui.test/META-INF/MANIFEST.MF Adds JUnit params dependency for new parameterized tests.
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java Adds a createConversation overload that accepts scoped workspace folders.
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/Constants.java Defines the new preference key and enum values/default.
com.microsoft.copilot.eclipse.core.test/src/com/microsoft/copilot/eclipse/core/CustomInstructionsChatLoadScopeTest.java Adds enum serialization/deserialization tests.

Comment on lines +1010 to +1015
List<WorkspaceFolder> workspaceFolders = deriveWorkspaceFolders(currentFile, references);
CompletableFuture<ChatCreateResult> createConversationFuture = null;
if (StringUtils.isBlank(agentSlug)) {
createConversationFuture = ls.createConversation(workDoneToken, processedMessage, references, currentFile,
currentSelection, turns, activeModel, chatModeName, customChatModeId, todosToRestore, null, null);
currentSelection, turns, activeModel, chatModeName, customChatModeId, todosToRestore, null, null,
workspaceFolders);
@iloveeclipse
Copy link
Copy Markdown

I think, as a user, I would expect the set of custom instructions to change with the file selection in the chat. WDYT?

Correct.

@travkin79 travkin79 force-pushed the feature/select-custom-instructions branch 2 times, most recently from f90fdfc to 6728703 Compare May 5, 2026 16:56
@travkin79
Copy link
Copy Markdown
Author

Hi @iloveeclipse,

I think, as a user, I would expect the set of custom instructions to change with the file selection in the chat. WDYT?

Correct.

I've adapted the code to retrieve custom instructions from selected files on each conversation turn, i.e. each time a new prompt is sent to the LS.

private static String getCustomInstrLoadScopeLabel(CustomInstructionsChatLoadScope scope) {
// the cases here must relate to SCOPE_ORDER array
return switch (scope) {
case ALL_PROJECTS -> Messages.preferences_page_custom_instructions_chat_load_scope_all;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about making the item label simpler, for example, just All Projects & Referenced Projects, and show the detailed text as their tooltip?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I checked that, but it seems, we can only add a single tooltip to the drop-down list, not to each entry. Besides, the combobox has enough space for longer text. What about adding an explaining tooltip to the combobox like that
image
and leaving relatively long, self-explaining drown-down list entries like that?
image

}
return switch (scope) {
// take all projects from Eclipse workspace
case ALL_PROJECTS -> LSPEclipseUtils.getWorkspaceFolders();
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.

As this is a UI package, you can use WorkspaceUtils.listWorkspaceFolders() instead.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've checked the code and there is a significant difference between using LSPEclipseUtils.getWorkspaceFolders() and WorkspaceUtils.listWorkspaceFolders():

  • LSPEclipseUtils.getWorkspaceFolders() takes all accessible projects from the Eclipse workspace
  • WorkspaceUtils.listWorkspaceFolders() takes only top-level accessible projects from the Eclipse workspace, no nested projects (Maybe the method should be renamed to listTopLevelWorkspaceFolders() to make that clear?)

Nested projects could also have custom instructions that we should take into account here, don't we?

@travkin79 travkin79 force-pushed the feature/select-custom-instructions branch from cf9a3ce to 66a07f1 Compare May 6, 2026 12:54
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.

5 participants