private TextViewTracker(IWpfTextView textView, ProjectTracker projectTracker, VSTextProperties vsTextProperties)
      : base() {
      Contract.Requires(textView != null);
      Contract.Requires(projectTracker != null);

      VSServiceProvider.Current.ExtensionFailed += OnFailed;
      this.TextView = textView;
      if (textView.TextBuffer != null)
      {
        textView.TextBuffer.Changed += OnTextBufferChanged;
      }
      TextView.Closed += OnClosed;
      this._projectTracker = projectTracker;
      projectTracker.BuildDone += OnBuildDone;
//      VSServiceProvider.Current.NewSourceFile += OnNewSourceFile;
      VSServiceProvider.Current.NewCompilation += OnNewComilation;
      
      //Timer
      _textBufferChangedTimer = new System.Timers.Timer();
      _textBufferChangedTimer.AutoReset = false;
      _textBufferChangedTimer.Elapsed += OnTextViewSettled;
      _textBufferChangedTimer.Interval = DelayOnTextViewOpened; //Wait two seconds before attempting to fetch any syntactic/semantic information. This gives VS a chance to properly initialize everything.
      _textBufferChangedTimer.Start();

      //Set the text properties
      VSTextProperties = vsTextProperties;
      VSServiceProvider.Current.QueueWorkItem((() => { VSTextProperties.LineHeight = TextView.LineHeight; }));

      //Set the file name
      var fn = TextView.GetFileName();
      if (fn == null) { fn = "dummyFileName"; }
      FileName = new FileName(fn);
    }
Exemple #2
0
        public static ProjectTracker GetOrCreateProjectTracker(VSProject vsProject)
        {
            Contract.Requires(vsProject != null);

            ProjectTracker projectTracker;

            if (!ProjectIsAvailable(vsProject.Project))
            {
                VSServiceProvider.Current.Logger.WriteToLog("Error: Project is not available! We can't create a 'ProjectTracker'!");
                return(null);
            }
            if (!VSServiceProvider.Current.ProjectTrackers.TryGetValue(vsProject.Project.UniqueName, out projectTracker))
            {
                projectTracker = new ProjectTracker(vsProject);
                if (vsProject.Project != null && vsProject.Project.UniqueName != null)
                {
                    VSServiceProvider.Current.ProjectTrackers[vsProject.Project.UniqueName] = projectTracker;
                }
                else
                {
                    // issue: project has no name, so we can't store it.
                }
            }
            return(projectTracker);
        }
    public ContractsProvider(ProjectTracker projectTracker) {
      Contract.Requires(projectTracker != null);

      //Grab a pointer back to our project tracker
      _projectTracker = projectTracker;

      //Initialize our caches
      _semanticMembersToCCIMethods = new Dictionary<CSharpMember, IMethodReference>();
      _semanticTypesToCCITypes = new Dictionary<CSharpType, ITypeReference>();
      _semanticAssemblysToCCIAssemblys = new Dictionary<CSharpAssembly, IAssemblyReference>();
      _semanticPropertiesToCCIAccessorMethods = new Dictionary<CSharpMember, Tuple<IMethodReference, IMethodReference>>();
    }
Exemple #4
0
        public ContractsProvider(ProjectTracker projectTracker)
        {
            Contract.Requires(projectTracker != null);

            //Grab a pointer back to our project tracker
            _projectTracker = projectTracker;

            //Initialize our caches
            _semanticMembersToCCIMethods            = new Dictionary <CSharpMember, IMethodReference>();
            _semanticTypesToCCITypes                = new Dictionary <CSharpType, ITypeReference>();
            _semanticAssemblysToCCIAssemblys        = new Dictionary <CSharpAssembly, IAssemblyReference>();
            _semanticPropertiesToCCIAccessorMethods = new Dictionary <CSharpMember, Tuple <IMethodReference, IMethodReference> >();
        }
    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;
    }
    public static ProjectTracker GetOrCreateProjectTracker(VSProject vsProject) {

      Contract.Requires(vsProject != null);

      ProjectTracker projectTracker;
      if (!ProjectIsAvailable(vsProject.Project)) {
        VSServiceProvider.Current.Logger.WriteToLog("Error: Project is not available! We can't create a 'ProjectTracker'!");
        return null;
      }
      if (!VSServiceProvider.Current.ProjectTrackers.TryGetValue(vsProject.Project.UniqueName, out projectTracker)) {
        projectTracker = new ProjectTracker(vsProject);
        if (vsProject.Project != null && vsProject.Project.UniqueName != null)
        {
          VSServiceProvider.Current.ProjectTrackers[vsProject.Project.UniqueName] = projectTracker;
        }
        else
        {
          // issue: project has no name, so we can't store it.
        }
      }
      return projectTracker;
    }
        private TextViewTracker(IWpfTextView textView, ProjectTracker projectTracker, VSTextProperties vsTextProperties)
            : base()
        {
            Contract.Requires(textView != null);
            Contract.Requires(projectTracker != null);

            VSServiceProvider.Current.ExtensionFailed += OnFailed;
            this.TextView = textView;
            if (textView.TextBuffer != null)
            {
                textView.TextBuffer.Changed += OnTextBufferChanged;
            }
            TextView.Closed          += OnClosed;
            this._projectTracker      = projectTracker;
            projectTracker.BuildDone += OnBuildDone;
//      VSServiceProvider.Current.NewSourceFile += OnNewSourceFile;
            VSServiceProvider.Current.NewCompilation += OnNewComilation;

            //Timer
            _textBufferChangedTimer           = new System.Timers.Timer();
            _textBufferChangedTimer.AutoReset = false;
            _textBufferChangedTimer.Elapsed  += OnTextViewSettled;
            _textBufferChangedTimer.Interval  = DelayOnTextViewOpened; //Wait two seconds before attempting to fetch any syntactic/semantic information. This gives VS a chance to properly initialize everything.
            _textBufferChangedTimer.Start();

            //Set the text properties
            VSTextProperties = vsTextProperties;
            VSServiceProvider.Current.QueueWorkItem((() => { VSTextProperties.LineHeight = TextView.LineHeight; }));

            //Set the file name
            var fn = TextView.GetFileName();

            if (fn == null)
            {
                fn = "dummyFileName";
            }
            FileName = new FileName(fn);
        }
        /// <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");
        }
 public static TextViewTracker GetOrCreateTextViewTracker(IWpfTextView textView, ProjectTracker projectTracker, VSTextProperties vsTextProperties) {
   Contract.Requires(textView != null);
   Contract.Requires(projectTracker != null);
   Contract.Ensures(Contract.Result<TextViewTracker>() != null);
   return textView.TextBuffer.Properties.GetOrCreateSingletonProperty<TextViewTracker>(TextViewTrackerKey, delegate { return new TextViewTracker(textView, projectTracker, vsTextProperties); });
 }
Exemple #10
0
 /// <summary>
 /// Gets or creates a MetadataTracker for a particular text view.
 /// </summary>
 public static MetadataTracker GetOrCreateMetadataTracker(IWpfTextView textView, ProjectTracker projectTracker, VSTextProperties vsTextProperties)
 {
     Contract.Requires(textView != null);
     Contract.Assume(textView.Properties != null);
     return(textView.Properties.GetOrCreateSingletonProperty <MetadataTracker>(MetadataTrackerKey, delegate { return new MetadataTracker(textView, projectTracker, vsTextProperties); }));
 }
 public static TextViewTracker GetOrCreateTextViewTracker(IWpfTextView textView, ProjectTracker projectTracker, VSTextProperties vsTextProperties)
 {
     Contract.Requires(textView != null);
     Contract.Requires(projectTracker != null);
     Contract.Ensures(Contract.Result <TextViewTracker>() != null);
     return(textView.TextBuffer.Properties.GetOrCreateSingletonProperty <TextViewTracker>(TextViewTrackerKey, delegate { return new TextViewTracker(textView, projectTracker, vsTextProperties); }));
 }
 /// <summary>
 /// Gets or creates a MetadataTracker for a particular text view.
 /// </summary>
 public static MetadataTracker GetOrCreateMetadataTracker(IWpfTextView textView, ProjectTracker projectTracker, VSTextProperties vsTextProperties) {
   Contract.Requires(textView != null);
   Contract.Assume(textView.Properties != null);
   return textView.Properties.GetOrCreateSingletonProperty<MetadataTracker>(MetadataTrackerKey, delegate { return new MetadataTracker(textView, projectTracker, vsTextProperties); });
 }