Suppress compose code lenses for documents outside the workspace#544
Draft
bwateratmsft with Copilot wants to merge 3 commits into
Draft
Suppress compose code lenses for documents outside the workspace#544bwateratmsft with Copilot wants to merge 3 commits into
bwateratmsft with Copilot wants to merge 3 commits into
Conversation
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
Contributor
There was a problem hiding this comment.
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/isDocumentInWorkspaceFoldersutilities to check whether a document URI belongs to an open workspace folder (with safe prefix matching). - Updated
ServiceStartupCodeLensProviderto gate lens emission on workspace membership (nowasync, returnsundefinedwhen out-of-workspace). - Expanded test infrastructure and coverage to simulate
workspace/workspaceFoldersand 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 upcommand requires the file to belong to a workspace folder.The
ServiceStartupCodeLensProvidernow consults the client's open workspace folders and only emits lenses when the document is contained within one of them.Changes
isDocumentInWorkspaceutility — Issues aworkspace/workspaceFoldersrequest (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 pureisDocumentInWorkspaceFolders(uri, folders)for testability. Prefix matching is slash-normalized sofile:///workspacedoes not matchfile:///workspace-other.ServiceStartupCodeLensProvider— Nowasync; returnsundefinedwhen the document is outside all workspace folders.TestConnection— Answersworkspace/workspaceFoldersvia a settableworkspaceFoldersfield to support integration tests.Note on unsupported clients
When the client does not advertise the
workspaceFolderscapability, the check short-circuits totrueand 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.