Skip to content

Commit 7719c6e

Browse files
duzitongCopilot
andcommitted
fix: isolate per-folder exception in mode picker for multi-project workspaces
In McpPreferencePage.getWorkspaceNameForMode(), the entire workspace-folder loop was wrapped in one try-catch. If any project had a non-file:// URI (e.g. EFS-backed sftp://, ecf:// or other custom linked resources), Paths.get(URI.create(...)) would throw and the catch would return '' for ALL custom modes — hiding them from the mode picker dropdown. Move the Paths.get() call into a per-folder inner try-catch so one bad URI only skips that folder; the loop continues for the rest. Also add INFO/WARN diagnostic logs so future issues can be diagnosed from workspace.log without a debugger. Fixes: #180 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 63b3c1b commit 7719c6e

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/McpPreferencePage.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -967,13 +967,16 @@ private void loadModeOptions() {
967967
// Add custom agents
968968
try {
969969
List<CustomChatMode> customModes = CustomChatModeManager.INSTANCE.getCustomModes();
970+
CopilotCore.LOGGER.info("[McpPreferencePage] loadModeOptions: customModes.size()=" + customModes.size());
970971
for (CustomChatMode mode : customModes) {
971972
String workspaceName = getWorkspaceNameForMode(mode);
972973
if (workspaceName.isEmpty()) {
973-
CopilotCore.LOGGER.info("Workspace name is empty for custom agent: " + mode.getDisplayName()
974-
+ " (ID: " + mode.getId() + ")");
974+
CopilotCore.LOGGER.info("[McpPreferencePage] Workspace name is empty for custom agent: "
975+
+ mode.getDisplayName() + " (ID: " + mode.getId() + ")");
975976
continue;
976977
}
978+
CopilotCore.LOGGER.info("[McpPreferencePage] Adding mode option: " + workspaceName + ": "
979+
+ mode.getDisplayName());
977980
options.add(workspaceName + ": " + mode.getDisplayName());
978981
}
979982
} catch (Exception e) {
@@ -1081,19 +1084,33 @@ private String extractModeIdFromSelection(String selectionText) {
10811084
private String getWorkspaceNameForMode(CustomChatMode mode) {
10821085
try {
10831086
String modeId = mode.getId();
1087+
CopilotCore.LOGGER.info("[McpPreferencePage] getWorkspaceNameForMode: modeId=" + modeId);
10841088
Path modePath = Paths.get(java.net.URI.create(modeId));
1089+
CopilotCore.LOGGER.info("[McpPreferencePage] modePath=" + modePath);
10851090

10861091
List<WorkspaceFolder> workspaceFolders = WorkspaceUtils.listWorkspaceFolders();
1092+
CopilotCore.LOGGER.info("[McpPreferencePage] workspaceFolders.size()="
1093+
+ (workspaceFolders == null ? "null" : workspaceFolders.size()));
10871094
if (workspaceFolders != null) {
10881095
for (WorkspaceFolder folder : workspaceFolders) {
1089-
Path folderPath = Paths.get(java.net.URI.create(folder.getUri()));
1090-
if (modePath.startsWith(folderPath)) {
1091-
return folder.getName();
1096+
CopilotCore.LOGGER.info("[McpPreferencePage] checking folder: uri=" + folder.getUri()
1097+
+ " name=" + folder.getName());
1098+
try {
1099+
Path folderPath = Paths.get(java.net.URI.create(folder.getUri()));
1100+
CopilotCore.LOGGER.info("[McpPreferencePage] folderPath=" + folderPath
1101+
+ " startsWith=" + modePath.startsWith(folderPath));
1102+
if (modePath.startsWith(folderPath)) {
1103+
return folder.getName();
1104+
}
1105+
} catch (Exception folderEx) {
1106+
CopilotCore.LOGGER.error("[McpPreferencePage] failed to process folder uri="
1107+
+ folder.getUri(), folderEx);
10921108
}
10931109
}
10941110
}
10951111
} catch (Exception e) {
1096-
CopilotCore.LOGGER.error("Failed to get workspace name for mode", e);
1112+
CopilotCore.LOGGER.error("[McpPreferencePage] Failed to get workspace name for mode id="
1113+
+ mode.getId(), e);
10971114
}
10981115
return "";
10991116
}

0 commit comments

Comments
 (0)