LanguageService.GetProximityExpressions 方法

返回在 汽车 窗口将计算和显示的表达式列表,行特定的大小。

命名空间:  Microsoft.VisualStudio.Package
程序集:   Microsoft.VisualStudio.Package.LanguageService.9.0(在 Microsoft.VisualStudio.Package.LanguageService.9.0.dll 中)
  Microsoft.VisualStudio.Package.LanguageService.10.0(在 Microsoft.VisualStudio.Package.LanguageService.10.0.dll 中)
  Microsoft.VisualStudio.Package.LanguageService.11.0(在 Microsoft.VisualStudio.Package.LanguageService.11.0.dll 中)
  Microsoft.VisualStudio.Package.LanguageService(在 Microsoft.VisualStudio.Package.LanguageService.dll 中)

语法

声明
Public Overridable Function GetProximityExpressions ( _
    buffer As IVsTextBuffer, _
    line As Integer, _
    col As Integer, _
    cLines As Integer, _
    <OutAttribute> ByRef ppEnum As IVsEnumBSTR _
) As Integer
public virtual int GetProximityExpressions(
    IVsTextBuffer buffer,
    int line,
    int col,
    int cLines,
    out IVsEnumBSTR ppEnum
)

参数

  • line
    类型:System.Int32
    [in] 检查范围的第一行的表达式。
  • col
    类型:System.Int32
    [in] 在启动的第一行的偏移量查找表达式。

返回值

类型:System.Int32
如果成功,则返回 S_OK,返回 S_FALSE ,如果没有表达式;否则,返回错误代码。

实现

IVsLanguageDebugInfo.GetProximityExpressions(IVsTextBuffer, Int32, Int32, Int32, IVsEnumBSTR%)

备注

此方法调用在调试获取过程中 汽车 窗口中显示变量的列表。行的大小通常包含方法或函数。

此方法实现使用 AutoExpression 方法收集了表达式 AuthoringSink 类的版本。实现将搜索在分析操作中收集的表达式列表,并返回属于该范围的任何表达式都由 line、 col和 cLines 参数指定了。

该基方法始终返回 null 值。

示例

这是调用 ParseSource 方法分析器获取代码大小与当前位置 GetProximityExpressions 方法的一个可能的实现。请注意 ParseSource 调用方法当前线程,这样处理 Autos 分析原因必须是非常快避免移除在填充 汽车 窗口的延迟。

在本示例中显示的 GetAutoExpressionsCount 和 GetAutoExpression 方法是在 MyAuthoringSink 对象的自定义方法和添加支持本示例实现。此外, MyVsEnumBSTR 类是一个实现 IVsEnumBSTR 接口的类。

using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Package;
using Microsoft.VisualStudio.TextManager.Interop;

namespace MyLanguagePackage
{
    public class MyLanguageService : LanguageService
    {
        public override int GetProximityExpressions(IVsTextBuffer buffer,
                                                    int line,
                                                    int col,
                                                    int cLines,
                                                    out IVsEnumBSTR ppEnum)
        {
            int retval = HRESULT.E_NOTIMPL;
            ppEnum = null;
            if (buffer != null)
            {
                IVsTextLines textLines = buffer as IVsTextLines;
                if (textLines != null)
                {
                    Source src = this.GetSource(textLines);
                    if (src != null)
                    {
                        TokenInfo tokenInfo = new TokenInfo();
                        string text = src.GetText();
                        ParseRequest req = CreateParseRequest(src,
                                                              line,
                                                              col,
                                                              tokenInfo,
                                                              text,
                                                              src.GetFilePath(),
                                                              ParseReason.Autos,
                                                              null);
                        req.Scope = this.ParseSource(req);
                        MyAuthoringSink sink = req.Sink as MyAuthoringSink;

                        retval = VSConstants.S_FALSE;
                        int spanCount = sink.GetAutoExpressionsCount();
                        if (spanCount > 0) {
                            MyVsEnumBSTR bstrList = new MyVsEnumBSTR();
                            for (int i = 0; i < spanCount; i++)
                            {
                                TextSpan span;
                                sink.GetAutoExpression(i, out span);
                                string expression = src.GetText(span.iStartLine,
                                                                span.iStartIndex,
                                                                span.iEndLine,
                                                                span.iEndIndex);
                                bstrList.AddString(expression);
                            }
                            ppEnum = bstrList;
                            retval = VSConstants.S_OK;
                        }
                    }
                }
            }
            return retval;
        }
    }
}

.NET Framework 安全性

请参见

参考

LanguageService 类

Microsoft.VisualStudio.Package 命名空间