/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.RoslynServices.Options/RoslynPreferences.cs

https://github.com/directhex/monodevelop · C# · 89 lines · 54 code · 9 blank · 26 comment · 0 complexity · 30c30065ffd6d900907048108770a2ed MD5 · raw file

  1. //
  2. // RoslynPreferences.cs
  3. //
  4. // Author:
  5. // Marius Ungureanu <maungu@microsoft.com>
  6. //
  7. // Copyright (c) 2018 Microsoft Inc.
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. using System;
  27. using System.Collections.Generic;
  28. using System.ComponentModel.Composition;
  29. using System.Linq;
  30. using Microsoft.CodeAnalysis;
  31. using Microsoft.CodeAnalysis.Completion;
  32. using Microsoft.CodeAnalysis.Editor.Options;
  33. using Microsoft.CodeAnalysis.Editor.Implementation.TodoComments;
  34. using Microsoft.CodeAnalysis.Options;
  35. using Microsoft.CodeAnalysis.Shared.Options;
  36. using MonoDevelop.Core;
  37. using MonoDevelop.Ide.Composition;
  38. using Roslyn.Utilities;
  39. namespace MonoDevelop.Ide.RoslynServices.Options
  40. {
  41. sealed partial class RoslynPreferences
  42. {
  43. internal PerLanguagePreferences CSharp => languageConfigs [LanguageNames.CSharp];
  44. public PerLanguagePreferences For (string languageName) => languageConfigs [languageName];
  45. // Preferences migrated from the IDE to roslyn keys are held here.
  46. internal const string globalKey = "MonoDevelop.RoslynPreferences";
  47. readonly Dictionary<string, PerLanguagePreferences> languageConfigs = new Dictionary<string, PerLanguagePreferences> ();
  48. internal RoslynPreferences ()
  49. {
  50. foreach (var language in RoslynService.AllLanguages)
  51. languageConfigs.Add (language, new PerLanguagePreferences (language, this));
  52. }
  53. public class PerLanguagePreferences
  54. {
  55. public readonly ConfigurationProperty<bool> PlaceSystemNamespaceFirst;
  56. public readonly ConfigurationProperty<bool> SeparateImportDirectiveGroups;
  57. public readonly ConfigurationProperty<bool> SuggestForTypesInNuGetPackages;
  58. public readonly ConfigurationProperty<bool?> SolutionCrawlerClosedFileDiagnostic;
  59. internal PerLanguagePreferences (string language, RoslynPreferences preferences)
  60. {
  61. PlaceSystemNamespaceFirst = preferences.Wrap<bool> (
  62. new OptionKey (Microsoft.CodeAnalysis.Editing.GenerationOptions.PlaceSystemNamespaceFirst, language),
  63. language + ".PlaceSystemNamespaceFirst"
  64. );
  65. SeparateImportDirectiveGroups = preferences.Wrap<bool> (
  66. new OptionKey (Microsoft.CodeAnalysis.Editing.GenerationOptions.SeparateImportDirectiveGroups, language),
  67. language + ".SeparateImportDirectiveGroups"
  68. );
  69. SuggestForTypesInNuGetPackages = preferences.Wrap (
  70. new OptionKey (Microsoft.CodeAnalysis.SymbolSearch.SymbolSearchOptions.SuggestForTypesInNuGetPackages, language),
  71. true
  72. );
  73. SolutionCrawlerClosedFileDiagnostic = preferences.Wrap<bool?> (
  74. new OptionKey (ServiceFeatureOnOffOptions.ClosedFileDiagnostic, language),
  75. true
  76. );
  77. }
  78. }
  79. }
  80. }