Add a comment stb generation

SyntaxEditor for WPF Forum

Posted 3 years ago by Eyal Lefler
Version: 16.1.0635
Avatar

Hi,

I want to add a comment stub after the user types /// before a function or a variable ( I saw you implemented this faeture in your c# addon).

I would love to get some guidelines.

 

Thanks,

Sharon

Comments (5)

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Sharon,

I assume this request is for a custom syntax language of your own.  Here's what we effectively do.  We basically made a CSharpDocumentationCommentAutoCompleter class that implements IEditorDocumentTextChangeEventSink and in the NotifyDocumentTextChanged method, we watch for a non-read-only document to get an e.TypedText of "/".  If that scenario occurs, we get a reader (via view.GetReader()) and scan characters to make sure there is no existing doc comment.  Then we take a look at the AST in the parse data to see if there is a type or member defined at the offset.  Based on what we find there, we construct the doc comment text to insert and call view.InsertSurroundingText to insert it.  We put text like " <summary>\n" + indentText + "/// " before the offset and the remainder of the doc comment after.  That way the caret is properly surrounded by doc comment and the user can begin typing the summary immediately.  I hope that helps!


Actipro Software Support

Posted 2 years ago by Sharon Gal-Ed
Avatar

Hi actipro,

I finally got arround to add this feature.

How should I handle the new comment format in the language designer ?

I currently have 2 lexical states for comments - for single line comments and for multi line comments.

Do I need a third state for the summary comment ?

How should I define the tags (for example - <summary></summary> , <param></param> ?

Thanks,

Sharon

[Modified 2 years ago]

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Sharon,

In the C# lexer for our .NET Languages Add-on we use a programmatic (written in code) lexer.  In that we have three lexical states: default, documentation comment, and pre-processor directive.  Normal single-line and multi-line comments are parsed into single tokens within the default lexical state.  In your case, you have separate lexical states for those, which is fine too.  Then in our documentation comment lexical state, we look for tags and mark each one as a single token.  The comment text in between and around tags is all another documentation text token.  There aren't any lexical states nested in that documentation comment lexical state.  I hope that helps!


Actipro Software Support

Posted 2 years ago by Sharon Gal-Ed
Avatar

Thanks ! It helps a lot.

I planned to mark the tag name(param, summary) as a token and the surrondings ( <,>,/) as tokens, and define a non terminal in the grammer for a legal documentation comment.

What did you do in the .Net add-on ?

Thanks,

 

Sharon

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Sharon,

We are excluding all comments and documentation comments from the parser ever seeing them in our .NET Languages Add-on.  Although we do cache up documentation comment text in our token reader, and pull it in when we reach a new type/member in the parser so that we can associate it with the related type/member.  


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.