예제 #1
0
    public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList<ISignature> signatures) {
      VSServiceProvider.Current.Logger.PublicEntry(() => {

        //Record our start time for preformance considerations
        var startTime = DateTime.Now;

        //Do we have signatures?
        if (signatures == null || signatures.Count < 1)
          return;

        //Do we have a well-formed session?
        if (session == null || session.TextView == null || session.TextView.TextBuffer == null)
          return;
        
        //Can we get our trigger point?
        var triggerPoint = session.GetTriggerPoint(_textBuffer);
        if (triggerPoint == null)
          return;

        //Can we get our snapshot?
        var workingSnapshot = _textBuffer.CurrentSnapshot;
        if (workingSnapshot == null)
          return;

        //Can we get our SourceFile?
        var sourceFile = _textViewTracker.LatestSourceFile;
        if (sourceFile == null)
          return;

        //Can we get our ParseTree?
        var parseTree = sourceFile.GetParseTree();
        if (parseTree == null)
          return;

        //Can we get our compilation?
        var comp = _textViewTracker.LatestCompilation;
        if (comp == null)
          return;

        //Is the model ready?
        if (!VSServiceProvider.IsModelReady(parseTree) || _textViewTracker.IsLatestCompilationStale || _textViewTracker.IsLatestSourceFileStale) {

          //Ask for a new model
          VSServiceProvider.Current.AskForNewVSModel();

          //Return a message saying we aren't ready yet
          VSServiceProvider.Current.Logger.WriteToLog("The VS model is out of date! Aborting contract lookup.");
          return;//"(VS isn't ready for possible contract lookup yet. Please try again in a few seconds.)";
        }

        string[] contractContents = null;

        //Proceed cautiously
        try
        {

            //Can we get a call node?
            var callNode = IntellisenseContractsHelper.GetAnyCallNodeAboveTriggerPoint(triggerPoint, workingSnapshot, parseTree);
            if (callNode == null || comp == null || sourceFile == null)
                return;

            //Can we get our semantic member?
            var semanticMember = IntellisenseContractsHelper.GetSemanticMember(callNode, comp, sourceFile);
            if (semanticMember == null)
                return;

            var declType = semanticMember.ContainingType;
            // find all members of the same name (virt/non-virt)

            var overloads = GetSignatureOverloads(declType, signatures, semanticMember);

            contractContents = GetContractsForOverloads(overloads);


            //Give up on our contracts if we get an exception
        }
        catch (IllFormedSemanticModelException)
        {
            return;
        }
        catch (InvalidOperationException e)
        {
            if (!e.Message.Contains(VSServiceProvider.InvalidOperationExceptionMessage_TheSnapshotIsOutOfDate))
                throw e;
            else
            {
                this._textViewTracker.IsLatestCompilationStale = true;
                return;
            }
        }
        catch (System.Runtime.InteropServices.COMException)
        {
          // various reasons for COMException
          // - binding failed
          // - project unavailable
          // - ...
          return;
        }

        //Enumerate the signatures and append our custom content
        for (int i = 0; i < signatures.Count; i++) {
          var sig = signatures[i];

          if (contractContents != null && !String.IsNullOrEmpty(contractContents[i]))
          {
              signatures[i] = new SignatureWithContracts(sig, contractContents[i]);
          }
        }

        //Print our elapsed time for preformance considerations
        var elapseTime = DateTime.Now - startTime;
        VSServiceProvider.Current.Logger.WriteToLog("Time to compute quickinfo: " + elapseTime.Milliseconds + "ms");
      
      }, "AugmentSignatureHelpSession");
    }
예제 #2
0
        public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures)
        {
            ContractsPackageAccessor.Current.Logger.PublicEntry(() => {
                //Record our start time for preformance considerations
                var startTime = DateTime.Now;

                //Do we have signatures?
                if (signatures == null || signatures.Count < 1)
                {
                    return;
                }

                //Do we have a well-formed session?
                if (session == null || session.TextView == null || session.TextView.TextBuffer == null)
                {
                    return;
                }

                //Can we get our trigger point?
                var triggerPoint = session.GetTriggerPoint(_textBuffer);
                if (triggerPoint == null)
                {
                    return;
                }

                //Can we get our snapshot?
                var workingSnapshot = _textBuffer.CurrentSnapshot;
                if (workingSnapshot == null)
                {
                    return;
                }

                //Can we get our SourceFile?
                var sourceFile = _textViewTracker.LatestSourceFile;
                if (sourceFile == null)
                {
                    return;
                }

                //Can we get our ParseTree?
                var parseTree = sourceFile.GetParseTree();
                if (parseTree == null)
                {
                    return;
                }

                //Can we get our compilation?
                var comp = _textViewTracker.LatestCompilation;
                if (comp == null)
                {
                    return;
                }

                //Is the model ready?
                if (!parseTree.IsModelReady() || _textViewTracker.IsLatestCompilationStale || _textViewTracker.IsLatestSourceFileStale)
                {
                    //Ask for a new model
                    ContractsPackageAccessor.Current.AskForNewVSModel(_textBuffer);

                    //Return a message saying we aren't ready yet
                    ContractsPackageAccessor.Current.Logger.WriteToLog("The VS model is out of date! Aborting contract lookup.");
                    return;//"(VS isn't ready for possible contract lookup yet. Please try again in a few seconds.)";
                }

                string[] contractContents = null;

                //Proceed cautiously
                try
                {
                    //Can we get a call node?
                    var callNode = IntellisenseContractsHelper.GetAnyCallNodeAboveTriggerPoint(triggerPoint, workingSnapshot, parseTree);
                    if (callNode == null || comp == null || sourceFile == null)
                    {
                        return;
                    }

                    //Can we get our semantic member?
                    var semanticMember = IntellisenseContractsHelper.GetSemanticMember(callNode, comp, sourceFile);
                    if (semanticMember == null)
                    {
                        return;
                    }

                    var declType = semanticMember.ContainingType;
                    // find all members of the same name (virt/non-virt)

                    var overloads = GetSignatureOverloads(declType, signatures, semanticMember);

                    contractContents = GetContractsForOverloads(overloads);


                    //Give up on our contracts if we get an exception
                }
                catch (IllFormedSemanticModelException)
                {
                    return;
                }
                catch (InvalidOperationException e)
                {
                    if (!e.Message.Contains(ContractsPackageAccessor.InvalidOperationExceptionMessage_TheSnapshotIsOutOfDate))
                    {
                        throw e;
                    }
                    else
                    {
                        this._textViewTracker.IsLatestCompilationStale = true;
                        return;
                    }
                }
                catch (System.Runtime.InteropServices.COMException)
                {
                    // various reasons for COMException
                    // - binding failed
                    // - project unavailable
                    // - ...
                    return;
                }

                //Enumerate the signatures and append our custom content
                for (int i = 0; i < signatures.Count; i++)
                {
                    var sig = signatures[i];

                    if (contractContents != null && !String.IsNullOrEmpty(contractContents[i]))
                    {
                        signatures[i] = new SignatureWithContracts(sig, contractContents[i]);
                    }
                }

                //Print our elapsed time for preformance considerations
                var elapseTime = DateTime.Now - startTime;
                ContractsPackageAccessor.Current.Logger.WriteToLog("Time to compute quickinfo: " + elapseTime.Milliseconds + "ms");
            }, "AugmentSignatureHelpSession");
        }