Fix CodeLens positioned inside preceding code blocks#15893
Fix CodeLens positioned inside preceding code blocks#15893adamint wants to merge 3 commits intomicrosoft:mainfrom
Conversation
The _findStatementStartLine() method walked backwards from a resource
match looking for ';' or '{' but ignored '}'. When a code block like
if (...) { ... } preceded a resource call, the algorithm walked past
the '}' into the block and stopped at its '{', placing the CodeLens
inside the preceding block instead of on the resource line.
Fix: add '}' as a statement delimiter in the backward walk so that
closing braces correctly bound the start of the current statement.
Also fix tsconfig.json to include mocha types for test globals and
skipLibCheck to avoid MCP duplicate type definition conflicts.
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15893Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15893" |
There was a problem hiding this comment.
Pull request overview
Fixes incorrect CodeLens placement in the VS Code extension by improving how the AppHost parsers compute the start line of a resource statement when preceded by code blocks.
Changes:
- Update C# and JS/TS AppHost parsers to treat
}as a statement delimiter when walking backwards to findstatementStartLine. - Add extensive unit tests for
statementStartLinebehavior around preceding blocks (C# + JS/TS). - Update
extension/tsconfig.json(mocha types,skipLibCheck) to address editor/test typing issues.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| extension/tsconfig.json | Adds mocha/node types and enables skipLibCheck for TS build/editor experience. |
| extension/src/test/parsers.test.ts | Adds coverage for statementStartLine with preceding blocks and complex brace scenarios. |
| extension/src/editor/parsers/jsTsAppHostParser.ts | Includes } as a delimiter in statement-start detection for JS/TS AppHost parsing. |
| extension/src/editor/parsers/csharpAppHostParser.ts | Includes } as a delimiter in statement-start detection for C# AppHost parsing. |
…ailing comment test
| while (i >= 0) { | ||
| const ch = text[i]; | ||
| if (ch === ';' || ch === '{') { | ||
| if (ch === ';' || ch === '{' || ch === '}') { |
There was a problem hiding this comment.
This still breaks existing fluent chains where the Add* call comes after a callback block in the same statement. For example, playground/TestShop/TestShop.AppHost/AppHost.cs has .WithPgAdmin(resource => { ... }).AddDatabase("catalogdb"), and playground/waitfor/WaitForSandbox.AppHost/AppHost.cs has .RunAsContainer(c => { ... }).AddDatabase("db"). In both cases the new } stop condition makes _findStatementStartLine stop at the callback closing brace, so statementStartLine becomes the .AddDatabase(...) line instead of the top of the fluent chain.
That means the CodeLens is still misplaced for real AppHost code after merge, and it regresses the statementStartLine contract from "first line of the full statement chain" to "line after the last callback block". The fix likely needs to distinguish a } that closes a previous statement from one that belongs to the current fluent call (for example by tracking nesting / scanning for the previous real statement boundary), and this needs a focused regression test for these callback-chain shapes. The same issue is duplicated in jsTsAppHostParser.ts.
Description
Fix CodeLens being positioned inside preceding code blocks instead of on the resource declaration line.
Root cause:
_findStatementStartLine()in both the C# and JS/TS AppHost parsers walked backwards from a resource match looking for;or{as statement delimiters, but ignored}. When a code block likeif (...) { ... }preceded a resource call, the algorithm walked past the}into the block and stopped at its{, placing the CodeLens inside the preceding block.Fix: Add
}as a statement delimiter in the backward walk so that closing braces correctly bound the start of the current statement.Also fixes:
tsconfig.jsonupdated to includemochatypes (resolves "Cannot find name 'test'" errors in VS Code) andskipLibCheck: true(resolves duplicate MCP type definition conflicts between@types/vscodeand the proposed API file).Validation: 26 new tests (13 C#, 13 JS/TS) covering: preceding if blocks, nested braces, blocks with semicolons, comments between blocks and resources (line comments, block comments, mixed comment styles), multi-line fluent chains, try/catch blocks, single-line blocks, empty blocks, for loops, multiple resources interspersed with blocks, and comments before fluent chains after blocks. All existing tests continue to pass.
Fixes #15618
Checklist
<remarks />and<code />elements on your triple slash comments?aspire.devissue: