Partager via


ParseResultHandler Delegate

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

This API is not CLS-compliant. The CLS-compliant alternative is [None].

Namespace:  Microsoft.VisualStudio.Package
Assemblies:   Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)
  Microsoft.VisualStudio.Package.LanguageService.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)

Syntax

'Déclaration
<CLSCompliantAttribute(False)> _
Public Delegate Sub ParseResultHandler ( _
    request As ParseRequest _
)
'Utilisation
Dim instance As New ParseResultHandler(AddressOf HandlerMethod)
[CLSCompliantAttribute(false)]
public delegate void ParseResultHandler(
    ParseRequest request
)
[CLSCompliantAttribute(false)]
public delegate void ParseResultHandler(
    ParseRequest^ request
)
[<CLSCompliantAttribute(false)>]
type ParseResultHandler = 
    delegate of 
        request:ParseRequest -> unit
JScript does not support delegates.

Parameters

Remarks

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.

Examples

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) {
            }
        }
    }
}

See Also

Reference

Microsoft.VisualStudio.Package Namespace