Can you point me in the right direction?

SyntaxEditor for WPF Forum

Posted 9 years ago by SledgeHammer01
Version: 10.1.0522
Avatar
Hi,

I am using the SyntaxEditor in my app. Currently, we use it like this:

scriptEditor.Document.Language = LoadLanguageDefinitionFromResourceStream("JScript.langdef");
JScript.langdef is your provided JavaScript language definition.

We would like to add red squiggles for syntax errors, etc. Not even sure where to begin.

I found the language tool and opened up the jscript.langdef. I noticed I can generate 6 files through the tool.

JscriptSyntaxLanguage.cs, JScriptlexer.cs, etc.

I assume we need to use these .cs files and can't just use the .langdef?

None of the samples give us an indication of where to go with this.

Comments (4)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You can use the .langdef or the generated classes. For that particular language, either one works fine. Once you load the language instance, you can install any other services you want on it. If you plan on showing syntax errors, that means you'd likely need an IParser service, and in its implementation would need to write code to parse your document and return a list of syntax errors in the parse data. If the IParseData that comes back implements IParseErrorProvider, squiggle lines will be added in the appropriate spots.

Take a look at the Getting Started 7 QuickStart for a full simplistic sample of what I'm talking about.


Actipro Software Support

Posted 9 years ago by Mick George - Software Engineer, CNC Software, Inc.
Avatar
Sledge,

If it helps any I am using a combination of both and it's working fine so far so I assume this is OK to do, for example in one or our custom languages classes:

public class PostSyntaxLanguage : SyntaxLanguage, IEditorDocumentTextChangeEventSink, IActiveEditorViewChangeEventSink 
    {
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the PostSyntaxLanguage class.
        /// </summary>
        public PostSyntaxLanguage()
            : base("Post")
        {
            // Initialize this language from a language definition
            SyntaxEditorHelper.InitializeLanguageFromResourceStream(this, "Post.langdef");

            // Register an outliner, which tells the document's outlining manager that
            //   this language supports automatic outlining, and helps drive outlining updates
            this.RegisterService<IOutliner>(new TokenOutliner<PostOutliningSource>());

            // Register a built-in service that automatically provides quick info tips 
            //   when hovering over collapsed outlining nodes
            this.RegisterService(new CollapsedRegionQuickInfoProvider());

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

            this.RegisterService<IParser>(new PostParser());

            // Register a completion provider that displays a completion list when appropriate
            this.RegisterService(new PostCompletionProvider());

            // Register the language itself as an event sink for document text change events
            //   so that we can show a completion list as words are starting to be typed
            this.RegisterService<IEditorDocumentTextChangeEventSink>(this);

            this.RegisterService<IActiveEditorViewChangeEventSink>(this);

            this.RegisterService(new TokenTaggerProvider<PostTokenTagger>());

            this.RegisterService(new PostQuickInfoProvider());
           
            // Get and register the language files lexer
            this.RegisterService<ILexer>(this.GetLexer());

            // Register an line commenter allowing us to comments/uncomment documents
            this.RegisterService<ILineCommenter>(new LineBasedLineCommenter() { StartDelimiter = "//" });

            // Register a provider service that can create the custom adornment manager
            //this.RegisterService(new AdornmentManagerProvider<AlternatingRowsAdornmentManager>(typeof(AlternatingRowsAdornmentManager)));

            // Register a provider service that can create the custom adornment manager
            this.RegisterService(new AdornmentManagerProvider<HighlightLineAdornmentManager>(typeof(HighlightLineAdornmentManager)));

            this.CanShowCompletionListForNewWords = true;
        }
Posted 9 years ago by SledgeHammer01
Avatar
Thanks for the tips!
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Mick,

Yes what you are doing there is certainly a good way to do things. Thanks for sharing. It's nice because you are initializing some parts with the .langdef, and then setting up more advanced services for your language as well. Best of all since you have a dedicated language class, you can create it directly in XAML.


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.