From 12dc5778ca48c214f8c369ea1292cf60c42ccc27 Mon Sep 17 00:00:00 2001 From: Arexoor Date: Fri, 29 May 2026 13:39:39 +0200 Subject: [PATCH] Fix prompts and skill discovery when using ADT project --- .../eclipse/core/utils/WorkspaceUtils.java | 33 ++++++++++++++++--- .../chat/services/ChatCompletionService.java | 14 ++++++-- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/utils/WorkspaceUtils.java b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/utils/WorkspaceUtils.java index 28fce9eb..5ff7ca81 100644 --- a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/utils/WorkspaceUtils.java +++ b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/utils/WorkspaceUtils.java @@ -82,19 +82,42 @@ public static List listTopLevelProjectsWithGitRepository() { } /** - * List all top level projects as workspace folders in the current workspace. + * List all top level projects as workspace folders in the current workspace, including the workspace root. */ public static List listWorkspaceFolders() { List projects = WorkspaceUtils.listTopLevelProjects(); List folders = new ArrayList<>(); + java.util.Set seenUris = new java.util.HashSet<>(); + + // Add workspace root first so it can be searched for root-level prompt files and skills + try { + URI workspaceRootUri = ResourcesPlugin.getWorkspace().getRoot().getLocationURI(); + if (workspaceRootUri != null) { + String rootUriString = workspaceRootUri.toASCIIString(); + WorkspaceFolder rootFolder = new WorkspaceFolder(); + rootFolder.setUri(rootUriString); + rootFolder.setName("workspace-root"); + folders.add(rootFolder); + seenUris.add(rootUriString); + } + } catch (Exception e) { + // If we can't get workspace root URI, continue with projects only + } + + // Add top-level projects (avoiding duplicates) for (IProject project : projects) { URI uri = project.getLocationURI(); if (uri != null) { - WorkspaceFolder folder = new WorkspaceFolder(); - folder.setUri(uri.toASCIIString()); - folder.setName(project.getName()); - folders.add(folder); + String uriString = uri.toASCIIString(); + // Avoid adding the same URI twice (project might be at workspace root in some configurations) + if (!seenUris.contains(uriString)) { + WorkspaceFolder folder = new WorkspaceFolder(); + folder.setUri(uriString); + folder.setName(project.getName()); + folders.add(folder); + seenUris.add(uriString); + } } } return folders; diff --git a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/services/ChatCompletionService.java b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/services/ChatCompletionService.java index cff99834..b31a12c1 100644 --- a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/services/ChatCompletionService.java +++ b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/services/ChatCompletionService.java @@ -21,7 +21,6 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.e4.core.services.events.IEventBroker; -import org.eclipse.lsp4e.LSPEclipseUtils; import org.eclipse.lsp4j.WorkspaceFolder; import org.eclipse.ui.PlatformUI; import org.osgi.service.event.EventHandler; @@ -38,6 +37,7 @@ import com.microsoft.copilot.eclipse.core.lsp.protocol.CopilotScope; import com.microsoft.copilot.eclipse.core.lsp.protocol.CopilotStatusResult; import com.microsoft.copilot.eclipse.core.lsp.protocol.TemplateSource; +import com.microsoft.copilot.eclipse.core.utils.WorkspaceUtils; import com.microsoft.copilot.eclipse.ui.utils.PreferencesUtils; /** @@ -115,7 +115,17 @@ private void initConversationTemplates(IProgressMonitor monitor) { // Pass workspace folders so the language server returns workspace-specific // prompt files (.prompt.md) and skills (SKILL.md) alongside built-in templates. try { - List workspaceFolders = LSPEclipseUtils.getWorkspaceFolders(); + List workspaceFolders = WorkspaceUtils.listWorkspaceFolders(); + // Log workspace folders for debugging prompt/skill discovery + if (!workspaceFolders.isEmpty()) { + StringBuilder folderLog = new StringBuilder("Discovering prompts and skills from workspace folders: "); + for (WorkspaceFolder folder : workspaceFolders) { + folderLog.append("[").append(folder.getName()).append(": ").append(folder.getUri()).append("] "); + } + CopilotCore.LOGGER.info(folderLog.toString()); + } else { + CopilotCore.LOGGER.info("No workspace folders available for prompt and skill discovery"); + } ConversationTemplate[] rawTemplates = this.lsConnection.listConversationTemplates(workspaceFolders).get(); if (monitor.isCanceled()) { return;