Fix #890: never emit documentSymbol entries with empty names#896
Merged
Conversation
Incomplete or error declarations (e.g. `func`/`struct`/`enum` with no name, or `let = 42`) produce missing identifier tokens whose `Text` is null. The language server's DocumentSymbolComputer copied that null directly into the DocumentSymbol.Name, so the textDocument/documentSymbol response contained symbols with falsy names. The vscode-languageclient `asDocumentSymbols` converter validates every symbol has a non-empty name and threw "name must not be falsy", breaking the Outline view and breadcrumbs. Guard symbol construction with a SymbolName helper that substitutes a sensible non-empty fallback (e.g. <function>, <struct>, <enum>, <variable>, <field>, <member>) whenever the identifier token is missing, empty, or whitespace. This covers every node kind the computer emits, including child field and enum-member symbols, so a null/empty name can never be produced. Adds regression tests asserting no DocumentSymbol (or child) ever has an empty name for incomplete declarations, while valid symbols keep their real names. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Fixes #890
Root cause
The VSCode extension repeatedly logged:
SyntaxToken.IsMissingis defined asText == null, and the parser'sMatchTokenreturns a token withnullTextwhenever an expected token ismissing. For incomplete or error declarations — e.g.
func/struct/enumwith no name, or
let = 42— the identifier token is synthesized with anullText.DocumentSymbolComputer.ComputeDocumentSymbolscopiedIdentifier.Textstraight into
DocumentSymbol.Name, so thetextDocument/documentSymbolresponse contained symbols whose
namewasnull/empty (falsy). Thevscode-languageclientasDocumentSymbolsprotocol converter validates thatevery symbol has a non-empty
nameand throws "name must not be falsy",which breaks the Outline view and breadcrumbs for the affected file.
Fix
Guard every symbol-construction site in
DocumentSymbolComputerwith a newSymbolName(SyntaxToken identifier, string fallback)helper that substitutes asensible, non-empty fallback name whenever the identifier token is missing,
empty, or whitespace:
<function>,<variable>,<struct>,<enum>for top-level declarations<field>,<member>for struct fields and enum members (child symbols)This covers every node kind the computer can emit (functions, global
variables, structs + their fields, enums + their members), so a null/empty
namecan never reach the protocol layer. The fix is in the language serversource, not the bundled extension artifact.
Tests
Added regression tests in
DocumentSymbolHandlerTeststhat:DocumentSymbol(or any child) ever has an empty/nullname for a range of incomplete declarations, and
incomplete ones.
Local build + test results
dotnet build GSharp.sln -c Release --no-restore -graph→ succeeded, 0 errorsdotnet test GSharp.sln -c Release --no-build→ all green:Files changed
src/LanguageServer/HoverComputer.cs—DocumentSymbolComputerfixtest/LanguageServer.Tests/DocumentSymbolHandlerTests.cs— regression tests