CompletionStatisticsManager

Hey, I need the last triggered item for the code completion. Found the class CompletionStatisticsManager with the public strings LastChoiceContextId and LastChoiceItemId which are exactly what I'm looking for. The Problem is, I don`t know when this variables are written. For the first time they are null, and I can write them e.g to a file but after that point I don´t know when these variables change which would implie that a new completion is triggered. So I need something like an onComplete Event. I have found out, that these variables are written in the isAvailble method which consumes CSharpCodeCompletionContext. Can I get the informations I need there? Greetings T0a

4 comments
Comment actions Permalink

Hi Toa. What are you trying to achieve? These values are really there for calculating statistics on most frequently used items in code completion, and are not really intended to be an indication of the last selected item (for example, there's no way of knowing if you've selected a type, property, method, variable or overload). It's hard to recommend an alternative without knowing what you're actually trying to do.

Thanks
Matt

0
Comment actions Permalink

Hey Matt, I want to log the last selected item in the Code Completion. But to log only new completion choices, I need to know when these variables change (which indicates that the user selected a new completion).

Here some minimal example:

 
public class CodeCompletionAnalyserProcess : IDaemonStageProcess
{
 
                 public void Execute(Action<DaemonStageResult> commiter)
        {
            //So far no completion used
            if (String.IsNullOrEmpty(statisticManager.LastChoiceContextId) ||
                String.IsNullOrEmpty(statisticManager.LastChoiceItemId))
            {
                return;
            }
  
            using (StreamWriter w = File.AppendText("log.txt"))
            {                
                SimpleLog.log("ContextID: " + statisticManager.LastChoiceContextId + "\t" + "ItemID: " + statisticManager.LastChoiceItemId + "\t", w);
            }
            statisticManager.LastChoiceContextId = null;
            statisticManager.LastChoiceItemId = null;
        }
 }


As you can see this workaround will damage the last choice functionality from resharper :(


Greetings Toa

0
Comment actions Permalink

OK, I don't think there's a direct way to do this, but it might be possible with a bit of legwork. I'd not recommend using the statistics manager - it doesn't seem suitable for this. What you could try is to get ILookupWindowManager (injected by the container), and subscribing to the BeforeLookupWindowShown event. In your handler, you can get the CurrentLookup property to give you an instance of ILookup, and then subscribe to the ItemCompleted event. This will give you the ILookupItem that the user chose. I can't see what happens if the user cancels - I don't know if the ItemCompleted event is still fired with a null lookup item, or if the event just doesn't get fired. You'll have to check. Also, remember to unsubscribe from any ILookup events when it completes or is dismissed.

0
Comment actions Permalink

Thank you, that was what I'm looking for. Works like a charm. Is there a possibility to access in the handler for the completion event something like the LastChoiceContextId
(e.g completion of IsNullOrEmpty on String should give me "IsNullOrEmpty" as name and String as context)? I only found in ILookupItem the property DisplayName. Greetings Toa

0

Please sign in to leave a comment.