private GoToDefinitionFilter Register(IVsTextView textViewAdapter, IWpfTextView textView, bool fireNavigationEvent)
        {
            var generalOptions = Setting.getGeneralOptions(_serviceProvider);

            if (generalOptions == null || (!generalOptions.GoToMetadataEnabled && !generalOptions.GoToSymbolSourceEnabled))
            {
                return(null);
            }
            // Favor Navigate to Source feature over Go to Metadata
            var preference = generalOptions.GoToSymbolSourceEnabled
                                ? (generalOptions.GoToMetadataEnabled ? NavigationPreference.SymbolSourceOrMetadata : NavigationPreference.SymbolSource)
                                : NavigationPreference.Metadata;
            ITextDocument doc;

            if (_textDocumentFactoryService.TryGetTextDocument(textView.TextBuffer, out doc))
            {
                var commandFilter = new GoToDefinitionFilter(doc, textView, _editorOptionsFactory,
                                                             _fsharpVsLanguageService, _serviceProvider, _projectFactory,
                                                             _referenceSourceProvider, preference, fireNavigationEvent);
                if (!_referenceSourceProvider.IsActivated && generalOptions.GoToSymbolSourceEnabled)
                {
                    _referenceSourceProvider.Activate();
                }
                textView.Properties.AddProperty(serviceType, commandFilter);
                AddCommandFilter(textViewAdapter, commandFilter);
                return(commandFilter);
            }
            return(null);
        }
Example #2
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = editorFactory.GetWpfTextView(textViewAdapter);

            if (textView == null)
            {
                return;
            }

            var generalOptions = Setting.getGeneralOptions(serviceProvider);

            if (generalOptions == null || (!generalOptions.GoToMetadataEnabled && !generalOptions.GoToSymbolSourceEnabled))
            {
                return;
            }
            // Favor Navigate to Source feature over Go to Metadata
            var preference = generalOptions.GoToSymbolSourceEnabled
                                ? (generalOptions.GoToMetadataEnabled ? NavigationPreference.SymbolSourceOrMetadata : NavigationPreference.SymbolSource)
                                : NavigationPreference.Metadata;
            ITextDocument doc;

            if (textDocumentFactoryService.TryGetTextDocument(textView.TextBuffer, out doc))
            {
                Debug.Assert(doc != null, "Text document shouldn't be null.");
                var commandFilter = new GoToDefinitionFilter(doc, textView, editorOptionsFactory,
                                                             fsharpVsLanguageService, serviceProvider, projectFactory,
                                                             referenceSourceProvider, preference);
                if (!referenceSourceProvider.IsActivated && generalOptions.GoToSymbolSourceEnabled)
                {
                    referenceSourceProvider.Activate();
                }
                textView.Properties.AddProperty(serviceType, commandFilter);
                AddCommandFilter(textViewAdapter, commandFilter);
            }
        }
        private static void AddCommandFilter(IVsTextView viewAdapter, GoToDefinitionFilter commandFilter)
        {
            if (!commandFilter.IsAdded)
            {
                // Get the view adapter from the editor factory
                IOleCommandTarget next;
                int hr = viewAdapter.AddCommandFilter(commandFilter, out next);

                if (hr == VSConstants.S_OK)
                {
                    commandFilter.IsAdded = true;
                    // You'll need the next target for Exec and QueryStatus
                    if (next != null) commandFilter.NextTarget = next;
                }
            }
        }
Example #4
0
        private static void AddCommandFilter(IVsTextView viewAdapter, GoToDefinitionFilter commandFilter)
        {
            if (!commandFilter.IsAdded)
            {
                // Get the view adapter from the editor factory
                IOleCommandTarget next;
                int hr = viewAdapter.AddCommandFilter(commandFilter, out next);

                if (hr == VSConstants.S_OK)
                {
                    commandFilter.IsAdded = true;
                    // You'll need the next target for Exec and QueryStatus
                    if (next != null)
                    {
                        commandFilter.NextTarget = next;
                    }
                }
            }
        }
 private void Cleanup()
 {
     GoToDefinitionFilter.ClearXmlDocCache();
 }
 private GoToDefinitionFilter Register(IVsTextView textViewAdapter, IWpfTextView textView, bool fireNavigationEvent)
 {
     var generalOptions = Setting.getGeneralOptions(_serviceProvider);
     if (generalOptions == null || (!generalOptions.GoToMetadataEnabled && !generalOptions.GoToSymbolSourceEnabled)) return null;
     // Favor Navigate to Source feature over Go to Metadata
     var preference = generalOptions.GoToSymbolSourceEnabled
                         ? (generalOptions.GoToMetadataEnabled ? NavigationPreference.SymbolSourceOrMetadata : NavigationPreference.SymbolSource)
                         : NavigationPreference.Metadata;
     ITextDocument doc;
     if (_textDocumentFactoryService.TryGetTextDocument(textView.TextBuffer, out doc))
     {
         var commandFilter = new GoToDefinitionFilter(doc, textView, _editorOptionsFactory,
                                                      _fsharpVsLanguageService, _serviceProvider, _projectFactory,
                                                      _referenceSourceProvider, preference, fireNavigationEvent);
         if (!_referenceSourceProvider.IsActivated && generalOptions.GoToSymbolSourceEnabled)
             _referenceSourceProvider.Activate();
         textView.Properties.AddProperty(serviceType, commandFilter);
         AddCommandFilter(textViewAdapter, commandFilter);
         return commandFilter;
     }
     return null;
 }