├── .gitignore
├── CodeAnalysisDictionary.xml
├── CommonAssemblyInfo.cs
├── LICENSE
├── LocalTestRun.testrunconfig
├── README.md
├── Settings.StyleCop
├── T4Toolbox.Common.props
├── T4Toolbox.Common.ruleset
├── T4Toolbox.sln
├── appveyor.yml
├── build
├── Module.psm1
└── Module.tests.ps1
├── src
├── T4Toolbox.DirectiveProcessors
│ ├── AssemblyInfo.cs
│ ├── DirectiveProcessor.cs
│ ├── T4Toolbox.DirectiveProcessors.csproj
│ ├── TransformationContextProcessor.cs
│ └── packages.config
├── T4Toolbox.TemplateAnalysis
│ ├── AssemblyDirective.cs
│ ├── Attribute.cs
│ ├── AttributeDescriptor.cs
│ ├── AttributeName.cs
│ ├── AttributeValue.cs
│ ├── BlockEnd.cs
│ ├── CaptureNode.cs
│ ├── ClassBlockStart.cs
│ ├── Code.cs
│ ├── CodeBlock.cs
│ ├── CodeBlockStart.cs
│ ├── CustomDirective.cs
│ ├── Directive.cs
│ ├── DirectiveBlockStart.cs
│ ├── DirectiveDescriptor.cs
│ ├── DirectiveName.cs
│ ├── DoubleQuote.cs
│ ├── EndOfFile.cs
│ ├── Equals.cs
│ ├── ExpressionBlockStart.cs
│ ├── GlobalSuppressions.cs
│ ├── HashCode.cs
│ ├── ImportDirective.cs
│ ├── IncludeDirective.cs
│ ├── KnownValuesAttribute.cs
│ ├── NonterminalNode.cs
│ ├── OutputDirective.cs
│ ├── ParameterDirective.cs
│ ├── Position.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── ShiftReduceParserCode.cs
│ ├── StatementBlockStart.cs
│ ├── SyntaxNode.cs
│ ├── SyntaxNodeVisitor.cs
│ ├── SyntaxToken.cs
│ ├── T4Toolbox.TemplateAnalysis.csproj
│ ├── Template.cs
│ ├── TemplateDirective.cs
│ ├── TemplateError.cs
│ ├── TemplateLanguage.cs
│ ├── TemplateParser.partial.cs
│ ├── TemplateParser.y
│ ├── TemplateScanner.lex
│ ├── TemplateScanner.partial.cs
│ ├── TemplateVisibility.cs
│ ├── TerminalNode.cs
│ ├── ValueDescriptor.cs
│ └── packages.config
├── T4Toolbox.VisualStudio.Editor
│ ├── ClassificationFormatDefinitions.cs
│ ├── ClassificationTypeDefinitions.cs
│ ├── ClassificationTypeName.cs
│ ├── ITemplateEditorOptions.cs
│ ├── T4Toolbox.VisualStudio.Editor.csproj
│ ├── TemplateAnalysis.cs
│ ├── TemplateAnalyzer.cs
│ ├── TemplateClassificationTagger.cs
│ ├── TemplateClassificationTaggerProvider.cs
│ ├── TemplateCompletionBuilder.cs
│ ├── TemplateCompletionHandler.cs
│ ├── TemplateCompletionHandlerProvider.cs
│ ├── TemplateCompletionSource.cs
│ ├── TemplateCompletionSourceProvider.cs
│ ├── TemplateContentType.cs
│ ├── TemplateErrorReporter.cs
│ ├── TemplateErrorReporterProvider.cs
│ ├── TemplateErrorTagger.cs
│ ├── TemplateErrorTaggerProvider.cs
│ ├── TemplateOutliningTagger.cs
│ ├── TemplateOutliningTaggerProvider.cs
│ ├── TemplateQuickInfoSource.cs
│ ├── TemplateQuickInfoSourceProvider.cs
│ ├── TemplateTagger.cs
│ └── packages.config
├── T4Toolbox.VisualStudio.ItemTemplates
│ ├── C#
│ │ ├── Generator
│ │ │ ├── Generator.tt
│ │ │ └── Generator.vstemplate
│ │ ├── Script
│ │ │ ├── Script.tt
│ │ │ └── Script.vstemplate
│ │ └── Template
│ │ │ ├── Template.tt
│ │ │ └── Template.vstemplate
│ ├── T4Toolbox.VisualStudio.ItemTemplates.csproj
│ └── VB
│ │ ├── Generator
│ │ ├── Generator.tt
│ │ └── Generator.vstemplate
│ │ ├── Script
│ │ ├── Script.tt
│ │ └── Script.vstemplate
│ │ └── Template
│ │ ├── Template.tt
│ │ └── Template.vstemplate
├── T4Toolbox.VisualStudio
│ ├── AssemblyInfo.cs
│ ├── BrowseObjectExtender.cs
│ ├── BrowseObjectExtenderProvider.cs
│ ├── CustomToolParameter.cs
│ ├── CustomToolParameters.cs
│ ├── CustomToolTemplateEditor.cs
│ ├── EnvDteExtensions.cs
│ ├── ItemMetadataWizard.cs
│ ├── OutputFileManager.cs
│ ├── ProjectItemProperty.cs
│ ├── ProjectItemTemplateWizard.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── ScriptFileGenerator.cs
│ ├── T4Toolbox.VisualStudio.csproj
│ ├── T4ToolboxOptions.cs
│ ├── T4ToolboxOptionsPage.cs
│ ├── T4ToolboxPackage.cs
│ ├── TemplateLocator.cs
│ ├── TemplatedFileGenerator.cs
│ ├── TransformationContextProvider.cs
│ └── packages.config
├── T4Toolbox.vsix
│ ├── Dark.vstheme
│ ├── DarkTheme.pkgdef
│ ├── Include
│ │ └── T4Toolbox.tt
│ ├── License.txt
│ ├── T4Toolbox.vsix.csproj
│ └── source.extension.vsixmanifest
├── T4Toolbox
│ ├── AssemblyInfo.cs
│ ├── CSharpTemplate.cs
│ ├── ClrTemplate.cs
│ ├── CopyToOutputDirectory.cs
│ ├── FileMethods.cs
│ ├── Generator.cs
│ ├── ITransformationContextProvider.cs
│ ├── ItemMetadata.cs
│ ├── ItemType.cs
│ ├── NativeMethods.cs
│ ├── OutputFile.cs
│ ├── OutputItem.cs
│ ├── T4Toolbox.csproj
│ ├── Template.cs
│ ├── TransformationContext.cs
│ ├── TransformationException.cs
│ └── packages.config
└── TextTemplate.ico
└── test
├── Settings.StyleCop
├── T4Toolbox.TemplateAnalysis.Tests
├── AssemblyDirectiveTest.cs
├── AttributeDescriptorTest.cs
├── AttributeNameTest.cs
├── AttributeTest.cs
├── AttributeValueTest.cs
├── BlockEndTest.cs
├── CaptureNodeTest.cs
├── ClassBlockStartTest.cs
├── CodeBlockTest.cs
├── CodeTest.cs
├── CustomDirectiveTest.cs
├── DirectiveBlockStartTest.cs
├── DirectiveDescriptorTest.cs
├── DirectiveNameTest.cs
├── DirectiveTest.cs
├── DoubleQuoteTest.cs
├── EndOfFileTest.cs
├── EqualsTest.cs
├── ExpressionBlockStartTest.cs
├── ImportDirectiveTest.cs
├── IncludeDirectiveTest.cs
├── KnownValuesAttributeTest.cs
├── NonterminalNodeTest.cs
├── OutputDirectiveTest.cs
├── ParameterDirectiveTest.cs
├── PositionTest.cs
├── StatementBlockStartTest.cs
├── SyntaxNodeTest.cs
├── SyntaxNodeVisitorTest.cs
├── SyntaxTokenTest.cs
├── T4Toolbox.TemplateAnalysis.Tests.csproj
├── TemplateDirectiveTest.cs
├── TemplateErrorTest.cs
├── TemplateParserTest.cs
├── TemplateScannerTest.cs
├── TemplateTest.cs
├── TerminalNodeTest.cs
├── ValueDescriptorTest.cs
└── packages.config
├── T4Toolbox.Tests.props
├── T4Toolbox.Tests.ruleset
├── T4Toolbox.Tests
├── CSharpTemplateTest.cs
├── ClrTemplateTest.cs
├── FakeGenerator.cs
├── FakeTemplate.cs
├── FakeTextTemplatingService.cs
├── FakeTransformation.cs
├── GeneratorTest.cs
├── GlobalSuppressions.cs
├── OutputItemTest.cs
├── T4Toolbox.Tests.csproj
├── TemplateTest.cs
├── TransformationContextTest.cs
└── packages.config
├── T4Toolbox.VisualStudio.Editor.Tests
├── FakeClassificationType.cs
├── FakeClassificationTypeRegistryService.cs
├── FakeCompletionSession.cs
├── FakeQuickInfoSession.cs
├── FakeTextBuffer.cs
├── FakeTextSnapshot.cs
├── FakeTrackingSpan.cs
├── SubstituteExporter.cs
├── T4Toolbox.VisualStudio.Editor.Tests.csproj
├── TemplateAnalyzerTest.cs
├── TemplateClassificationTaggerProviderTest.cs
├── TemplateClassificationTaggerTest.cs
├── TemplateCompletionBuilderTest.cs
├── TemplateCompletionHandlerProviderTest.cs
├── TemplateCompletionHandlerTest.cs
├── TemplateCompletionSourceProviderTest.cs
├── TemplateCompletionSourceTest.cs
├── TemplateErrorReporterProviderTest.cs
├── TemplateErrorTaggerProviderTest.cs
├── TemplateErrorTaggerTest.cs
├── TemplateOutliningTaggerProviderTest.cs
├── TemplateOutliningTaggerTest.cs
├── TemplateQuickInfoSourceProviderTest.cs
├── TemplateQuickInfoSourceTest.cs
├── TemplateTaggerTest.cs
└── packages.config
├── T4Toolbox.VisualStudio.IntegrationTests
├── CustomToolParametersTest.cs
├── CustomToolTemplateTest.cs
├── GlobalSuppressions.cs
├── IntegrationTest.cs
├── ItemTemplateTest.cs
├── OutputFileManagerTest.cs
├── PackageTest.cs
├── ScriptFileGeneratorTest.cs
├── T4Toolbox.VisualStudio.IntegrationTests.csproj
├── T4ToolboxOptionsPageTest.cs
├── TargetProject.cs
├── TargetProject.xml
├── TemplateErrorReporterTest.cs
├── TemplateLocatorTest.cs
├── TemplatedFileGeneratorTest.cs
├── TransformationContextProviderTest.cs
├── TransformationContextTest.cs
└── packages.config
└── T4Toolbox.VisualStudio.Tests
├── BrowseObjectExtenderTest.cs
├── CustomToolParameterTest.cs
├── CustomToolParametersTest.cs
├── CustomToolTemplateEditorTest.cs
├── Fakes
├── FakeDte.cs
├── FakeObjectExtenders.cs
├── FakeProject.cs
├── FakeProjectItem.cs
├── FakeProjectItems.cs
├── FakeProjects.cs
├── FakeProperties.cs
├── FakeProperty.cs
├── FakeSolution.cs
├── FakeTemplateLocator.cs
├── FakeTextTemplating.cs
├── FakeTypeDescriptorContext.cs
├── FakeVsActivityLog.cs
├── StubIPersistDocData.cs
├── StubIVsQueryEditQuerySave.cs
└── StubIVsRunningDocumentTable.cs
├── GlobalSuppressions.cs
├── ItemMetadataWizardTest.cs
├── OutputFileManagerTest.cs
├── T4Toolbox.VisualStudio.Tests.csproj
├── T4ToolboxOptionsTest.cs
├── T4ToolboxPackageTest.cs
├── TransformationContextProviderTest.cs
└── packages.config
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio and Git files and folders
2 |
3 | *.suo
4 | *.user
5 | *.cache
6 | *.vspscc
7 | *.patch
8 | *.exe
9 | *.snk
10 |
11 | [Bb]ackup*/
12 | [Bb]in/
13 | [Oo]bj/
14 | [Tt]est[Rr]esult*/
15 | [Pp]ackages/
16 | .vs/
17 |
--------------------------------------------------------------------------------
/CodeAnalysisDictionary.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Lex
5 | LLoc
6 | EOF
7 | Polymorphically
8 |
9 |
10 |
--------------------------------------------------------------------------------
/CommonAssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | using System.Reflection;
6 | using System.Resources;
7 | using System.Runtime.CompilerServices;
8 | using System.Runtime.InteropServices;
9 |
10 | #if DEBUG
11 | [assembly: AssemblyConfiguration("Debug")]
12 | #else
13 | [assembly: AssemblyConfiguration("Release")]
14 | #endif
15 |
16 | [assembly: AssemblyProduct(T4Toolbox.AssemblyInfo.Product)]
17 | [assembly: AssemblyDescription(T4Toolbox.AssemblyInfo.Description)]
18 | [assembly: AssemblyCompany("Oleg Sych")]
19 | [assembly: AssemblyCopyright("Copyright © Oleg Sych. All Rights Reserved.")]
20 | [assembly: AssemblyTrademark("")]
21 | [assembly: AssemblyCulture("")]
22 | [assembly: AssemblyVersion(T4Toolbox.AssemblyInfo.Version)]
23 | [assembly: AssemblyFileVersion(T4Toolbox.AssemblyInfo.Version)]
24 | [assembly: ComVisible(false)]
25 | [assembly: NeutralResourcesLanguage("en-US")]
26 |
27 | // Allow all projects in this solution to access each-other's internals by default.
28 | // In many instances, we need this to enable testing as well as to access constants
29 | // in T4Toolbox.AssemblyInfo class. Revisit this decision when the number of assemblies
30 | // in the project increases to the point where limiting access to internals within the
31 | // solution becomes beneficial.
32 | [assembly: InternalsVisibleTo("T4Toolbox.DirectiveProcessors" + T4Toolbox.AssemblyInfo.PublicKey)]
33 | [assembly: InternalsVisibleTo("T4Toolbox.TemplateAnalysis" + T4Toolbox.AssemblyInfo.PublicKey)]
34 | [assembly: InternalsVisibleTo("T4Toolbox.TemplateAnalysis.Tests" + T4Toolbox.AssemblyInfo.PublicKey)]
35 | [assembly: InternalsVisibleTo("T4Toolbox.Tests" + T4Toolbox.AssemblyInfo.PublicKey)]
36 | [assembly: InternalsVisibleTo("T4Toolbox.VisualStudio" + T4Toolbox.AssemblyInfo.PublicKey)]
37 | [assembly: InternalsVisibleTo("T4Toolbox.VisualStudio.Editor" + T4Toolbox.AssemblyInfo.PublicKey)]
38 | [assembly: InternalsVisibleTo("T4Toolbox.VisualStudio.Editor.Tests" + T4Toolbox.AssemblyInfo.PublicKey)]
39 | [assembly: InternalsVisibleTo("T4Toolbox.VisualStudio.IntegrationTests" + T4Toolbox.AssemblyInfo.PublicKey)]
40 | [assembly: InternalsVisibleTo("T4Toolbox.VisualStudio.Tests" + T4Toolbox.AssemblyInfo.PublicKey)]
41 |
42 | #if SIGN_ASSEMBLY
43 | [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
44 | #else
45 | [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
46 | #endif
47 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2008 Oleg Sych
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/LocalTestRun.testrunconfig:
--------------------------------------------------------------------------------
1 |
2 |
3 | Test settings required to run Visual Studio integration tests.
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/T4Toolbox.Common.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | AnyCPU
7 | $(MSBuildProjectName)
8 | $(MSBuildProjectName)
9 | Properties
10 | v4.6
11 |
12 | 15.0
13 | 15.0
14 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
15 | true
16 | full
17 | prompt
18 | 4
19 | 512
20 | true
21 | bin\$(Configuration)\
22 | $(MSBuildThisFileDirectory)\T4Toolbox.Common.ruleset
23 | false
24 |
25 |
26 |
27 | true
28 | TRACE
29 | $(OutputPath)$(AssemblyName).xml
30 | true
31 |
32 |
33 |
34 | false
35 | DEBUG;TRACE
36 | false
37 |
38 |
39 |
40 |
41 | true
42 | $(MSBuildThisFileDirectory)\T4Toolbox.snk
43 | $(DefineConstants);SIGN_ASSEMBLY
44 |
45 |
46 |
47 |
48 |
49 | False
50 |
55 | False
56 |
57 |
58 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | # CI build definition for https://ci.appveyor.com/project/olegsych/t4toolbox
2 | # To learn more, see http://www.appveyor.com/docs/appveyor-yml
3 |
4 | version: 15.0.0.{build}
5 |
6 | image: Visual Studio 2017
7 |
8 | branches:
9 | only:
10 | - master
11 |
12 | pull_requests:
13 | do_not_increment_build_number: true
14 |
15 | skip_tags: true
16 |
17 | configuration: Release
18 |
19 | environment:
20 | T4ToolboxSnk:
21 | secure: qikNDVTVELcu7WnxruC2+vO9vOdK0whuxosiF5xiV2vI1v/UNno8rtqhoYgKjGoI4IxTvUEtOseNKqF6n0LjKjC2KiiqQj+zvdbkghr9GmWGFiCw27QlbbO/NU9+xWLULt8WxuOTHp681290l304YGRyE2SS2Tb0i86XJXJ5BXC5YvMgK6woVCOHCEITiTmUZBwppFoc5IR3bnyXSSLimLXP0mYPuT+zzPGit2V6HA5VmrXUe8K4DJ1NYDATmcztKusz1klcVzIrtQiII4CWKBvmHHk8g6Hoy8sWHb4CtzHr8QeCvcBwpb6TINLY71M620ELKBczMf2HAUvmcyNY9v+eFnJ8Vcz0gc5o0ENLQ8A/f0i6v57MqnBC9g9WH3kLCNGKe2GVhSdx9+cnaoD5Lnwt3+Qyi9N8UxbGg9yRzSG7u+PU2d/OvneT/r0AGqFIau/yBjSFL3QVMX6j3ycfH653UQOoM/Y8cbyf89tCtz810Y2/IQ4wXUTNEeXvlAiRDlRXPavfjvk8GlCf3ub0LoNbKAx2MXzLN1cQsPmdvCxT7Zlca2PKFwXp4PvIXT50f+QK1HPAn33X2WijYLc9IdiauyKHbP3hdf82b6jmdeCleaFpxRbOUbQyifldxURkla/dZNM5MjdQSMuwqohcK02+t+TzINKTNOQEyOM5JmllU8Y+csgX255G1DyxMNPlsGKor3yhAFsLalbcZu5VMCgPzxvDJSOs3ksAJF9IJB2GynM/Yzy76j8sGbRsx7GW8mT+TxIIiOd/+Y2n/C2jEKoA6RWorNjp1Bw2pjQvI5Z7p8bemTqOjNssQXFJ2m9xfamtlWqQAaBB2KAVjzSPyOCaKGqGXoUsY4XEkoDQ8Nlm0ZJfVGgzz4ccpX4Plhh6sIHThZU0nENypdqy/nNStOkKRw5MKnh57ObgL77bnrWHu0aWZhBfgVFQTo87WWxLEhWFnVfC8rXhXItdz+VWf4oCJ/nrxT13SeMYQ+/FETzF2TCMzP7tQvLRHLuNWNaPvJIsQ56g9uamZQDR7i1jvCjZ16RllA4Vv0y6z34ruaA=
22 |
23 | before_build:
24 | - nuget restore
25 | - ps: >-
26 | Import-Module .\build\Module.psm1
27 |
28 | if (!$env:APPVEYOR_PULL_REQUEST_NUMBER) {
29 | CreateAssemblyKeyFile "T4ToolboxSnk" "T4Toolbox.snk"
30 | }
31 |
32 | build:
33 | parallel: true
34 | verbosity: minimal
35 |
36 | test:
37 | assemblies: '**\*.tests.dll'
38 |
39 | artifacts:
40 | - path: '**\T4Toolbox.*.vsix'
--------------------------------------------------------------------------------
/build/Module.psm1:
--------------------------------------------------------------------------------
1 | function CreateAssemblyKeyFile([string] $environmentVariableName, [string] $fileName) {
2 | $base64string = [Environment]::GetEnvironmentVariable($environmentVariableName)
3 | $bytes = [Convert]::FromBase64String($base64string)
4 | $filePath = [IO.Path]::Combine((Get-Location).Path, $fileName)
5 | Write-Host "Writing from $environmentVariableName environment variable to $filePath"
6 | Set-Content -Path $filePath -Value $bytes -Encoding Byte
7 | }
8 |
9 | Export-ModuleMember -Function CreateAssemblyKeyFile
--------------------------------------------------------------------------------
/build/Module.tests.ps1:
--------------------------------------------------------------------------------
1 | # This is a PowerShell Unit Test file. To run tests
2 | # PM> Install-Module Pester -Scope CurrentUser
3 | # PM> Invoke-Pester
4 |
5 | Import-Module .\Module.psm1
6 |
7 | Describe "Module" {
8 | Context "CreateAssemblyFile" {
9 | $originalLocation = Get-Location
10 |
11 | It "Converts value of environment variable from Base64 to binary and writes it to file in current location" {
12 | $keyBytes = [Guid]::NewGuid().ToByteArray()
13 | $env:TestKey = [Convert]::ToBase64String($keyBytes)
14 | Set-Location "TestDrive:\"
15 |
16 | CreateAssemblyKeyFile "TestKey" "Test.snk"
17 |
18 | $fileBytes = Get-Content -Path "TestDrive:\Test.snk" -Encoding Byte
19 | $fileBytes | Should Be $keyBytes
20 | }
21 |
22 | Set-Location $originalLocation
23 | }
24 | }
25 |
26 | Remove-Module Module
--------------------------------------------------------------------------------
/src/T4Toolbox.DirectiveProcessors/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | using System;
6 |
7 | [assembly: CLSCompliant(false)]
8 |
9 | namespace T4Toolbox.DirectiveProcessors
10 | {
11 | ///
12 | /// Defines constants describing the T4Toolbox.VisualStudio assembly.
13 | ///
14 | internal abstract class AssemblyInfo : T4Toolbox.AssemblyInfo
15 | {
16 | ///
17 | /// Gets the name of the assembly.
18 | ///
19 | public new const string Name = "T4Toolbox.DirectiveProcessors";
20 | }
21 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.DirectiveProcessors/T4Toolbox.DirectiveProcessors.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {E0282961-2D83-48CC-B4D4-8257449CF8F7}
5 | Library
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | Properties\CommonAssemblyInfo.cs
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | {682e771a-76f7-4972-bbdc-1250b67f399b}
29 | T4Toolbox
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/src/T4Toolbox.DirectiveProcessors/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/AssemblyDirective.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System;
8 | using System.Collections.Generic;
9 | using System.ComponentModel;
10 | using System.ComponentModel.DataAnnotations;
11 | using System.Diagnostics;
12 |
13 | [DisplayName("assembly"), Description("Loads an assembly so that your template code can use its types. The effect is similar to adding an assembly reference in a Visual Studio project.")]
14 | internal sealed class AssemblyDirective : Directive
15 | {
16 | public AssemblyDirective(DirectiveBlockStart start, DirectiveName name, IEnumerable attributes, BlockEnd end)
17 | : base(start, name, attributes, end)
18 | {
19 | Debug.Assert(name.Text.Equals("assembly", StringComparison.OrdinalIgnoreCase), "name");
20 | }
21 |
22 | [DisplayName("Name"), Required(ErrorMessage = "The Name attribute is required"), Description("Name of an assembly in the GAC or absolute file path to the assembly.")]
23 | public string AssemblyName
24 | {
25 | get { return this.GetAttributeValue(); }
26 | }
27 |
28 | protected internal override void Accept(SyntaxNodeVisitor visitor)
29 | {
30 | visitor.VisitAssemblyDirective(this);
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/Attribute.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System.Collections.Generic;
8 | using System.Diagnostics;
9 | using Microsoft.VisualStudio.Text;
10 |
11 | internal sealed class Attribute : NonterminalNode
12 | {
13 | private readonly AttributeName name;
14 | private readonly Equals equals;
15 | private readonly DoubleQuote quote1;
16 | private readonly AttributeValue value;
17 | private readonly DoubleQuote quote2;
18 |
19 | public Attribute(AttributeName name, Equals equals, DoubleQuote quote1, AttributeValue value, DoubleQuote quote2)
20 | {
21 | Debug.Assert(name != null, "name");
22 | Debug.Assert(equals != null, "equals");
23 | Debug.Assert(quote1 != null, "quote1");
24 | Debug.Assert(value != null, "value");
25 | Debug.Assert(quote2 != null, "quote2");
26 |
27 | this.name = name;
28 | this.equals = equals;
29 | this.quote1 = quote1;
30 | this.value = value;
31 | this.quote2 = quote2;
32 | }
33 |
34 | public override SyntaxKind Kind
35 | {
36 | get { return SyntaxKind.Attribute; }
37 | }
38 |
39 | public string Name
40 | {
41 | get { return this.name.Text; }
42 | }
43 |
44 | public override Position Position
45 | {
46 | get { return this.name.Position; }
47 | }
48 |
49 | public override Span Span
50 | {
51 | get { return Span.FromBounds(this.name.Span.Start, this.quote2.Span.End); }
52 | }
53 |
54 | public string Value
55 | {
56 | get { return this.value.Text; }
57 | }
58 |
59 | public override IEnumerable ChildNodes()
60 | {
61 | yield return this.name;
62 | yield return this.equals;
63 | yield return this.quote1;
64 | yield return this.value;
65 | yield return this.quote2;
66 | }
67 |
68 | protected internal override void Accept(SyntaxNodeVisitor visitor)
69 | {
70 | visitor.VisitAttribute(this);
71 | }
72 | }
73 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/AttributeName.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | internal sealed class AttributeName : CaptureNode
8 | {
9 | public AttributeName(int start, string text, Position position = default(Position)) : base(start, text, position)
10 | {
11 | }
12 |
13 | public override SyntaxKind Kind
14 | {
15 | get { return SyntaxKind.AttributeName; }
16 | }
17 |
18 | protected internal override void Accept(SyntaxNodeVisitor visitor)
19 | {
20 | visitor.VisitAttributeName(this);
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/AttributeValue.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | internal sealed class AttributeValue : CaptureNode
8 | {
9 | public AttributeValue(int start, string text, Position position = default(Position)) : base(start, text, position)
10 | {
11 | }
12 |
13 | public override SyntaxKind Kind
14 | {
15 | get { return SyntaxKind.AttributeValue; }
16 | }
17 |
18 | protected internal override void Accept(SyntaxNodeVisitor visitor)
19 | {
20 | visitor.VisitAttributeValue(this);
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/BlockEnd.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System.ComponentModel;
8 | using Microsoft.VisualStudio.Text;
9 |
10 | [Description("Ends a text template control block or directive.")]
11 | internal sealed class BlockEnd : SyntaxToken
12 | {
13 | public BlockEnd(int start, Position position = default(Position)) : base(start, position)
14 | {
15 | }
16 |
17 | public override SyntaxKind Kind
18 | {
19 | get { return SyntaxKind.BlockEnd; }
20 | }
21 |
22 | public override Span Span
23 | {
24 | get { return new Span(this.Start, 2); }
25 | }
26 |
27 | protected internal override void Accept(SyntaxNodeVisitor visitor)
28 | {
29 | visitor.VisitBlockEnd(this);
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/CaptureNode.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using Microsoft.VisualStudio.Text;
8 |
9 | internal abstract class CaptureNode : TerminalNode
10 | {
11 | private readonly int start;
12 | private readonly string text;
13 |
14 | protected CaptureNode(int start, string text, Position position) : base(position)
15 | {
16 | this.start = start;
17 | this.text = text;
18 | }
19 |
20 | public string Text
21 | {
22 | get { return this.text; }
23 | }
24 |
25 | public sealed override Span Span
26 | {
27 | get { return new Span(this.start, this.text.Length); }
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/ClassBlockStart.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System.ComponentModel;
8 | using Microsoft.VisualStudio.Text;
9 |
10 | [Description("Starts a class feature control block, which contains Visual Basic or Visual C# code (methods, fields, properties, etc.) that will become a part of the compiled TextTransformation class.")]
11 | internal sealed class ClassBlockStart : CodeBlockStart
12 | {
13 | public ClassBlockStart(int start, Position position = default(Position)) : base(start, position)
14 | {
15 | }
16 |
17 | public override SyntaxKind Kind
18 | {
19 | get { return SyntaxKind.ClassBlockStart; }
20 | }
21 |
22 | public override Span Span
23 | {
24 | get { return new Span(this.Start, 3); }
25 | }
26 |
27 | protected internal override void Accept(SyntaxNodeVisitor visitor)
28 | {
29 | visitor.VisitClassBlockStart(this);
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/Code.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using Microsoft.VisualStudio.Text;
8 |
9 | internal sealed class Code : TerminalNode
10 | {
11 | private readonly Span span;
12 |
13 | public Code(Span span, Position position = default(Position)) : base(position)
14 | {
15 | this.span = span;
16 | }
17 |
18 | public override SyntaxKind Kind
19 | {
20 | get { return SyntaxKind.Code; }
21 | }
22 |
23 | public override Span Span
24 | {
25 | get { return this.span; }
26 | }
27 |
28 | protected internal override void Accept(SyntaxNodeVisitor visitor)
29 | {
30 | visitor.VisitCode(this);
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/CodeBlock.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System.Collections.Generic;
8 | using System.Diagnostics;
9 | using Microsoft.VisualStudio.Text;
10 |
11 | internal sealed class CodeBlock : NonterminalNode
12 | {
13 | private readonly CodeBlockStart start;
14 | private readonly Code code;
15 | private readonly BlockEnd end;
16 |
17 | public CodeBlock(CodeBlockStart start, BlockEnd end)
18 | {
19 | Debug.Assert(start != null, "start");
20 | Debug.Assert(end != null, "end");
21 | this.start = start;
22 | this.end = end;
23 | }
24 |
25 | public CodeBlock(CodeBlockStart start, Code code, BlockEnd end) : this(start, end)
26 | {
27 | Debug.Assert(code != null, "code");
28 | this.code = code;
29 | }
30 |
31 | public BlockEnd End
32 | {
33 | get { return this.end; }
34 | }
35 |
36 | public override SyntaxKind Kind
37 | {
38 | get { return SyntaxKind.CodeBlock; }
39 | }
40 |
41 | public override Position Position
42 | {
43 | get { return this.start.Position; }
44 | }
45 |
46 | public override Span Span
47 | {
48 | get { return Span.FromBounds(this.start.Span.Start, this.end.Span.End); }
49 | }
50 |
51 | public CodeBlockStart Start
52 | {
53 | get { return this.start; }
54 | }
55 |
56 | public override IEnumerable ChildNodes()
57 | {
58 | yield return this.start;
59 |
60 | if (this.code != null)
61 | {
62 | yield return this.code;
63 | }
64 |
65 | yield return this.end;
66 | }
67 |
68 | protected internal override void Accept(SyntaxNodeVisitor visitor)
69 | {
70 | visitor.VisitCodeBlock(this);
71 | }
72 | }
73 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/CodeBlockStart.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | internal abstract class CodeBlockStart : SyntaxToken
8 | {
9 | protected CodeBlockStart(int start, Position position) : base(start, position)
10 | {
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/CustomDirective.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System.Collections.Generic;
8 | using System.ComponentModel;
9 | using System.ComponentModel.DataAnnotations;
10 | using System.Linq;
11 |
12 | [Description("Custom directive.")]
13 | internal sealed class CustomDirective : Directive
14 | {
15 | public CustomDirective(DirectiveBlockStart start, DirectiveName name, IEnumerable attributes, BlockEnd end)
16 | : base(start, name, attributes, end)
17 | {
18 | }
19 |
20 | [Required(ErrorMessage = "The Processor attribute is required")]
21 | [Description("Name of a custom directive processor.")]
22 | public string Processor
23 | {
24 | get { return this.GetAttributeValue(); }
25 | }
26 |
27 | protected internal override void Accept(SyntaxNodeVisitor visitor)
28 | {
29 | visitor.VisitCustomDirective(this);
30 | }
31 |
32 | protected override IEnumerable ValidateAttributes()
33 | {
34 | // Custom directives can contain any custom attributes they need
35 | return Enumerable.Empty();
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/DirectiveBlockStart.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System.ComponentModel;
8 | using Microsoft.VisualStudio.Text;
9 |
10 | [Description("Starts a directive, which provides instructions to the text template transformation engine on how to process the template.")]
11 | internal sealed class DirectiveBlockStart : SyntaxToken
12 | {
13 | public DirectiveBlockStart(int start, Position position = default(Position)) : base(start, position)
14 | {
15 | }
16 |
17 | public override SyntaxKind Kind
18 | {
19 | get { return SyntaxKind.DirectiveBlockStart; }
20 | }
21 |
22 | public override Span Span
23 | {
24 | get { return new Span(this.Start, 3); }
25 | }
26 |
27 | protected internal override void Accept(SyntaxNodeVisitor visitor)
28 | {
29 | visitor.VisitDirectiveBlockStart(this);
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/DirectiveName.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | internal sealed class DirectiveName : CaptureNode
8 | {
9 | public DirectiveName(int start, string text, Position position = default(Position)) : base(start, text, position)
10 | {
11 | }
12 |
13 | public override SyntaxKind Kind
14 | {
15 | get { return SyntaxKind.DirectiveName; }
16 | }
17 |
18 | protected internal override void Accept(SyntaxNodeVisitor visitor)
19 | {
20 | visitor.VisitDirectiveName(this);
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/DoubleQuote.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using Microsoft.VisualStudio.Text;
8 |
9 | internal sealed class DoubleQuote : SyntaxToken
10 | {
11 | public DoubleQuote(int start, Position position = default(Position)) : base(start, position)
12 | {
13 | }
14 |
15 | public override SyntaxKind Kind
16 | {
17 | get { return SyntaxKind.DoubleQuote; }
18 | }
19 |
20 | public override Span Span
21 | {
22 | get { return new Span(this.Start, 1); }
23 | }
24 |
25 | protected internal override void Accept(SyntaxNodeVisitor visitor)
26 | {
27 | visitor.VisitDoubleQuote(this);
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/EndOfFile.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using Microsoft.VisualStudio.Text;
8 |
9 | internal sealed class EndOfFile : SyntaxToken
10 | {
11 | public EndOfFile(int start, Position position = default(Position)) : base(start, position)
12 | {
13 | }
14 |
15 | public override SyntaxKind Kind
16 | {
17 | get { return SyntaxKind.EOF; }
18 | }
19 |
20 | public override Span Span
21 | {
22 | get { return new Span(this.Start, 0); }
23 | }
24 |
25 | protected internal override void Accept(SyntaxNodeVisitor visitor)
26 | {
27 | visitor.VisitEndOfFile(this);
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/Equals.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using Microsoft.VisualStudio.Text;
8 |
9 | internal sealed class Equals : SyntaxToken
10 | {
11 | public Equals(int start, Position position = default(Position)) : base(start, position)
12 | {
13 | }
14 |
15 | public override SyntaxKind Kind
16 | {
17 | get { return SyntaxKind.Equals; }
18 | }
19 |
20 | public override Span Span
21 | {
22 | get { return new Span(this.Start, 1); }
23 | }
24 |
25 | protected internal override void Accept(SyntaxNodeVisitor visitor)
26 | {
27 | visitor.VisitEquals(this);
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/ExpressionBlockStart.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System.ComponentModel;
8 | using Microsoft.VisualStudio.Text;
9 |
10 | [Description("Starts an expression control block, which contains a Visual Basic or Visual C# expression that will be converted to a string and written to the output file.")]
11 | internal sealed class ExpressionBlockStart : CodeBlockStart
12 | {
13 | public ExpressionBlockStart(int start, Position position = default(Position)) : base(start, position)
14 | {
15 | }
16 |
17 | public override SyntaxKind Kind
18 | {
19 | get { return SyntaxKind.ExpressionBlockStart; }
20 | }
21 |
22 | public override Span Span
23 | {
24 | get { return new Span(this.Start, 3); }
25 | }
26 |
27 | protected internal override void Accept(SyntaxNodeVisitor visitor)
28 | {
29 | visitor.VisitExpressionBlockStart(this);
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/GlobalSuppressions.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/olegsych/T4Toolbox/22ea14adf093be3414f418c71cb5cba67dd1e55c/src/T4Toolbox.TemplateAnalysis/GlobalSuppressions.cs
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/HashCode.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | internal static class HashCode
8 | {
9 | internal static int Combine(int hashCode1, int hashCode2)
10 | {
11 | return (hashCode1 << 5) + hashCode1 ^ hashCode2;
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/ImportDirective.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System;
8 | using System.Collections.Generic;
9 | using System.ComponentModel;
10 | using System.ComponentModel.DataAnnotations;
11 | using System.Diagnostics;
12 |
13 | [DisplayName("import"), Description("Allows the use of types in a namespace without providing a fully-qualified name. It is the equivalent of using in C# or imports in Visual Basic.")]
14 | internal sealed class ImportDirective : Directive
15 | {
16 | public ImportDirective(DirectiveBlockStart start, DirectiveName name, IEnumerable attributes, BlockEnd end)
17 | : base(start, name, attributes, end)
18 | {
19 | Debug.Assert(name.Text.Equals("import", StringComparison.OrdinalIgnoreCase), "name");
20 | }
21 |
22 | [Required(ErrorMessage = "The Namespace attribute is required")]
23 | [Description("The fully-qualified name of the namespace being imported. Can be a string of namespaces nested to any level.")]
24 | public string Namespace
25 | {
26 | get { return this.GetAttributeValue(); }
27 | }
28 |
29 | protected internal override void Accept(SyntaxNodeVisitor visitor)
30 | {
31 | visitor.VisitImportDirective(this);
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/IncludeDirective.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System;
8 | using System.Collections.Generic;
9 | using System.ComponentModel;
10 | using System.ComponentModel.DataAnnotations;
11 | using System.Diagnostics;
12 |
13 | [DisplayName("include"), Description("Includes text from another file in the current template.")]
14 | internal sealed class IncludeDirective : Directive
15 | {
16 | public IncludeDirective(DirectiveBlockStart start, DirectiveName name, IEnumerable attributes, BlockEnd end)
17 | : base(start, name, attributes, end)
18 | {
19 | Debug.Assert(name.Text.Equals("include", StringComparison.OrdinalIgnoreCase), "name");
20 | }
21 |
22 | [Required(ErrorMessage = "The File attribute is required")]
23 | [Description("Absolute or relative path to the included file.")]
24 | public string File
25 | {
26 | get { return this.GetAttributeValue(); }
27 | }
28 |
29 | protected internal override void Accept(SyntaxNodeVisitor visitor)
30 | {
31 | visitor.VisitIncludeDirective(this);
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/KnownValuesAttribute.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System;
8 | using System.Collections.Generic;
9 | using System.ComponentModel.DataAnnotations;
10 | using System.Diagnostics;
11 | using System.Linq;
12 | using System.Linq.Expressions;
13 | using System.Reflection;
14 |
15 | [AttributeUsage(AttributeTargets.Property)]
16 | internal sealed class KnownValuesAttribute : System.Attribute
17 | {
18 | private readonly Func> getKnownValues;
19 | private IReadOnlyList knownValues;
20 |
21 | public KnownValuesAttribute(Type enumType)
22 | {
23 | this.getKnownValues = () => GetKnownValues(enumType);
24 | }
25 |
26 | public KnownValuesAttribute(Type factoryType, string methodName)
27 | {
28 | Debug.Assert(factoryType != null, "factoryType");
29 | Debug.Assert(methodName != null, "methodName");
30 |
31 | MethodInfo factoryMethod = factoryType.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Static);
32 |
33 | Debug.Assert(factoryMethod != null, "factoryMethod");
34 |
35 | this.getKnownValues = Expression
36 | .Lambda>>(Expression.Call(factoryMethod))
37 | .Compile();
38 | }
39 |
40 | public IReadOnlyList KnownValues
41 | {
42 | get { return this.knownValues ?? (this.knownValues = this.getKnownValues().ToList()); }
43 | }
44 |
45 | private static ValueDescriptor CreateValueDescriptor(FieldInfo enumValue)
46 | {
47 | Debug.Assert(enumValue != null, "enumValue");
48 |
49 | string displayName = null;
50 | string description = null;
51 |
52 | var displayAttribute = enumValue.GetCustomAttribute();
53 | if (displayAttribute != null)
54 | {
55 | displayName = displayAttribute.Name;
56 | description = displayAttribute.Description;
57 | }
58 |
59 | displayName = displayName ?? enumValue.Name;
60 |
61 | return new ValueDescriptor(displayName, description);
62 | }
63 |
64 | private static IEnumerable GetKnownValues(Type enumType)
65 | {
66 | Debug.Assert(enumType != null, "null");
67 | Debug.Assert(enumType.IsEnum, "IsEnum");
68 | return enumType
69 | .GetFields(BindingFlags.Static | BindingFlags.GetField | BindingFlags.Public)
70 | .Select(CreateValueDescriptor);
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/NonterminalNode.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System.Collections.Generic;
8 |
9 | internal abstract class NonterminalNode : SyntaxNode
10 | {
11 | public override string ToString()
12 | {
13 | return this.Kind.ToString() + "(" + string.Join(", ", this.ChildNodes()) + ")";
14 | }
15 |
16 | public override IEnumerable Validate()
17 | {
18 | foreach (SyntaxNode childNode in this.ChildNodes())
19 | {
20 | foreach (TemplateError error in childNode.Validate())
21 | {
22 | yield return error;
23 | }
24 | }
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/OutputDirective.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System;
8 | using System.Collections.Generic;
9 | using System.ComponentModel;
10 | using System.ComponentModel.DataAnnotations;
11 | using System.Linq;
12 | using System.Text;
13 |
14 | [DisplayName("output"), Description("Defines extension and encoding of the output file.")]
15 | internal sealed class OutputDirective : Directive
16 | {
17 | public OutputDirective(DirectiveBlockStart start, DirectiveName name, IEnumerable attributes, BlockEnd end)
18 | : base(start, name, attributes, end)
19 | {
20 | }
21 |
22 | [Required(ErrorMessage = "The Extension attribute is required")]
23 | [Description("Extension of the output file.")]
24 | public string Extension
25 | {
26 | get { return this.GetAttributeValue(); }
27 | }
28 |
29 | [KnownValues(typeof(OutputDirective), "GetKnownEncodingValues")]
30 | [Description("Encoding of the output file.")]
31 | public string Encoding
32 | {
33 | get { return this.GetAttributeValue(); }
34 | }
35 |
36 | protected internal override void Accept(SyntaxNodeVisitor visitor)
37 | {
38 | visitor.VisitOutputDirective(this);
39 | }
40 |
41 | private static IEnumerable GetKnownEncodingValues()
42 | {
43 | var uniqueNames = new HashSet(StringComparer.OrdinalIgnoreCase);
44 | foreach (EncodingInfo encoding in System.Text.Encoding.GetEncodings())
45 | {
46 | // Eliminate encodings that differ only by casing
47 | if (uniqueNames.Add(encoding.Name))
48 | {
49 | yield return new ValueDescriptor(encoding.Name, encoding.DisplayName);
50 | }
51 | }
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/ParameterDirective.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System;
8 | using System.Collections.Generic;
9 | using System.ComponentModel;
10 | using System.ComponentModel.DataAnnotations;
11 | using System.Diagnostics;
12 |
13 | [DisplayName("parameter"), Description("Declares a property in template code initialized with a value passed in from the external context.")]
14 | internal sealed class ParameterDirective : Directive
15 | {
16 | public ParameterDirective(DirectiveBlockStart start, DirectiveName name, IEnumerable attributes, BlockEnd end)
17 | : base(start, name, attributes, end)
18 | {
19 | Debug.Assert(name.Text.Equals("parameter", StringComparison.OrdinalIgnoreCase), "name");
20 | }
21 |
22 | [DisplayName("Name"), Required(ErrorMessage = "The Name attribute is required")]
23 | [Description("Name of the property.")]
24 | public string ParameterName
25 | {
26 | get { return this.GetAttributeValue(); }
27 | }
28 |
29 | [DisplayName("Type"), Required(ErrorMessage = "The Type attribute is required")]
30 | [Description("Fully-qualified name of the property type.")]
31 | public string ParameterType
32 | {
33 | get { return this.GetAttributeValue(); }
34 | }
35 |
36 | protected internal override void Accept(SyntaxNodeVisitor visitor)
37 | {
38 | visitor.VisitParameterDirective(this);
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/Position.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System;
8 | using System.Globalization;
9 |
10 | internal struct Position : IEquatable
11 | {
12 | private readonly int line;
13 | private readonly int column;
14 |
15 | public Position(int line, int column)
16 | {
17 | this.line = line;
18 | this.column = column;
19 | }
20 |
21 | public int Line
22 | {
23 | get { return this.line; }
24 | }
25 |
26 | public int Column
27 | {
28 | get { return this.column; }
29 | }
30 |
31 | public bool Equals(Position other)
32 | {
33 | return this.Line == other.Line && this.Column == other.Column;
34 | }
35 |
36 | public override int GetHashCode()
37 | {
38 | return HashCode.Combine(this.Line.GetHashCode(), this.Column.GetHashCode());
39 | }
40 |
41 | public override bool Equals(object other)
42 | {
43 | return (other is Position) && this.Equals((Position)other);
44 | }
45 |
46 | public override string ToString()
47 | {
48 | return string.Format(CultureInfo.InvariantCulture, "({0},{1})", this.Line, this.Column);
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | using System;
6 |
7 | [assembly: CLSCompliant(true)]
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/StatementBlockStart.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System.ComponentModel;
8 | using Microsoft.VisualStudio.Text;
9 |
10 | [Description("Starts a statement control block, which contains Visual Basic or Visual C# code that will become a part of the TransformText method in the compiled TextTransformation class.")]
11 | internal sealed class StatementBlockStart : CodeBlockStart
12 | {
13 | public StatementBlockStart(int start, Position position = default(Position)) : base(start, position)
14 | {
15 | }
16 |
17 | public override SyntaxKind Kind
18 | {
19 | get { return SyntaxKind.StatementBlockStart; }
20 | }
21 |
22 | public override Span Span
23 | {
24 | get { return new Span(this.Start, 2); }
25 | }
26 |
27 | protected internal override void Accept(SyntaxNodeVisitor visitor)
28 | {
29 | visitor.VisitStatementBlockStart(this);
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/SyntaxToken.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | internal abstract class SyntaxToken : TerminalNode
8 | {
9 | private readonly int start;
10 |
11 | protected SyntaxToken(int start, Position position) : base(position)
12 | {
13 | this.start = start;
14 | }
15 |
16 | protected int Start
17 | {
18 | get { return this.start; }
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/Template.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Diagnostics;
10 | using Microsoft.VisualStudio.Text;
11 |
12 | internal sealed class Template : NonterminalNode
13 | {
14 | private readonly SyntaxNode[] childNodes;
15 |
16 | public Template(params SyntaxNode[] childNodes)
17 | {
18 | Debug.Assert(childNodes != null, "childNodes");
19 | this.childNodes = childNodes;
20 | }
21 |
22 | public override SyntaxKind Kind
23 | {
24 | get { return SyntaxKind.Template; }
25 | }
26 |
27 | public override Position Position
28 | {
29 | get { return new Position(0, 0); }
30 | }
31 |
32 | public override Span Span
33 | {
34 | get
35 | {
36 | if (this.childNodes.Length == 0)
37 | {
38 | return new Span();
39 | }
40 |
41 | int start = int.MaxValue;
42 | int end = 0;
43 | foreach (SyntaxNode child in this.childNodes)
44 | {
45 | start = Math.Min(start, child.Span.Start);
46 | end = Math.Max(end, child.Span.End);
47 | }
48 |
49 | return Span.FromBounds(start, end);
50 | }
51 | }
52 |
53 | public override IEnumerable ChildNodes()
54 | {
55 | return this.childNodes;
56 | }
57 |
58 | protected internal override void Accept(SyntaxNodeVisitor visitor)
59 | {
60 | visitor.VisitTemplate(this);
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/TemplateError.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System.Diagnostics;
8 | using Microsoft.VisualStudio.Text;
9 |
10 | internal class TemplateError
11 | {
12 | public TemplateError(string message, Span span, Position position)
13 | {
14 | Debug.Assert(message != null, "message");
15 |
16 | this.Message = message;
17 | this.Position = position;
18 | this.Span = span;
19 | }
20 |
21 | public string Message { get; private set; }
22 |
23 | public Position Position { get; private set; }
24 |
25 | public Span Span { get; private set; }
26 | }
27 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/TemplateLanguage.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System;
8 | using System.Collections.Generic;
9 | using System.ComponentModel.DataAnnotations;
10 | using System.Linq;
11 | using System.Text;
12 | using System.Threading.Tasks;
13 |
14 | internal enum TemplateLanguage
15 | {
16 | [Display(Name = "C#", Description = "Visual C#. C# is the default template language.")]
17 | CSharp,
18 |
19 | [Display(Name = "VB", Description = "Visual Basic")]
20 | VisualBasic
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/TemplateVisibility.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System.ComponentModel.DataAnnotations;
8 |
9 | internal enum TemplateVisibility
10 | {
11 | [Display(Name = "public", Description = "Changes visibility of generated template class to public. Public is the default.")]
12 | Public,
13 |
14 | [Display(Name = "internal", Description = "Changes visibility of generated template class to internal.")]
15 | Internal
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/TerminalNode.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System.Collections.Generic;
8 | using System.Linq;
9 |
10 | internal abstract class TerminalNode : SyntaxNode
11 | {
12 | private readonly Position position;
13 |
14 | protected TerminalNode(Position position)
15 | {
16 | this.position = position;
17 | }
18 |
19 | public override Position Position
20 | {
21 | get { return this.position; }
22 | }
23 |
24 | public sealed override IEnumerable ChildNodes()
25 | {
26 | return Enumerable.Empty();
27 | }
28 |
29 | public override string ToString()
30 | {
31 | return this.Kind.ToString() + this.Span.ToString() + this.Position.ToString();
32 | }
33 |
34 | public override IEnumerable Validate()
35 | {
36 | return Enumerable.Empty();
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/ValueDescriptor.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.TemplateAnalysis
6 | {
7 | using System.Diagnostics;
8 |
9 | ///
10 | /// Encapsulates metadata describing an attribute value.
11 | ///
12 | internal sealed class ValueDescriptor
13 | {
14 | public ValueDescriptor(string displayName, string description = null)
15 | {
16 | Debug.Assert(!string.IsNullOrWhiteSpace(displayName), "displayName");
17 | this.DisplayName = displayName;
18 | this.Description = description ?? string.Empty;
19 | }
20 |
21 | public string DisplayName { get; private set; }
22 |
23 | public string Description { get; private set; }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/T4Toolbox.TemplateAnalysis/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/T4Toolbox.VisualStudio.Editor/ClassificationTypeDefinitions.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.VisualStudio.Editor
6 | {
7 | using System.ComponentModel.Composition;
8 | using Microsoft.VisualStudio.Text.Classification;
9 | using Microsoft.VisualStudio.Utilities;
10 |
11 | ///
12 | /// Provides metadata information for registering text template classification types with the Visual Studio editor.
13 | ///
14 | internal static class ClassificationTypeDefinitions
15 | {
16 | [Export, Name(ClassificationTypeName.AttributeName)]
17 | internal static ClassificationTypeDefinition AttributeName { get; set; }
18 |
19 | [Export, Name(ClassificationTypeName.AttributeValue)]
20 | internal static ClassificationTypeDefinition AttributeValue { get; set; }
21 |
22 | [Export, Name(ClassificationTypeName.CodeBlock)]
23 | internal static ClassificationTypeDefinition CodeBlock { get; set; }
24 |
25 | [Export, Name(ClassificationTypeName.Delimiter)]
26 | internal static ClassificationTypeDefinition Delimiter { get; set; }
27 |
28 | [Export, Name(ClassificationTypeName.DirectiveName)]
29 | internal static ClassificationTypeDefinition DirectiveName { get; set; }
30 | }
31 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.VisualStudio.Editor/ClassificationTypeName.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.VisualStudio.Editor
6 | {
7 | ///
8 | /// Defines names of Text Template classification types.
9 | ///
10 | internal static class ClassificationTypeName
11 | {
12 | internal const string AttributeName = TemplateContentType.Name + ".AttributeName";
13 | internal const string AttributeValue = TemplateContentType.Name + ".AttributeValue";
14 | internal const string CodeBlock = TemplateContentType.Name + ".CodeBlock";
15 | internal const string Delimiter = TemplateContentType.Name + ".Delimiter";
16 | internal const string DirectiveName = TemplateContentType.Name + ".DirectiveName";
17 | }
18 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.VisualStudio.Editor/ITemplateEditorOptions.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.VisualStudio.Editor
6 | {
7 | internal interface ITemplateEditorOptions
8 | {
9 | bool CompletionListsEnabled { get; }
10 |
11 | bool ErrorReportingEnabled { get; }
12 |
13 | bool ErrorUnderliningEnabled { get; }
14 |
15 | bool QuickInfoTooltipsEnabled { get; }
16 |
17 | bool SyntaxColorizationEnabled { get; }
18 |
19 | bool TemplateOutliningEnabled { get; }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/T4Toolbox.VisualStudio.Editor/TemplateAnalysis.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.VisualStudio.Editor
6 | {
7 | using System;
8 | using System.Collections.Generic;
9 | using Microsoft.VisualStudio.Text;
10 | using T4Toolbox.TemplateAnalysis;
11 |
12 | internal class TemplateAnalysis : EventArgs
13 | {
14 | public TemplateAnalysis(ITextSnapshot textSnapshot, Template template, IReadOnlyList errors)
15 | {
16 | this.TextSnapshot = textSnapshot;
17 | this.Template = template;
18 | this.Errors = errors;
19 | }
20 |
21 | public IReadOnlyList Errors { get; private set; }
22 |
23 | public Template Template { get; private set; }
24 |
25 | public ITextSnapshot TextSnapshot { get; private set; }
26 | }
27 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.VisualStudio.Editor/TemplateAnalyzer.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.VisualStudio.Editor
6 | {
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Diagnostics;
10 | using Microsoft.VisualStudio.Text;
11 | using T4Toolbox.TemplateAnalysis;
12 |
13 | internal sealed class TemplateAnalyzer
14 | {
15 | private TemplateAnalyzer(ITextBuffer textBuffer)
16 | {
17 | textBuffer.Changed += this.BufferChanged;
18 | this.ParseTextSnapshot(textBuffer.CurrentSnapshot);
19 | }
20 |
21 | public event EventHandler TemplateChanged;
22 |
23 | public TemplateAnalysis CurrentAnalysis { get; private set; }
24 |
25 | public static TemplateAnalyzer GetOrCreate(ITextBuffer buffer)
26 | {
27 | Debug.Assert(buffer != null, "buffer");
28 | return buffer.Properties.GetOrCreateSingletonProperty(() => new TemplateAnalyzer(buffer));
29 | }
30 |
31 | private void BufferChanged(object sender, TextContentChangedEventArgs e)
32 | {
33 | this.ParseTextSnapshot(e.After);
34 | }
35 |
36 | private void OnTemplateChanged(TemplateAnalysis templateAnalysis)
37 | {
38 | this.CurrentAnalysis = templateAnalysis;
39 |
40 | EventHandler handler = this.TemplateChanged;
41 | if (handler != null)
42 | {
43 | handler(this, templateAnalysis);
44 | }
45 | }
46 |
47 | private void ParseTextSnapshot(ITextSnapshot snapshot)
48 | {
49 | var scanner = new TemplateScanner(snapshot.GetText());
50 |
51 | var parser = new TemplateParser(scanner);
52 | parser.Parse();
53 |
54 | // Always return a template object, even if the parser couldn't build one, to avoid downstream errors.
55 | Template template = parser.Template ?? new Template();
56 |
57 | var errors = new List(parser.Errors);
58 | errors.AddRange(template.Validate());
59 |
60 | this.OnTemplateChanged(new TemplateAnalysis(snapshot, template, errors));
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.VisualStudio.Editor/TemplateClassificationTaggerProvider.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.VisualStudio.Editor
6 | {
7 | using System;
8 | using System.ComponentModel.Composition;
9 | using Microsoft.VisualStudio.Text;
10 | using Microsoft.VisualStudio.Text.Classification;
11 | using Microsoft.VisualStudio.Text.Tagging;
12 | using Microsoft.VisualStudio.Utilities;
13 |
14 | [Export(typeof(ITaggerProvider)), TagType(typeof(ClassificationTag)), ContentType(TemplateContentType.Name)]
15 | internal sealed class TemplateClassificationTaggerProvider : ITaggerProvider
16 | {
17 | private readonly ITemplateEditorOptions options;
18 | private readonly IClassificationTypeRegistryService classificationTypeRegistry;
19 |
20 | [ImportingConstructor]
21 | public TemplateClassificationTaggerProvider(ITemplateEditorOptions options, IClassificationTypeRegistryService classificationTypeRegistry)
22 | {
23 | if (options == null)
24 | {
25 | throw new ArgumentNullException(nameof(options));
26 | }
27 |
28 | if (classificationTypeRegistry == null)
29 | {
30 | throw new ArgumentNullException(nameof(classificationTypeRegistry));
31 | }
32 |
33 | this.options = options;
34 | this.classificationTypeRegistry = classificationTypeRegistry;
35 | }
36 |
37 | public ITagger CreateTagger(ITextBuffer buffer) where T : ITag
38 | {
39 | if (this.options.SyntaxColorizationEnabled)
40 | {
41 | return buffer.Properties.GetOrCreateSingletonProperty(() => new TemplateClassificationTagger(buffer, this.classificationTypeRegistry)) as ITagger;
42 | }
43 |
44 | return null;
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.VisualStudio.Editor/TemplateCompletionSource.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.VisualStudio.Editor
6 | {
7 | using System.Collections.Generic;
8 | using System.Diagnostics;
9 | using System.Diagnostics.CodeAnalysis;
10 | using System.Linq;
11 | using Microsoft.VisualStudio.Language.Intellisense;
12 | using Microsoft.VisualStudio.Text;
13 |
14 | internal sealed class TemplateCompletionSource : ICompletionSource
15 | {
16 | private readonly ITextBuffer buffer;
17 | private readonly TemplateAnalyzer analyzer;
18 |
19 | internal TemplateCompletionSource(ITextBuffer buffer)
20 | {
21 | Debug.Assert(buffer != null, "buffer");
22 |
23 | this.buffer = buffer;
24 | this.analyzer = TemplateAnalyzer.GetOrCreate(buffer);
25 | }
26 |
27 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "This method is called by the Visual Studio editor and expects to receive valid arguments")]
28 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "1", Justification = "This method is called by the Visual Studio editor and expects to receive valid arguments")]
29 | public void AugmentCompletionSession(ICompletionSession session, IList completionSets)
30 | {
31 | Debug.Assert(session != null, "session");
32 | Debug.Assert(completionSets != null, "completionSets");
33 |
34 | TemplateAnalysis current = this.analyzer.CurrentAnalysis;
35 | var builder = new TemplateCompletionBuilder(session.GetTriggerPoint(current.TextSnapshot).Value.Position);
36 | builder.Visit(current.Template);
37 | if (builder.Completions != null)
38 | {
39 | ITrackingSpan applicableTo = current.TextSnapshot.CreateTrackingSpan(builder.Node.Span, SpanTrackingMode.EdgeInclusive);
40 | IEnumerable completions = builder.Completions.OrderBy(completion => completion.DisplayText);
41 | var completionSet = new CompletionSet("All", "All", applicableTo, completions, null);
42 | completionSets.Add(completionSet);
43 | }
44 | }
45 |
46 | public void Dispose()
47 | {
48 | this.buffer.Properties.RemoveProperty(this.GetType());
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.VisualStudio.Editor/TemplateCompletionSourceProvider.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.VisualStudio.Editor
6 | {
7 | using System.ComponentModel.Composition;
8 | using System.Diagnostics;
9 | using System.Diagnostics.CodeAnalysis;
10 | using Microsoft.VisualStudio.Language.Intellisense;
11 | using Microsoft.VisualStudio.Text;
12 | using Microsoft.VisualStudio.Utilities;
13 |
14 | [Export(typeof(ICompletionSourceProvider)), Name(TemplateContentType.Name), ContentType(TemplateContentType.Name)]
15 | internal sealed class TemplateCompletionSourceProvider : ICompletionSourceProvider
16 | {
17 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "This method is called by only by the Visual Studio editor and assumes that a textBuffer is supplied")]
18 | public ICompletionSource TryCreateCompletionSource(ITextBuffer textBuffer)
19 | {
20 | Debug.Assert(textBuffer != null, "textBuffer");
21 | return textBuffer.Properties.GetOrCreateSingletonProperty(() => new TemplateCompletionSource(textBuffer));
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.VisualStudio.Editor/TemplateContentType.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.VisualStudio.Editor
6 | {
7 | using System.ComponentModel.Composition;
8 | using Microsoft.VisualStudio.Utilities;
9 |
10 | internal static class TemplateContentType
11 | {
12 | internal const string Name = "TextTemplate";
13 |
14 | [Export, Name(Name), BaseDefinition("code")]
15 | internal static ContentTypeDefinition Definition { get; set; } // Used for metadata only
16 |
17 | [Export, FileExtension(".tt"), ContentType(Name)]
18 | internal static FileExtensionToContentTypeDefinition FileAssociation { get; set; } // Used for metadata only
19 | }
20 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.VisualStudio.Editor/TemplateErrorReporterProvider.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.VisualStudio.Editor
6 | {
7 | using System;
8 | using System.ComponentModel.Composition;
9 | using Microsoft.VisualStudio.Shell;
10 | using Microsoft.VisualStudio.Text;
11 | using Microsoft.VisualStudio.Text.Tagging;
12 | using Microsoft.VisualStudio.Utilities;
13 |
14 | [Export(typeof(ITaggerProvider)), TagType(typeof(ErrorTag)), ContentType(TemplateContentType.Name)]
15 | internal sealed class TemplateErrorReporterProvider : ITaggerProvider
16 | {
17 | private readonly ITemplateEditorOptions options;
18 | private readonly IServiceProvider serviceProvider;
19 | private readonly ITextDocumentFactoryService textDocumentFactory;
20 |
21 | [ImportingConstructor]
22 | public TemplateErrorReporterProvider(
23 | ITemplateEditorOptions options,
24 | SVsServiceProvider serviceProvider,
25 | ITextDocumentFactoryService textDocumentFactory)
26 | {
27 | if (options == null)
28 | {
29 | throw new ArgumentNullException(nameof(options));
30 | }
31 |
32 | if (serviceProvider == null)
33 | {
34 | throw new ArgumentNullException(nameof(serviceProvider));
35 | }
36 |
37 | if (textDocumentFactory == null)
38 | {
39 | throw new ArgumentNullException(nameof(textDocumentFactory));
40 | }
41 |
42 | this.options = options;
43 | this.serviceProvider = serviceProvider;
44 | this.textDocumentFactory = textDocumentFactory;
45 | }
46 |
47 | public ITagger CreateTagger(ITextBuffer buffer) where T : ITag
48 | {
49 | if (this.options.ErrorReportingEnabled)
50 | {
51 | TemplateErrorReporter.GetOrCreate(buffer, this.serviceProvider, this.textDocumentFactory);
52 | }
53 |
54 | return null;
55 | }
56 | }
57 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.VisualStudio.Editor/TemplateErrorTagger.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.VisualStudio.Editor
6 | {
7 | using System.Diagnostics.CodeAnalysis;
8 | using Microsoft.VisualStudio.Text;
9 | using Microsoft.VisualStudio.Text.Adornments;
10 | using Microsoft.VisualStudio.Text.Tagging;
11 | using T4Toolbox.TemplateAnalysis;
12 |
13 | internal sealed class TemplateErrorTagger : TemplateTagger
14 | {
15 | public TemplateErrorTagger(ITextBuffer buffer) : base(buffer)
16 | {
17 | this.UpdateTagSpans(this.Analyzer.CurrentAnalysis);
18 | }
19 |
20 | [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "This is an internal method, called by base class.")]
21 | protected override void CreateTagSpans(TemplateAnalysis analysis)
22 | {
23 | ITextSnapshot snapshot = analysis.TextSnapshot;
24 | foreach (TemplateError error in analysis.Errors)
25 | {
26 | this.CreateTagSpan(snapshot.CreateTrackingSpan(error.Span, SpanTrackingMode.EdgeNegative), new ErrorTag(PredefinedErrorTypeNames.SyntaxError, error.Message));
27 | }
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.VisualStudio.Editor/TemplateErrorTaggerProvider.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.VisualStudio.Editor
6 | {
7 | using System;
8 | using System.ComponentModel.Composition;
9 | using Microsoft.VisualStudio.Text;
10 | using Microsoft.VisualStudio.Text.Tagging;
11 | using Microsoft.VisualStudio.Utilities;
12 |
13 | [Export(typeof(ITaggerProvider)), TagType(typeof(ErrorTag)), ContentType(TemplateContentType.Name)]
14 | internal sealed class TemplateErrorTaggerProvider : ITaggerProvider
15 | {
16 | private readonly ITemplateEditorOptions options;
17 |
18 | [ImportingConstructor]
19 | public TemplateErrorTaggerProvider(ITemplateEditorOptions options)
20 | {
21 | if (options == null)
22 | {
23 | throw new ArgumentNullException(nameof(options));
24 | }
25 |
26 | this.options = options;
27 | }
28 |
29 | public ITagger CreateTagger(ITextBuffer buffer) where T : ITag
30 | {
31 | if (buffer == null)
32 | {
33 | throw new ArgumentNullException(nameof(buffer));
34 | }
35 |
36 | if (this.options.ErrorUnderliningEnabled)
37 | {
38 | return buffer.Properties.GetOrCreateSingletonProperty(() => new TemplateErrorTagger(buffer)) as ITagger;
39 | }
40 |
41 | return null;
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.VisualStudio.Editor/TemplateOutliningTaggerProvider.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.VisualStudio.Editor
6 | {
7 | using System;
8 | using System.ComponentModel.Composition;
9 | using Microsoft.VisualStudio.Text;
10 | using Microsoft.VisualStudio.Text.Tagging;
11 | using Microsoft.VisualStudio.Utilities;
12 |
13 | [Export(typeof(ITaggerProvider)), TagType(typeof(OutliningRegionTag)), ContentType(TemplateContentType.Name)]
14 | internal sealed class TemplateOutliningTaggerProvider : ITaggerProvider
15 | {
16 | private readonly ITemplateEditorOptions options;
17 |
18 | [ImportingConstructor]
19 | public TemplateOutliningTaggerProvider(ITemplateEditorOptions options)
20 | {
21 | if (options == null)
22 | {
23 | throw new ArgumentNullException(nameof(options));
24 | }
25 |
26 | this.options = options;
27 | }
28 |
29 | public ITagger CreateTagger(ITextBuffer buffer) where T : ITag
30 | {
31 | if (buffer == null)
32 | {
33 | throw new ArgumentNullException(nameof(buffer));
34 | }
35 |
36 | if (this.options.TemplateOutliningEnabled)
37 | {
38 | return buffer.Properties.GetOrCreateSingletonProperty(() => new TemplateOutliningTagger(buffer)) as ITagger;
39 | }
40 |
41 | return null;
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/src/T4Toolbox.VisualStudio.Editor/TemplateQuickInfoSource.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright © Oleg Sych. All Rights Reserved.
3 | //
4 |
5 | namespace T4Toolbox.VisualStudio.Editor
6 | {
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Diagnostics;
10 | using Microsoft.VisualStudio.Language.Intellisense;
11 | using Microsoft.VisualStudio.Text;
12 |
13 | internal sealed class TemplateQuickInfoSource : IQuickInfoSource
14 | {
15 | private readonly TemplateAnalyzer analyzer;
16 |
17 | public TemplateQuickInfoSource(ITextBuffer buffer)
18 | {
19 | Debug.Assert(buffer != null, "buffer");
20 | this.analyzer = TemplateAnalyzer.GetOrCreate(buffer);
21 | }
22 |
23 | public void AugmentQuickInfoSession(IQuickInfoSession session, IList