Patterns loaded at runtime are being squiggled

SyntaxEditor for WPF Forum

Posted 11 years ago by Josh Luth - Software Developer, Esha Research
Version: 12.2.0573
Avatar

I'm a bit new to the SyntaxEditor, but I'm having an issue with Squiggles.

I've defined a language using the Language Designer. It contains a patterngroup that is explicit with one pattern added. At runtime, I get that patterngroup, clear the patterns, and add more patterns.

I've registered the CodeDocumentTaggerProvider<ParseErrorTagger> and now when I type in the Editor, if I type one of my patterns, the squiggle is there. If I type the original pattern that was first set up before I cleared them, then there is no squiggle. Do I need to somehow refresh something after I add patterns to any of the lexical states?

 

// Part of the auto generated Lexer.g.cs class

// Initialize the Default lexical state
lexicalState = lexicalStates["Default"];
lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "ThePattern", classificationTypeProvider.MyType);
lexicalPatternGroup.TokenId = MyTokenId.MyType;
lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("ThePattern"));

 

// Part of my code that initializes the patterns
 
var myLexer = (DynamicLexer)syntaxEditor.Document.Language.GetLexer();

using (var batch = myLexer.CreateChangeBatch())
{
  var myPatternGroup = myLexer.DefaultLexicalState.LexicalPatternGroups.FirstOrDefault(g => g.TokenId.Equals(MyTokenId.MyType));

  if (myPatternGroup == null)
  {
      return;
  }

  myPatternGroup.Patterns.Clear();

  foreach (var pattern in listofpatterns)
  {
      myPatternGroup.Patterns.Add(new DynamicLexicalPattern(pattern.ToString()));
  }
}

[Modified 11 years ago]

Comments (5)

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

Hi Josh,

Please let me know if I understand this correctly.  This pattern group is defined in the lexer and you dynamically update the patterns in it at run-time from your listofpatterns.  Then you have a squiggle tagger set up to look for any tokens from that pattern group, and if found you squiggle them.  It works for the first one you define but not for any after you dynamically change the lexer.

What happens after you change the lexer and then type on a line that has one of the new patterns.  Does it refresh in that case?  If so, what you probably need to do is raise the TagsChanged event from your tagger and tell it that the entire document snapshot range changed.  That will cause a refresh of the lines.


Actipro Software Support

Posted 11 years ago by Josh Luth - Software Developer, Esha Research
Avatar

You are mostly correct. I'm using the ParseErrorTagger, so the squiggle is showing up when what I type in doesn't match one of my patterns. So currently the squiggle shows on anything I type in, except for the one pattern that is set up directly in the lexer.

I was looking at how to call the TagsChanged event and I wasn't sure where to do that. If its in the code where I add patterns, can I get to the Tagger from my SyntaxEditor object and call the TagsChanged event? And what range would I give it, since at that point no text has been typed in yet.

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

Hi Josh,

Check out the AdornmentsIntraTextNotes QuickStart's MainControl code behind.  In that you can see how we get a registered tagger (via the Document.Properties).

You might need to make a class that inherits ParseErrorTagger and add this method that you'll be able to call externally:

public void RaiseTagsChanged(TagsChangedEventArgs e) {
	this.OnTagsChanged(e);
}

The range would need to be the document's snapshot range (e.g. Document.CurrentSnapshot.SnapshotRange) to make sure the entire document is refreshed.

Although if you are saying no text has been typed in yet, it almost sounds like something in your tagger's code is caching old data.  Make sure it's not using something like another instance of the lexer than the one you are modifying.


Actipro Software Support

Posted 11 years ago by Josh Luth - Software Developer, Esha Research
Avatar

It sounds cached to me as well. I don't have any tagger code, I'm just relying on the ParseErrorTagger. And I only have one lexer which I'm retrieving by calling "syntaxEditor.Document.Language.GetLexer()" I assume that's the way to get the right lexer?

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

Hi Josh,

Other that what we suggested, I'm not sure.  If you'd like us to look into it further, please make a new simple sample project that shows the issue (keep it as minimal as possible) and email that to our support address.  Rename the .zip file extension so it doesn't get spam blocked.  Thanks!


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.