public LanguageSettingsPersister(
            [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
            IGlobalOptionService optionService)
            : base(assertIsForeground: true)
        {
            _textManager   = (IVsTextManager4)serviceProvider.GetService(typeof(SVsTextManager));
            _optionService = optionService;

            // TODO: make this configurable
            _languageMap = BidirectionalMap <string, Tuple <Guid> > .Empty.Add(LanguageNames.Hlsl, Tuple.Create(Guids.HlslLanguageServiceId))
                           .Add(LanguageNames.ShaderLab, Tuple.Create(Guids.ShaderLabLanguageServiceId));

            foreach (var languageGuid in _languageMap.Values)
            {
                var languagePreferences = new LANGPREFERENCES3[1];
                languagePreferences[0].guidLang = languageGuid.Item1;

                // 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);
                }
            }

            _textManagerEvents2Sink = ComEventSink.Advise <IVsTextManagerEvents4>(_textManager, this);
        }
Пример #2
0
        public LanguageSettingsPersister(
            [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
            IGlobalOptionService optionService)
            : base(assertIsForeground: true)
        {
            _textManager   = (IVsTextManager4)serviceProvider.GetService(typeof(SVsTextManager));
            _optionService = optionService;

            // TODO: make this configurable
            _languageMap = BidirectionalMap <string, Tuple <Guid> > .Empty.Add(LanguageNames.CSharp, Tuple.Create(Guids.CSharpLanguageServiceId))
                           .Add(LanguageNames.VisualBasic, Tuple.Create(Guids.VisualBasicLanguageServiceId))
                           .Add("TypeScript", Tuple.Create(new Guid("4a0dddb5-7a95-4fbf-97cc-616d07737a77")))
                           .Add("F#", Tuple.Create(new Guid("BC6DD5A5-D4D6-4dab-A00D-A51242DBAF1B")))
                           .Add("Xaml", Tuple.Create(new Guid("CD53C9A1-6BC2-412B-BE36-CC715ED8DD41")));

            foreach (var languageGuid in _languageMap.Values)
            {
                var languagePreferences = new LANGPREFERENCES3[1];
                languagePreferences[0].guidLang = languageGuid.Item1;

                // 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);
                }
            }

            _textManagerEvents2Sink = ComEventSink.Advise <IVsTextManagerEvents4>(_textManager, this);
        }
        public bool TryPersist(OptionKey optionKey, object value)
        {
            if (!_supportedOptions.Contains(optionKey.Option))
            {
                value = null;
                return(false);
            }

            if (!_languageMap.TryGetValue(optionKey.Language, out var languageServiceGuid))
            {
                value = null;
                return(false);
            }

            var languagePreferences = new LANGPREFERENCES3[1];

            languagePreferences[0].guidLang = languageServiceGuid.Item1;
            Marshal.ThrowExceptionForHR(_textManager.GetUserPreferences4(null, languagePreferences, null));

            SetValueForOption(optionKey.Option, ref languagePreferences[0], value);
            SetUserPreferencesMaybeAsync(languagePreferences);

            // Even if we didn't call back, say we completed the persist
            return(true);
        }
Пример #4
0
        public LanguageSettingsPersister(
            [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
            IGlobalOptionService optionService)
            : base(assertIsForeground: true)
        {
            _textManager = (IVsTextManager4)serviceProvider.GetService(typeof(SVsTextManager));
            _optionService = optionService;

            // TODO: make this configurable
            _languageMap = BidirectionalMap<string, Tuple<Guid>>.Empty.Add(LanguageNames.CSharp, Tuple.Create(Guids.CSharpLanguageServiceId))
                                                               .Add(LanguageNames.VisualBasic, Tuple.Create(Guids.VisualBasicLanguageServiceId))
                                                               .Add("TypeScript", Tuple.Create(new Guid("4a0dddb5-7a95-4fbf-97cc-616d07737a77")))
                                                               .Add("F#", Tuple.Create(new Guid("BC6DD5A5-D4D6-4dab-A00D-A51242DBAF1B")))
                                                               .Add("Xaml", Tuple.Create(new Guid("CD53C9A1-6BC2-412B-BE36-CC715ED8DD41")));

            foreach (var languageGuid in _languageMap.Values)
            {
                var languagePreferences = new LANGPREFERENCES3[1];
                languagePreferences[0].guidLang = languageGuid.Item1;

                // 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);
                }
            }

            _textManagerEvents2Sink = ComEventSink.Advise<IVsTextManagerEvents4>(_textManager, this);
        }
Пример #5
0
        public static LANGPREFERENCES3[] GetNodejsLanguagePreferencesFromTypeScript(IVsTextManager4 textMgr)
        {
            var langPrefs = new LANGPREFERENCES3[1];

            langPrefs[0].guidLang = Guids.TypeScriptLanguageInfo;
            ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences4(null, langPrefs, null));
            langPrefs[0].guidLang = typeof(NodejsLanguageInfo).GUID;
            textMgr.SetUserPreferences4(null, langPrefs, null);
            return(langPrefs);
        }
Пример #6
0
        private void LoadLanguagePreferences()
        {
            var langPrefs = new LANGPREFERENCES3[1];

            langPrefs[0].guidLang = _languageServiceId;

            var hr = _textManager.GetUserPreferences4(null, langPrefs, null);

            if (hr == VSConstants.S_OK)
            {
                _langPrefs = langPrefs[0];
            }
            Debug.Assert(_langPrefs != null);
        }
Пример #7
0
        private void getOptions()
        {
            _alignDoCase = _optionsPage.AlignDoCase;
            _alignMethod = _optionsPage.AlignMethod;
            var languagePreferences = new LANGPREFERENCES3[1];

            languagePreferences[0].guidLang = GuidStrings.guidLanguageService;
            var result = _textManager.GetUserPreferences4(pViewPrefs: null, pLangPrefs: languagePreferences, pColorPrefs: null);

            if (result == VSConstants.S_OK)
            {
                _indentStyle = languagePreferences[0].IndentStyle;
                _tabSize     = (int)languagePreferences[0].uTabSize;
            }
        }
        // We make sure this code is from the UI by asking for the optionservice in the initialize() in AbstractPackage`2
        public AbstractLanguageSettingsSerializer(Guid languageServiceguid, string languageName, IServiceProvider serviceProvider)
            : base(assertIsForeground: true)
        {
            _serviceProvider = serviceProvider;
            _languageName    = languageName;

            _textManager = (IVsTextManager4)serviceProvider.GetService(typeof(SVsTextManager));

            var langPrefs = new LANGPREFERENCES3[1];

            langPrefs[0].guidLang = languageServiceguid;
            Marshal.ThrowExceptionForHR(_textManager.GetUserPreferences4(pViewPrefs: null, pLangPrefs: langPrefs, pColorPrefs: null));
            _languageSetting        = langPrefs[0];
            _textManagerEvents2Sink = ComEventSink.Advise <IVsTextManagerEvents4>(_textManager, this);
        }
Пример #9
0
        public static LANGPREFERENCES3[] GetNodejsLanguagePreferencesFromTypeScript(IVsTextManager4 textMgr)
        {
            var langPrefs = new LANGPREFERENCES3[1];

            langPrefs[0].guidLang = Guids.TypeScriptLanguageInfo;
            int hr = textMgr.GetUserPreferences4(null, langPrefs, null);

            if (ErrorHandler.Failed(hr))
            {
                MessageBox.Show(Project.SR.GetString(Project.SR.CouldNotGetTypeScriptLanguagePreferences), Project.SR.ProductName);
                ErrorHandler.ThrowOnFailure(hr);
            }
            langPrefs[0].guidLang = typeof(NodejsLanguageInfo).GUID;
            textMgr.SetUserPreferences4(null, langPrefs, null);
            return(langPrefs);
        }
Пример #10
0
        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);
        }
Пример #11
0
        public LanguageSettingsPersister(
            [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
            IGlobalOptionService optionService)
            : base(assertIsForeground: true)
        {
            _textManager = (IVsTextManager4)serviceProvider.GetService(typeof(SVsTextManager));
            _optionService = optionService;

            // TODO: make this configurable
            _languageMap = BidirectionalMap<string, Guid>.Empty.Add(LanguageNames.CSharp, Guids.CSharpLanguageServiceId)
                                                               .Add(LanguageNames.VisualBasic, Guids.VisualBasicLanguageServiceId)
                                                               .Add("TypeScript", new Guid("4a0dddb5-7a95-4fbf-97cc-616d07737a77"));

            foreach (var languageGuid in _languageMap.Values)
            {
                var languagePreferences = new LANGPREFERENCES3[1];
                languagePreferences[0].guidLang = languageGuid;
                Marshal.ThrowExceptionForHR(_textManager.GetUserPreferences4(pViewPrefs: null, pLangPrefs: languagePreferences, pColorPrefs: null));

                RefreshLanguageSettings(languagePreferences);
            }

            _textManagerEvents2Sink = ComEventSink.Advise<IVsTextManagerEvents4>(_textManager, this);
        }
Пример #12
0
        //CompletionOptionsPage _completionOptionsPage;
        public void GetIntellisenseSettings()
        {
            if (_intellisensePage == null)
            {
                _intellisensePage = (IntellisenseOptionsPage)GetDialogPage(typeof(IntellisenseOptionsPage));
            }
            if (_formattingPage == null)
            {
                _formattingPage = (FormattingOptionsPage)GetDialogPage(typeof(FormattingOptionsPage));
            }
            if (_indentingPage == null)
            {
                _indentingPage = (IndentingOptionsPage)GetDialogPage(typeof(IndentingOptionsPage));
            }
            if (_otherOptionsPage == null)
            {
                _otherOptionsPage = (OtherOptionsPage)GetDialogPage(typeof(OtherOptionsPage));
            }
            //if (_completionOptionsPage == null)
            //{
            //    _completionOptionsPage = (CompletionOptionsPage)GetDialogPage(typeof(CompletionOptionsPage));
            //}
            // Intellisense
            XSettings.EnableOutputWindowLogging = _intellisensePage.EnableOutputPane;
            XSettings.EnableBraceMatchLog       = _intellisensePage.EnableBraceMatchLog;
            XSettings.EnableCodeCompletionLog   = _intellisensePage.EnableCodeCompletionLog;
            XSettings.EnableDatabaseLog         = _intellisensePage.EnableDatabaseLog;
            XSettings.EnableParameterLog        = _intellisensePage.EnableParameterLog;
            XSettings.EnableParseLog            = _intellisensePage.EnableParserLog;
            XSettings.EnableQuickInfoLog        = _intellisensePage.EnableQuickInfoLog;
            XSettings.EnableReferenceInfoLog    = _intellisensePage.EnableReferenceInfoLog;
            XSettings.EnableTypelookupLog       = _intellisensePage.EnableTypelookupLog;


            XSettings.DisableAssemblyReferences       = _intellisensePage.DisableAssemblyReferences;
            XSettings.DisableBraceMatching            = _intellisensePage.DisableBraceMatching;
            XSettings.DisableCaseSynchronization      = _intellisensePage.DisableCaseSynchronization;
            XSettings.DisableClassViewObjectView      = _intellisensePage.DisableClassViewObjectView;
            XSettings.DisableCodeCompletion           = _intellisensePage.DisableCodeCompletion;
            XSettings.DisableEditorDropDowns          = _intellisensePage.DisableEditorDropdowns;
            XSettings.DisableEntityParsing            = _intellisensePage.DisableEntityParsing;
            XSettings.DisableForeignProjectReferences = _intellisensePage.DisableForeignProjectReferences;
            XSettings.DisableGotoDefinition           = _intellisensePage.DisableGotoDefinition;
            XSettings.DisableHighLightWord            = _intellisensePage.DisableHighLightWord;
            XSettings.DisableLightBulb               = _intellisensePage.DisableLightBulb;
            XSettings.DisableParameterInfo           = _intellisensePage.DisableParameterInfo;
            XSettings.DisablePeekDefinition          = _intellisensePage.DisablePeekDefinition;
            XSettings.DisableQuickInfo               = _intellisensePage.DisableQuickInfo;
            XSettings.DisableRegions                 = _intellisensePage.DisableRegions;
            XSettings.DisableSyntaxHighlighting      = _intellisensePage.DisableSyntaxColorization;
            XSettings.DisableXSharpProjectReferences = _intellisensePage.DisableXSharpProjectReferences;

            //XSettings.EditorIndentSize
            XSettings.EditorCompletionListTabs          = _intellisensePage.CompletionListTabs;
            XSettings.EditorCommitChars                 = _intellisensePage.CommitChars;
            XSettings.EditorCompletionAutoPairs         = _intellisensePage.AutoPairs;
            XSettings.EditorCompletionListAfterEachChar = false; // _intellisensePage.ShowAfterChar;
            XSettings.EditorKeywordsInAll               = _intellisensePage.KeywordsInAll;

            XSettings.EditorNavigationSorted                       = _intellisensePage.SortNavigationBars;
            XSettings.EditorNavigationIncludeFields                = _intellisensePage.IncludeFieldsInNavigationBars;
            XSettings.EditorNavigationMembersOfCurrentTypeOnly     = _intellisensePage.ShowMembersOfCurrentTypeOnly;
            XSettings.EditorNavigationExcludeMembersFromOtherFiles = _intellisensePage.ExcludeMembersFromOtherFiles;
            var languagePreferences = new LANGPREFERENCES3[1];

            languagePreferences[0].guidLang = GuidStrings.guidLanguageService;
            int result = VSConstants.S_FALSE;

            ThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                result = _txtManager.GetUserPreferences4(pViewPrefs: null, pLangPrefs: languagePreferences, pColorPrefs: null);
            });
            if (result == VSConstants.S_OK)
            {
                XSettings.EditorIndentStyle         = (int)languagePreferences[0].IndentStyle;
                XSettings.EditorHideAdvancedMembers = languagePreferences[0].fHideAdvancedAutoListMembers != 0;
                XSettings.EditorTabSize             = (int)languagePreferences[0].uTabSize;
                XSettings.EditorIndentSize          = (int)languagePreferences[0].uIndentSize;
                XSettings.EditorTabsAsSpaces        = languagePreferences[0].fInsertTabs == 0;
            }
            // Formatting
            XSettings.EditorIndentFactor           = _formattingPage.MultiFactor;
            XSettings.IdentifierCase               = _formattingPage.IdentifierCase;
            XSettings.UDCKeywordCase               = _formattingPage.UdcCase;
            XSettings.EditorTrimTrailingWhiteSpace = _formattingPage.TrimTrailingWhiteSpace;
            XSettings.EditorInsertFinalNewline     = _formattingPage.InsertFinalNewLine;
            XSettings.KeywordCase = _formattingPage.KeywordCase;
            // Indentation
            XSettings.IndentEntityContent = _indentingPage.IndentEntityContent;
            XSettings.IndentBlockContent  = _indentingPage.IndentBlockContent;
            XSettings.IndentCaseContent   = _indentingPage.IndentCaseContent;
            XSettings.IndentCaseLabel     = _indentingPage.IndentCaseLabel;
            XSettings.IndentMultiLines    = _indentingPage.IndentMultiLines;

            // Completion
            //XSettings.CompleteLocals = _completionOptionsPage.CompleteLocals;
            //XSettings.CompleteSelf = _completionOptionsPage.CompleteSelf;
            //XSettings.CompleteParent = _completionOptionsPage.CompleteParent;
            //XSettings.CompleteNamespaces = _completionOptionsPage.CompleteNamespaces;
            //XSettings.CompleteTypes = _completionOptionsPage.CompleteTypes;
            //XSettings.CompleteKeywords = _completionOptionsPage.CompleteKeywords;
            //XSettings.CompleteSnippets = _completionOptionsPage.CompleteSnippets;
            //XSettings.CompleteGlobals = _completionOptionsPage.CompleteGlobals;
            //XSettings.CompleteGlobalsP = _completionOptionsPage.CompleteGlobalsP;
            //XSettings.CompleteGlobalsA = _completionOptionsPage.CompleteGlobalsA;
            //XSettings.CompleteFunctions = _completionOptionsPage.CompleteFunctions;
            //XSettings.CompleteFunctionsP = _completionOptionsPage.CompleteFunctionsP;
            //XSettings.CompleteFunctionsA = _completionOptionsPage.CompleteFunctionsA;
            //XSettings.CompleteNumChars = _completionOptionsPage.CompleteNumChars;
            //XSettings.MaxCompletionEntries = _completionOptionsPage.MaxCompletionEntries;
            // Other
            XSettings.EditorShowDividers           = _otherOptionsPage.ShowDividers;
            XSettings.EditorShowSingleLineDividers = _otherOptionsPage.ShowSingleLineDividers;
            XSettings.CodeGeneratorShowXmlComments = _otherOptionsPage.ShowXmlComments;
            XSettings.CodeGeneratorPrivateStyle    = (PrivateStyle)_otherOptionsPage.PrivateStyle;
            XSettings.CodeGeneratorPublicStyle     = (PublicStyle)_otherOptionsPage.PublicStyle;
            XSettings.FormEditorMakeBackupFiles    = _otherOptionsPage.FormEditorMakeBackupFiles;
            XSettings.EnableFileLogging            = _otherOptionsPage.LanguageServiceLogging;

            // Persist in registry for CodeDomProvider code generation
            Constants.WriteSetting(Constants.RegistryKeywordCase, (int)XSettings.KeywordCase);
            Constants.WriteSetting(Constants.RegistryPrivateKeyword, (int)XSettings.CodeGeneratorPrivateStyle);
            Constants.WriteSetting(Constants.RegistryPublicKeyword, (int)XSettings.CodeGeneratorPublicStyle);
            Constants.WriteSetting(Constants.RegistryUseTabs, XSettings.EditorTabsAsSpaces ? 0 : 1);
            Constants.WriteSetting(Constants.RegistryTabSize, XSettings.EditorTabSize);
            Constants.WriteSetting(Constants.RegistryIndentSize, XSettings.EditorIndentSize);
            optionWasChanged = false;
            return;
        }
Пример #13
0
 public static LANGPREFERENCES3[] GetNodejsLanguagePreferencesFromTypeScript(IVsTextManager4 textMgr) {
     var langPrefs = new LANGPREFERENCES3[1];
     langPrefs[0].guidLang = Guids.TypeScriptLanguageInfo;
     ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences4(null, langPrefs, null));
     langPrefs[0].guidLang = typeof(NodejsLanguageInfo).GUID;
     textMgr.SetUserPreferences4(null, langPrefs, null);
     return langPrefs;
 }
Пример #14
0
 public static LANGPREFERENCES3[] GetNodejsLanguagePreferencesFromTypeScript(IVsTextManager4 textMgr) {
     var langPrefs = new LANGPREFERENCES3[1];
     langPrefs[0].guidLang = Guids.TypeScriptLanguageInfo;
     int hr = textMgr.GetUserPreferences4(null, langPrefs, null);
     if (ErrorHandler.Failed(hr)) {
         MessageBox.Show(Project.SR.GetString(Project.SR.CouldNotGetTypeScriptLanguagePreferences), Project.SR.ProductName);
         ErrorHandler.ThrowOnFailure(hr);
     }
     langPrefs[0].guidLang = typeof(NodejsLanguageInfo).GUID;
     textMgr.SetUserPreferences4(null, langPrefs, null);
     return langPrefs;
 }