public bool Equals(AnalyzerReference?other) { if (other != null) { return(other.Display == this.Display && other.FullPath == this.FullPath); } return(base.Equals(other)); }
private void ResetReferenceAndErrors(out AnalyzerReference?reference, out ImmutableArray <DiagnosticData> loadErrors) { lock (_gate) { loadErrors = _analyzerLoadErrors; reference = _analyzerReference; _analyzerLoadErrors = ImmutableArray <DiagnosticData> .Empty; _analyzerReference = null; } }
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; } }
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); } }
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)) ); } } } }
// 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); }
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);