Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# scripting should use language version "latest" by default #2001

Merged
merged 2 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/OmniSharp.Script/ScriptProjectProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class ScriptProjectProvider
"System.Threading.Tasks"
};

private static readonly CSharpParseOptions ParseOptions = new CSharpParseOptions(LanguageVersion.CSharp8, DocumentationMode.Parse, SourceCodeKind.Script);
private static readonly CSharpParseOptions ParseOptions = new CSharpParseOptions(LanguageVersion.Latest, DocumentationMode.Parse, SourceCodeKind.Script);

private readonly Lazy<CSharpCompilationOptions> _compilationOptions;
private readonly Lazy<CSharpCommandLineArguments> _commandLineArgs;
Expand Down Expand Up @@ -103,7 +103,6 @@ private CSharpCompilationOptions CreateCompilationOptions()

compilationOptions = compilationOptions
.WithAllowUnsafe(true)

.WithMetadataReferenceResolver(metadataReferenceResolver)
.WithSourceReferenceResolver(sourceResolver)
.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default)
Expand Down
23 changes: 23 additions & 0 deletions tests/OmniSharp.Script.Tests/ScriptProjectProviderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.IO;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Scripting.Hosting;
using Microsoft.Extensions.Logging;
using OmniSharp.Services;
using Xunit;

namespace OmniSharp.Script.Tests
{
public class ScriptProjectProviderTests
{
[Fact]
public void DefaultLanguageVersionShouldBeLatest()
{
var scriptProjectProvider = new ScriptProjectProvider(new ScriptOptions(), new OmniSharpEnvironment(), new LoggerFactory(), true, false);
var scriptProjectInfo = scriptProjectProvider.CreateProject("test.csx", Enumerable.Empty<MetadataReference>(), Path.GetTempPath(), typeof(CommandLineScriptGlobals));
Assert.Equal(LanguageVersion.Latest, ((CSharpParseOptions)scriptProjectInfo.ParseOptions).SpecifiedLanguageVersion);
Assert.Equal(LanguageVersion.CSharp9, ((CSharpParseOptions)scriptProjectInfo.ParseOptions).LanguageVersion);
}
}
}
1 change: 1 addition & 0 deletions tests/OmniSharp.Script.Tests/WorkspaceInformationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Scripting.Hosting;
using OmniSharp.Models.FilesChanged;
using OmniSharp.Models.WorkspaceInformation;
Expand Down