Skip to content

Suppress compose code lenses for documents outside the workspace#544

Draft
bwateratmsft with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-code-lens-error
Draft

Suppress compose code lenses for documents outside the workspace#544
bwateratmsft with Copilot wants to merge 3 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 requested a review from bwateratmsft July 22, 2026 18:46
@bwateratmsft
bwateratmsft requested a review from Copilot July 23, 2026 14:35

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 on lines +21 to +25
// The code lens commands (compose up, etc.) require the document to be within an open workspace folder.
// If it is not, running them results in an error, so the code lenses should not be shown.
// See https://github.com/microsoft/vscode-containers/issues/535
if (!await isDocumentInWorkspace(ctx, params.document.uri)) {
return undefined;
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

3 participants