LanguageService.ValidateBreakpointLocation Method
Called to determine if the given location can have a breakpoint applied to it.
Namespace: Microsoft.VisualStudio.Package
Assembly: Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)
Syntax
'Declaration
Public Overridable Function ValidateBreakpointLocation ( _
buffer As IVsTextBuffer, _
line As Integer, _
col As Integer, _
pCodeSpan As TextSpan() _
) As Integer
'Usage
Dim instance As LanguageService
Dim buffer As IVsTextBuffer
Dim line As Integer
Dim col As Integer
Dim pCodeSpan As TextSpan()
Dim returnValue As Integer
returnValue = instance.ValidateBreakpointLocation(buffer, _
line, col, pCodeSpan)
public virtual int ValidateBreakpointLocation(
IVsTextBuffer buffer,
int line,
int col,
TextSpan[] pCodeSpan
)
public:
virtual int ValidateBreakpointLocation(
IVsTextBuffer^ buffer,
int line,
int col,
array<TextSpan>^ pCodeSpan
)
public function ValidateBreakpointLocation(
buffer : IVsTextBuffer,
line : int,
col : int,
pCodeSpan : TextSpan[]
) : int
Parameters
buffer
Type: Microsoft.VisualStudio.TextManager.Interop.IVsTextBuffer[in] The IVsTextBuffer object containing the source file.
line
Type: System.Int32[in] The line number where the breakpoint is to be set.
col
Type: System.Int32[in] The offset into the line where the breakpoint is to be set.
pCodeSpan
Type: array<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).
Implements
IVsLanguageDebugInfo.ValidateBreakpointLocation(IVsTextBuffer, Int32, Int32, array<TextSpan[])
Remarks
Warning
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.
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.
Note
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;
}
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.