AsmHighlighter.AsmHighlighterLanguageService.ValidateBreakpointLocation C# (CSharp) Method

ValidateBreakpointLocation() public method

Validates the breakpoint location.
public ValidateBreakpointLocation ( IVsTextBuffer buffer, int line, int col, TextSpan pCodeSpan ) : int
buffer IVsTextBuffer The buffer.
line int The line.
col int The col.
pCodeSpan TextSpan The TextSpans to update.
return int
        public override int ValidateBreakpointLocation(IVsTextBuffer buffer, int line, int col, TextSpan[] pCodeSpan)
        {
            // Return noimpl by default
            int retval = VSConstants.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 = 0;
                pCodeSpan[0].iEndLine = line;
                pCodeSpan[0].iEndIndex = col;
            }

            if (buffer != null)
            {
                IVsTextLines textLines = buffer as IVsTextLines;
                if (textLines != null)
                {
                    AsmHighlighterScanner scanner = AsmHighlighterScannerFactory.GetScanner(textLines);
                    Scanner lexer = scanner.Lexer;

                    int maxColumn;
                    textLines.GetLengthOfLine(line, out maxColumn);
                    string lineToParse;
                    textLines.GetLineText(line, 0, line, maxColumn, out lineToParse);

                    // Setup token scanner
                    lexer.SetSource(lineToParse, 0);

                    int state = 0;
                    int start, end;

                    AsmHighlighterToken token = (AsmHighlighterToken)lexer.GetNext(ref state, out start, out end);

                    // Set Not a valid breakpoint
                    retval = VSConstants.S_FALSE;
                    switch (token)
                    {
                        case AsmHighlighterToken.INSTRUCTION:
                        case AsmHighlighterToken.FPUPROCESSOR:
                        case AsmHighlighterToken.SIMDPROCESSOR:
                            if (pCodeSpan != null)
                            {
                                // Breakpoint covers the whole line (including comment)
                                pCodeSpan[0].iEndIndex = maxColumn;
                            }
                            // Set valid breakpoint
                            retval = VSConstants.S_OK;
                            break;
                    }
                }
            }
            return retval;
        }