Repository navigation
Fix XAML IntelliSense bug-bash issues (#356, #359, #360, #363, #366) - #377
Chiara Mooney (chiaramooney) wants to merge 3 commits into
Conversation
- Report a server that stopped restarting with a Restart action instead of a spinning status (#363) - Bound deep element nesting and always answer requests whose results fail to serialize (#366) - Treat CR as a line break and replace lone surrogates in synced text (#360) - Keep WinApp formatting on unless C# Dev Kit provides a XAML formatter (#359) - Report XML well-formedness errors in XAML documents (#356) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
VSIX Build
Updated 2026-11-24 22:59:12 UTC · commit |
There was a problem hiding this comment.
🟡 Changes recommended
Valid quoted indexer keys and zero-padded quote entities can trigger false XAML0019 diagnostics, while the integration test fails to exercise the demand-driven server-start guard.
3 open issues
What changed in this PR
This PR addresses five XAML IntelliSense bug-bash issues across the VS Code client, parser, and language server: crash recovery, deep nesting, document synchronization, formatter selection, and XML diagnostics.
Changes:
- Adds a stopped-server status with restart actions and corrects automatic formatter selection for C# Dev Kit.
- Bounds deeply nested responses, handles serialization failures, and supports CR-only line endings and lone surrogates.
- Adds XML and markup-extension diagnostics with unit and integration regression tests.
| File | Description |
|---|---|
test/xaml-integration/well-formedness-and-depth.test.js |
Tests syntax diagnostics and deeply nested outlines. |
test/xaml-integration/client.test.js |
Tests crash-limit stopping and manual recovery. |
src/xaml/xamlLanguageService.ts |
Handles terminal stops and formatter-choice changes. |
src/xaml/xamlConfiguration.ts |
Updates stopped status and formatter selection. |
src/xaml/serverStopHandling.ts |
Reports terminal client errors and closures. |
src/xaml/projectContextStatus.ts |
Defines the stopped-server status-bar presentation. |
src/xaml/degradedNotification.ts |
Offers restart and output actions after stopping. |
src/test/xaml-server-stop-handling.test.ts |
Tests terminal-stop handling and presentation. |
src/test/xaml-configuration.test.ts |
Tests formatter selection and stopped status. |
server/test/WinUiXaml.Xaml.Tests/WellFormednessTests.cs |
Tests XML validation and parser depth limits. |
server/test/WinUiXaml.LanguageServer.Tests/DocumentSyncRegressionTests.cs |
Tests line endings, surrogates, and response serialization. |
server/src/WinUiXaml.Xaml/XamlParser.cs |
Adds syntax checks, quote handling, and depth recovery. |
server/src/WinUiXaml.Xaml/XamlDiagnostic.cs |
Defines the new diagnostic identifiers. |
server/src/WinUiXaml.LanguageServer/XamlSelectionRange.cs |
Caps selection-range nesting. |
server/src/WinUiXaml.LanguageServer/XamlNamespaceImport.cs |
Uses shared line-ending handling for imports. |
server/src/WinUiXaml.LanguageServer/XamlLanguageServer.DocumentFeatures.cs |
Bounds outline nesting and updates generated-code line endings. |
server/src/WinUiXaml.LanguageServer/XamlLanguageServer.CompletionAndResources.cs |
Uses shared position conversion. |
server/src/WinUiXaml.LanguageServer/XamlFormatter.cs |
Formats documents using recognized line boundaries. |
server/src/WinUiXaml.LanguageServer/TextDocument.cs |
Centralizes line indexing and exposes line starts. |
server/src/WinUiXaml.LanguageServer/Lsp/LspTypes.cs |
Applies lenient decoding to synchronized document text. |
server/src/WinUiXaml.LanguageServer/Lsp/LspJsonContext.cs |
Defines the shared response-nesting limit. |
server/src/WinUiXaml.LanguageServer/Lsp/LenientStringConverter.cs |
Replaces unpaired surrogates during text decoding. |
server/src/WinUiXaml.LanguageServer/Lsp/JsonRpcConnection.cs |
Returns errors when result serialization fails. |
server/src/WinUiXaml.LanguageServer/LineBreaks.cs |
Provides shared CR, LF, and CRLF utilities. |
README.md |
Documents C# Dev Kit formatter selection. |
package.json |
Updates formatter help and registers stop-handling tests. |
Review effort: Balanced
…it test Quotes inside [] now delimit markup values, so x:Bind indexer keys like ['}'] and ['a,b'] no longer raise a false XAML0019. Numeric quote references read every digit with a saturating value instead of stopping at eight. The crash-limit test now opens a separate XAML document to exercise the demand-start guard, and waits for each restarted server to initialize before killing it. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Nikola Metulev (nmetulev)
left a comment
There was a problem hiding this comment.
Nice work on this one. The rest of the PR checked out well: the restart state machine, the JSON-RPC error replies, CR/CRLF positions, surrogate handling, the depth caps, and the Dev Kit formatter logic all look right. Locally, npm run compile-tsc and npm run lint pass with 0 errors. WinUiXaml.Xaml.Tests passed 110/110, WinUiXaml.LanguageServer.Tests passed 1052/1052, and the XAML TS unit tests passed 47/47.
There's one must-fix. The new XAML0019 check flags two valid WinUI escapes, so pages that build and run fine show red errors. Both cases are clean on main. Details are in the inline comments:
| Input | main |
This PR |
|---|---|---|
{Binding Price, Converter={StaticResource C}, ConverterParameter={}{0:N2}} |
clean | 3× XAML0019 |
{Binding Name, FallbackValue={}{none}} |
clean | 2× XAML0019 |
{x:Bind sys:String.Format('It^'s {0}', Name)} |
clean | 1× XAML0019 |
Could you add both cases to WellFormedDocuments_HaveNoDiagnostics along with the fix?
| @@ -483,33 +557,7 @@ private XamlMarkupExtensionArgument ParseMarkupArgument(ref int p, int limit, in | |||
| } | |||
There was a problem hiding this comment.
A leading {} in a named value is WinUI's literal escape. MeScanner treats the rest of the value as plain text, not as a nested markup extension. This branch (the { check at L553) sends it to ParseMarkupExtension, which reports a missing extension name and then "positional after named".
These inputs are clean on main and get false XAML0019 errors here:
{Binding Price, Converter={StaticResource C}, ConverterParameter={}{0:N2}}gives 3 errors: "Expected a markup extension name after '{'." twice, and "Positional arguments must come before named arguments."{Binding Name, FallbackValue={}{none}}gives 2 errors.
Suggested fix: when the value starts with {}, skip it and scan the rest as a scalar up to the next top-level , or }, balancing {/} so {0:N2} stays inside the value.
| while (close < limit && | ||
| !(TryReadQuote(close, limit, out char closing, out closeLength) && closing == quote)) | ||
| { | ||
| close += _text[close] == '\\' ? 2 : 1; |
There was a problem hiding this comment.
Inside quoted strings in x:Bind function arguments, ^ escapes a quote. The function-bindings docs say: "Use the hat (^) to escape quotes in strings". This loop only honors \, so ^' ends the string early, and the following {0} is parsed as a nested extension.
Repro: {x:Bind sys:String.Format('It^'s {0}', Name)} is clean on main and gives a false XAML0019 ("Expected a markup extension name after '{'.") here.
Suggested fix: treat ^ like \ here (skip the next character) while scanning a quoted string.

Description
Fixes five XAML IntelliSense bugs from the bug bash.
Server stops restarting ([Bug]: Status bar spins forever after the XAML server stops restarting #363): after the server crashes 5 times in 3 minutes, the status bar now shows WinApp: XAML Language Server Stopped instead of spinning forever. Clicking it restarts the server. The warning offers Restart Language Server and Show Output, and opening another XAML file no longer silently restarts a server the client gave up on.
Deep nesting ([Bug]: Deeply nested XAML hangs Outline and produces bogus diagnostics #366): a page with 500 nested elements now gets an outline promptly and no bogus "no matching end tag" diagnostics. The root cause was the outline response exceeding
Utf8JsonWriter's depth limit of 1000. The exception was thrown outside the handler's try block, so the request was never answered. Changes:Line endings and surrogates ([Bug]: XAML document sync breaks on CR-only line endings and unpaired surrogates #360):
\r,\nand\r\nare all line breaks for positions, formatting, namespace insertion and generated event handlers. A lone UTF-16 surrogate indidOpen/didChangebecomes U+FFFD, so the document still updates and the character is reported, instead of the notification failing with aJsonException.Formatting with only the C# extension ([Bug]: XAML formatting does nothing when only the C# extension is installed #359):
winapp.xaml.formatting.provider = autonow defers only when C# Dev Kit is installed anddotnet.enableXamlToolsis on, since the C# extension formats XAML only with Dev Kit. Installing or removing Dev Kit restarts the server so the choice takes effect.XML syntax errors ([Bug]: XML syntax errors are not reported in XAML files #356): new diagnostics XAML0011 to XAML0019 cover:
&, bad entities and invalid character references.<in attribute values.< Button/>and</ Button>.Markup values recognize every XML spelling of a quote (literal,
'/", decimal or hex), so valid escaped values aren't flagged.Usage Example
Each line shows the input, then the result.
Related Issue
Fixes #356
Fixes #359
Fixes #360
Fixes #363
Fixes #366
Type of Change
Checklist
package.jsoncontribution points / command/debugger/custom-editor docs updated (if extension surface changed)Screenshots / Demo
No screenshots captured. The visible changes are the stopped status-bar item and warning, which the VS Code integration test exercises (below). All other changes are diagnostics and server behavior, shown in the example above.
Additional Notes
Validation (local, Windows ARM64):
dotnet test server/test/WinUiXaml.Xaml.Tests: passed, 110 tests. Includes well-formedness cases and depth guards that parse at 512 and 5000 levels on a 1 MB thread.dotnet test server/test/WinUiXaml.LanguageServer.Tests: passed, 1030 tests. Includes CR-only positions, surrogate replacement, deep outline and selection-range serialization throughJsonRpcConnection, and an error reply for unserializable results.node server/test/lsp-smoke/smoke.mjs: passed.npm run compile-tsc: passed.npm run lint: no errors; the 10 warnings are in files this PR doesn't touch.npx tsx --test: 68 passed, covering configuration, degraded notification, server stop handling, project context status and lifecycle. Fullnpm run test:unit: 5 manifest-validator tests fail locally only becauseschemas/isn't synced on this machine; this PR doesn't touch them.npx vscode-testwithtest/xaml-integration/client.test.js: 11 passed. One new test kills the real server 5 times, then checks that it stays stopped, that opening a XAML document doesn't restart it, and that Restart Language Server recovers it.npx vscode-testwith the false-positive sweep, nested markup, styles/templates, parser edges, formatting, outline, code actions and the newwell-formedness-and-depth.test.js: 228 passed, no new false positives.Not validated: I didn't build or install the packaged VSIX with the release AOT server, because this machine's package feed can't restore the AOT runtime packs. CI's bundled-server step covers that.
Known limits:
AI Description
This section is auto-generated by AI when the PR is opened or updated. To opt out, delete this entire section including the marker comments.