Partager via


LanguageService.GetProximityExpressions Method

Returns a list of expressions to be evaluated and shown in the Autos window, for a given span of lines.

Namespace:  Microsoft.VisualStudio.Package
Assemblies:   Microsoft.VisualStudio.Package.LanguageService.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)
  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.12.0 (in Microsoft.VisualStudio.Package.LanguageService.12.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.11.0 (in Microsoft.VisualStudio.Package.LanguageService.11.0.dll)

Syntax

'Declaration
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
)
public:
virtual int GetProximityExpressions(
    IVsTextBuffer^ buffer, 
    int line, 
    int col, 
    int cLines, 
    [OutAttribute] IVsEnumBSTR^% ppEnum
)
abstract GetProximityExpressions : 
        buffer:IVsTextBuffer * 
        line:int * 
        col:int * 
        cLines:int * 
        ppEnum:IVsEnumBSTR byref -> int  
override GetProximityExpressions : 
        buffer:IVsTextBuffer * 
        line:int * 
        col:int * 
        cLines:int * 
        ppEnum:IVsEnumBSTR byref -> int
public function GetProximityExpressions(
    buffer : IVsTextBuffer, 
    line : int, 
    col : int, 
    cLines : int, 
    ppEnum : IVsEnumBSTR
) : int

Parameters

  • line
    Type: Int32

    [in] The first line of the span to examine for expressions.

  • col
    Type: Int32

    [in] The offset on the first line to start looking for expressions.

  • cLines
    Type: Int32

    [in] The number of lines to examine.

Return Value

Type: Int32
If successful, returns S_OK, returns S_FALSE if there are no expressions; otherwise, returns an error code.

Implements

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

Remarks

This method is called during debugging to get a list of variables that can be displayed in the Autos window. The range of lines typically encompasses a method or function.

This method can be implemented to use your version of the AuthoringSink class that has collected expressions through the AutoExpression method. Your implementation would search the list of expressions gathered during a parsing operation and return all expressions that fell within the span specified by the line, col, and cLines arguments.

The base method always returns a null value.

Examples

Here is one possible implementation of the GetProximityExpressions method that calls the ParseSource method parser to obtain the code span associated with the current location. Note that the ParseSource method is called on the current thread so the handling of the Autos parse reason must be very quick to avoid undo delays in populating the Autos window.

The GetAutoExpressionsCount and GetAutoExpression methods shown in the example are custom methods on the MyAuthoringSink object and were added to support this example implementation. In addition, the MyVsEnumBSTR class is a class that implements the IVsEnumBSTR interface.

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 Security

See Also

Reference

LanguageService Class

Microsoft.VisualStudio.Package Namespace