mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-29 00:31:05 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using Sandbox;
|
|
using Microsoft.CodeAnalysis;
|
|
using Microsoft.CodeAnalysis.CSharp;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Sandbox.Generator
|
|
{
|
|
static class LinePreserve
|
|
{
|
|
public static T AddLineNumber<T>( T node, T originalNode, SyntaxTree tree, Worker master ) where T : SyntaxNode
|
|
{
|
|
if ( !master.IsFullGeneration )
|
|
return node;
|
|
|
|
if ( tree.FilePath.StartsWith( "_gen_" ) )
|
|
return node;
|
|
|
|
var lineSpan = originalNode.GetLocation().GetLineSpan();
|
|
if ( originalNode.HasLeadingTrivia ) lineSpan = originalNode.GetLeadingTrivia().First().GetLocation().GetLineSpan();
|
|
|
|
var lineNm = SyntaxFactory.Literal( $"{lineSpan.StartLinePosition.Line + 1}", lineSpan.StartLinePosition.Line + 1 );
|
|
var file = SyntaxFactory.Literal( $"{tree.FilePath}" );
|
|
|
|
var line = SyntaxFactory.LineDirectiveTrivia( lineNm, file, true ).NormalizeWhitespace().WithLeadingTrivia( SyntaxFactory.CarriageReturn );
|
|
|
|
var trivia = node.HasLeadingTrivia ? node.GetLeadingTrivia() : SyntaxFactory.TriviaList();
|
|
|
|
trivia = trivia.Insert( 0, SyntaxFactory.Trivia( line ) );
|
|
|
|
return node.WithLeadingTrivia( trivia );
|
|
}
|
|
}
|
|
}
|