Shy Beginner (looking for a starting point)

SyntaxEditor for WPF Forum

Posted 3 years ago by Richard Langin
Version: 11.1.0543
Avatar

Good evening. I’ve been reading several pages from SyntaxEditor’s documentation, opened the Sample Browser, snooped into the only provided Visual Studio solution — the overwhelming Sample Browser’s source code — and I feel very frustrated, because, as far as my examination has gone, I can say there’s no real «getting started» example anywhere neither in the reference nor in the example code.


Even the so-called «getting started» section at the beginning of the manual is a lot of theory — necessary theory, no question about that — but there’s nothing like a simple but fully worked Visual Studio example project, from start to finish and, most of all, step by step. I was expecting some tutorial, like: 1) add the required references; 2) create and place the control; 3) use the Language Designer to build a new (simple) language; 4) register this language in the control; (… plus some application related to syntax recognition, completion list or even simpler stuff). I’m talking a «Syntax Editor for Dummies» tutorial before hitting the heavy details, just to let the user «feel» the path to follow, or just understand where’s the starting point and what are the first steps.


I thought that knowing the essential theory about C# and WPF were the only requirements for learning about this control but its documentation seems to assume much more, like… mastering Syntax Editor already! Every single piece of information is described in detail, but the help manual is a web of mutual cross-references and there’s no place — as far as I could see — where a complete picture of how those pieces can be glued together into a small, simple project is shown.


Is there anywhere in Actipro’s website or discussion forum anything like this kind of «getting started» material? Otherwise, I hope somebody — either in the staff or the expert users — will have the merciful patience to answer my upcoming «how can I..?» posts while I try to make my way through SyntaxEditor. Reading through this forum’s posts I can see it’s made up of 100% experts already confident with SyntaxEditor, hence I assume a very shy beginner like me can be invited to the party.


Thank you for your attention.

Comments (6)

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

Hi Richard,

Thank you for your comments.  We realize that as a product as complex as SyntaxEditor grows and grows in features and functionality, it can get difficult to make sure the documentation and samples are still approachable for new customers.  We are happy to work with you to adjust our documentation so that there is a better onboarding experience.

Our SyntaxEditor Getting Started series of samples (in the main samples project under /ProductSamples/SyntaxEditorSamples/QuickStart/GettingStartedXX) is intended to be a step-by-step introduction to building a feature-rich syntax language.  It starts off with basic syntax highlighting and adds features like parsing, code outlining, automated IntelliPrompt, etc. as each step progresses.

What enhancements to the documentation would help most to get you pointed to that Getting Started series of samples so that it's more clear on how to get going?  In the meantime, feel free to ask questions if you can't find related documentation or samples and we can answer them.


Actipro Software Support

Posted 3 years ago by Richard Langin
Avatar

Thank you very much for your reply.

Either by pure coincidence or by my «complaint» triggering something in my mind, few minutes after posting my message something «unlocked» and I succeeded in writing a very elementary project (bare-bone editor, «Simple» language loaded in it, completion list popping up when typing «this.», as instructed by your manual). This strongly feels like a beginning, after a long «frozen» time spent trying to find a thread to pull. Before posting my next question I’ll make sure it’s not already clearly (to me) answered in either your documentation or samples.

 Best regards. R.

Posted 2 years ago by Richard Langin
Avatar

Good evening.

 

Subject:

Connecting a TaggerBase<ISquiggleTag> object to an editor.

 

Preliminaries:


 

I have faithfully copied a snippet shown in SyntaxEditor’s manual ( Text/Parsing Framework - Tagging --> Taggers and Tagger Providers --> Sample: ITagger<ISquiggleTag> Implementation ), which I repeat here:

public class CustomSquiggleTagger : TaggerBase<ISquiggleTag>
    {

        public CustomSquiggleTagger(ICodeDocument document) : base("ActiProPatternBasedSquiggle", null, document, true) { }

        public override IEnumerable<TagSnapshotRange<ISquiggleTag>> GetTags(NormalizedTextSnapshotRangeCollection snapshotRanges, object parameter)
        {
            if (snapshotRanges != null)
            {
                foreach (TextSnapshotRange snapshotRange in snapshotRanges)
                {
                    string text = snapshotRange.Text;

                    MatchCollection matches = Regex.Matches(text, @"My Test Sentence", RegexOptions.IgnoreCase);

                    if (matches.Count > 0)
                    {

                        foreach (Match match in matches)
                        {
                            SquiggleTag tag = new SquiggleTag();
                            yield return new TagSnapshotRange<ISquiggleTag>
                                (TextSnapshotRange.FromSpan(snapshotRange.Snapshot, 
                                snapshotRange.StartOffset + match.Index, match.Length), tag);
                        }
                    
                    }
                }
            
            }
        }

    }

 I have replaced your test string @"\bActipro\b" with @"My Test Sentence".

 

My question:


 

How do I effectively «glue» (is «register» the correct name for this?) my editor (a SyntaxEditor control instance named myeditor on the WPF form) to this CustomSquiggleTagger object, so that typing «My Test Sentence» actually squiggles it?

 

Further information:


 

This is what happens in MainWindow.xaml.cs:

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            // the method defined below is called
            InitEditor(myeditor);

        }

        static void InitEditor(SyntaxEditor myeditor)
        {

            SyntaxLanguageDefinitionSerializer serializer =
                new SyntaxLanguageDefinitionSerializer();               

            ISyntaxLanguage language =
                serializer.LoadFromFile("Simple-Basic.langdef");        

            myeditor.Document.Language = language;                      

            
            myeditor.DocumentTextChanged += Prompter;        /* Prompter(s, e) is a method I use
							     to show a completion list */
        
        }
}

 Thank you very much for your attention, kind regards.

[Modified 2 years ago]

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

Hello Richard,

Please check out the language class in the AdornmentsSquigglesIntro QuickStart in the samples.  That shows you how you can register a tagger like this with the language.  Then any SyntaxEditor that uses that language on its document will get the tagged used.


Actipro Software Support

Posted 2 years ago by Richard Langin
Avatar

I followed your advice and everything worked perfectly. I found inspiration in this line:

this.RegisterService(new CodeDocumentTaggerProvider<CustomSquiggleTagger>(typeof(CustomSquiggleTagger)));

 (courtesy of the CustomSyntaxLanguage.cs file included in the project AdornmentsSquigglesIntro you pointed out)

Hence in my MainWindow’s code I added:

language.RegisterService(new CodeDocumentTaggerProvider<CustomSquiggleTagger>(typeof(CustomSquiggleTagger)));

and now every occurrence of the string My Test Sentence gets squiggled as soon as it’s typed.

Thank you very much for two reasons: 1) your prompt and enlightening help in this specific issue; 2) the overall increasing confidence I’m gaining in what I can find in the already-made sample files, with my «sight» becoming clearer while I peruse them.


Gratefully, R.

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

Great, you got it exactly right.  We tried to design SyntaxEditor so everything is more or less done in syntax language services that are registered.  That way the syntax language is portable and can be used in multiple SyntaxEditors at the same time, bringing all the functionality with it.

We try to make a QuickStart for every feature area that focus specifically on some small-ish task in that area.  They can be very helpful starting points for various feature areas.


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.