ParseResultHandler Delegate

 
clsCompliantAlternativeNone

Used to define a delegate for a parsing operation completion handler in a language service.

Namespace:   Microsoft.VisualStudio.Package
Assembly:  Microsoft.VisualStudio.Package.LanguageService.14.0 (in Microsoft.VisualStudio.Package.LanguageService.14.0.dll)

[CLSCompliantAttribute(false)]
public delegate void ParseResultHandler(
	ParseRequest request
)

Parameters

request
Type: Microsoft.VisualStudio.Package.ParseRequest

[in] A ParseRequest object that describes what the parsing operation did.

This delegate describes a handler that is called when a parsing operation is complete. The ParseRequest object provides access to the results of the parsing operation. This delegate is passed to the BeginParse method in the LanguageService class.

Here is an example of how this delegate is used. This code is based on the code in the Source class that handles a parse for a completion operation.

namespace Microsoft.VisualStudio.Package
{
    [CLSCompliant(false)]
    public class Source :
        IDisposable,
        IVsTextLinesEvents,
        IVsFinalTextChangeCommitEvents,
        IVsHiddenTextClient
    {
        private LanguageService service;
        private CompletionSet completionSet;

        public virtual void Completion(IVsTextView textView,
                                       TokenInfo info,
                                       ParseReason reason)
        {
            int line;
            int idx;

            int hr = textView.GetCaretPos(out line, out idx));
            if (hr == VSConstants.S_OK)
            {
                bool synchronous = (reason == ParseReason.CompleteWord ||
                                    reason == ParseReason.DisplayMemberList);
                this.BeginParse(line,
                                idx,
                                info,
                                reason,
                                textView,
                                new ParseResultHandler(this.HandleCompletionResponse),
                                synchronous);
            }
        }

        internal void HandleCompletionResponse(ParseRequest req)
        {
            try
            {
                if (this.service == null || req.Scope == null || this.completionSet == null)
                    return;

                ParseReason reason = req.Reason;
                Declarations decls = req.Scope.GetDeclarations(req.View,
                          req.Line,
                          req.Col,
                          req.TokenInfo,
                          reason);
                bool completeWord = (reason == ParseReason.CompleteWord);
                if ( decls.GetCount() > 0 &&
                    (this.service.Preferences.AutoListMembers || completeWord))
                {
                    this.completionSet.Init(req.View, decls, completeWord);
                }
            } catch (Exception e) {
            }
        }
    }
}
Return to top
Show: