验证断点 (托管包结构)

断点指示程序执行应停止在特定位置,当在调试器时运行。 用户在任意行上放置断点在源文件,因为,编辑器不了解组合断点的有效位置。 当调试器生成时,所有清单断点 (称为等待断点) 绑定到正在运行的程序中的相应位置。 同时断点验证确保它们指示活动代码位置。 例如,在中,因为没有代码在源代码中,该位置在注释的断点无效。 调试器禁用无效断点。

因为语言服务知道显示的源代码,它可以验证断点,在调试器中启动之前。 可以重写 ValidateBreakpointLocation 方法返回的大小指定有效的位置为断点。 断点位置仍验证,当调试器启动时,但是,用户发出通知无效断点,而不必等待调试器加载。

实现用于验证断点支持

  • 提供 ValidateBreakpointLocation 方法断点的位置。 实现必须决定位置是否有效并将返回标识代码与行位置断点的文本范围指示此操作。

  • 返回 S_OK ,如果位置是有效的,或者 S_FALSE ,如果是无效的。

  • 如果断点是有效的文本范围的断点以及显示。

  • 如果断点无效,错误消息会在状态栏。

示例

此示例演示调用该分析器获取代码范围 ValidateBreakpointLocation 方法的实现 (如果有) 在指定的位置。

此示例假定,您已添加了一个 GetCodeSpan 方法以验证文本范围并返回 true 的 AuthoringSink 类,如果它是有效的断点位置。

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

namespace TestLanguagePackage
{
    class TestLanguageService : LanguageService
    {
        public override int ValidateBreakpointLocation(IVsTextBuffer buffer,
                                                       int line,
                                                       int col,
                                                       TextSpan[] pCodeSpan)
        {
            int retval = VSConstants.S_FALSE;
            if (pCodeSpan != null)
            {
                // Initialize span to current line 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);
                        TestAuthoringSink sink = req.Sink as TestAuthoringSink;

                        TextSpan span = new TextSpan();
                        if (sink.GetCodeSpan(out span))
                        {
                            pCodeSpan[0] = span;
                            retval = VSConstants.S_OK;
                        }
                    }
                }
            }
            return retval;
        }
    }
}

请参见

其他资源

语言服务功能 (托管包结构)