Condividi tramite


LanguageService.ValidateBreakpointLocation Method

Definition

Called to determine if the given location can have a breakpoint applied to it.

public:
 virtual int ValidateBreakpointLocation(Microsoft::VisualStudio::TextManager::Interop::IVsTextBuffer ^ buffer, int line, int col, cli::array <Microsoft::VisualStudio::TextManager::Interop::TextSpan> ^ pCodeSpan);
public:
 virtual int ValidateBreakpointLocation(Microsoft::VisualStudio::TextManager::Interop::IVsTextBuffer ^ buffer, int line, int col, Platform::Array <Microsoft::VisualStudio::TextManager::Interop::TextSpan> ^ pCodeSpan);
 virtual int ValidateBreakpointLocation(Microsoft::VisualStudio::TextManager::Interop::IVsTextBuffer const & buffer, int line, int col, std::Array <Microsoft::VisualStudio::TextManager::Interop::TextSpan> const & pCodeSpan);
public virtual int ValidateBreakpointLocation (Microsoft.VisualStudio.TextManager.Interop.IVsTextBuffer buffer, int line, int col, Microsoft.VisualStudio.TextManager.Interop.TextSpan[] pCodeSpan);
abstract member ValidateBreakpointLocation : Microsoft.VisualStudio.TextManager.Interop.IVsTextBuffer * int * int * Microsoft.VisualStudio.TextManager.Interop.TextSpan[] -> int
override this.ValidateBreakpointLocation : Microsoft.VisualStudio.TextManager.Interop.IVsTextBuffer * int * int * Microsoft.VisualStudio.TextManager.Interop.TextSpan[] -> int
Public Overridable Function ValidateBreakpointLocation (buffer As IVsTextBuffer, line As Integer, col As Integer, pCodeSpan As TextSpan()) As Integer

Parameters

buffer
IVsTextBuffer

[in] The IVsTextBuffer object containing the source file.

line
Int32

[in] The line number where the breakpoint is to be set.

col
Int32

[in] The offset into the line where the breakpoint is to be set.

pCodeSpan
TextSpan[]

[out] Returns the TextSpan giving the extent of the code affected by the breakpoint if the breakpoint can be set.

Returns

If successful, returns S_OK; otherwise returns S_FALSE if there is no code at the given position or returns an error code (the validation is deferred until the debug engine is loaded).

Implements

Examples

Here is one possible implementation of the ValidateBreakpointLocation 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 CodeSpan parse reason must be very quick to avoid delays in placing the breakpoint.

The GetCodeSpan method shown in the example is a custom method on the MyAuthoringSink object and was added to support this example implementation.

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

namespace MyLanguagePackage  
{  
    public class MyLanguageService : LanguageService  
    {  
        public override int ValidateBreakpointLocation(IVsTextBuffer buffer,  
                                                       int line,  
                                                       int col,  
                                                       TextSpan[] pCodeSpan)  
        {  
            int retval = HRESULT.E_NOTIMPL;  
            if (pCodeSpan != null)  
            {  
                // Make sure the span is set to at least the current  
                // position by default.  
                pCodeSpan[0].iStartLine = line;  
                pCodeSpan[0].iStartIndex = col;  
                pCodeSpan[0].iEndLine = line;  
                pCodeSpan[0].iEndIndex = col;  
            }  
            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.CodeSpan,  
                                                              null);  
                        req.Scope = this.ParseSource(req);  

                        MyAuthoringSink sink = req.Sink as MyAuthoringSink;  
                        TextSpan span = new TextSpan();  
                        retval = VSConstants.S_FALSE;  
                        if (sink != null && sink.GetCodeSpan(out span))  
                        {  
                            pCodeSpan[0] = span;  
                            retval = VSConstants.S_OK;  
                        }  
                    }  
                }  
            }  
            return retval;  
        }  
    }  
}  

Remarks

Even if you do not intend to support the ValidateBreakpointLocation but your language does support breakpoints, you must override the ValidateBreakpointLocation method and return a span that contains the specified line and column; otherwise, breakpoints cannot be set anywhere except line 1. You can return E_NOTIMPL to indicate that you do not otherwise support this method but the span must always be set. The example shows how this can be done.

Since the language service parses the code, it generally knows what is considered code and what is not. Normally, the debug engine is loaded and the pending breakpoints are bound to the source. It is at this time the breakpoint location is validated. This method is a fast way to determine if a breakpoint can be set at a particular location without loading the debug engine.

You can implement this method to call the ParseSource method with the parse reason of CodeSpan. The parser examines the specified location and returns a span identifying the code at that location. If there is code at the location, the span identifying that code should be passed to your implementation of the CodeSpan method in your version of the AuthoringSink class. Then your implementation of the ValidateBreakpointLocation method retrieves that span from your version of the AuthoringSink class and returns that span in the pCodeSpan argument.

The base method returns E_NOTIMPL.

Applies to