public bool TryFetch(OptionKey optionKey, out object value) { // This particular serializer is a bit strange, since we have to initially read things out on the UI thread. // Therefore, we refresh the values in the constructor, meaning that this should never get called for our values. if (_supportedOptions.Contains(optionKey.Option) && _languageMap.ContainsKey(optionKey.Language)) { FatalError.ReportWithDumpAndCatch(new InvalidOperationException("Unexpected call to " + nameof(LanguageSettingsPersister) + "." + nameof(TryFetch)), ErrorSeverity.Diagnostic); } value = null; return(false); }
public LanguageSettingsPersister( IThreadingContext threadingContext, IVsTextManager4 textManager, IGlobalOptionService globalOptions) : base(threadingContext, assertIsForeground: true) { _textManager = textManager; _globalOptions = globalOptions; var languageMap = BidirectionalMap <string, Tuple <Guid> > .Empty; InitializeSettingsForLanguage(LanguageNames.CSharp, Guids.CSharpLanguageServiceId); InitializeSettingsForLanguage(LanguageNames.VisualBasic, Guids.VisualBasicLanguageServiceId); InitializeSettingsForLanguage(InternalLanguageNames.TypeScript, new Guid("4a0dddb5-7a95-4fbf-97cc-616d07737a77")); InitializeSettingsForLanguage("F#", new Guid("BC6DD5A5-D4D6-4dab-A00D-A51242DBAF1B")); InitializeSettingsForLanguage("Xaml", new Guid("CD53C9A1-6BC2-412B-BE36-CC715ED8DD41")); void InitializeSettingsForLanguage(string languageName, Guid languageGuid) { var languagePreferences = new LANGPREFERENCES3[1]; languagePreferences[0].guidLang = languageGuid; // The function can potentially fail if that language service isn't installed if (ErrorHandler.Succeeded(_textManager.GetUserPreferences4(pViewPrefs: null, pLangPrefs: languagePreferences, pColorPrefs: null))) { RefreshLanguageSettings(languagePreferences, languageName); languageMap = languageMap.Add(languageName, Tuple.Create(languageGuid)); } else { FatalError.ReportWithDumpAndCatch(new InvalidOperationException("GetUserPreferences4 failed"), ErrorSeverity.Diagnostic); } } _languageMap = languageMap; _textManagerEvents2Sink = ComEventSink.Advise <IVsTextManagerEvents4>(_textManager, this); }