Skip to content

Commit

Permalink
Show missing nodes without constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
Rekkonnect committed May 15, 2024
1 parent 579dbf6 commit 3b481b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 18 additions & 9 deletions Syndiesis/Core/DisplayAnalysis/NodeLineCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed partial class NodeLineCreator(NodeLineCreationOptions options)
SyntaxNodeOrToken nodeOrToken, DisplayValueSource valueSource = default)
{
var rootLine = CreateNodeOrTokenLine(nodeOrToken, valueSource);
var children = () => CreateNodeOrTokenChildren(nodeOrToken);
var children = GetChildRetrieverForNodeOrToken(nodeOrToken);
return new SyntaxTreeListNode
{
NodeLine = rootLine,
Expand All @@ -37,14 +37,15 @@ public sealed partial class NodeLineCreator(NodeLineCreationOptions options)
};
}

private IReadOnlyList<SyntaxTreeListNode> CreateNodeOrTokenChildren(SyntaxNodeOrToken nodeOrToken)
private Func<IReadOnlyList<SyntaxTreeListNode>>? GetChildRetrieverForNodeOrToken(
SyntaxNodeOrToken nodeOrToken)
{
if (nodeOrToken.IsNode)
{
return CreateNodeChildren(nodeOrToken.AsNode()!);
return GetChildRetrieverForNode(nodeOrToken.AsNode()!);
}

return CreateTokenChildren(nodeOrToken.AsToken());
return GetChildRetrieverForToken(nodeOrToken.AsToken());
}

private SyntaxTreeListNodeLine CreateNodeOrTokenLine(
Expand All @@ -62,7 +63,7 @@ private IReadOnlyList<SyntaxTreeListNode> CreateNodeOrTokenChildren(SyntaxNodeOr
SyntaxNode node, DisplayValueSource valueSource = default)
{
var rootLine = CreateNodeLine(node, valueSource);
var children = () => CreateNodeChildren(node);
var children = GetChildRetrieverForNode(node);
return new SyntaxTreeListNode
{
NodeLine = rootLine,
Expand All @@ -71,6 +72,14 @@ private IReadOnlyList<SyntaxTreeListNode> CreateNodeOrTokenChildren(SyntaxNodeOr
};
}

private Func<IReadOnlyList<SyntaxTreeListNode>>? GetChildRetrieverForNode(SyntaxNode node)
{
if (node.IsMissing && !node.HasAnyTrivia())
return null;

return () => CreateNodeChildren(node);
}

public SyntaxTreeListNode CreateTokenNode(
SyntaxToken token, DisplayValueSource valueSource = default)
{
Expand All @@ -92,6 +101,9 @@ private IReadOnlyList<SyntaxTreeListNode> CreateNodeOrTokenChildren(SyntaxNodeOr
return null;
}

if (token.IsMissing && !token.HasAnyTrivia())
return null;

return () => CreateTokenChildren(token);
}

Expand Down Expand Up @@ -448,10 +460,7 @@ private bool ShouldIncludeValue(object? value)
case SyntaxToken token:
if (token.IsMissing)
{
if (!_options.ShowTrivia || !token.HasAnyTrivia())
{
return false;
}
return true;
}

return token != default;
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Detailed property display of display values
- Moving cursor by right-clicking on node
- Display `GetStructure()` on structured syntax trivia
- Display missing nodes without constraints
- General
- Include usage reference
- Logging
Expand All @@ -25,6 +26,7 @@
- Improve cursor icon persistence
- Syntax tree view
- Disabled text line display correctly displays affected lines
- Missing nodes or tokens no longer have children when inside a syntax list

### Performance

Expand Down

0 comments on commit 3b481b0

Please sign in to comment.