Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Revert "Fixed issues #73 and #68"
Browse files Browse the repository at this point in the history
This reverts commit c3ca447.
  • Loading branch information
Malware committed Aug 11, 2018
1 parent c3ca447 commit a6e294c
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 136 deletions.
39 changes: 0 additions & 39 deletions Source/MDK/Build/AnalysisExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,45 +44,6 @@ public static T Unindented<T>(this T node, int indentations) where T: SyntaxNode
return (T)rewriter.Visit(node);
}

/// <summary>
/// Removes indentations from the given node if they are equal to or larger than the indicated number of indentations.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="node"></param>
/// <param name="indentations"></param>
/// <returns></returns>
public static SyntaxToken Unindented(this SyntaxToken node, int indentations)
{
var rewriter = new UnindentRewriter(indentations);
return rewriter.VisitToken(node);
}

/// <summary>
/// Removes indentations from the given node if they are equal to or larger than the indicated number of indentations.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="node"></param>
/// <param name="indentations"></param>
/// <returns></returns>
public static SyntaxTrivia Unindented(this SyntaxTrivia node, int indentations)
{
var rewriter = new UnindentRewriter(indentations);
return rewriter.VisitTrivia(node);
}

/// <summary>
/// Removes indentations from the given node if they are equal to or larger than the indicated number of indentations.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="node"></param>
/// <param name="indentations"></param>
/// <returns></returns>
public static SyntaxTriviaList Unindented(this SyntaxTriviaList node, int indentations)
{
var rewriter = new UnindentRewriter(indentations);
return SyntaxFactory.TriviaList(node.Select(rewriter.VisitTrivia));
}

/// <summary>
/// Retrieves the fully qualified name of the given symbol.
/// </summary>
Expand Down
69 changes: 34 additions & 35 deletions Source/MDK/Build/DocumentAnalysis/DocumentAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,46 +136,45 @@ public override void VisitEnumDeclaration(EnumDeclarationSyntax node)
public override void VisitClassDeclaration(ClassDeclarationSyntax node)
{
if (node.GetFullName(DeclarationFullNameFlags.WithoutNamespaceName) == "Program")
_parts.Add(new ProgramScriptPart(_document, node, _sortWeight));
//_parts.Add(new ProgramScriptPart(_document, MoveBraceTrivia(node), _sortWeight));
_parts.Add(new ProgramScriptPart(_document, MoveBraceTrivia(node), _sortWeight));
else
_parts.Add(new ExtensionScriptPart(_document, node, _sortWeight));
_sortWeight++;
}

//ClassDeclarationSyntax MoveBraceTrivia(ClassDeclarationSyntax node)
//{
// // If there is some node to move the brace trivia to, do so in order
// // to have it treated correctly by the composers. Otherwise it doesn't
// // matter.
// var firstChild = node.ChildNodes().FirstOrDefault();
// if (firstChild != null)
// {
// var trailingTrivia = node.OpenBraceToken.TrailingTrivia;

// // Skip the whitespace and line the brace itself is on
// var i = 0;
// while (i < trailingTrivia.Count && trailingTrivia[i].Kind() == SyntaxKind.WhitespaceTrivia)
// i++;
// if (i < trailingTrivia.Count && trailingTrivia[i].Kind() == SyntaxKind.EndOfLineTrivia)
// i++;
// node = node.WithOpenBraceToken(node.OpenBraceToken.WithTrailingTrivia(SyntaxFactory.EndOfLine("\n")));
// if (i < trailingTrivia.Count)
// {
// node = node.ReplaceNode(firstChild, firstChild.WithLeadingTrivia(firstChild.GetLeadingTrivia().InsertRange(0, trailingTrivia.Skip(i))));
// }
// }

// var lastChild = node.ChildNodes().LastOrDefault();
// if (lastChild != null)
// {
// var leadingTrivia = node.CloseBraceToken.LeadingTrivia;
// node = node.WithCloseBraceToken(node.CloseBraceToken.WithLeadingTrivia());
// node = node.ReplaceNode(lastChild, lastChild.WithTrailingTrivia(lastChild.GetTrailingTrivia().AddRange(leadingTrivia)));
// }

// return node;
//}
ClassDeclarationSyntax MoveBraceTrivia(ClassDeclarationSyntax node)
{
// If there is some node to move the brace trivia to, do so in order
// to have it treated correctly by the composers. Otherwise it doesn't
// matter.
var firstChild = node.ChildNodes().FirstOrDefault();
if (firstChild != null)
{
var trailingTrivia = node.OpenBraceToken.TrailingTrivia;

// Skip the whitespace and line the brace itself is on
var i = 0;
while (i < trailingTrivia.Count && trailingTrivia[i].Kind() == SyntaxKind.WhitespaceTrivia)
i++;
if (i < trailingTrivia.Count && trailingTrivia[i].Kind() == SyntaxKind.EndOfLineTrivia)
i++;
node = node.WithOpenBraceToken(node.OpenBraceToken.WithTrailingTrivia(SyntaxFactory.EndOfLine("\n")));
if (i < trailingTrivia.Count)
{
node = node.ReplaceNode(firstChild, firstChild.WithLeadingTrivia(firstChild.GetLeadingTrivia().InsertRange(0, trailingTrivia.Skip(i))));
}
}

var lastChild = node.ChildNodes().LastOrDefault();
if (lastChild != null)
{
var leadingTrivia = node.CloseBraceToken.LeadingTrivia;
node = node.WithCloseBraceToken(node.CloseBraceToken.WithLeadingTrivia());
node = node.ReplaceNode(lastChild, lastChild.WithTrailingTrivia(lastChild.GetTrailingTrivia().AddRange(leadingTrivia)));
}

return node;
}
}
}
}
73 changes: 21 additions & 52 deletions Source/MDK/Build/DocumentAnalysis/ProgramScriptPart.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
Expand All @@ -25,32 +24,7 @@ public ProgramScriptPart(Document document, ClassDeclarationSyntax partRoot, int
/// Retrieves the leading trivia of this part.
/// </summary>
/// <returns></returns>
public IEnumerable<SyntaxTrivia> GetLeadingTrivia() => SkipFirstTriviaLine(((ClassDeclarationSyntax)PartRoot).OpenBraceToken.TrailingTrivia);

IEnumerable<SyntaxTrivia> SkipFirstTriviaLine(SyntaxTriviaList triviaList)
{
var skipCount = FindTriviaSkipCount(triviaList);
return triviaList.Skip(skipCount);
}

static int FindTriviaSkipCount(SyntaxTriviaList triviaList)
{
for (var index = 0; index < triviaList.Count; index++)
{
var trivia = triviaList[index];
switch (trivia.Kind())
{
case SyntaxKind.WhitespaceTrivia:
continue;
case SyntaxKind.EndOfLineTrivia:
return index + 1;
default:
return 0;
}
}

return triviaList.Count;
}
public IEnumerable<SyntaxTrivia> GetLeadingTrivia() => ((ClassDeclarationSyntax)PartRoot).OpenBraceToken.TrailingTrivia;

/// <summary>
/// Gets the content of this part.
Expand Down Expand Up @@ -95,22 +69,20 @@ public override string GenerateContent()
{
var classDeclaration = (ClassDeclarationSyntax)PartRoot;
var buffer = new StringBuilder();
foreach (var trivia in GetLeadingTrivia())
buffer.Append(trivia.ToFullString());
//// Write opening brace trailing trivia
//if (classDeclaration.OpenBraceToken.HasTrailingTrivia)
//{
// var trailingTrivia = classDeclaration.OpenBraceToken.TrailingTrivia;
// Write opening brace trailing trivia
if (classDeclaration.OpenBraceToken.HasTrailingTrivia)
{
var trailingTrivia = classDeclaration.OpenBraceToken.TrailingTrivia;

// // Skip the whitespace and line the brace itself is on
// var i = 0;
// while (i < trailingTrivia.Count && trailingTrivia[i].Kind() == SyntaxKind.WhitespaceTrivia)
// i++;
// if (i < trailingTrivia.Count && trailingTrivia[i].Kind() == SyntaxKind.EndOfLineTrivia)
// i++;
// for (; i < trailingTrivia.Count; i++)
// buffer.Append(trailingTrivia[i].ToFullString());
//}
// Skip the whitespace and line the brace itself is on
var i = 0;
while (i < trailingTrivia.Count && trailingTrivia[i].Kind() == SyntaxKind.WhitespaceTrivia)
i++;
if (i < trailingTrivia.Count && trailingTrivia[i].Kind() == SyntaxKind.EndOfLineTrivia)
i++;
for (; i < trailingTrivia.Count; i++)
buffer.Append(trailingTrivia[i].ToFullString());
}

// Write general content
foreach (var node in PartRoot.ChildNodes())
Expand All @@ -137,16 +109,13 @@ public override string GenerateContent()
}
}

foreach (var trivia in GetTrailingTrivia())
buffer.Append(trivia.ToFullString());

//// Write closing brace opening trivia
//// Write opening brace trailing trivia
//if (classDeclaration.CloseBraceToken.HasLeadingTrivia)
//{
// foreach (var trivia in classDeclaration.CloseBraceToken.LeadingTrivia)
// buffer.Append(trivia.ToFullString());
//}
// Write closing brace opening trivia
// Write opening brace trailing trivia
if (classDeclaration.CloseBraceToken.HasLeadingTrivia)
{
foreach (var trivia in classDeclaration.CloseBraceToken.LeadingTrivia)
buffer.Append(trivia.ToFullString());
}

return buffer.ToString();
}
Expand Down
7 changes: 1 addition & 6 deletions Source/MDK/Build/Solution/ProgramDocumentComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,10 @@ Document CreateProgramDocument(Project project, ProjectContent content)
}
}

members.AddRange(nodes.Select(node => node/*.Unindented(2)*/));
members.AddRange(nodes.Select(node => node.Unindented(2)));
}

programDeclaration = programDeclaration.WithMembers(new SyntaxList<MemberDeclarationSyntax>().AddRange(members));
if (pendingTrivia.Count > 0)
{
programDeclaration = programDeclaration.WithCloseBraceToken(programDeclaration.CloseBraceToken.WithLeadingTrivia(SyntaxFactory.TriviaList(pendingTrivia)));
programDeclaration = programDeclaration.WithCloseBraceToken(programDeclaration.CloseBraceToken.Unindented(2));
}

var extensionDeclarations = content.Parts
.OfType<ExtensionScriptPart>()
Expand Down
2 changes: 1 addition & 1 deletion Source/MDK/MDKPackage.GeneratedInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public partial class MDKPackage
/// <summary>
/// The current package version
/// </summary>
public static readonly Version Version = new Version("1.1.17");
public static readonly Version Version = new Version("1.1.18");

/// <summary>
/// The required IDE version
Expand Down
2 changes: 1 addition & 1 deletion Source/MDK/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="MDK.Morten Aune Lyrstad.e02b602e-3099-44a5-88c6-cb30cab978f6" Version="1.1.17" Language="en-US" Publisher="Morten Aune Lyrstad" />
<Identity Id="MDK.Morten Aune Lyrstad.e02b602e-3099-44a5-88c6-cb30cab978f6" Version="1.1.18" Language="en-US" Publisher="Morten Aune Lyrstad" />
<DisplayName>MDK/SE</DisplayName>
<Description xml:space="preserve">A toolkit to help with ingame script (programmable block) development for Keen Software House's space sandbox Space Engineers.

Expand Down
2 changes: 1 addition & 1 deletion Source/MDKServices/ProjectScriptInfo.GeneratedInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ partial class ProjectScriptInfo
/// <summary>
/// The current package version this utility assembly targets
/// </summary>
public static readonly Version TargetPackageVersion = new Version("1.1.17");
public static readonly Version TargetPackageVersion = new Version("1.1.18");
}
}
2 changes: 1 addition & 1 deletion Source/MDKUtilities/MDKFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static void DefaultEcho(string text)

/// <summary>
/// Runs the Save method of the given program, if there is any.
/// </summary>
/// </summary>
/// <param name="gridProgram"></param>
/// <returns></returns>
public static string Save(IMyGridProgram gridProgram)
Expand Down

0 comments on commit a6e294c

Please sign in to comment.