提交 e96907af 编写于 作者: A Andrew Hall (METAL)

Update strings, refactor code to csharp shim

上级 2ad4d952
......@@ -87,9 +87,9 @@ internal static class FeatureOnOffOptions
nameof(FeatureOnOffOptions), nameof(UseEnhancedColors), defaultValue: 1,
storageLocations: new RoamingProfileStorageLocation("WindowManagement.Options.UseEnhancedColorsForManagedLanguages"));
public static readonly Option<int> UseNullableReferenceTypes = new Option<int>(
nameof(FeatureOnOffOptions), nameof(UseNullableReferenceTypes), defaultValue: 0,
storageLocations: new RoamingProfileStorageLocation($"TextEditor.CSharp.{nameof(UseNullableReferenceTypes)}"));
public static readonly Option<int> UseNullableReferenceTypeAnalysis = new Option<int>(
nameof(FeatureOnOffOptions), nameof(UseNullableReferenceTypeAnalysis), defaultValue: 0,
storageLocations: new RoamingProfileStorageLocation($"TextEditor.CSharp.{nameof(UseNullableReferenceTypeAnalysis)}"));
// Note: no storage location since this is intentionally a session variable
public static readonly Option<bool> AcceptedDecompilerDisclaimer = new Option<bool>(
......
......@@ -20,7 +20,7 @@
<CheckBox x:Name="Enable_navigation_to_decompiled_sources"
Content="{x:Static local:AdvancedOptionPageStrings.Option_Enable_navigation_to_decompiled_sources}" />
<CheckBox x:Name="Enable_use_nullable_reference_types"
Content="{x:Static local:AdvancedOptionPageStrings.Option_Enable_use_nullable_reference_types}" />
Content="{x:Static local:AdvancedOptionPageStrings.Option_use_nullable_reference_type_analysis}" />
</StackPanel>
</GroupBox>
<GroupBox x:Uid="UsingDirectivesGroupBox"
......
......@@ -23,7 +23,7 @@ public AdvancedOptionPageControl(OptionStore optionStore) : base(optionStore)
BindToFullSolutionAnalysisOption(Enable_full_solution_analysis, LanguageNames.CSharp);
BindToOption(Enable_navigation_to_decompiled_sources, FeatureOnOffOptions.NavigateToDecompiledSources);
BindToOption(Enable_use_nullable_reference_types, FeatureOnOffOptions.UseNullableReferenceTypes);
BindToOption(Enable_use_nullable_reference_types, FeatureOnOffOptions.UseNullableReferenceTypeAnalysis);
BindToOption(PlaceSystemNamespaceFirst, GenerationOptions.PlaceSystemNamespaceFirst, LanguageNames.CSharp);
BindToOption(SeparateImportGroups, GenerationOptions.SeparateImportDirectiveGroups, LanguageNames.CSharp);
......
......@@ -18,8 +18,8 @@ public static string Option_Enable_full_solution_analysis
public static string Option_Enable_navigation_to_decompiled_sources
=> ServicesVSResources.Enable_navigation_to_decompiled_sources;
public static string Option_Enable_use_nullable_reference_types
=> ServicesVSResources.Enable_use_nullable_reference_types;
public static string Option_use_nullable_reference_type_analysis
=> ServicesVSResources.Enable_nullable_reference_type_analysis;
public static string Option_RenameTrackingPreview => CSharpVSResources.Show_preview_for_rename_tracking;
public static string Option_Split_string_literals_on_enter => CSharpVSResources.Split_string_literals_on_enter;
......
......@@ -5,7 +5,9 @@
using System.IO;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.LanguageServices.CSharp.ProjectSystemShim.Interop;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
using Roslyn.Utilities;
......@@ -21,11 +23,25 @@ private class OptionsProcessor : VisualStudioProjectOptionsProcessor
private readonly object[] _options = new object[(int)CompilerOptions.LARGEST_OPTION_ID];
private string _mainTypeName;
private OutputKind _outputKind;
private IOptionService _optionService;
public OptionsProcessor(VisualStudioProject visualStudioProject, HostWorkspaceServices workspaceServices)
: base(visualStudioProject, workspaceServices)
{
_visualStudioProject = visualStudioProject;
_optionService = workspaceServices.GetRequiredService<IOptionService>();
// For C#, we need to listen to the options for NRT analysis
// that can change in VS through tools > options
_optionService.OptionChanged += OptionService_OptionChanged;
}
private void OptionService_OptionChanged(object sender, OptionChangedEventArgs e)
{
if (e.Option.Feature == FeatureOnOffOptions.UseNullableReferenceTypeAnalysis.Feature)
{
UpdateProjectForNewHostValues();
}
}
public object this[CompilerOptions compilerOption]
......@@ -216,6 +232,15 @@ private string GetStringOption(CompilerOptions optionID, string defaultValue)
protected override ParseOptions ComputeParseOptionsWithHostValues(ParseOptions parseOptions)
{
var useNullableReferenceAnalysisOption = _optionService.GetOption(FeatureOnOffOptions.UseNullableReferenceTypeAnalysis);
parseOptions = useNullableReferenceAnalysisOption switch
{
-1 => parseOptions.WithFeatures(new[] { KeyValuePairUtil.Create("run-nullable-analysis", "false") }),
1 => parseOptions.WithFeatures(new[] { KeyValuePairUtil.Create("run-nullable-analysis", "true") }),
_ => parseOptions
};
var symbols = GetStringOption(CompilerOptions.OPTID_CCSYMBOLS, defaultValue: "").Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
// The base implementation of OptionsProcessor already tried this, but it didn't have the real documentation
......
......@@ -2,9 +2,7 @@
using System.Collections.Immutable;
using System.IO;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Options;
using Roslyn.Utilities;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
......@@ -14,7 +12,6 @@ internal class VisualStudioProjectOptionsProcessor : IDisposable
private readonly VisualStudioProject _project;
private readonly HostWorkspaceServices _workspaceServices;
private readonly ICommandLineParserService _commandLineParserService;
private IOptionService _optionService;
/// <summary>
/// Gate to guard all mutable fields in this class.
......@@ -31,27 +28,11 @@ public VisualStudioProjectOptionsProcessor(VisualStudioProject project, HostWork
_project = project ?? throw new ArgumentNullException(nameof(project));
_workspaceServices = workspaceServices;
_commandLineParserService = workspaceServices.GetLanguageServices(project.Language).GetRequiredService<ICommandLineParserService>();
_optionService = workspaceServices.GetRequiredService<IOptionService>();
if (project.Language == LanguageNames.CSharp)
{
// For C#, we need to listen to the options for NRT analysis
// that can change in VS through tools > options
_optionService.OptionChanged += OptionService_OptionChanged;
}
// Set up _commandLineArgumentsForCommandLine to a default. No lock taken since we're in the constructor so nothing can race.
ReparseCommandLine_NoLock();
}
private void OptionService_OptionChanged(object sender, OptionChangedEventArgs e)
{
if (e.Option.Feature == FeatureOnOffOptions.UseNullableReferenceTypes.Feature)
{
UpdateProjectForNewHostValues();
}
}
public string CommandLine
{
get
......@@ -178,18 +159,6 @@ private void UpdateProjectOptions_NoLock()
compilationOptions = ComputeCompilationOptionsWithHostValues(compilationOptions, this._ruleSetFile?.Target.Value);
parseOptions = ComputeParseOptionsWithHostValues(parseOptions);
if (_project.Language == LanguageNames.CSharp)
{
var useNullableReferenceTypesOption = _optionService.GetOption(FeatureOnOffOptions.UseNullableReferenceTypes);
parseOptions = useNullableReferenceTypesOption switch
{
-1 => parseOptions.WithFeatures(new[] { KeyValuePairUtil.Create("run-nullable-analysis", "false") }),
1 => parseOptions.WithFeatures(new[] { KeyValuePairUtil.Create("run-nullable-analysis", "true") }),
_ => parseOptions
};
}
// For managed projects, AssemblyName has to be non-null, but the command line we get might be a partial command line
// and not contain the existing value. Only update if we have one.
_project.AssemblyName = _commandLineArgumentsForCommandLine.CompilationName ?? _project.AssemblyName;
......@@ -256,12 +225,6 @@ public void Dispose()
lock (_gate)
{
DisposeOfRuleSetFile_NoLock();
if (_optionService != null)
{
_optionService.OptionChanged -= OptionService_OptionChanged;
_optionService = null;
}
}
}
}
......
......@@ -906,11 +906,11 @@ internal class ServicesVSResources {
}
/// <summary>
/// Looks up a localized string similar to Enable use nullable reference types.
/// Looks up a localized string similar to Enable nullable reference type analysis.
/// </summary>
internal static string Enable_use_nullable_reference_types {
internal static string Enable_nullable_reference_type_analysis {
get {
return ResourceManager.GetString("Enable_use_nullable_reference_types", resourceCulture);
return ResourceManager.GetString("Enable_nullable_reference_type_analysis", resourceCulture);
}
}
......
......@@ -1201,7 +1201,7 @@ I agree to all of the foregoing:</value>
<data name="Use_enhanced_colors_for_C_and_Basic" xml:space="preserve">
<value>Use enhanced colors for C# and Basic</value>
</data>
<data name="Enable_use_nullable_reference_types" xml:space="preserve">
<value>Enable use nullable reference types</value>
<data name="Enable_nullable_reference_type_analysis" xml:space="preserve">
<value>Enable nullable reference type analysis</value>
</data>
</root>
\ No newline at end of file
......@@ -72,9 +72,9 @@
<target state="translated">Element není platný.</target>
<note />
</trans-unit>
<trans-unit id="Enable_use_nullable_reference_types">
<source>Enable use nullable reference types</source>
<target state="new">Enable use nullable reference types</target>
<trans-unit id="Enable_nullable_reference_type_analysis">
<source>Enable nullable reference type analysis</source>
<target state="new">Enable nullable reference type analysis</target>
<note />
</trans-unit>
<trans-unit id="Finish">
......
......@@ -72,9 +72,9 @@
<target state="translated">Das Element ist ungültig.</target>
<note />
</trans-unit>
<trans-unit id="Enable_use_nullable_reference_types">
<source>Enable use nullable reference types</source>
<target state="new">Enable use nullable reference types</target>
<trans-unit id="Enable_nullable_reference_type_analysis">
<source>Enable nullable reference type analysis</source>
<target state="new">Enable nullable reference type analysis</target>
<note />
</trans-unit>
<trans-unit id="Finish">
......
......@@ -72,9 +72,9 @@
<target state="translated">El elemento no es válido.</target>
<note />
</trans-unit>
<trans-unit id="Enable_use_nullable_reference_types">
<source>Enable use nullable reference types</source>
<target state="new">Enable use nullable reference types</target>
<trans-unit id="Enable_nullable_reference_type_analysis">
<source>Enable nullable reference type analysis</source>
<target state="new">Enable nullable reference type analysis</target>
<note />
</trans-unit>
<trans-unit id="Finish">
......
......@@ -72,9 +72,9 @@
<target state="translated">L'élément n'est pas valide.</target>
<note />
</trans-unit>
<trans-unit id="Enable_use_nullable_reference_types">
<source>Enable use nullable reference types</source>
<target state="new">Enable use nullable reference types</target>
<trans-unit id="Enable_nullable_reference_type_analysis">
<source>Enable nullable reference type analysis</source>
<target state="new">Enable nullable reference type analysis</target>
<note />
</trans-unit>
<trans-unit id="Finish">
......
......@@ -72,9 +72,9 @@
<target state="translated">L'elemento non è valido.</target>
<note />
</trans-unit>
<trans-unit id="Enable_use_nullable_reference_types">
<source>Enable use nullable reference types</source>
<target state="new">Enable use nullable reference types</target>
<trans-unit id="Enable_nullable_reference_type_analysis">
<source>Enable nullable reference type analysis</source>
<target state="new">Enable nullable reference type analysis</target>
<note />
</trans-unit>
<trans-unit id="Finish">
......
......@@ -72,9 +72,9 @@
<target state="translated">要素が有効ではありません。</target>
<note />
</trans-unit>
<trans-unit id="Enable_use_nullable_reference_types">
<source>Enable use nullable reference types</source>
<target state="new">Enable use nullable reference types</target>
<trans-unit id="Enable_nullable_reference_type_analysis">
<source>Enable nullable reference type analysis</source>
<target state="new">Enable nullable reference type analysis</target>
<note />
</trans-unit>
<trans-unit id="Finish">
......
......@@ -72,9 +72,9 @@
<target state="translated">요소가 잘못되었습니다.</target>
<note />
</trans-unit>
<trans-unit id="Enable_use_nullable_reference_types">
<source>Enable use nullable reference types</source>
<target state="new">Enable use nullable reference types</target>
<trans-unit id="Enable_nullable_reference_type_analysis">
<source>Enable nullable reference type analysis</source>
<target state="new">Enable nullable reference type analysis</target>
<note />
</trans-unit>
<trans-unit id="Finish">
......
......@@ -72,9 +72,9 @@
<target state="translated">Element jest nieprawidłowy.</target>
<note />
</trans-unit>
<trans-unit id="Enable_use_nullable_reference_types">
<source>Enable use nullable reference types</source>
<target state="new">Enable use nullable reference types</target>
<trans-unit id="Enable_nullable_reference_type_analysis">
<source>Enable nullable reference type analysis</source>
<target state="new">Enable nullable reference type analysis</target>
<note />
</trans-unit>
<trans-unit id="Finish">
......
......@@ -72,9 +72,9 @@
<target state="translated">O elemento é inválido.</target>
<note />
</trans-unit>
<trans-unit id="Enable_use_nullable_reference_types">
<source>Enable use nullable reference types</source>
<target state="new">Enable use nullable reference types</target>
<trans-unit id="Enable_nullable_reference_type_analysis">
<source>Enable nullable reference type analysis</source>
<target state="new">Enable nullable reference type analysis</target>
<note />
</trans-unit>
<trans-unit id="Finish">
......
......@@ -72,9 +72,9 @@
<target state="translated">Элемент недопустим.</target>
<note />
</trans-unit>
<trans-unit id="Enable_use_nullable_reference_types">
<source>Enable use nullable reference types</source>
<target state="new">Enable use nullable reference types</target>
<trans-unit id="Enable_nullable_reference_type_analysis">
<source>Enable nullable reference type analysis</source>
<target state="new">Enable nullable reference type analysis</target>
<note />
</trans-unit>
<trans-unit id="Finish">
......
......@@ -72,9 +72,9 @@
<target state="translated">Öğe geçerli değil.</target>
<note />
</trans-unit>
<trans-unit id="Enable_use_nullable_reference_types">
<source>Enable use nullable reference types</source>
<target state="new">Enable use nullable reference types</target>
<trans-unit id="Enable_nullable_reference_type_analysis">
<source>Enable nullable reference type analysis</source>
<target state="new">Enable nullable reference type analysis</target>
<note />
</trans-unit>
<trans-unit id="Finish">
......
......@@ -72,9 +72,9 @@
<target state="translated">元素无效。</target>
<note />
</trans-unit>
<trans-unit id="Enable_use_nullable_reference_types">
<source>Enable use nullable reference types</source>
<target state="new">Enable use nullable reference types</target>
<trans-unit id="Enable_nullable_reference_type_analysis">
<source>Enable nullable reference type analysis</source>
<target state="new">Enable nullable reference type analysis</target>
<note />
</trans-unit>
<trans-unit id="Finish">
......
......@@ -72,9 +72,9 @@
<target state="translated">元素無效。</target>
<note />
</trans-unit>
<trans-unit id="Enable_use_nullable_reference_types">
<source>Enable use nullable reference types</source>
<target state="new">Enable use nullable reference types</target>
<trans-unit id="Enable_nullable_reference_type_analysis">
<source>Enable nullable reference type analysis</source>
<target state="new">Enable nullable reference type analysis</target>
<note />
</trans-unit>
<trans-unit id="Finish">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册