ValidateBreakpointLocation Method
Collapse the table of content
Expand the table of content

LanguageService.ValidateBreakpointLocation Method (IVsTextBuffer, Int32, Int32, TextSpan[])


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

Namespace:   Microsoft.VisualStudio.Package
Assembly:  Microsoft.VisualStudio.Package.LanguageService.14.0 (in Microsoft.VisualStudio.Package.LanguageService.14.0.dll)

public virtual int ValidateBreakpointLocation(
	IVsTextBuffer buffer,
	int line,
	int col,
	TextSpan[] pCodeSpan


Type: Microsoft.VisualStudio.TextManager.Interop.IVsTextBuffer

[in] The IVsTextBuffer object containing the source file.

Type: System.Int32

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

Type: System.Int32

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

Type: Microsoft.VisualStudio.TextManager.Interop.TextSpan[]

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

Return Value

Type: System.Int32

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).

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.

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,
                        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;
Return to top
© 2016 Microsoft