Skip to content

Commit

Permalink
code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
filipw committed Mar 4, 2019
1 parent e514da2 commit 27ea453
Show file tree
Hide file tree
Showing 21 changed files with 109 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/Scripting/CSharp/CSharpScriptCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class CSharpScriptCompiler : ScriptCompiler
{
public static readonly ScriptCompiler Instance = new CSharpScriptCompiler();

private static readonly CSharpParseOptions s_defaultOptions = new CSharpParseOptions(kind: SourceCodeKind.Script, languageVersion: LanguageVersion.Latest);
internal static readonly CSharpParseOptions DefaultParseOptions = new CSharpParseOptions(kind: SourceCodeKind.Script, languageVersion: LanguageVersion.Latest);

private CSharpScriptCompiler()
{
Expand All @@ -23,8 +23,8 @@ private CSharpScriptCompiler()

public override bool IsCompleteSubmission(SyntaxTree tree) => SyntaxFactory.IsCompleteSubmission(tree);

public override SyntaxTree ParseSubmission(SourceText text, ScriptOptions scriptOptions, CancellationToken cancellationToken) =>
SyntaxFactory.ParseSyntaxTree(text, scriptOptions.ParseOptions ?? s_defaultOptions, cancellationToken: cancellationToken);
public override SyntaxTree ParseSubmission(SourceText text, ParseOptions parseOptions, CancellationToken cancellationToken) =>
SyntaxFactory.ParseSyntaxTree(text, parseOptions ?? DefaultParseOptions, cancellationToken: cancellationToken);

public override Compilation CreateSubmission(Script script)
{
Expand All @@ -40,7 +40,7 @@ public override Compilation CreateSubmission(Script script)
// TODO: report diagnostics
diagnostics.Free();

var tree = SyntaxFactory.ParseSyntaxTree(script.SourceText, script.Options.ParseOptions ?? s_defaultOptions, script.Options.FilePath);
var tree = SyntaxFactory.ParseSyntaxTree(script.SourceText, script.Options.ParseOptions ?? DefaultParseOptions, script.Options.FilePath);

string assemblyName, submissionTypeName;
script.Builder.GenerateSubmissionId(out assemblyName, out submissionTypeName);
Expand Down
14 changes: 11 additions & 3 deletions src/Scripting/CSharp/CSharpScriptingResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions src/Scripting/CSharp/CSharpScriptingResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,24 @@
<value>Copyright (C) Microsoft Corporation. All rights reserved.</value>
</data>
<data name="InteractiveHelp" xml:space="preserve">
<value><![CDATA[Usage: csi [option] ... [script-file.csx] [script-argument] ...
<value>Usage: csi [option] ... [script-file.csx] [script-argument] ...

Executes script-file.csx if specified, otherwise launches an interactive REPL (Read Eval Print Loop).

Options:
/help Display this usage message (alternative form: /?)
/version Display the version and exit
/i Drop to REPL after executing the specified script.
/r:<file> Reference metadata from the specified assembly file (alternative form: /reference)
/r:<file list> Reference metadata from the specified assembly files (alternative form: /reference)
/lib:<path list> List of directories where to look for libraries specified by #r directive.
/r:&lt;file&gt; Reference metadata from the specified assembly file (alternative form: /reference)
/r:&lt;file list&gt; Reference metadata from the specified assembly files (alternative form: /reference)
/lib:&lt;path list&gt; List of directories where to look for libraries specified by #r directive.
(alternative forms: /libPath /libPaths)
/u:<namespace> Define global namespace using (alternative forms: /using, /usings, /import, /imports)
@<file> Read response file for more options
/u:&lt;namespace&gt; Define global namespace using (alternative forms: /using, /usings, /import, /imports)
@&lt;file&gt; Read response file for more options
-- Indicates that the remaining arguments should not be treated as options.
]]></value>
</value>
</data>
<data name="CannotSetCSharpLanguageVersion" xml:space="preserve">
<value>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</value>
</data>
</root>
8 changes: 5 additions & 3 deletions src/Scripting/CSharp/ScriptOptionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.CodeAnalysis.Scripting;

namespace Microsoft.CodeAnalysis.CSharp.Scripting
Expand All @@ -8,10 +9,11 @@ public static class ScriptOptionsExtensions
{
public static ScriptOptions WithLanguageVersion(this ScriptOptions options, LanguageVersion languageVersion)
{
if (options.ParseOptions is CSharpParseOptions csharpParseOptions && csharpParseOptions.LanguageVersion == languageVersion)
return options;
var parseOptions = (options.ParseOptions is null)
? CSharpScriptCompiler.DefaultParseOptions
: (options.ParseOptions is CSharpParseOptions existing) ? existing : throw new InvalidOperationException(CSharpScriptingResources.CannotSetCSharpLanguageVersion);

return options.WithParseOptions(new CSharpParseOptions(kind: SourceCodeKind.Script, languageVersion: languageVersion));
return options.WithParseOptions(parseOptions.WithLanguageVersion(languageVersion));
}
}
}
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="cs" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Verze kompilátoru Microsoft (R) Visual C# Interactive {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="de" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Microsoft (R) Visual C# Interactive – Compilerversion {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="es" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Compilador de Microsoft (R) Visual C# interactivo, versión {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="fr" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Compilateur Microsoft (R) Visual C# Interactive version {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="it" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Compilatore Microsoft (R) Visual C# Interactive versione {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ja" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Microsoft (R) Visual C# インタラクティブ コンパイラ バージョン {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ko" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Microsoft (R) Visual C# 대화형 컴파일러 버전 {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pl" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Microsoft (R) Visual C# Interactive — wersja kompilatora {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pt-BR" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Versão {0} do Compilador C# Interativo do Microsoft (R) Visual</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ru" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Компилятор Microsoft (R) Visual C# Interactive версии {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="tr" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Microsoft (R) Visual C# Etkileşimli Derleyici sürümü {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="zh-Hans" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Microsoft (R) Visual C# 交互窗口编译器版本 {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="zh-Hant" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Microsoft (R) Visual C# 互動編譯器 {0} 版</target>
Expand Down
Loading

0 comments on commit 27ea453

Please sign in to comment.