Skip to content

Suppress compose code lenses for documents outside the workspace - #544

Merged
Brandon Waterloo [MSFT] (bwateratmsft) merged 7 commits into
mainfrom
copilot/fix-code-lens-error
Aug 13, 2026
Merged

Suppress compose code lenses for documents outside the workspace#544
Brandon Waterloo [MSFT] (bwateratmsft) merged 7 commits into
mainfrom
copilot/fix-code-lens-error

Conversation

Copilot AI commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Compose service-startup code lenses ("Run All Services" / "Run Service") were shown for compose files opened outside the current workspace, and running them errored because the underlying compose up command requires the file to belong to a workspace folder.

The ServiceStartupCodeLensProvider now consults the client's open workspace folders and only emits lenses when the document is contained within one of them.

Changes

  • isDocumentInWorkspace utility — Issues a workspace/workspaceFolders request (when the client advertises the capability) and checks whether the document URI falls under an open folder. Splits into an async, context-aware entry point and a pure isDocumentInWorkspaceFolders(uri, folders) for testability. Prefix matching is slash-normalized so file:///workspace does not match file:///workspace-other.
  • ServiceStartupCodeLensProvider — Now async; returns undefined when the document is outside all workspace folders.
  • TestConnection — Answers workspace/workspaceFolders via a settable workspaceFolders field to support integration tests.
  • Tests — Unit coverage for the membership check plus provider integration tests for in-workspace, outside-workspace, and no-folders scenarios.

Note on unsupported clients

When the client does not advertise the workspaceFolders capability, the check short-circuits to true and lenses are shown as before. The issue discussion left this case open; keeping prior behavior avoids regressing clients that can't answer the request. In practice VS Code always advertises the capability, so the gate is active there.

if (!await isDocumentInWorkspace(ctx, params.document.uri)) {
    return undefined;
}

Copilot AI changed the title [WIP] Fix code lens issue for files outside workspace Suppress compose code lenses for documents outside the workspace Jul 22, 2026

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.

Pull request overview

Prevents Compose service-startup code lenses (“Run All Services” / “Run Service”) from appearing for Compose documents opened outside any workspace folder, avoiding commands that would error because compose up requires the file to belong to a workspace folder.

Changes:

  • Added isDocumentInWorkspace / isDocumentInWorkspaceFolders utilities to check whether a document URI belongs to an open workspace folder (with safe prefix matching).
  • Updated ServiceStartupCodeLensProvider to gate lens emission on workspace membership (now async, returns undefined when out-of-workspace).
  • Expanded test infrastructure and coverage to simulate workspace/workspaceFolders and validate in/out/no-folder scenarios.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/compose-language-service/src/service/utils/isDocumentInWorkspace.ts Adds workspace-folder membership checks (capability-aware) and a pure helper for unit testing.
packages/compose-language-service/src/service/providers/ServiceStartupCodeLensProvider.ts Suppresses service-startup code lenses when the document is outside the workspace.
packages/compose-language-service/src/test/TestConnection.ts Adds mock support for workspace/workspaceFolders via a configurable workspaceFolders field.
packages/compose-language-service/src/test/utils/isDocumentInWorkspace.test.ts Unit tests for URI-within-folder logic (including prefix/sibling edge cases).
packages/compose-language-service/src/test/providers/ServiceStartupCodeLensProvider.test.ts Integration tests for in-workspace/out-of-workspace/no-folders behavior.
packages/compose-language-service/bin/docker-compose-langserver Adds the package bin entrypoint script for launching the language server.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/compose-language-service/src/service/utils/isDocumentInWorkspace.ts Outdated
Comment thread packages/compose-language-service/src/service/utils/isDocumentInWorkspace.ts Outdated
Addresses PR feedback:
- Mark isDocumentInWorkspaceFolders as @internal (exported only for tests)
- Inline uriIsWithinFolder into isDocumentInWorkspaceFolders
- Replace the raw string-prefix check with WHATWG URL parsing, comparing
  scheme, authority, and decoded path segments

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@bwateratmsft
Brandon Waterloo [MSFT] (bwateratmsft) marked this pull request as ready for review August 13, 2026 13:53
The executable bit was flipped incidentally; the file content is unchanged,
so revert it to keep the PR diff focused.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment thread packages/compose-language-service/src/service/utils/isDocumentInWorkspace.ts Outdated
Co-authored-by: bwateratmsft <36966225+bwateratmsft@users.noreply.github.com>
@bwateratmsft
Brandon Waterloo [MSFT] (bwateratmsft) merged commit de9e002 into main Aug 13, 2026
2 checks passed
@bwateratmsft
Brandon Waterloo [MSFT] (bwateratmsft) deleted the copilot/fix-code-lens-error branch August 13, 2026 17:06
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.

Compose code lens do not work for files that are outside the workspace

4 participants