用于定义一个分析操作完成处理程序的委托在语言服务中。
此 API 不兼容 CLS。 兼容 CLS 的替代 API 为 [None]。
命名空间: Microsoft.VisualStudio.Package
程序集: Microsoft.VisualStudio.Package.LanguageService.11.0(在 Microsoft.VisualStudio.Package.LanguageService.11.0.dll 中)
Microsoft.VisualStudio.Package.LanguageService.10.0(在 Microsoft.VisualStudio.Package.LanguageService.10.0.dll 中)
Microsoft.VisualStudio.Package.LanguageService.9.0(在 Microsoft.VisualStudio.Package.LanguageService.9.0.dll 中)
Microsoft.VisualStudio.Package.LanguageService(在 Microsoft.VisualStudio.Package.LanguageService.dll 中)
语法
声明
<CLSCompliantAttribute(False)> _
Public Delegate Sub ParseResultHandler ( _
request As ParseRequest _
)
[CLSCompliantAttribute(false)]
public delegate void ParseResultHandler(
ParseRequest request
)
参数
- request
类型:Microsoft.VisualStudio.Package.ParseRequest
[in] 介绍的 ParseRequest 对象的分析操作。
备注
此委托描述调用的处理程序,在分析操作完成时。ParseRequest 对象提供对分析操作的结果。此委托传递给 LanguageService 类的 BeginParse 方法。
示例
这是的示例演示如何使用此委托。此代码基于该 Source 类的代码处理完成操作的分析。
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) {
}
}
}
}