Beispiel #1
0
        void ICodeCellView.RenderDiagnostic(InteractiveDiagnostic diagnostic)
        {
            RenderBuffer();

            var resetConsole = false;

            try {
                if (cell.GetPreviousCell <CodeCell> () != null)
                {
                    output.WriteLine();
                }

                if (output == System.Console.Out)
                {
                    resetConsole = true;
                    System.Console.ForegroundColor = ConsoleColor.Red;
                }

                output.WriteLine(diagnostic.Message);
            } finally {
                if (resetConsole)
                {
                    System.Console.ResetColor();
                }
            }
        }
Beispiel #2
0
        public void RenderDiagnostic(InteractiveDiagnostic diagnostic)
        {
            if (diagnosticsElem == null)
            {
                diagnosticsElem = CreateContentContainer("diagnostics");
                if (HasErrorDiagnostics)
                {
                    diagnosticsElem.AddCssClass("error");
                }
                ContentElement.AppendChild(diagnosticsElem);
            }

            var displayMessage = new StringBuilder();
            var position       = diagnostic.Span.StartLinePosition;
            var severity       = diagnostic.Severity.ToString().ToLowerInvariant();

            var listElem = diagnosticsElem.FirstElementChild;

            if (listElem == null)
            {
                diagnosticsElem.AppendChild(listElem = Document.CreateElement("ul"));
            }

            var itemElement = Document.CreateElement("li", @class: severity);

            if (diagnostic.Span.IsValid)
            {
                displayMessage.Append($"({position.Line + 1},{position.Character + 1}): ");
                itemElement.AddEventListener("click", evnt => {
                    if (!WindowHasSelection)
                    {
                        editor.Focus();
                        editor.CursorPosition = position;
                    }
                });
            }

            displayMessage.Append(severity);

            if (!String.IsNullOrEmpty(diagnostic.Id))
            {
                displayMessage.Append(' ').Append(diagnostic.Id);
            }

            displayMessage.Append(": ").Append(diagnostic.Message);

            itemElement.AppendChild(Document.CreateTextNode(displayMessage.ToString()));
            listElem.AppendChild(itemElement);
        }
Beispiel #3
0
        static void RenderDiagnostic(InteractiveDiagnostic diagnostic)
        {
            switch (diagnostic.Severity)
            {
            case Microsoft.CodeAnalysis.DiagnosticSeverity.Warning:
                ForegroundColor = ConsoleColor.DarkYellow;
                Write($"warning ({diagnostic.Id}): ");
                break;

            case Microsoft.CodeAnalysis.DiagnosticSeverity.Error:
                ForegroundColor = ConsoleColor.Red;
                Write($"error ({diagnostic.Id}): ");
                break;

            default:
                return;
            }

            ResetColor();

            var(line, column) = diagnostic.Span;
            WriteLine($"({line},{column}): {diagnostic.Message}");
        }
Beispiel #4
0
        public InteractiveModule(IRequestTracing sessionProvider, IInteractiveDiagnostics interactiveDiagnostics)
            : base("/interactive")
        {
            this.interactiveDiagnostics = interactiveDiagnostics;

            Get["/"] = _ => View["InteractiveDiagnostics"];

            Get["/providers"] = _ =>
            {
                var providers = this.interactiveDiagnostics
                                .AvailableDiagnostics
                                .Select(p => new { p.Name, p.Description, Type = p.GetType().Name, p.GetType().Namespace, Assembly = p.GetType().Assembly.GetName().Name })
                                .ToArray();

                return(Response.AsJson(providers));
            };

            Get["/providers/{providerName}"] = ctx =>
            {
                InteractiveDiagnostic diagnostic = this.interactiveDiagnostics.GetDiagnostic(ctx.providerName);

                if (diagnostic == null)
                {
                    return(HttpStatusCode.NotFound);
                }

                var methods = diagnostic.Methods
                              .Select(m => new
                {
                    m.MethodName,
                    ReturnType = m.ReturnType.ToString(),
                    m.Description,
                    Arguments = m.Arguments.Select(a => new
                    {
                        ArgumentName = a.Item1,
                        ArgumentType = a.Item2.ToString()
                    })
                })
                              .ToArray();

                return(Response.AsJson(methods));
            };

            Get["/providers/{providerName}/{methodName}"] = ctx =>
            {
                InteractiveDiagnosticMethod method = this.interactiveDiagnostics.GetMethod(ctx.providerName, ctx.methodName);

                if (method == null)
                {
                    return(HttpStatusCode.NotFound);
                }

                object[] arguments = this.GetArguments(method, this.Request.Query);

                return(Response.AsJson(new { Result = this.interactiveDiagnostics.ExecuteDiagnostic(method, arguments) }));
            };

            Get["/templates/{providerName}/{methodName}"] = ctx =>
            {
                InteractiveDiagnosticMethod method = this.interactiveDiagnostics.GetMethod(ctx.providerName, ctx.methodName);

                if (method == null)
                {
                    return(HttpStatusCode.NotFound);
                }

                var template = this.interactiveDiagnostics.GetTemplate(method);

                if (template == null)
                {
                    return(HttpStatusCode.NotFound);
                }

                return(template);
            };
        }
Beispiel #5
0
 public void RenderDiagnostic(InteractiveDiagnostic diagnostic)
 {
 }