public async Task SemanticErrorReported() { using var workspace = TestWorkspace.CreateCSharp( "class C : Bar { }", composition: SquiggleUtilities.CompositionWithSolutionCrawler ); var spans = await TestDiagnosticTagProducer <DiagnosticsSquiggleTaggerProvider> .GetDiagnosticsAndErrorSpans( workspace ); Assert.Equal(1, spans.Item2.Count()); var firstDiagnostic = spans.Item1.First(); var firstSpan = spans.Item2.First(); Assert.Equal(PredefinedErrorTypeNames.SyntaxError, firstSpan.Tag.ErrorType); var expectedToolTip = new ContainerElement( ContainerElementStyle.Wrapped, new ClassifiedTextElement( new ClassifiedTextRun( ClassificationTypeNames.Text, "CS0246", QuickInfoHyperLink.TestAccessor.CreateNavigationAction( new Uri( "https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS0246)", UriKind.Absolute ) ), "https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS0246)" ), new ClassifiedTextRun(ClassificationTypeNames.Punctuation, ":"), new ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "), new ClassifiedTextRun(ClassificationTypeNames.Text, firstDiagnostic.Message) ) ); ToolTipAssert.EqualContent(expectedToolTip, firstSpan.Tag.ToolTipContent); }
public async Task SemanticErrorReported() { using var workspace = TestWorkspace.CreateCSharp("class C : Bar { }", composition: SquiggleUtilities.CompositionWithSolutionCrawler); var spans = await TestDiagnosticTagProducer <DiagnosticsSquiggleTaggerProvider> .GetDiagnosticsAndErrorSpans(workspace); Assert.Equal(1, spans.Item2.Count()); var firstDiagnostic = spans.Item1.First(); var firstSpan = spans.Item2.First(); Assert.Equal(PredefinedErrorTypeNames.SyntaxError, firstSpan.Tag.ErrorType); var expectedToolTip = new ContainerElement( ContainerElementStyle.Wrapped, new ClassifiedTextElement( new ClassifiedTextRun(ClassificationTypeNames.Text, "CS0246"), new ClassifiedTextRun(ClassificationTypeNames.Punctuation, ":"), new ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "), new ClassifiedTextRun(ClassificationTypeNames.Text, firstDiagnostic.Message))); ToolTipAssert.EqualContent(expectedToolTip, firstSpan.Tag.ToolTipContent); }
public async Task CustomizableTagsForUnnecessaryCode() { var workspaceXml = @"<Workspace> <Project Language=""C#"" CommonReferences=""true""> <Document FilePath = ""Test.cs"" > // System is used - rest are unused. using System.Collections; using System; using System.Diagnostics; using System.Collections.Generic; class Program { void Test() { Int32 x = 2; // Int32 can be simplified. x += 1; } } </Document> </Project> </Workspace>"; using var workspace = TestWorkspace.Create(workspaceXml, composition: SquiggleUtilities.CompositionWithSolutionCrawler); var options = new Dictionary <OptionKey2, object>(); var language = workspace.Projects.Single().Language; var preferIntrinsicPredefinedTypeOption = new OptionKey2(CodeStyleOptions2.PreferIntrinsicPredefinedTypeKeywordInDeclaration, language); var preferIntrinsicPredefinedTypeOptionValue = new CodeStyleOption2 <bool>(value: true, notification: NotificationOption2.Error); options.Add(preferIntrinsicPredefinedTypeOption, preferIntrinsicPredefinedTypeOptionValue); workspace.ApplyOptions(options); var analyzerMap = new Dictionary <string, ImmutableArray <DiagnosticAnalyzer> > { { LanguageNames.CSharp, ImmutableArray.Create <DiagnosticAnalyzer>( new CSharpSimplifyTypeNamesDiagnosticAnalyzer(), new CSharpRemoveUnnecessaryImportsDiagnosticAnalyzer(), new ReportOnClassWithLink()) } }; var diagnosticsAndSpans = await TestDiagnosticTagProducer <DiagnosticsSquiggleTaggerProvider> .GetDiagnosticsAndErrorSpans(workspace, analyzerMap); var spans = diagnosticsAndSpans.Item1 .Zip(diagnosticsAndSpans.Item2, (diagnostic, span) => (diagnostic, span)) .OrderBy(s => s.span.Span.Span.Start).ToImmutableArray(); Assert.Equal(4, spans.Length); var first = spans[0].span; var second = spans[1].span; var third = spans[2].span; var fourth = spans[3].span; var expectedToolTip = new ContainerElement( ContainerElementStyle.Wrapped, new ClassifiedTextElement( new ClassifiedTextRun(ClassificationTypeNames.Text, "IDE0005"), new ClassifiedTextRun(ClassificationTypeNames.Punctuation, ":"), new ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "), new ClassifiedTextRun(ClassificationTypeNames.Text, CSharpAnalyzersResources.Using_directive_is_unnecessary))); Assert.Equal(PredefinedErrorTypeNames.Suggestion, first.Tag.ErrorType); ToolTipAssert.EqualContent(expectedToolTip, first.Tag.ToolTipContent); Assert.Equal(40, first.Span.Start); Assert.Equal(25, first.Span.Length); expectedToolTip = new ContainerElement( ContainerElementStyle.Wrapped, new ClassifiedTextElement( new ClassifiedTextRun(ClassificationTypeNames.Text, "IDE0005"), new ClassifiedTextRun(ClassificationTypeNames.Punctuation, ":"), new ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "), new ClassifiedTextRun(ClassificationTypeNames.Text, CSharpAnalyzersResources.Using_directive_is_unnecessary))); Assert.Equal(PredefinedErrorTypeNames.Suggestion, second.Tag.ErrorType); ToolTipAssert.EqualContent(expectedToolTip, second.Tag.ToolTipContent); Assert.Equal(82, second.Span.Start); Assert.Equal(60, second.Span.Length); expectedToolTip = new ContainerElement( ContainerElementStyle.Wrapped, new ClassifiedTextElement( new ClassifiedTextRun(ClassificationTypeNames.Text, "id", QuickInfoHyperLink.TestAccessor.CreateNavigationAction(new Uri("https://github.com/dotnet/roslyn", UriKind.Absolute)), "https://github.com/dotnet/roslyn"), new ClassifiedTextRun(ClassificationTypeNames.Punctuation, ":"), new ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "), new ClassifiedTextRun(ClassificationTypeNames.Text, "messageFormat"))); Assert.Equal(PredefinedErrorTypeNames.Warning, third.Tag.ErrorType); ToolTipAssert.EqualContent(expectedToolTip, third.Tag.ToolTipContent); Assert.Equal(152, third.Span.Start); Assert.Equal(7, third.Span.Length); expectedToolTip = new ContainerElement( ContainerElementStyle.Wrapped, new ClassifiedTextElement( new ClassifiedTextRun(ClassificationTypeNames.Text, "IDE0049"), new ClassifiedTextRun(ClassificationTypeNames.Punctuation, ":"), new ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "), new ClassifiedTextRun(ClassificationTypeNames.Text, WorkspacesResources.Name_can_be_simplified))); Assert.Equal(PredefinedErrorTypeNames.SyntaxError, fourth.Tag.ErrorType); ToolTipAssert.EqualContent(expectedToolTip, fourth.Tag.ToolTipContent); Assert.Equal(196, fourth.Span.Start); Assert.Equal(5, fourth.Span.Length); }