2

I am working on a language service and would like the parsing after the user types code to be faster.

Right now I rely on the ParseReason.Check and OnIdle mechanism that's documented on MSDN, but its often called a long time after the user has typed code. Sometimes it helps to move the cursor to another line to trigger it faster.

What I'd like to do is to force parse the file after I detect the user has typed in the file. I'm able to detect when the user is typing, but I don't know how to trigger the parser with a ParseRequest.

Drew Gaynor
  • 8,292
  • 5
  • 40
  • 53
Anthony Brien
  • 6,106
  • 7
  • 43
  • 56
  • I just noticed the LanguageService class has a CreateParseRequest method. So I tried invoking it from OnCaretMoved with ParseReason.Check, but it doesn't call my ParseSource method... So confused. – Anthony Brien Mar 15 '12 at 20:09

2 Answers2

0

You could try calling BeginParse() on your Source implementation. That creates a ParseRequest with the Check parse reason. I turned off the OnIdle timer in my language service and tested it out and it appears to work.

If your code that detects user key-presses has access to an instance of your LanguageService implementation, then you can use service.GetSource(...).BeginParse(). If it has access to the Source itself, then it's even easier.

Jon Senchyna
  • 7,867
  • 2
  • 26
  • 46
0

I was running into a similar problem, I wanted to scan files not opened in VS. The best I could do was to abstract out my parse functionality so it gets called by VS, but also called by another internal function to my extension whenever I desired without going through VS, and this would store my parse results to the same structures as the direct VS call on ParseRequest.

I'd be curious to know if you find a better way of doing it though.

ColinCren
  • 595
  • 3
  • 13