Fix CodeLens positioned inside preceding code blocks#15893
Fix CodeLens positioned inside preceding code blocks#15893adamint merged 5 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
JamesNK
left a comment
There was a problem hiding this comment.
3 issues found: missing test coverage for callback-in-chain regression (1), skipLibCheck: true suppressing all .d.ts type-checking (1), minor edge case in } line-skip logic (1).
…e } else {
- Fix _findStatementStartLine to track brace nesting: when a '}' is
encountered during the backward walk, match it with '{' and check
if preceded by '=>'. Lambda bodies are skipped; other blocks are
treated as statement boundaries. Fixes regression where callback
lambdas in fluent chains (e.g. .WithPgAdmin(r => { ... }).AddDatabase())
caused CodeLens to stop at the callback's '}' instead of reaching
the top of the chain.
- Change } line-skip to only skip lines matching '} [// comment]',
not lines like '} else {' or '} catch (e) {'.
- Revert tsconfig.json: remove skipLibCheck and types array (compilation
succeeds without them; the mocha/MCP type issues are pre-existing
and should be addressed separately).
- Add tests for callback lambda chains, RunAsContainer callbacks,
and } else { between blocks and resource calls.
|
Re-running the failed jobs in the CI workflow for this pull request because 2 jobs were identified as retry-safe transient failures in the CI run attempt.
|
JamesNK
left a comment
There was a problem hiding this comment.
There is some duplication. It would be good if parsing can be reused where possible. e.g. C#, TS and Java probably share some parsing logic because they're all C syntax languages.
Move _findStatementStartLine, _findMatchingOpenBrace, and _isPrecededByArrow from both C# and JS/TS parsers into a shared parserUtils.ts module. Both parsers now import from parserUtils instead of duplicating the identical implementations. Addresses review feedback from JamesNK about code duplication.
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: