예제 #1
0
        public bool Equals(AnalyzerReference?other)
        {
            if (other != null)
            {
                return(other.Display == this.Display &&
                       other.FullPath == this.FullPath);
            }

            return(base.Equals(other));
        }
예제 #2
0
        private void ResetReferenceAndErrors(out AnalyzerReference?reference, out ImmutableArray <DiagnosticData> loadErrors)
        {
            lock (_gate)
            {
                loadErrors = _analyzerLoadErrors;
                reference  = _analyzerReference;

                _analyzerLoadErrors = ImmutableArray <DiagnosticData> .Empty;
                _analyzerReference  = null;
            }
        }
예제 #3
0
        public CpsDiagnosticItemSource(Workspace workspace, string projectPath, ProjectId projectId, IVsHierarchyItem item, IAnalyzersCommandHandler commandHandler, IDiagnosticAnalyzerService analyzerService)
            : base(workspace, projectId, commandHandler, analyzerService)
        {
            _item = item;
            _projectDirectoryPath = Path.GetDirectoryName(projectPath);

            _analyzerReference = TryGetAnalyzerReference(Workspace.CurrentSolution);
            if (_analyzerReference == null)
            {
                // The workspace doesn't know about the project and/or the analyzer yet.
                // Hook up an event handler so we can update when it does.
                Workspace.WorkspaceChanged += OnWorkspaceChangedLookForAnalyzer;
            }
        }
예제 #4
0
        public AnalyzerReference GetReference()
        {
            lock (_gate)
            {
                if (_analyzerReference == null)
                {
                    // TODO: ensure the file watcher is subscribed
                    // (tracked by https://devdiv.visualstudio.com/DevDiv/_workitems/edit/661546)

                    var analyzerFileReference = new AnalyzerFileReference(FullPath, s_analyzerAssemblyLoader);
                    analyzerFileReference.AnalyzerLoadFailed += OnAnalyzerLoadError;
                    _analyzerReference = analyzerFileReference;
                }

                return(_analyzerReference);
            }
        }
예제 #5
0
        private void OnWorkspaceChangedLookForAnalyzer(object sender, WorkspaceChangeEventArgs e)
        {
            if (
                e.Kind == WorkspaceChangeKind.SolutionCleared ||
                e.Kind == WorkspaceChangeKind.SolutionReloaded ||
                e.Kind == WorkspaceChangeKind.SolutionRemoved
                )
            {
                Workspace.WorkspaceChanged -= OnWorkspaceChangedLookForAnalyzer;
            }
            else if (e.Kind == WorkspaceChangeKind.SolutionAdded)
            {
                _analyzerReference = TryGetAnalyzerReference(e.NewSolution);
                if (_analyzerReference != null)
                {
                    Workspace.WorkspaceChanged -= OnWorkspaceChangedLookForAnalyzer;

                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(HasItems)));
                }
            }
            else if (e.ProjectId == ProjectId)
            {
                if (e.Kind == WorkspaceChangeKind.ProjectRemoved)
                {
                    Workspace.WorkspaceChanged -= OnWorkspaceChangedLookForAnalyzer;
                }
                else if (
                    e.Kind == WorkspaceChangeKind.ProjectAdded ||
                    e.Kind == WorkspaceChangeKind.ProjectChanged
                    )
                {
                    _analyzerReference = TryGetAnalyzerReference(e.NewSolution);
                    if (_analyzerReference != null)
                    {
                        Workspace.WorkspaceChanged -= OnWorkspaceChangedLookForAnalyzer;

                        PropertyChanged?.Invoke(
                            this,
                            new PropertyChangedEventArgs(nameof(HasItems))
                            );
                    }
                }
            }
        }
예제 #6
0
        // legacy, for backwards compat:
        public bool Equals(AnalyzerReference?other)
        {
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            if (other is null)
            {
                return(false);
            }

            if (other is AnalyzerFileReference fileReference)
            {
                return(Equals(fileReference));
            }

            return(FullPath == other.FullPath);
        }
예제 #7
0
        public AnalyzerReference GetReference()
        {
            lock (_gate)
            {
                if (_analyzerReference == null)
                {
                    if (File.Exists(FullPath))
                    {
                        // Pass down a custom loader that will ensure we are watching for file changes once we actually load the assembly.
                        var assemblyLoaderForFileTracker = new AnalyzerAssemblyLoaderThatEnsuresFileBeingWatched(this);
                        var analyzerFileReference        = new AnalyzerFileReference(FullPath, assemblyLoaderForFileTracker);
                        analyzerFileReference.AnalyzerLoadFailed += OnAnalyzerLoadError;

                        _analyzerReference = analyzerFileReference;
                    }
                    else
                    {
                        _analyzerReference = new VisualStudioUnresolvedAnalyzerReference(FullPath, this);
                    }
                }

                return(_analyzerReference);
            }
        }
 public int GetHashCode(AnalyzerReference?obj) => obj?.FullPath?.GetHashCode() ?? 0;
 public bool Equals(AnalyzerReference?x, AnalyzerReference?y) =>
 string.Equals(x?.FullPath, y?.FullPath, StringComparison.OrdinalIgnoreCase);