Posted 7 years ago by Frank Link - CEO, FLK Consulting UG
Version: 16.1.0635
Avatar

Hi,

is it possible to filter error messages so that they appear in the script nor in the error list.

We are using the XmlSyntaxLanguage into the SyntaxEditor.

regards

Frank

Comments (4)

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

Hi Frank,

Any error messages we pass through come from the parse data.  If you have a parse error tagger provider service registered on your language, it will show squiggles for the parse errors in the editors.  Any list controls external to SyntaxEditor rely on you to populate them.  So you can choose to not include parser errors in an Error List tool window by excluding whatever code you have that populates the list from the parse data's error collection.  If the above doesn't answer your question, kindly provide some more detail about your scenario.


Actipro Software Support

Posted 7 years ago by Frank Link - CEO, FLK Consulting UG
Avatar

Hi,

we have implemented a xml like language to create programs for SharePoint. The syntax of this language is defined in a xsd file.

But the user can use his own attributes in a defined tag. E.g.

<EnsureNavigation p_GlobalIncludeSubSites="false" p_GlobalIncludePages="false" p_CurrentIncludeSubSites="false" p_CurrentIncludePages="false" />

All variables with p_ are variables that the user can defined by it self. They are not defined in the xsd file and we would like to filter them so that they didn't display in errorlist and not squiggles.

regards

Frank

Posted 7 years ago by Frank Link - CEO, FLK Consulting UG
Avatar

Hi,

first step is ok. I have found the solution for this step:

    public class PscXmlParser : XmlParser
    {
        protected override void Validate(IParseRequest request, IParserState state)
        {
            if (request == null) return;
            if (state == null) return;
            if (request.TextBufferReader == null || request.Language == null) return;
            var service = request.Language.GetService<IXmlValidator>();
            if (service == null) return;
            var ast = state.AstNodeBuilder?.RootNode;
            var parseErrors = service.Validate(request, ast);
            if (parseErrors == null) return;
            foreach (var parseError in parseErrors)
            {
                if (parseError == null) continue;
                var textRange = request.Snapshot.PositionRangeToTextRange(parseError.PositionRange);
                var text = request.Snapshot.GetSubstring(textRange);
                if (!string.IsNullOrEmpty(text))
                {
                    if (text.ToLower().StartsWith("p_") || text.ToLower().StartsWith("v_")) continue;
                }
                state.ReportError(parseError);
            }
        }
    }

 Next step is identify the parent token of an given error.

The user can define his own funition into the xml code each funtion has parameters this parameters are not defined in the xsd.

My next step is to find out wich tag is the owner from this ParserError.

if found the node with error :

                    var textRange = request.Snapshot.PositionRangeToTextRange(parseError.PositionRange);
                    var node = state.AstNodeBuilder.RootNode.FindDescendantNode(textRange.StartOffset);

 I get the node from error but in this node the Parent is null.

What is the correct way to get the main tag from from the current node?

regards

Frank

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

Hi Frank,

Ok I see, you have a XSD validation but want to allow custom attributes as well.  What if you used something like XSD's anyAttribute to allow them?  You could still validate all your core tags/attributes like normal and anyAttribute would cover the custom ones.

That would be the easiest way, but if you want to get more low level, our XmlValidator class also has a virtual IsValidationExceptionAllowed method that is called any time an error is located by the XSD.  You can return false from that if you don't want a particular error to be reported.  You'd make a class that inherits XmlValidator and overrides that method.  Then override our default XmlValidator language service like:

language.RegisterService<XmlValidator>(new PscXmlValidator());

Would that work better than what you are trying to do?  IsValidationExceptionAllowed is passed in the validation error info we received from the XSD validation.  See if either of those approaches work for you. 


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.