Sdílet prostřednictvím


LanguageService.GetProximityExpressions Method

Definition

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

public:
 virtual int GetProximityExpressions(Microsoft::VisualStudio::TextManager::Interop::IVsTextBuffer ^ buffer, int line, int col, int cLines, [Runtime::InteropServices::Out] Microsoft::VisualStudio::TextManager::Interop::IVsEnumBSTR ^ % ppEnum);
public:
 virtual int GetProximityExpressions(Microsoft::VisualStudio::TextManager::Interop::IVsTextBuffer ^ buffer, int line, int col, int cLines, [Runtime::InteropServices::Out] Microsoft::VisualStudio::TextManager::Interop::IVsEnumBSTR ^ &  ppEnum);
 virtual int GetProximityExpressions(Microsoft::VisualStudio::TextManager::Interop::IVsTextBuffer const & buffer, int line, int col, int cLines, [Runtime::InteropServices::Out] Microsoft::VisualStudio::TextManager::Interop::IVsEnumBSTR const & & ppEnum);
public virtual int GetProximityExpressions (Microsoft.VisualStudio.TextManager.Interop.IVsTextBuffer buffer, int line, int col, int cLines, out Microsoft.VisualStudio.TextManager.Interop.IVsEnumBSTR ppEnum);
abstract member GetProximityExpressions : Microsoft.VisualStudio.TextManager.Interop.IVsTextBuffer * int * int * int * IVsEnumBSTR -> int
override this.GetProximityExpressions : Microsoft.VisualStudio.TextManager.Interop.IVsTextBuffer * int * int * int * IVsEnumBSTR -> int
Public Overridable Function GetProximityExpressions (buffer As IVsTextBuffer, line As Integer, col As Integer, cLines As Integer, ByRef ppEnum As IVsEnumBSTR) As Integer

Parameters

buffer
IVsTextBuffer

[in] The IVsTextBuffer holding the source file.

line
Int32

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

col
Int32

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

cLines
Int32

[in] The number of lines to examine.

ppEnum
IVsEnumBSTR

[out] An IVsEnumBSTR object that contains the list of expressions to examine. Return a null value to indicate no expressions.

Returns

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

Implements

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;  
        }  
    }  
}  

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.

Applies to