-
Notifications
You must be signed in to change notification settings - Fork 14
Add Copilot preference for a chat's custom instructions loading (from all projects or from referenced projects only) #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jdneo
merged 1 commit into
microsoft:main
from
travkin79:feature/select-custom-instructions
May 13, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...core.test/src/com/microsoft/copilot/eclipse/core/CustomInstructionsChatLoadScopeTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package com.microsoft.copilot.eclipse.core; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.EnumSource; | ||
| import org.junit.jupiter.params.provider.NullSource; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
|
|
||
| import com.microsoft.copilot.eclipse.core.chat.CustomInstructionsChatLoadScope; | ||
|
|
||
| class CustomInstructionsChatLoadScopeTest { | ||
|
|
||
| @ParameterizedTest | ||
| @EnumSource(CustomInstructionsChatLoadScope.class) | ||
| void testStringToEnumEntryConversion(CustomInstructionsChatLoadScope enumEntry) { | ||
| String inputValue = enumEntry.getValue(); | ||
|
|
||
| CustomInstructionsChatLoadScope actualResult = CustomInstructionsChatLoadScope.fromValue(inputValue); | ||
|
|
||
| assertEquals(enumEntry, actualResult); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { "wrongValue" }) | ||
| @NullSource | ||
| void testStringToEnumEntryConversionThrowsExceptionForWrongValues(String value) { | ||
| assertThrows(IllegalArgumentException.class, () -> CustomInstructionsChatLoadScope.fromValue(value)); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...pse.core/src/com/microsoft/copilot/eclipse/core/chat/CustomInstructionsChatLoadScope.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package com.microsoft.copilot.eclipse.core.chat; | ||
|
|
||
| import com.microsoft.copilot.eclipse.core.Constants; | ||
|
|
||
| /** | ||
| * Scope loading modes for custom instructions in GitHub Copilot chat. | ||
| * <ul> | ||
| * <li><b>ALL_PROJECTS</b>: Load custom instructions from all projects in the Eclipse workspace | ||
| * <li><b>REFERENCED_PROJECTS</b>: Load custom instructions only from parent projects of files/folders referenced in the | ||
| * Copilot chat | ||
| * </ul> | ||
| */ | ||
| public enum CustomInstructionsChatLoadScope { | ||
| ALL_PROJECTS(Constants.CUSTOM_INSTRUCTIONS_CHAT_LOAD_SCOPE_ALL), | ||
| REFERENCED_PROJECTS(Constants.CUSTOM_INSTRUCTIONS_CHAT_LOAD_SCOPE_REFERENCED); | ||
|
|
||
| public static final CustomInstructionsChatLoadScope DEFAULT_VALUE = CustomInstructionsChatLoadScope.ALL_PROJECTS; | ||
|
|
||
| private final String value; | ||
|
|
||
| CustomInstructionsChatLoadScope(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the string value representing this enum entry for preference serialization. | ||
| * | ||
| * @return the string value for this preference setting | ||
| */ | ||
| public String getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the enum constant corresponding to the given string value if available, otherwise an | ||
| * {@link IllegalArgumentException} is thrown. | ||
| * | ||
| * @param value the string value (preference) representing an enum entry | ||
| * @return the enum entry representing the given value | ||
| * @throws IllegalArgumentException if the value does not correspond to any enum entry | ||
| */ | ||
| public static CustomInstructionsChatLoadScope fromValue(String value) { | ||
| for (CustomInstructionsChatLoadScope scope : values()) { | ||
| if (scope.getValue().equals(value)) { | ||
| return scope; | ||
| } | ||
| } | ||
| throw new IllegalArgumentException("Unknown CustomInstructionsLoadScope value: " + value); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...ilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/utils/PreferencesUtilsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package com.microsoft.copilot.eclipse.ui.utils; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import org.eclipse.jface.preference.IPreferenceStore; | ||
| import org.eclipse.jface.preference.PreferenceStore; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.EnumSource; | ||
|
|
||
| import com.microsoft.copilot.eclipse.core.Constants; | ||
| import com.microsoft.copilot.eclipse.core.chat.CustomInstructionsChatLoadScope; | ||
|
|
||
| class PreferencesUtilsTest { | ||
|
|
||
| private IPreferenceStore store; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| store = new PreferenceStore(); | ||
| store.setDefault(Constants.CUSTOM_INSTRUCTIONS_CHAT_LOAD_SCOPE, | ||
| CustomInstructionsChatLoadScope.DEFAULT_VALUE.getValue()); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void tearDown() { | ||
| store = null; | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @EnumSource(CustomInstructionsChatLoadScope.class) | ||
| void testGetCustomInstructionsChatLoadScope_returnsStoredValue(CustomInstructionsChatLoadScope scope) { | ||
| store.setValue(Constants.CUSTOM_INSTRUCTIONS_CHAT_LOAD_SCOPE, scope.getValue()); | ||
|
|
||
| CustomInstructionsChatLoadScope result = PreferencesUtils.getCustomInstructionsChatLoadScope(store); | ||
|
|
||
| assertEquals(scope, result); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetCustomInstructionsChatLoadScope_fallsBackToDefaultInCaseOfInvalidValueInStore() { | ||
| store.setValue(Constants.CUSTOM_INSTRUCTIONS_CHAT_LOAD_SCOPE, "invalid_value"); | ||
|
|
||
| CustomInstructionsChatLoadScope result = PreferencesUtils.getCustomInstructionsChatLoadScope(store); | ||
|
|
||
| assertEquals(CustomInstructionsChatLoadScope.DEFAULT_VALUE, result); | ||
| assertEquals(CustomInstructionsChatLoadScope.DEFAULT_VALUE.getValue(), | ||
| store.getString(Constants.CUSTOM_INSTRUCTIONS_CHAT_LOAD_SCOPE), | ||
| "The invalid stored value should have been corrected to the default"); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetCustomInstructionsChatLoadScopeDefault_returnsConfiguredDefault() { | ||
| // explicitly store varying values for InstanceScope and DefaultScope | ||
| store.setValue(Constants.CUSTOM_INSTRUCTIONS_CHAT_LOAD_SCOPE, | ||
| CustomInstructionsChatLoadScope.ALL_PROJECTS.getValue()); | ||
| store.setDefault(Constants.CUSTOM_INSTRUCTIONS_CHAT_LOAD_SCOPE, | ||
| CustomInstructionsChatLoadScope.REFERENCED_PROJECTS.getValue()); | ||
|
|
||
| CustomInstructionsChatLoadScope result = PreferencesUtils.getCustomInstructionsChatLoadScopeDefault(store); | ||
|
|
||
| // Should return the default value, not the stored value | ||
| assertEquals(CustomInstructionsChatLoadScope.REFERENCED_PROJECTS, result); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetCustomInstructionsChatLoadScopeDefault_fallsBackToValidDefaultInCaseOfInvalidValue() { | ||
| String invalidDefaultValue = "invalid_default_value"; | ||
| String instanceScopValue = CustomInstructionsChatLoadScope.REFERENCED_PROJECTS.getValue(); | ||
| store.setDefault(Constants.CUSTOM_INSTRUCTIONS_CHAT_LOAD_SCOPE, invalidDefaultValue); | ||
| store.setValue(Constants.CUSTOM_INSTRUCTIONS_CHAT_LOAD_SCOPE, instanceScopValue); | ||
|
|
||
| CustomInstructionsChatLoadScope result = PreferencesUtils.getCustomInstructionsChatLoadScopeDefault(store); | ||
|
|
||
| assertEquals(CustomInstructionsChatLoadScope.DEFAULT_VALUE, result); | ||
| assertEquals(invalidDefaultValue, | ||
| store.getDefaultString(Constants.CUSTOM_INSTRUCTIONS_CHAT_LOAD_SCOPE), | ||
| "The stored DefaultScope value should not change, even if it's invalid. " | ||
| + "That is repsonsibility of a PreferenceInitializer."); | ||
| assertEquals(instanceScopValue, | ||
| store.getString(Constants.CUSTOM_INSTRUCTIONS_CHAT_LOAD_SCOPE), | ||
| "The stored InstanceScope value should not change"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.