LanguageService.ValidateBreakpointLocation 方法
调用确定给定位置是否可以具有断点应用于它。
命名空间: Microsoft.VisualStudio.Package
程序集: Microsoft.VisualStudio.Package.LanguageService.9.0(在 Microsoft.VisualStudio.Package.LanguageService.9.0.dll 中)
Microsoft.VisualStudio.Package.LanguageService.10.0(在 Microsoft.VisualStudio.Package.LanguageService.10.0.dll 中)
Microsoft.VisualStudio.Package.LanguageService.11.0(在 Microsoft.VisualStudio.Package.LanguageService.11.0.dll 中)
Microsoft.VisualStudio.Package.LanguageService(在 Microsoft.VisualStudio.Package.LanguageService.dll 中)
语法
声明
Public Overridable Function ValidateBreakpointLocation ( _
buffer As IVsTextBuffer, _
line As Integer, _
col As Integer, _
pCodeSpan As TextSpan() _
) As Integer
public virtual int ValidateBreakpointLocation(
IVsTextBuffer buffer,
int line,
int col,
TextSpan[] pCodeSpan
)
参数
- buffer
类型:Microsoft.VisualStudio.TextManager.Interop.IVsTextBuffer
[in] 包含源文件的 IVsTextBuffer 对象。
- line
类型:System.Int32
[in] 行号断点将设置的位置。
- col
类型:System.Int32
[in] 偏移量断点将设置的行中。
- pCodeSpan
类型:array<Microsoft.VisualStudio.TextManager.Interop.TextSpan[]
[out] 如果断点,可以设置,返回给定代码区域 TextSpan 受影响的断点。
返回值
类型:System.Int32
如果成功,则返回; S_OK否则返回 S_FALSE ,如果没有代码在给定位置或返回错误代码 (该验证推迟,直到调试引擎加载)。
实现
IVsLanguageDebugInfo.ValidateBreakpointLocation(IVsTextBuffer, Int32, Int32, array<TextSpan[])
备注
即使您不打算支持 ValidateBreakpointLocation ,但该语言支持断点,必须重写 ValidateBreakpointLocation 方法并返回包含指定的行和列的大小;否则,断点不能设置任何位置排除行将 1。 可以返回 E_NOTIMPL 指示您未以其他方式支持此方法,但必须始终设置范围。 该示例演示了如何实现的。
因为语言服务分析代码,它通常知道被视为代码,以及不是。 通常,调试引擎加载,并且挂起的断点绑定到该数据源。 它是目前断点位置进行验证。 此方法是一种更快确定断点是否可以在特定位置设置,而无需加载调试引擎。
可以执行此方法调用与 CodeSpan分析原因的 ParseSource 方法。 该分析器检查指定的位置并返回标识代码的大小在该位置。 如果有代码在位置,标识的范围应该通过代码添加到 CodeSpan 方法的实现。 AuthoringSink 类的版本。 然后 ValidateBreakpointLocation 方法的实现从 AuthoringSink 类的版本检索范围并返回该 pCodeSpan 参数的范围。
基方法返回 E_NOTIMPL。
示例
这是调用 ParseSource 方法分析器获取代码大小与当前位置 ValidateBreakpointLocation 方法的一个可能的实现。 请注意 ParseSource 调用方法当前线程,这样处理 CodeSpan 在放置断点分析原因必须是非常快避免延迟。
在本示例中显示的 GetCodeSpan 方法是在 MyAuthoringSink 对象的自定义和方法添加支持本示例实现。
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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。