VisualBasicSyntaxFormattingService.vb 2.6 KB
Newer Older
J
Jonathon Marolf 已提交
1 2 3
' Licensed to the .NET Foundation under one or more agreements.
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
P
Pilchie 已提交
4 5 6 7 8 9 10

Imports System.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Formatting
Imports Microsoft.CodeAnalysis.Formatting.Rules
Imports Microsoft.CodeAnalysis.Shared.Collections
Imports Microsoft.CodeAnalysis.Text
11
Imports Microsoft.CodeAnalysis.Diagnostics
P
Pilchie 已提交
12

13
#If Not CODE_STYLE Then
14 15 16 17
Imports System.Composition
Imports Microsoft.CodeAnalysis.Host.Mef
#End If

P
Pilchie 已提交
18
Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting
19
#If Not CODE_STYLE Then
20
    <ExportLanguageService(GetType(ISyntaxFormattingService), LanguageNames.VisualBasic), [Shared]>
P
Pilchie 已提交
21
    Friend Class VisualBasicSyntaxFormattingService
22 23 24
#Else
    Friend Class VisualBasicSyntaxFormattingService
#End If
P
Pilchie 已提交
25 26
        Inherits AbstractSyntaxFormattingService

27
        Private ReadOnly _rules As ImmutableList(Of AbstractFormattingRule)
P
Pilchie 已提交
28

29 30 31 32
#If CODE_STYLE Then
        Public Shared ReadOnly Instance As New VisualBasicSyntaxFormattingService
#End If

33
#If Not CODE_STYLE Then
P
Pilchie 已提交
34
        <ImportingConstructor>
35 36
        <Obsolete(MefConstruction.ImportingConstructorMessage, True)>
        Public Sub New()
37 38 39
#Else
        Public Sub New()
#End If
40
            _rules = ImmutableList.Create(Of AbstractFormattingRule)(
41 42 43 44 45
                New StructuredTriviaFormattingRule(),
                New ElasticTriviaFormattingRule(),
                New AdjustSpaceFormattingRule(),
                New AlignTokensFormattingRule(),
                New NodeBasedFormattingRule(),
46
                DefaultOperationProvider.Instance)
P
Pilchie 已提交
47 48
        End Sub

49
        Public Overrides Function GetDefaultFormattingRules() As IEnumerable(Of AbstractFormattingRule)
50
            Return _rules
P
Pilchie 已提交
51 52
        End Function

53
        Protected Overrides Function CreateAggregatedFormattingResult(node As SyntaxNode, results As IList(Of AbstractFormattingResult), Optional formattingSpans As SimpleIntervalTree(Of TextSpan, TextSpanIntervalIntrospector) = Nothing) As IFormattingResult
P
Pilchie 已提交
54 55 56
            Return New AggregatedFormattingResult(node, results, formattingSpans)
        End Function

57 58
        Protected Overrides Function Format(root As SyntaxNode, options As AnalyzerConfigOptions, formattingRules As IEnumerable(Of AbstractFormattingRule), token1 As SyntaxToken, token2 As SyntaxToken, cancellationToken As CancellationToken) As AbstractFormattingResult
            Return New VisualBasicFormatEngine(root, options, formattingRules, token1, token2).Format(cancellationToken)
P
Pilchie 已提交
59 60
        End Function
    End Class
61
End Namespace