Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
The C# language level is now set for T4 files to avoid C# 6 suggestio…
Browse files Browse the repository at this point in the history
…ns. Fixes #58.
  • Loading branch information
MrJul committed May 18, 2016
1 parent ff65273 commit 5255ea1
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 12 deletions.
1 change: 1 addition & 0 deletions GammaJul.ReSharper.ForTea/GammaJul.ReSharper.ForTea.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
<Compile Include="Psi\IT4FileDependencyInvalidator.cs" />
<Compile Include="Psi\PsiExtensions.cs" />
<Compile Include="Psi\T4CachingLexerService.cs" />
<Compile Include="Psi\T4CSharpLanguageLevelProvider.cs" />
<Compile Include="Psi\T4FileDependencyManager.Invalidator.cs" />
<Compile Include="Psi\T4FileDependencyManager.cs" />
<Compile Include="Psi\T4CSharpCodeGenerator.cs" />
Expand Down
3 changes: 2 additions & 1 deletion GammaJul.ReSharper.ForTea/GammaJul.ReSharper.ForTea.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
<authors>Julien Lebosquain</authors>
<description>Adds support for editing T4 text templating files (.tt)</description>
<releaseNotes>
- Added support for ReSharper 2016.1 (#72)
- Added support for ReSharper 2016.1 (#72).
- The TransformText method is now resolved from base classes (#64).
- C# 6.0 language features aren't enabled anymore in VS versions before VS2015 update 2 (#58).
</releaseNotes>
<projectUrl>https://github.com/MrJul/ForTea/</projectUrl>
<iconUrl>https://raw.github.com/MrJul/ForTea/master/Logo/ForTea%20128x128.png</iconUrl>
Expand Down
51 changes: 51 additions & 0 deletions GammaJul.ReSharper.ForTea/Psi/T4CSharpLanguageLevelProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#region License
// Copyright 2012 Julien Lebosquain
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion


using System;
using JetBrains.Annotations;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.CSharp;
using JetBrains.ReSharper.Psi.CSharp.Impl;
using JetBrains.ReSharper.Psi.Modules;

namespace GammaJul.ReSharper.ForTea.Psi {

[SolutionFeaturePart]
public class T4CSharpLanguageLevelProvider : CSharpLanguageLevelProvider {

[NotNull] private readonly T4Environment _t4Environment;

public override bool IsApplicable(IPsiModule psiModule)
=> psiModule is T4PsiModule;

public override bool CanSetLanguageLevel(IPsiModule psiModule)
=> false;

public override CSharpLanguageLevel GetLanguageLevel(IPsiModule psiModule)
=> _t4Environment.CSharpLanguageLevel;

public override void SetLanguageLevel(IPsiModule psiModule, CSharpLanguageLevel languageLevel) {
throw new InvalidOperationException("Language level cannot be set for a T4 module.");
}

public T4CSharpLanguageLevelProvider([NotNull] T4Environment t4Environment) {
_t4Environment = t4Environment;
}

}

}
30 changes: 19 additions & 11 deletions GammaJul.ReSharper.ForTea/T4Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using JetBrains.Application;
using JetBrains.Application.Components;
using JetBrains.Application.platforms;
using JetBrains.ReSharper.Psi.CSharp;
using JetBrains.VsIntegration.Shell;
using JetBrains.Util;
using Microsoft.Win32;
Expand All @@ -42,20 +43,18 @@ public class T4Environment {
[CanBeNull] private IList<FileSystemPath> _includePaths;

[NotNull]
public Optional<ITextTemplatingComponents> Components {
get { return _components.Value; }
}

public Optional<ITextTemplatingComponents> Components
=> _components.Value;

/// <summary>
/// Gets the version of the Visual Studio we're running under, two components only, <c>Major.Minor</c>. Example: “8.0”.
/// </summary>
[NotNull]
public Version2 VsVersion2 {
get { return _vsEnvironmentInformation.VsVersion2; }
}
public Version2 VsVersion2
=> _vsEnvironmentInformation.VsVersion2;

/// <summary>
/// Gets the platform ID (.NET 4.0 under VS2010, .NET 4.5 under VS2012).
/// Gets the platform ID (.NET 4.0 under VS2010, .NET 4.5 under VS2012+).
/// </summary>
[NotNull]
public PlatformID PlatformID {
Expand All @@ -66,6 +65,11 @@ public PlatformID PlatformID {
}
}

/// <summary>
/// Gets the C# language version.
/// </summary>
public CSharpLanguageLevel CSharpLanguageLevel { get; }

/// <summary>
/// Gets the default included assemblies.
/// </summary>
Expand All @@ -81,9 +85,8 @@ public IEnumerable<string> TextTemplatingAssemblyNames {
/// <summary>
/// Gets whether the current environment is supported. VS2005 and VS2008 aren't.
/// </summary>
public bool IsSupported {
get { return _platformID != null; }
}
public bool IsSupported
=> _platformID != null;

/// <summary>
/// Gets the common include paths from the registry.
Expand Down Expand Up @@ -135,6 +138,7 @@ public T4Environment([NotNull] IVsEnvironmentInformation vsEnvironmentInformatio

case VsVersions.Vs2010:
_platformID = new PlatformID(FrameworkIdentifier.NetFramework, new Version(4, 0));
CSharpLanguageLevel = CSharpLanguageLevel.CSharp40;
_textTemplatingAssemblyNames = new[] {
"Microsoft.VisualStudio.TextTemplating.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
"Microsoft.VisualStudio.TextTemplating.Interfaces.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Expand All @@ -143,6 +147,7 @@ public T4Environment([NotNull] IVsEnvironmentInformation vsEnvironmentInformatio

case VsVersions.Vs2012:
_platformID = new PlatformID(FrameworkIdentifier.NetFramework, new Version(4, 5));
CSharpLanguageLevel = CSharpLanguageLevel.CSharp50;
_textTemplatingAssemblyNames = new[] {
"Microsoft.VisualStudio.TextTemplating.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
"Microsoft.VisualStudio.TextTemplating.Interfaces.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
Expand All @@ -152,6 +157,7 @@ public T4Environment([NotNull] IVsEnvironmentInformation vsEnvironmentInformatio

case VsVersions.Vs2013:
_platformID = new PlatformID(FrameworkIdentifier.NetFramework, new Version(4, 5));
CSharpLanguageLevel = CSharpLanguageLevel.CSharp50;
_textTemplatingAssemblyNames = new[] {
"Microsoft.VisualStudio.TextTemplating.12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
"Microsoft.VisualStudio.TextTemplating.Interfaces.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
Expand All @@ -161,6 +167,8 @@ public T4Environment([NotNull] IVsEnvironmentInformation vsEnvironmentInformatio

case VsVersions.Vs2015:
_platformID = new PlatformID(FrameworkIdentifier.NetFramework, new Version(4, 5));
const int vs2015Update2Build = 25123;
CSharpLanguageLevel = vsEnvironmentInformation.VsVersion4.Build >= vs2015Update2Build ? CSharpLanguageLevel.CSharp60 : CSharpLanguageLevel.CSharp50;
_textTemplatingAssemblyNames = new[] {
"Microsoft.VisualStudio.TextTemplating.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
"Microsoft.VisualStudio.TextTemplating.Interfaces.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
Expand Down

0 comments on commit 5255ea1

Please sign in to comment.