From 481f6d942196434f169fba593edd7318705eb14d Mon Sep 17 00:00:00 2001 From: Zidong Lu Date: Thu, 14 May 2026 11:23:04 +0800 Subject: [PATCH] fix: isolate per-folder exception in mode picker for multi-project workspaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> --- .../ui/preferences/McpPreferencePage.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/McpPreferencePage.java b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/McpPreferencePage.java index 61dd9d45..a3682cf9 100644 --- a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/McpPreferencePage.java +++ b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/McpPreferencePage.java @@ -970,8 +970,8 @@ private void loadModeOptions() { for (CustomChatMode mode : customModes) { String workspaceName = getWorkspaceNameForMode(mode); if (workspaceName.isEmpty()) { - CopilotCore.LOGGER.info("Workspace name is empty for custom agent: " + mode.getDisplayName() - + " (ID: " + mode.getId() + ")"); + CopilotCore.LOGGER.info("Workspace name is empty for custom agent: " + + mode.getDisplayName() + " (ID: " + mode.getId() + ")"); continue; } options.add(workspaceName + ": " + mode.getDisplayName()); @@ -1086,14 +1086,18 @@ private String getWorkspaceNameForMode(CustomChatMode mode) { List workspaceFolders = WorkspaceUtils.listWorkspaceFolders(); if (workspaceFolders != null) { for (WorkspaceFolder folder : workspaceFolders) { - Path folderPath = Paths.get(java.net.URI.create(folder.getUri())); - if (modePath.startsWith(folderPath)) { - return folder.getName(); + try { + Path folderPath = Paths.get(java.net.URI.create(folder.getUri())); + if (modePath.startsWith(folderPath)) { + return folder.getName(); + } + } catch (Exception folderEx) { + CopilotCore.LOGGER.error("Failed to process folder uri=" + folder.getUri(), folderEx); } } } } catch (Exception e) { - CopilotCore.LOGGER.error("Failed to get workspace name for mode", e); + CopilotCore.LOGGER.error("Failed to get workspace name for mode id=" + mode.getId(), e); } return ""; }