CSharpSyntaxLanguage: Bug with HeaderText property.

SyntaxEditor .NET Languages Add-on for Windows Forms Forum

Posted 9 years ago by Marina
Version: 4.0.0285
Platform: Universal Windows Controls
Environment: Windows 7 (32-bit)
Avatar
Hello,

We have discovered a bug that is critical to our environment.
In our app we need to set syntaxEditor.Document.HeaderText and syntaxEditor.Document.FooterText along with syntaxEditor.Document.Text.

HeaderText usually ends with xml comment like this:
//<edited name = "text">
On the next line we have the text that is displayed in syntaxEditor.Document.Text and is shown to user. Line in HeaderText while debugging shows that it ends with \n\r.

It appears that when setting HeaderText it gets trimmed so that document.Text is under comment line (//). Under these circumstances IntelliComplete is not shown for variables that are declared in the beginning of the line.

This happens not always though, so I provide you with an example:

 var header =
                @"

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Linq;
using System.Linq.Expressions;

namespace n
{
    public class cl
    {

        public void method()
        {

            try
            {
                //
";
            var text = "System.Activator a;       a.        ";
            var footer = 
        @"// </edited>
            }
            finally
            {
            }
        }

        
    }
}

";
            syntaxEditor_.Document.HeaderText = header;
            syntaxEditor_.Document.FooterText = footer;
            syntaxEditor_.Document.Text = text;
As you can see there's a new line in header, when looking in debug mode this line is still there. Intellicomplete for variable a is not shown in this case.
If I remove line // in the header text, Intellicomplete works.
If i do like this:

syntaxEditor_.Document.HeaderText = header + "\n";
            syntaxEditor_.Document.FooterText = footer;
            syntaxEditor_.Document.Text = text;
Intellicomplete starts to work. Unfortunately, new line addition is not a desirable solution for us.

Also when i compose this text and set to the Document.Text it works perfectly fine.

string text = syntaxEditor_.Document.HeaderText + syntaxEditor_.Document.Text +
                          syntaxEditor_.Document.FooterText;
            syntaxEditor_.Document.FooterText = string.Empty;
            syntaxEditor_.Document.HeaderText = string.Empty;
            syntaxEditor_.Document.Text = text;

Comments (2)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Marina,

We have debugged the issue and found that the header is not trimmed, but the problem is being introduced because the comment is ending up with a TextRange of say -3 to -1 (due to it being the header and we keep the document text zero-based). The -1 is a trigger that marks the TextRange as "deleted" elsewhere, which is a flag that ends up marking the AST node for the comment as "open" and containing the subsequent text. There isn't an easy fix for this without some big updates.

What you can do is offset the comment by one backward. So after the line feed that follows the comment, add another space at the very end of your header. Or as you also found add a second line feed at the header end. It achieves the same effect.

We've made a note about this on our TODO list, however I'd recommend the above workaround in the meantime. Alternatively you could iterate the CompilationUnit and pull out the AST node for the comment that is causing issues, but adding the space would be easier.


Actipro Software Support

Posted 9 years ago by Marina
Avatar
Thank you very much for the answer!
We have implemented the hotfix with new line and it works okay.

Hope the issue will be fixed, will be waiting for the new version.

Regards,
Marina
The latest build of this product (v2018.1 build 0341) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.