コード例 #1
0
            public AdornmentManagerTester()
            {
                _subjectBuffer = EditorFactory.CreateBuffer(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, "Hi There");

                _textView = new Mock <IWpfTextView>();
                var aggregatorService = new Mock <IViewTagAggregatorFactoryService>();

                _adornmentLayer = new Mock <IAdornmentLayer>();
                _aggregator     = new Mock <ITagAggregator <Tag> >();

                var layerName = "LayerName";

                _textView.Setup(tv => tv.GetAdornmentLayer(layerName)).Returns(_adornmentLayer.Object);
                _textView.SetupGet(tv => tv.VisualElement).Returns(new FrameworkElement());

                aggregatorService.Setup(a => a.CreateTagAggregator <Tag>(_textView.Object)).Returns(_aggregator.Object);

                var textViewModel = new Mock <ITextViewModel>();

                textViewModel.Setup(tvm => tvm.VisualBuffer).Returns(_subjectBuffer);
                _textView.Setup(tv => tv.TextViewModel).Returns(textViewModel.Object);

                var workspace = new TestWorkspace();

                Manager = AdornmentManager <Tag> .Create(
                    workspace.ExportProvider.GetExportedValue <IThreadingContext>(),
                    _textView.Object,
                    aggregatorService.Object,
                    AsynchronousOperationListenerProvider.NullListener,
                    adornmentLayerName : layerName);
            }
コード例 #2
0
            public AdornmentManagerTester()
            {
                _subjectBuffer = EditorFactory.CreateBuffer(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, "Hi There");

                _textView = new Mock <IWpfTextView>();
                var aggregatorService = new Mock <IViewTagAggregatorFactoryService>();

                _adornmentLayer = new Mock <IAdornmentLayer>();
                _aggregator     = new Mock <ITagAggregator <Tag> >();

                var layerName = "LayerName";

                _textView.Setup(tv => tv.GetAdornmentLayer(layerName)).Returns(_adornmentLayer.Object);
                _textView.SetupGet(tv => tv.VisualElement).Returns(new FrameworkElement());

                aggregatorService.Setup(a => a.CreateTagAggregator <Tag>(_textView.Object)).Returns(_aggregator.Object);

                var textViewModel = new Mock <ITextViewModel>();

                textViewModel.Setup(tvm => tvm.VisualBuffer).Returns(_subjectBuffer);
                _textView.Setup(tv => tv.TextViewModel).Returns(textViewModel.Object);

                var workspace = new TestWorkspace();

                var listener = new AggregateAsynchronousOperationListener(
                    Enumerable.Empty <Lazy <IAsynchronousOperationListener, FeatureMetadata> >(),
                    FeatureAttribute.LineSeparators);

                Manager = AdornmentManager <Tag> .Create(_textView.Object,
                                                         aggregatorService.Object,
                                                         listener,
                                                         adornmentLayerName : layerName);
            }
コード例 #3
0
        public ILineTransformSource Create(IWpfTextView textView)
        {
            Contract.Assume(textView != null);

            if (VSServiceProvider.Current == null || VSServiceProvider.Current.ExtensionHasFailed)
            {
                //If the VSServiceProvider is not initialize, we can't do anything.
                return(null);// new DummyLineTransformSource();
            }

            try {
                VSServiceProvider.Current.ExtensionFailed += OnFailed;

                if (hasFailed)
                {
                    return(null);
                }

                Contract.Assume(this.OutliningManagerService != null, "Import attribute guarantees this.");

                var outliningManager = OutliningManagerService.GetOutliningManager(textView);
                if (outliningManager == null)
                {
                    return(null);//new DummyLineTransformSource();
                }
                var inheritanceManager = AdornmentManager.GetOrCreateAdornmentManager(textView, "InheritanceAdornments", outliningManager, VSServiceProvider.Current.Logger);
                var metadataManager    = AdornmentManager.GetOrCreateAdornmentManager(textView, "MetadataAdornments", outliningManager, VSServiceProvider.Current.Logger);

                return(new LineTransformSource(VSServiceProvider.Current.Logger, inheritanceManager.Adornments.Values, metadataManager.Adornments.Values));
            } catch (Exception exn) {
                VSServiceProvider.Current.Logger.PublicEntryException(exn, "Create");
                return(null);// new DummyLineTransformSource();
            }
        }
コード例 #4
0
        private MetadataTracker(IWpfTextView textView, double defaultFontSize = 10.0d)
        {
            this.defaultFontSize = defaultFontSize;
            this.textView        = textView;

            bool isMetadataFile = false;

            fileName = textView.TextBuffer.GetFileName();
            if (fileName.Contains('$'))//TODO: This is a very weak check, we need a better way to check this!
            {
                isMetadataFile = true;
            }

            if (!isMetadataFile)
            {
                return;
            }

            adornmentManager = AdornmentManager.GetOrCreateAdornmentManager(textView, "MetadataAdornments");

            //timer = new Timer();
            //timer.BeginInit();
            //timer.AutoReset = false;
            //timer.Elapsed += OnLayoutSettled;
            //timer.Interval = 2000;
            //timer.EndInit();
            //timer.Start();

            textView.LayoutChanged += OnLayoutChanged;

            var foo = new ContractAdornment(11, textView.TextSnapshot.CreateTrackingSpan(0, 10, SpanTrackingMode.EdgeExclusive), defaultFontSize);
        }
コード例 #5
0
    private MetadataTracker(IWpfTextView textView, ProjectTracker projectTracker, VSTextProperties vsTextProperties) {
      Contract.Requires(projectTracker != null);
      Contract.Requires(textView != null);
      this._vsTextProperties = vsTextProperties;
      this._textView = textView;
      this._projectTracker = projectTracker;
      VSServiceProvider.Current.ExtensionFailed += OnExtensionFailed;

      _timer = new System.Timers.Timer();
      _timer.AutoReset = false;

        if (!AdornmentManager.TryGetAdornmentManager(textView, "MetadataAdornments", out _adornmentManager))
      {
        VSServiceProvider.Current.Logger.WriteToLog("Metadata adornments layer not instantiated.");
        return;
      }
      
      _timer.Elapsed += OnLayoutSettled;
      textView.LayoutChanged += OnLayoutChanged;
    }
コード例 #6
0
        private InheritanceTracker(TextViewTracker textViewTracker)
        {
            Contract.Requires(textViewTracker != null);
            Contract.Requires(textViewTracker.TextView != null);
            if (!AdornmentManager.TryGetAdornmentManager(textViewTracker.TextView, "InheritanceAdornments", out _adornmentManager))
            {
                ContractsPackageAccessor.Current.Logger.WriteToLog("Inheritance adornment layer not instantiated.");
                throw new InvalidOperationException("Inheritance adornment layer not instantiated.");
            }

            _methodsNeedingContractLookup    = new Queue <KeyValuePair <object, MethodDeclarationNode> >();
            _propertiesNeedingContractLookup = new Queue <KeyValuePair <Tuple <object, object>, PropertyDeclarationNode> >();
            _methodKeys   = new HashSet <object>();
            _propertyKeys = new HashSet <object>();

            _textViewTracker = textViewTracker;
            _textViewTracker.LatestCompilationChanged += OnLatestCompilationChanged;
            _textViewTracker.LatestSourceFileChanged  += OnLatestSourceFileChanged;
            _textViewTracker.ProjectTracker.BuildDone += OnBuildDone;
            _textViewTracker.TextView.Closed          += OnClosed;
        }
コード例 #7
0
 public void TextViewCreated(IWpfTextView textView)
 {
     var manager         = AdornmentManager.GetOrCreateAdornmentManager(textView, "MetadataAdornments");
     var defaultFontSize = GetDefaultFontSize(textView);
     var metadataTracker = MetadataTracker.GetOrCreateMetadataTracker(textView, GetDefaultFontSize(textView));
 }
コード例 #8
0
        /// <summary>
        /// When a new text view is created, hook up the various "trackers" (<see cref="TextViewTracker"/>, <see cref="InheritanceTracker"/>, <see cref="QuickInfoTracker"/>).
        /// </summary>
        /// <param name="textView"></param>
        public void TextViewCreated(IWpfTextView textView)
        {
            Contract.Assume(textView != null);

            if (VSServiceProvider.Current == null || VSServiceProvider.Current.ExtensionHasFailed)
            {
                //If the VSServiceProvider is not initialize, we can't do anything.
                return;
            }

            VSServiceProvider.Current.Logger.PublicEntry(() => {
                #region Check if textView is valid
                var fileName = textView.GetFileName();
                if (fileName == null)
                {
                    VSServiceProvider.Current.Logger.WriteToLog("Couldn't retrieve file name for current view.");
                    return;
                }
                if (!File.Exists(fileName))
                {
                    VSServiceProvider.Current.Logger.WriteToLog("Couldn't find file for current view.");
                    return;
                }
                #endregion
                VSServiceProvider.Current.Logger.WriteToLog("Text view found: " + fileName);
                #region Check if textView is a CSharp file
                var IsCSharpFile = Path.GetExtension(fileName) == ".cs";
                #endregion
                #region Get text view properties
                var vsTextProperties = VSTextPropertiesProvider.GetVSTextProperties(textView);
                #endregion
                var vsProject = VSServiceProvider.Current.GetProjectForFile(fileName);//May be null!
                ProjectTracker projectTracker = null;
                if (vsProject != null)
                {
                    projectTracker = ProjectTracker.GetOrCreateProjectTracker(vsProject);
                    if (projectTracker != null)
                    {
                        textView.Properties.AddProperty(typeof(ProjectTracker), projectTracker);
                    }
                    else
                    {
                        VSServiceProvider.Current.Logger.WriteToLog("Warning: Couldn't create a 'ProjectTracker', we won't be able to show inheritance contract information for this text view. Close and reopen the text view to try again!");
                    }
                }
                #region Check if textView is an editable code file
                var IsEditableCodeFile = /*IsCSharpFile &&*/ textView.Roles.Contains("editable") && projectTracker != null; //TODO: We need a stronger check to see if it is a editable code file
                #endregion
                if (IsEditableCodeFile)
                {
                    textView.GotAggregateFocus += NewFocus;
                    var textViewTracker         = TextViewTracker.GetOrCreateTextViewTracker(textView, projectTracker, vsTextProperties);
                    //if (VSServiceProvider.Current.VSOptionsPage != null && (VSServiceProvider.Current.VSOptionsPage.InheritanceOnMethods || VSServiceProvider.Current.VSOptionsPage.InheritanceOnProperties)) {
                    //  //var inheritanceAdornmentManager = AdornmentManager.GetOrCreateAdornmentManager(textView, "InheritanceAdornments", outliningManager, VSServiceProvider.Current.Logger);
                    //  //var inheritanceTracker = InheritanceTracker.GetOrCreateAdornmentTracker(textViewTracker);
                    //}
                    //var quickInfoTracker = QuickInfoTracker.GetOrCreateQuickInfoTracker(textViewTracker); //Disabled for now, unfinished
                }
                #region Check if textView is a metadata file
                var IsMetadataFile = !IsEditableCodeFile && fileName.Contains('$'); //TODO: We need a strong check to see if it is a metadata file
                #endregion
                if (IsMetadataFile)
                {
                    if (lastFocus == null || !lastFocus.Properties.ContainsProperty(typeof(ProjectTracker)))
                    {
                        VSServiceProvider.Current.Logger.WriteToLog("Couldn't find project for metadata file.");
                    }
                    else
                    {
                        var outliningManager = OutliningManagerService.GetOutliningManager(textView);
                        if (outliningManager == null)
                        {
                            VSServiceProvider.Current.Logger.WriteToLog("Couldn't get outlining manager for current view.");
                            return;
                        }
                        projectTracker = lastFocus.Properties.GetProperty <ProjectTracker>(typeof(ProjectTracker));
                        textView.Properties.AddProperty(typeof(ProjectTracker), projectTracker);
                        textView.GotAggregateFocus += NewFocus;
                        if (VSServiceProvider.Current.VSOptionsPage != null && VSServiceProvider.Current.VSOptionsPage.Metadata)
                        {
                            var metadataAdornmentManager = AdornmentManager.GetOrCreateAdornmentManager(textView, "MetadataAdornments", outliningManager, VSServiceProvider.Current.Logger);
                            var metadataTracker          = MetadataTracker.GetOrCreateMetadataTracker(textView, projectTracker, vsTextProperties);
                        }
                    }
                }
            }, "TextViewCreated");
        }
コード例 #9
0
        public ILineTransformSource Create(IWpfTextView textView)
        {
            var adornmentManager = AdornmentManager.GetOrCreateAdornmentManager(textView, "MetadataAdornments");

            return(new LineTransformSource(adornmentManager.Adornments));
        }