.NetStar

Hi All,

I am trying to create a custom debugger in my application and I am trying to create the "ValidateBreakpointLocation" in my Lanugage Services Class.

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

namespace MyLanguagePackage
{
class MyLanguageService : LanguageService
{
public override int ValidateBreakpointLocation(IVsTextBuffer buffer,
int line,
int col,
TextSpan[] pCodeSpan)
{
int retval = VSConstants.E_NOTIMPL;
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);
MyAuthoringSink sink = req.Sink as MyAuthoringSink;

TextSpan span = new TextSpan();
// Assume line is invalid.
retval = VSConstants.S_FALSE;
if (sink.GetCodeSpan(out span))
{
pCodeSpan[0] = span;
retval = VSConstants.S_OK;
}
}
}
}
return retval;
}
}
}

This was the sample provided by the SDK Docs. What I want to do is override the AuthoringSink class (in particular the CodeSpan method.) As you can see above they have overridden their own AuthoringSink class. I am having a tough time trying to figure out how to implement it as the documentation says very little about it. Can someone please advise. Thanks!



Re: Visual Studio Extensibility Language Service- AuthoringSink

Dmitry Pavlov

Hi .NetStar,

I am not sure I understand what your problem is.

If you need to override AuthoringSink - return your inheritor instead standard AuthoringSink from LanguageSeervice.Parse method:

/// <summary>< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

/// Parses the source.

///

/// Note: Your ParseSource object must not touch any of the Visual Studio COM objects,

/// this means you must not touch the Source object or any of the other methods on

/// LanguageService since they are not multithread safe, therefore all the information

/// you need to parse must be gathered in CreateParseRequest. For example, you may need

/// project settings and so on.

/// </summary>

/// <param name="request">The request.</param>

/// <returns></returns>

public override AuthoringScope ParseSource(ParseRequest request)

{

                if (request == null)

                {

                                throw new ArgumentNullException("request");

                }

 

                request.Scope = new YourAuthoringScope(request);

                // other code here бн

                return request.Scope;

}

 






Re: Visual Studio Extensibility Language Service- AuthoringSink

.NetStar

Hi Dmitry,

 

Thanks for your reply!  I read in the SDK documents that :

The base class AuthoringSink does not support breakpoint validation so you have to derive a class from the AuthoringSink class and implement the CodeSpan method yourself.  I just wanted to know what exactly needs to be implemented in this codeSpan as there are no documents on what fields need to be populated in this method, etc.

 

I agree with you reply above on how to tell VS to use your Custom AuthoringSink but I just want to know about how to go about overriding this CodeSpan method in the AuthoringSink and what needs to be implemented in the method itself.  Do I have to store all the breakpoints somehow in the method itself





Re: Visual Studio Extensibility Language Service- AuthoringSink

Dmitry Pavlov

Ok, I got what did you mean.

So the last version od VSSDK documentation (RTM 4.0) contains following remarks for public virtual void CodeSpan (TextSpan span) method of AuthoringSink class:

The spans stored in the list by this method are used to validate breakpoints. If you want to support this functionality, you must derive a class from the AuthoringSink class and implement this method and the associated internal list. This list can then be used to implement the language service's ValidateBreakpointLocation method. You must supply the method needed to retrieve the code span from your version of the AuthoringSink class.

The base method does nothing.

So, the answer to your question "Do I have to store all the breakpoints somehow in the method itself " is yes - you do.