Parse Semantics prior to displaying SyntaxEditor object

SyntaxEditor for Windows Forms Forum

Posted 17 years ago by Tim Winquist - CTO, Analysis, Integration & Design, Inc.
Version: 4.0.0252
Avatar
I have a TreeView control whose nodes represent code files. When each node is added to the TreeView control a SyntaxEditor object is generated and the code file's text is assigned to the SyntaxEditor.Document object's Text property. Each SyntaxEditor object is then assigned to its corresponding TreeView node's Tag property. I'm doing this so that when I 'link' multiple code files, I can easily check that each code file contains no syntax errors before I continue the 'link' process.

Here is the code to make all of this happen:

if (this.dlgAddFiles.ShowDialog() == DialogResult.OK)
{
  foreach (string strFileNameWithPath in dlgAddFiles.FileNames)
  {
    TreeNode oRootTreeNode = this.treeView.Nodes[0];
    TreeNode oNewTreeNode = new TreeNode(System.IO.Path.GetFileName(strFileNameWithPath));

    FileStream streamInput = new FileStream(strFileNameWithPath, FileMode.Open);
    TextReader reader = new System.IO.StreamReader(streamInput);
    string strFileText = reader.ReadToEnd();                    
    reader.Close();
    streamInput.Close();

    SyntaxEditor oSyntaxEditor = new SyntaxEditor();
    oSyntaxEditor.Document.Text = strFileText;
    MyFileNode oFileNode = new MyFileNode(strFileNameWithPath, oSyntaxEditor);
    oNewTreeNode.Tag = oFileNode;                    
    oRootTreeNode.Nodes.Add(oNewTreeNode);
  }
  this.treeView.ExpandAll();
}
The problem I'm having is that I need the semantic parser for each new SyntaxEditor to be invoked at the time it is created (when it is assigned to each TreeView node's Tag property). This way I'll have immediate access to each code file's syntax errors. It seems that the semantic parser is only invoked when the SyntaxEditor object is visible. I've tried invoking Invalidate() but that didn't work either. The semantic parser is only getting invoked when I display the SyntaxEditor objects in their respective TabPage.

By the way, I'm using the SemanticParserService to Parse my documents in a separate thread.

Thanks in advance.

Comments (3)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Tim,

I might be wrong but I believe that the semantic parsing is completely Document driven. So basically as soon as you are setting your Document.Text, it will initiate the semantic parsing. Now depending on whether the worker thread is busy, etc. it might take a couple seconds to kick in and get the result. Also note that the result is asynchronous.

So with that info, we know the semantic parser does have a request logged when you set Document.Text. You want to be able to wait for the parse to complete and block the main thread, right? If so, try something like this:

Right after setting Document.Text, get the semantic parser request parse hashkey like so:
string hashKey = SemanticParserServiceRequest.GetParseHashKey(oSyntaxEditor.Document, oSyntaxEditor.Document);
Tell the semantic parser service you want to wait on the main thread until it has completed:
SemanticParserService.WaitForParse(parseHashKey, 1000000);
Hope that helps!


Actipro Software Support

Posted 17 years ago by Tim Winquist - CTO, Analysis, Integration & Design, Inc.
Avatar
It turns out that the semantic parser was actually being invoked, but inconsistently. I never figured out exactly what was going on with the invocation issue, but I did notice that when the parser WAS invoked, the semantic parser's IsAtEnd property was always TRUE. I did figure out how to fix the problem although I could never put my finger on what the problem was. For some reason when I initially instantiate the SyntaxEditor object the dynamic syntax language has to be assigned to the Document.Language property AFTER assigning the code to the object's Document.Text property.

If the code snippet is changed to the following, it works fine:

oSyntaxEditor.Document.Text = strFileText;
oSyntaxEditor.Document.Language = DynamicSyntaxLanguage.LoadFromXml("MyFileName.xml", 0);
Also, if the Language is assigned BEFORE the Text, no ITokens are generated.

Could you please shed some light on this so I know what exactly is going on? Thanks again!
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Tokens should most definitely be created and I do see them when I set Language and then Text. If you think there is a bug somewhere please repro it in a small sample project and email it over.

As for the original semantic parsing question, I apologize but there is a better way to do this. If you keep the SemanticParserService.Enabled = false, it will run the semantic parser in the main UI thread instead of a worker thread, thereby solving your issue.


Actipro Software Support

The latest build of this product (v24.1.0) 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.