Skip to content

Fix workspace folder URI resolution for SCM-backed projects - #448

Open
Henrik Hartvig Jensen (HHartvig) wants to merge 8 commits into
microsoft:mainfrom
HHartvig:fix/customagent-sourcecontrol-uri-support
Open

Henrik Hartvig Jensen (HHartvig) wants to merge 8 commits into
microsoft:mainfrom
HHartvig:fix/customagent-sourcecontrol-uri-support

Conversation

@HHartvig

Copy link
Copy Markdown

Problem

WorkspaceUtils.listWorkspaceFolders() used project.getLocationURI() directly to
build LSP WorkspaceFolder entries. For projects backed by a source-control provider
(e.g. semanticfs://, sourcecontrol://), this could return a URI that didn't match
what the rest of the codebase expects, since it bypassed the same file-URI resolution
used elsewhere (LSPEclipseUtils.toUri() + platform-resource fallback).
This made add custom agents fail, making it impossible to add custom agents on non git repos.

Solution

  • Added FileUtils.getResourceAsUri(IResource), a resource-agnostic version of the
    existing URI resolution logic: prefers LSPEclipseUtils.toUri() when the resource
    has a local getLocation(), falls back to getLocationURI() for remote/virtual
    resources, and finally falls back to a platform:/resource... URI built from the
    resource's portable full path.
  • Updated WorkspaceUtils.listWorkspaceFolders() to use FileUtils.getResourceAsUri()
    instead of calling project.getLocationURI() directly, so workspace folders are
    resolved consistently with the rest of the codebase regardless of the project's
    backing storage/SCM provider.

Testing

Added unit tests in FileUtilsTests covering all resolution branches of
getResourceAsUri:

  • Resource with a local getLocation() → returns the LSPEclipseUtils-resolved URI
  • Resource where getLocation() resolves to a file:// URI derived from the absolute
    path, even when getLocationURI() reports a different SCM scheme (locally-backed
    resource takes priority)
  • Resource without getLocation() but with getLocationURI() → returns that URI directly
  • Resource without either → falls back to a platform:/resource... URI

Ran .\mvnw test — all tests pass.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Fixes workspace folder URI resolution for SCM-backed and virtual projects.

Changes:

  • Adds resource URI resolution with local, remote, and platform fallbacks.
  • Uses the resolver when creating LSP workspace folders.
  • Adds unit tests for resolution branches.
File summaries
File Description
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/utils/WorkspaceUtils.java Updated as part of this pull request.
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/utils/FileUtils.java Updated as part of this pull request.
com.microsoft.copilot.eclipse.core.test/src/com/microsoft/copilot/eclipse/core/utils/FileUtilsTests.java Updated as part of this pull request.
Review details

Suppressed comments (2)

com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/utils/FileUtils.java:120

  • This method duplicates the complete resolution sequence already implemented by getResourceUri(IResource) above. Keeping two copies lets future URI fixes diverge; the fallback behavior is already different (toPortableString() here versus toString() there). Make one method delegate to the other and only convert to/from the string form at the boundary.
    // Try standard file location first
    if (resource.getLocation() != null) {
      URI uri = LSPEclipseUtils.toUri(resource);
      if (uri != null) {
        return uri;

com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/utils/WorkspaceUtils.java:95

  • The changed workspace-folder path is not covered by a WorkspaceUtils test: the new tests exercise FileUtils.getResourceAsUri directly, but none verifies that listWorkspaceFolders() passes an SCM/virtual project's resolved URI into its WorkspaceFolder. A regression in this integration point would therefore still pass the test suite; add a focused test for this method.
      URI uri = FileUtils.getResourceAsUri(project);
      if (uri != null) {
        WorkspaceFolder folder = new WorkspaceFolder();
        folder.setUri(uri.toASCIIString());
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@HHartvig

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Danske Bank"

@jdneo

Copy link
Copy Markdown
Member

Hi Henrik Hartvig Jensen (@HHartvig),

Please check the CI failure, thank you.

@HHartvig

Copy link
Copy Markdown
Author

For some reason a merge was not merged correctly, that has been updated now. Should build now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants