CommentLines command isn't working in language transistions mode

SyntaxEditor for WPF Forum

Posted 4 years ago by Dirk Zellerfeld
Version: 19.1.0685
Platform: .NET 3.0 (Core)
Environment: Windows 10 (64-bit)
Avatar

The inbuilt EditorCommands.CommentLines command of the SyntaxEditor always comment out in the primary language. Even if the caret / focus is set within a sub language and the sub language has an own LineBasedLineCommenter registered which should be used instead but isn't.

For example the primary language is C# and the sub language is XML and both have their own commenter service. If the caret is within XML code and you use the EditorCommands.CommentLines command the code gets commented out by // instead of <!-- -->

Comments (6)

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

Hi Dirk,

If you have a language transition scenario, you'd probably want to make some kind of proxy line commenter service on the primary language.  Look to see if the target offset is in the parent or child language, and then call into the appropriate parent or child language's normal line commenter to carry out the action.  There isn't anything built-in to do that by default.


Actipro Software Support

Posted 4 years ago by Dirk Zellerfeld
Avatar

I'm using the built in command service of the Syntax Editor. The same thing that executes when you press the comment button in the demo app. It's a one liner in my code. Of course I can write my own comment service but the syntax editor already have one and language transistions is a supported feature?!

[Modified 4 years ago]

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

Hi Dirk,

The predefined line commenters are written for a single language.  To support merged languages that have different line commenters, they would need another proxy line commenter that would have to call appropriate ones for the merged languages based on context.  I'm not sure we can prebuild that since some languages might only supply single-line commenters while others might have ranged ones.  And what happens if you select across multiple language boundaries?  Logic for that could get fairly complex and might be completely different for various parent/child language combinations.

Regardless, at this time, unfortunately a custom proxy line commenter would be needed.  You can call into other ones as appropriate though to save a bulk of the work once you identify which one to call.


Actipro Software Support

Posted 4 years ago by Dirk Zellerfeld
Avatar

For me it is unclear how I can detect in which language the user/caret currently is. I couldn't find anything in the documentation, am I missing something?

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

Hi Dirk,

You could probably do something like this to get the current token:

var token = editor.ActiveView.GetReader().Token;

Then examine the token to see which language it is.  If you also hold onto that reader instance while in the same method where you execute this, you can also scan around that token as needed.


Actipro Software Support

Posted 4 years ago by Dirk Zellerfeld
Avatar

Thanks to your help, i found an easier way to get the current language:

var language = Editor.editor.ActiveView.GetReader().Language
The latest build of this product (v24.1.2) was released 3 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.