驗證舊版語言服務中的中斷點
發行︰ 2016年7月
如需 Visual Studio 2017 的最新文件請參閱 Visual Studio 2017 文件。
中斷點會指出偵錯工具正在執行時,應該特定時間點停止程式執行。 使用者可以在原始程式檔中的任一行上放置中斷點,因為編輯器並不知道何者構成有效的位置中斷點。 啟動偵錯工具時,所有標記 (稱為暫止中斷點) 的中斷點繫結至執行中的程式中的適當位置。 同時驗證中斷點,以確保它們可以將有效的程式碼位置來標示。 例如,註解上的中斷點無效,因為沒有程式碼的原始程式碼中該位置。 偵錯工具停用無效的中斷點。
語言服務知道所顯示的原始碼,因為它可以在偵錯工具啟動前驗證中斷點。 您可以覆寫ValidateBreakpointLocation方法來傳回指定中斷點的有效位置的範圍。 啟動偵錯工具時,但不需等到偵錯工具載入通知使用者的無效的中斷點時,仍會進行驗證中斷點的位置。
實作支援驗證的中斷點
ValidateBreakpointLocation方法指定之中斷點的位置。 您的實作必須決定位置有效,以及指出這是傳回識別程式碼的文字範圍相關聯的行位置中斷點。
如果中斷點是有效的文字範圍會反白顯示中斷點以及。
如果中斷點是無效的則會在狀態列中顯示錯誤訊息。
範例
這個範例會示範實作ValidateBreakpointLocation方法呼叫 (如果有的話),取得一段程式碼剖析器在指定的位置。
這個範例假設您已新增GetCodeSpan
方法AuthoringSink類別所驗證的文字範圍和傳回true
如果它是有效的中斷點位置。
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;
}
}
}