Skip to content

Commit

Permalink
Merge pull request #91 from Rekkonnect/fix/89-empty-tree-details
Browse files Browse the repository at this point in the history
Fix bugs
  • Loading branch information
Rekkonnect authored Dec 25, 2024
2 parents 891f0b7 + a125f57 commit 4a2aa25
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 24 deletions.
3 changes: 0 additions & 3 deletions Syndiesis/Controls/LanguageVersionDropDownItems.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
using System.Diagnostics;
using System.Linq;

using CSharpVersion = Microsoft.CodeAnalysis.CSharp.LanguageVersion;
using VisualBasicVersion = Microsoft.CodeAnalysis.VisualBasic.LanguageVersion;

namespace Syndiesis.Controls;

public partial class LanguageVersionDropDownItems : UserControl
Expand Down
2 changes: 1 addition & 1 deletion Syndiesis/Core/CSharpSingleTreeCompilationSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected override CSharpParseOptions CreateDefaultParseOptions()
{
return CSharpParseOptions.Default
.WithLanguageVersion(
Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp12);
Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp13);
}

protected override void AdjustLanguageVersionCore(RoslynLanguageVersion version)
Expand Down
3 changes: 0 additions & 3 deletions Syndiesis/Core/ConversionUnion.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Operations;

using CSharpConversion = Microsoft.CodeAnalysis.CSharp.Conversion;
using VisualBasicConversion = Microsoft.CodeAnalysis.VisualBasic.Conversion;

namespace Syndiesis.Core;

public sealed record ConversionUnion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public abstract AnalysisTreeListNode CreateRootNodeList<TDisplayValueSource>(
;

public abstract AnalysisTreeListNode CreateRootTokenList<TDisplayValueSource>(
SyntaxTokenList list, TDisplayValueSource? valueSource, bool includeChildren = true)
IReadOnlyList<SyntaxToken> list, TDisplayValueSource? valueSource, bool includeChildren = true)
where TDisplayValueSource : IDisplayValueSource
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Linq;

namespace Syndiesis.Core.DisplayAnalysis;
Expand All @@ -20,6 +21,7 @@ namespace Syndiesis.Core.DisplayAnalysis;
using ComplexGroupedRunInline = ComplexGroupedRunInline.Builder;

using ReadOnlySyntaxNodeList = IReadOnlyList<SyntaxNode>;
using SyntaxTokenList = IReadOnlyList<SyntaxToken>;

public sealed partial class CSharpSyntaxAnalysisNodeCreator : BaseSyntaxAnalysisNodeCreator
{
Expand Down Expand Up @@ -947,9 +949,7 @@ private static string EndOfLineTriviaText(SyntaxTrivia trivia)

private static string DisabledTextTriviaText(SyntaxTrivia trivia)
{
// https://github.com/dotnet/roslyn/issues/76441
if (trivia.SyntaxTree is null)
return "[Unknown line bounds]";
Contract.Assert(trivia.SyntaxTree is not null);

var span = trivia.Span;
var lineSpan = trivia.SyntaxTree.GetLineSpan(span).Span;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

namespace Syndiesis.Core.DisplayAnalysis;

using CSharpConversion = Microsoft.CodeAnalysis.CSharp.Conversion;
using VisualBasicConversion = Microsoft.CodeAnalysis.VisualBasic.Conversion;
using AnalysisTreeListNode = UIBuilder.AnalysisTreeListNode;
using AnalysisTreeListNodeLine = UIBuilder.AnalysisTreeListNodeLine;
using SingleRunInline = SingleRunInline.Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Diagnostics;
using System.Linq;
using Garyon.Reflection;
using System.Diagnostics.Contracts;

namespace Syndiesis.Core.DisplayAnalysis;

Expand All @@ -20,6 +21,7 @@ namespace Syndiesis.Core.DisplayAnalysis;
using ComplexGroupedRunInline = ComplexGroupedRunInline.Builder;

using ReadOnlySyntaxNodeList = IReadOnlyList<SyntaxNode>;
using SyntaxTokenList = IReadOnlyList<SyntaxToken>;

public sealed partial class VisualBasicSyntaxAnalysisNodeCreator : BaseSyntaxAnalysisNodeCreator
{
Expand Down Expand Up @@ -953,9 +955,7 @@ private static string EndOfLineTriviaText(SyntaxTrivia trivia)

private static string DisabledTextTriviaText(SyntaxTrivia trivia)
{
// https://github.com/dotnet/roslyn/issues/76441
if (trivia.SyntaxTree is null)
return "[Unknown line bounds]";
Contract.Assert(trivia.SyntaxTree is not null);

var span = trivia.Span;
var lineSpan = trivia.SyntaxTree.GetLineSpan(span).Span;
Expand Down
3 changes: 0 additions & 3 deletions Syndiesis/Core/HybridSingleTreeCompilationSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
using System.Linq;
using System.Threading;

using CSharpSyntaxKind = Microsoft.CodeAnalysis.CSharp.SyntaxKind;
using VisualBasicSyntaxKind = Microsoft.CodeAnalysis.VisualBasic.SyntaxKind;

namespace Syndiesis.Core;

public sealed class HybridSingleTreeCompilationSource
Expand Down
2 changes: 1 addition & 1 deletion Syndiesis/Core/NodeViewAnalysisExecution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private static ComplexDisplayValueSource ConstructSemanticModelValueSource(
return null;
return
_container.SyntaxCreator.CreateRootTokenList(
new SyntaxTokenList(_node?.ChildTokens() ?? []),
_node?.ChildTokens().ToList() ?? [],
_childTokensValueSource);
}

Expand Down
18 changes: 18 additions & 0 deletions Syndiesis/Core/NodeViewAnalysisHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using System.Diagnostics.Contracts;
using System.Linq;

namespace Syndiesis.Core;

Expand Down Expand Up @@ -32,6 +34,11 @@ public static class NodeViewAnalysisHelpers
SyntaxTree syntaxTree,
TextSpan span)
{
if (syntaxTree.Length is 0)
{
return GetNodeViewAnalysisRootForEmptySyntaxTree(syntaxTree);
}

var rootNode = syntaxTree.SyntaxNodeAtSpanIncludingStructuredTrivia(span);
if (rootNode is null)
return null;
Expand All @@ -40,4 +47,15 @@ public static class NodeViewAnalysisHelpers
var trivia = rootNode.DeepestTriviaContainingSpan(span);
return new(syntaxTree, rootNode, token, trivia);
}

private static NodeViewAnalysisRoot? GetNodeViewAnalysisRootForEmptySyntaxTree(
SyntaxTree syntaxTree)
{
Contract.Assert(syntaxTree.Length is 0);

var rootNode = syntaxTree.GetRoot();
var token = rootNode.GetFirstToken();
var trivia = rootNode.GetTrailingTrivia().FirstOrDefault();
return new(syntaxTree, rootNode, token, trivia);
}
}
3 changes: 2 additions & 1 deletion Syndiesis/Core/RoslynExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ public static SyntaxNodeOrToken ChildThatContainsSpan(this SyntaxNode node, Text
this SyntaxTree tree, TextSpan span)
{
var root = tree.GetRoot();
var start = Math.Clamp(span.Start, 0, root.FullSpan.End - 1);
int lastIndex = Math.Max(0, root.FullSpan.End - 1);
var start = Math.Clamp(span.Start, 0, lastIndex);
var end = Math.Clamp(span.End, 0, root.FullSpan.End);
var clampedSpan = TextSpan.FromBounds(start, end);
return root.DeepestNodeContainingSpanIncludingStructuredTrivia(clampedSpan);
Expand Down
3 changes: 0 additions & 3 deletions Syndiesis/Core/RoslynLanguageVersion.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Microsoft.CodeAnalysis;

using CSharpVersion = Microsoft.CodeAnalysis.CSharp.LanguageVersion;
using VisualBasicVersion = Microsoft.CodeAnalysis.VisualBasic.LanguageVersion;

namespace Syndiesis.Core;

public readonly record struct RoslynLanguageVersion(string LanguageName, int RawVersionValue)
Expand Down
8 changes: 8 additions & 0 deletions Syndiesis/_GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
global using CSharpVersion = Microsoft.CodeAnalysis.CSharp.LanguageVersion;
global using VisualBasicVersion = Microsoft.CodeAnalysis.VisualBasic.LanguageVersion;

global using CSharpSyntaxKind = Microsoft.CodeAnalysis.CSharp.SyntaxKind;
global using VisualBasicSyntaxKind = Microsoft.CodeAnalysis.VisualBasic.SyntaxKind;

global using CSharpConversion = Microsoft.CodeAnalysis.CSharp.Conversion;
global using VisualBasicConversion = Microsoft.CodeAnalysis.VisualBasic.Conversion;

0 comments on commit 4a2aa25

Please sign in to comment.