Last CloseBraceToken and EndOfFileToken

Topics: APIs, General
Jun 3, 2014 at 11:46 PM
Man I hope I am doing this in the right place.

One of the annoyances I have been having is the way line breaks are handled at the end of a file.

For instance if I have the following:
namespace test
{
    class sample
    {
        public void samplemethod()
        {
        }
    }
}
That last EndOfLineTrivia will have the last CloseBracketToken in the NamespaceDeclaration be its parent and it will be considered trailing trivia.

If I add more two or more line breaks, like so,
namespace test
{
    class sample
    {
        public void samplemethod()
        {
        }
    }
}


The first EndOfLineTrivia will again have the last CloseBracketToken in the NamespaceDeclaration be its parent and it will be considered trailing trivia. But the remaining two will have EndOfFileToken be their parent and they will be considered leading trivia.

I would much rather have them all grouped as leading trivia under the EndOfFileToken.

Any thoughts?
Developer
Jun 5, 2014 at 4:30 AM
We have very simple rules for where trivia are attached, and they work remarkably well in virtually all situations. "Work" in the sense that they allow you to move syntactic constructs around and the trivia come with them in a fairly natural way.

On any given line, any trivia after the last token (including the end-of-line) is trailing trivia. Nothing else is trailing trivia. All other trivia is leading trivia for whatever token follows.

I don't understand why you think the tokens near the end-of-file should be an exception.
Jun 5, 2014 at 7:17 AM
My understanding of what was going on was clouded by what appears to be a bug. https://twitter.com/Schandlich/status/474281264426385408