예제 #1
0
        /// <summary>
        /// Gets the line and start offset of the current statement, assuming
        /// it is between two code snippets (<% %> current statement <% %>).
        /// </summary>
        /// <param name="linelookup">The line lookup to search in.</param>
        /// <param name="startOffset">The variable to place the start offset in.</param>
        /// <returns>The DocumentLine that the current statement starts on.</returns>
        private DocumentLine GetStartline_TextBetweenCodeSnippets(CompiledToTemplateLineLookup linelookup,
																  out int startOffset)
        {
            DocumentLine startline = syntaxEditor1.Document.Lines[linelookup.TemplateLineNumber];

            startOffset = startline.StartOffset + linelookup.TemplateColumn +
                          linelookup.SnippetLength + 2;

            TextStream stream = syntaxEditor1.Document.GetTextStream(startOffset);

            while (stream.TokenText != "%>")
                stream.ReadTokenReverse();

            startOffset = stream.Token.EndOffset;

            return startline;
        }
예제 #2
0
        ///// <summary>
        ///// Updates the UI with the latest information from the debugger.
        ///// </summary>
        ///// <param name="di">The information about the current state of the debugger.</param>
        ///// <param name="finished">True if the debugger has finished executing.</param>
        //public void UpdateDebugState(DebugInformation di, bool finished)
        //{
        //    if (finished)
        //    {
        //        ChangeOutputText(di.CurrentOutput);
        //        StopProgressBar();
        //        functionToolStripStatusLabel.Text = "Debugger Stopped";
        //        return;
        //    }
        //    ChangeOutputText(di.CurrentOutput);
        //    SetLocalVariables(di.LocalVariableInformation);
        //    if (!di.Stopped) return;
        //    if (di.StopReason == StopReason.ExceptionOccurred)
        //    {
        //        MessageBox.Show(di.ExceptionInformation.Message, "Error updating debug state", MessageBoxButtons.OK, MessageBoxIcon.Error);
        //    }
        //    else
        //        SetCurrentStatement(di);
        //}
        //private void SetLocalVariables(IEnumerable<LocalVariableInformation> information)
        //{
        //    Controller.Instance.MainForm.UcFunctions.SetLocalVariables(information);
        //}
        ///// <summary>
        ///// Sets the currently executing statement. Clears the previous marker
        ///// and adds a new CurrentStatementSpanIndicator to the current statement
        ///// layer.
        ///// </summary>
        ///// <param name="di">The information passed back from the debugger. Contains the information needed
        ///// to highlight the correct text in the syntax editor.</param>
        //public void SetCurrentStatement(DebugInformation di)
        //{
        //    int compiledLineNumber = di.StartLineNumber - 1, compiledColumnNumber = di.StartColumnNumber;
        //    List<CompiledToTemplateLineLookup> lookup =
        //        CompileHelper.TemplateLinesLookup[compiledLineNumber];
        //    int lookupIndex = 0;
        //    if (lookup.Count > 1)
        //    {
        //        for (int i = lookup.Count - 1; i >= 0; i--)
        //        {
        //            lookupIndex = i;
        //            CompiledToTemplateLineLookup ll = lookup[i];
        //            if (ll.CompiledColumn <= compiledColumnNumber)
        //                break;
        //        }
        //    }
        //    int startOffset, endOffset;
        //    // Calculate startOffset
        //    DocumentLine startline;
        //    if (compiledColumnNumber >= lookup[lookup.Count - 1].CompiledColumn + lookup[lookup.Count - 1].SnippetLength)
        //    {
        //        startline = GetStartline_CodeAtEndOfLine(lookup, compiledColumnNumber, out startOffset);
        //    }
        //    else if (compiledColumnNumber >= lookup[lookupIndex].CompiledColumn + lookup[lookupIndex].SnippetLength)
        //    {
        //        // The startOffset is between two <% %> blocks, like so
        //        // <% ... %> The text we are stopped on <% ... %>
        //        startline = GetStartline_TextBetweenCodeSnippets(lookup[lookupIndex], out startOffset);
        //    }
        //    else
        //    {
        //        startline = GetStartline(lookup[lookupIndex], compiledColumnNumber, out startOffset);
        //    }
        //    TextStream stream = syntaxEditor1.Document.GetTextStream(startOffset);
        //    SyntaxLanguage language = stream.Token.Language;
        //    if (language.Tag.ToString() == "ScriptLanguage")
        //    {
        //        if (compiledColumnNumber != 0 &&
        //            lookup[lookupIndex].CompiledColumn + lookup[lookupIndex].SnippetLength == 0)
        //        {
        //            // If there is no offset information about this specific piece of code,
        //            // assume this line in the template only contains code at the start (no <% ).
        //            // Just shift by the column number we get from the debugger.
        //            // An example of this would be stepping through foreach statements - each
        //            // piece of the statement is stepped though individually.
        //            startOffset = startline.StartOffset + compiledColumnNumber;
        //            endOffset = GetEndOffsetScriptLanguage(di, startline, startOffset);
        //        }
        //        else if (compiledColumnNumber != lookup[lookupIndex].CompiledColumn)
        //        {
        //            // Fix for multiple statements on one line.
        //            // <% Write(sb, "something"); if(somethingelse) { %>
        //            startOffset += compiledColumnNumber - lookup[lookupIndex].CompiledColumn;
        //            endOffset = GetEndOffsetScriptLanguage(di, startline, startOffset);
        //        }
        //        else if (syntaxEditor1.Document[startOffset - 3] == '=')
        //        {
        //            // Fix for <%= %> blocks.
        //            // Shift the stream to before the <%=
        //            stream.Offset = startOffset - 5;
        //            if (stream.TokenText == "<%")
        //            {
        //                startOffset -= 2;
        //                endOffset = GetEndOffsetLanguageBlock(syntaxEditor1, startOffset, "ScriptLanguage");
        //            }
        //            else // This is not a <%= %> block so treat it like normal.
        //                endOffset = GetEndOffsetScriptLanguage(di, startline, startOffset);
        //        }
        //        else // No special fixes - just use the start offset calculated before.
        //            endOffset = GetEndOffsetScriptLanguage(di, startline, startOffset);
        //    }
        //    else
        //    {
        //        // The -2 is to bring the offset back before the <%
        //        endOffset = GetEndOffsetLanguageBlock(syntaxEditor1, startOffset, "TemplateLanguage");
        //        if (syntaxEditor1.Document.Lines[syntaxEditor1.Document.Lines.Count - 1].EndOffset != endOffset)
        //            endOffset -= 2;
        //    }
        //    SpanIndicatorLayer layer = syntaxEditor1.Document.SpanIndicatorLayers[CurrentStatementLayerKey];
        //    TextRange range = new TextRange(startOffset, endOffset);
        //    layer.Clear();
        //    if (range.IsZeroLength)
        //    {
        //        // This forces the debugger to skip lines that cannot be displayed.
        //        // This may not be a good idea. I can't think of a better option at
        //        // this point though.
        //        Controller.Instance.TriggerNextDebugAction();
        //    }
        //    else
        //    {
        //        layer.Add(new CurrentStatementSpanIndicator(), range);
        //        functionToolStripStatusLabel.Text = "Breakpoint hit";
        //    }
        //    syntaxEditor1.SuspendPainting();
        //    syntaxEditor1.SelectedView.GotoNextSpanIndicator(layer, "Current Statement");
        //    syntaxEditor1.SelectedView.Selection.Collapse();
        //    syntaxEditor1.ResumePainting();
        //}
        /// <summary>
        /// Gets the line and start offset of the current statement, making no assumptions
        /// about the position of the current statement. Naive implementation, will fail
        /// for the cases that have specific functions for this. The specific functions will
        /// be named GetStartLine_[condition], where condition describes the situation in which
        /// the function should be used. If there is no other function which covers the current
        /// situation, use this one.
        /// </summary>
        /// <param name="linelookup">The line lookup to search in.</param>
        /// <param name="compiledColumnNumber">The column number of the current statement in the complied code.</param>
        /// <returns>The DocumentLine that the current statement starts on.</returns>
        /// <param name="startOffset"></param>
        private DocumentLine GetStartline(CompiledToTemplateLineLookup linelookup,
										  int compiledColumnNumber, out int startOffset)
        {
            DocumentLine startline = syntaxEditor1.Document.Lines[linelookup.TemplateLineNumber];

            if (compiledColumnNumber == 0 && CheckForClosingASPTag(startline.StartOffset))
            {
                startOffset = startline.StartOffset + 2;
            }
            else
            {
                startOffset = startline.StartOffset + linelookup.TemplateColumn;
            }
            return startline;
        }