|
10 | 10 | import java.util.UUID; |
11 | 11 | import java.util.concurrent.CompletableFuture; |
12 | 12 | import java.util.concurrent.ExecutionException; |
| 13 | +import java.util.stream.Stream; |
13 | 14 |
|
14 | 15 | import org.apache.commons.lang3.StringUtils; |
15 | 16 | import org.eclipse.core.resources.IFile; |
|
21 | 22 | import org.eclipse.e4.core.services.events.IEventBroker; |
22 | 23 | import org.eclipse.jdt.annotation.Nullable; |
23 | 24 | import org.eclipse.jface.preference.IPreferenceStore; |
| 25 | +import org.eclipse.lsp4e.LSPEclipseUtils; |
24 | 26 | import org.eclipse.lsp4j.Range; |
| 27 | +import org.eclipse.lsp4j.WorkspaceFolder; |
25 | 28 | import org.eclipse.swt.SWT; |
26 | 29 | import org.eclipse.swt.layout.GridData; |
27 | 30 | import org.eclipse.swt.layout.GridLayout; |
|
38 | 41 | import org.osgi.service.event.EventHandler; |
39 | 42 |
|
40 | 43 | import com.microsoft.copilot.eclipse.core.Constants; |
| 44 | +import com.microsoft.copilot.eclipse.core.Constants.CustomInstructionsChatLoadScope; |
41 | 45 | import com.microsoft.copilot.eclipse.core.CopilotCore; |
42 | 46 | import com.microsoft.copilot.eclipse.core.chat.BuiltInChatMode; |
43 | 47 | import com.microsoft.copilot.eclipse.core.chat.BuiltInChatModeManager; |
|
86 | 90 | import com.microsoft.copilot.eclipse.ui.chat.viewers.LoadingViewer; |
87 | 91 | import com.microsoft.copilot.eclipse.ui.chat.viewers.NoSubscriptionViewer; |
88 | 92 | import com.microsoft.copilot.eclipse.ui.swt.CssConstants; |
| 93 | +import com.microsoft.copilot.eclipse.ui.utils.ResourceUtils; |
89 | 94 | import com.microsoft.copilot.eclipse.ui.utils.SwtUtils; |
90 | 95 |
|
91 | 96 | /** |
@@ -957,7 +962,7 @@ private void onSendInternal(String workDoneToken, String message, String agentSl |
957 | 962 |
|
958 | 963 | CompletableFuture<ChatTurnResult> addConversationFuture = ls.addConversationTurn(workDoneToken, conversationId, |
959 | 964 | processedMessage, references, currentFile, currentSelection, activeModel, chatModeName, customChatModeId, |
960 | | - currentTodos, agentSlug, agentJobWorkspaceFolder); |
| 965 | + currentTodos, agentSlug, agentJobWorkspaceFolder, deriveWorkspaceFolders(currentFile, references)); |
961 | 966 | conversationFutures.add(addConversationFuture); |
962 | 967 |
|
963 | 968 | addConversationFuture.thenAccept(result -> { |
@@ -1002,16 +1007,18 @@ private void onSendInternal(String workDoneToken, String message, String agentSl |
1002 | 1007 | chatModeName, customChatModeId, currentFile, references); |
1003 | 1008 | } |
1004 | 1009 |
|
| 1010 | + List<WorkspaceFolder> workspaceFolders = deriveWorkspaceFolders(currentFile, references); |
1005 | 1011 | CompletableFuture<ChatCreateResult> createConversationFuture = null; |
1006 | 1012 | if (StringUtils.isBlank(agentSlug)) { |
1007 | 1013 | createConversationFuture = ls.createConversation(workDoneToken, processedMessage, references, currentFile, |
1008 | | - currentSelection, turns, activeModel, chatModeName, customChatModeId, todosToRestore, null, null); |
| 1014 | + currentSelection, turns, activeModel, chatModeName, customChatModeId, todosToRestore, null, null, |
| 1015 | + workspaceFolders); |
1009 | 1016 | } else { |
1010 | 1017 | // For conversations sending to agents, include agentSlug and specify the target agentJobWorkspaceFolder |
1011 | 1018 | // Don't send todo list for agent jobs - agents manage their own todo state independently |
1012 | 1019 | createConversationFuture = ls.createConversation(workDoneToken, processedMessage, references, currentFile, |
1013 | 1020 | currentSelection, turns, activeModel, chatModeName, customChatModeId, null, agentSlug, |
1014 | | - agentJobWorkspaceFolder); |
| 1021 | + agentJobWorkspaceFolder, workspaceFolders); |
1015 | 1022 | } |
1016 | 1023 | conversationFutures.add(createConversationFuture); |
1017 | 1024 |
|
@@ -1051,6 +1058,27 @@ private void onSendInternal(String workDoneToken, String message, String agentSl |
1051 | 1058 | } |
1052 | 1059 | } |
1053 | 1060 |
|
| 1061 | + List<WorkspaceFolder> deriveWorkspaceFolders(IFile currentFile, List<IResource> references) { |
| 1062 | + String chatInstrScope = CopilotUi.getPlugin().getPreferenceStore().getString( |
| 1063 | + Constants.CUSTOM_INSTRUCTIONS_CHAT_LOAD_SCOPE); |
| 1064 | + CustomInstructionsChatLoadScope scope; |
| 1065 | + try { |
| 1066 | + scope = CustomInstructionsChatLoadScope.fromValue(chatInstrScope); |
| 1067 | + } catch (Exception e) { |
| 1068 | + CopilotCore.LOGGER.error( |
| 1069 | + "Failed parsing custom instructions load scope for chat preference, using default value", e); |
| 1070 | + scope = CustomInstructionsChatLoadScope.DEFAULT_VALUE; |
| 1071 | + } |
| 1072 | + return switch (scope) { |
| 1073 | + // take all projects from Eclipse workspace |
| 1074 | + case ALL_PROJECTS -> LSPEclipseUtils.getWorkspaceFolders(); |
| 1075 | + |
| 1076 | + // take only projects from selected files/folders |
| 1077 | + case REFERENCED_PROJECTS -> ResourceUtils.deriveWorkspaceFoldersFrom( |
| 1078 | + Stream.concat(references.stream(), Stream.of(currentFile)).toList()); |
| 1079 | + }; |
| 1080 | + } |
| 1081 | + |
1054 | 1082 | /** |
1055 | 1083 | * Align with @Workspace of vscode, because we are actually indexing the whole workspace, not a single project. |
1056 | 1084 | * (@Project is only for IntelliJ.) |
|
0 commit comments