private async Task AssertIndentNotUsingSmartTokenFormatterButUsingIndenterAsync( string code, int indentationLine, int?expectedIndentation, IndentStyle indentStyle = IndentStyle.Smart) { // create tree service using (var workspace = TestWorkspace.CreateCSharp(code)) { workspace.Options = workspace.Options.WithChangedOption(SmartIndent, LanguageNames.CSharp, indentStyle); var hostdoc = workspace.Documents.First(); var buffer = hostdoc.GetTextBuffer(); var snapshot = buffer.CurrentSnapshot; var line = snapshot.GetLineFromLineNumber(indentationLine); var document = workspace.CurrentSolution.GetDocument(hostdoc.Id); var root = (await document.GetSyntaxRootAsync()) as CompilationUnitSyntax; Assert.False( CSharpIndentationService.ShouldUseSmartTokenFormatterInsteadOfIndenter( Formatter.GetDefaultFormattingRules(workspace, root.Language), root, line.AsTextLine(), await document.GetOptionsAsync(), out _)); TestIndentation(workspace, indentationLine, expectedIndentation); } }
private void AssertIndentNotUsingSmartTokenFormatterButUsingIndenter( string code, int indentationLine, int?expectedIndentation) { // create tree service using (var workspace = CSharpWorkspaceFactory.CreateWorkspaceFromLines(code)) { var hostdoc = workspace.Documents.First(); var buffer = hostdoc.GetTextBuffer(); var snapshot = buffer.CurrentSnapshot; var line = snapshot.GetLineFromLineNumber(indentationLine); var document = workspace.CurrentSolution.GetDocument(hostdoc.Id); var root = document.GetSyntaxRootAsync().Result as CompilationUnitSyntax; Assert.False( CSharpIndentationService.ShouldUseSmartTokenFormatterInsteadOfIndenter( Formatter.GetDefaultFormattingRules(workspace, root.Language), root, line, workspace.Options, CancellationToken.None)); TestIndentation(indentationLine, expectedIndentation, workspace); } }
private async Task AssertIndentUsingSmartTokenFormatterAsync( string code, char ch, int indentationLine, int?expectedIndentation) { // create tree service using (var workspace = TestWorkspace.CreateCSharp(code)) { var hostdoc = workspace.Documents.First(); var buffer = hostdoc.GetTextBuffer(); var snapshot = buffer.CurrentSnapshot; var line = snapshot.GetLineFromLineNumber(indentationLine); var document = workspace.CurrentSolution.GetDocument(hostdoc.Id); var root = (await document.GetSyntaxRootAsync()) as CompilationUnitSyntax; Assert.True( CSharpIndentationService.ShouldUseSmartTokenFormatterInsteadOfIndenter( Formatter.GetDefaultFormattingRules(workspace, root.Language), root, line.AsTextLine(), await document.GetOptionsAsync(), out _)); var actualIndentation = await GetSmartTokenFormatterIndentationWorkerAsync(workspace, buffer, indentationLine, ch); Assert.Equal(expectedIndentation.Value, actualIndentation); } }