Esempio n. 1
0
 public ImmutableArray <DiagnosticBucket> GetPushDiagnosticBuckets(
     Workspace workspace,
     ProjectId?projectId,
     DocumentId?documentId,
     Option2 <DiagnosticMode> diagnosticMode,
     CancellationToken cancellationToken
     )
 {
     return(GetDiagnosticBuckets(workspace, projectId, documentId));
 }
Esempio n. 2
0
 public static DiagnosticsUpdatedArgs DiagnosticsCreated(
     object id,
     Workspace workspace,
     Solution?solution,
     ProjectId?projectId,
     DocumentId?documentId,
     ImmutableArray <DiagnosticData> diagnostics)
 {
     return(new DiagnosticsUpdatedArgs(id, workspace, solution, projectId, documentId, diagnostics, DiagnosticsUpdatedKind.DiagnosticsCreated));
 }
 public TableEntriesSource(LiveTableDataSource source, Workspace workspace, IGlobalOptionService globalOptions, ProjectId?projectId, DocumentId?documentId, object id)
 {
     _source        = source;
     _workspace     = workspace;
     _globalOptions = globalOptions;
     _projectId     = projectId;
     _documentId    = documentId;
     _id            = id;
     _buildTool     = (id as BuildToolId)?.BuildTool ?? string.Empty;
 }
        public Task <ImmutableArray <DiagnosticData> > GetProjectDiagnosticsForIdsAsync(
            Solution solution, ProjectId?projectId = null, ImmutableHashSet <string>?diagnosticIds = null, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default)
        {
            if (_map.TryGetValue(solution.Workspace, out var analyzer))
            {
                return(analyzer.GetProjectDiagnosticsForIdsAsync(solution, projectId, diagnosticIds, includeSuppressedDiagnostics, cancellationToken));
            }

            return(SpecializedTasks.EmptyImmutableArray <DiagnosticData>());
        }
                protected ProjectId GetBestProjectId_NoLock <T>(
                    Dictionary <ProjectId, T> workQueue,
                    ProjectId?projectId,
                    ProjectDependencyGraph dependencyGraph,
                    IDiagnosticAnalyzerService?analyzerService
                    )
                {
                    if (projectId != null)
                    {
                        if (workQueue.ContainsKey(projectId))
                        {
                            return(projectId);
                        }

                        // prefer project that directly depends on the given project and has diagnostics as next project to
                        // process
                        foreach (
                            var dependingProjectId in dependencyGraph.GetProjectsThatDirectlyDependOnThisProject(
                                projectId
                                )
                            )
                        {
                            if (
                                workQueue.ContainsKey(dependingProjectId) &&
                                analyzerService?.ContainsDiagnostics(
                                    Workspace,
                                    dependingProjectId
                                    ) == true
                                )
                            {
                                return(dependingProjectId);
                            }
                        }
                    }

                    // prefer a project that has diagnostics as next project to process.
                    foreach (var pendingProjectId in workQueue.Keys)
                    {
                        if (
                            analyzerService?.ContainsDiagnostics(Workspace, pendingProjectId)
                            == true
                            )
                        {
                            return(pendingProjectId);
                        }
                    }

                    // explicitly iterate so that we can use struct enumerator
                    foreach (var pair in workQueue)
                    {
                        return(pair.Key);
                    }

                    throw ExceptionUtilities.Unreachable;
                }
Esempio n. 6
0
        /// <summary>
        /// Compares the struct with the other nullable struct value.
        /// </summary>
        /// <param name="other">Other nullable struct value</param>
        /// <returns>0 if two <see cref="ProjectId"/> are equal, 1 if this <see cref="ProjectId"/> comes after the other <see cref="ProjectId"/> and -1 if this <see cref="ProjectId"/> comes before the other <see cref="ProjectId"/>.</returns>
        public int CompareTo(ProjectId?other)
        {
            // if nullable has value, compare the struct like a non-nullable
            if (other.HasValue)
            {
                return(other.Value.CompareTo(this));
            }

            //otherwise the non-null value is considered greater
            return(1);
        }
Esempio n. 7
0
 public IdeLatestDiagnosticGetter(
     DiagnosticIncrementalAnalyzer owner,
     Solution solution,
     ProjectId?projectId,
     DocumentId?documentId,
     ImmutableHashSet <string>?diagnosticIds,
     bool includeSuppressedDiagnostics
     ) : base(owner, solution, projectId, documentId, includeSuppressedDiagnostics)
 {
     _diagnosticIds = diagnosticIds;
 }
Esempio n. 8
0
 internal static void OnAnalyzerException_NoTelemetryLogging(
     DiagnosticAnalyzer analyzer,
     Diagnostic?diagnostic,
     AbstractHostDiagnosticUpdateSource?hostDiagnosticUpdateSource,
     ProjectId?projectId)
 {
     if (diagnostic != null)
     {
         hostDiagnosticUpdateSource?.ReportAnalyzerDiagnostic(analyzer, diagnostic, hostDiagnosticUpdateSource?.Workspace, projectId);
     }
 }
        private Project?GetActiveProject()
        {
            ProjectId?activeProjectId = _getActiveProjectId();

            if (activeProjectId == null)
            {
                return(null);
            }

            return(_workspace.CurrentSolution.Projects.SingleOrDefault((p, id) => p.Id == id, activeProjectId));
        }
Esempio n. 10
0
 public DiagnosticBucket(
     object id,
     Workspace workspace,
     ProjectId?projectId,
     DocumentId?documentId
     )
 {
     Id         = id;
     Workspace  = workspace;
     ProjectId  = projectId;
     DocumentId = documentId;
 }
Esempio n. 11
0
        /// <summary>
        /// Internally, we store the DocumentId for the document that the FileCodeModel represents. If the underlying file
        /// is renamed, the DocumentId will become invalid because the Roslyn VS workspace treats file renames as a remove/add pair.
        /// To work around this, the FileCodeModel is notified when a file rename is about to occur. At that point, the
        /// <see cref="_documentId"/> field is null'd out and <see cref="_incomingFilePath"/> is set to the name of the new file.
        /// The next time that a FileCodeModel operation occurs that requires the DocumentId, it will be retrieved from the workspace
        /// using the <see cref="_incomingFilePath"/>.
        /// </summary>
        internal void OnRename(string newFilePath)
        {
            Debug.Assert(_editCount == 0, "FileCodeModel have an open edit and the underlying file is being renamed. This is a bug.");

            RoslynDebug.AssertNotNull(_documentId);

            _previousDocument  = Workspace.CurrentSolution.GetDocument(_documentId);
            _incomingFilePath  = newFilePath;
            _incomingProjectId = _documentId.ProjectId;

            _documentId = null;
        }
Esempio n. 12
0
 public UpdatedEventArgs(
     object id,
     Workspace workspace,
     ProjectId?projectId,
     DocumentId?documentId
     )
 {
     Id         = id;
     Workspace  = workspace;
     ProjectId  = projectId;
     DocumentId = documentId;
 }
Esempio n. 13
0
 public PinnedSolutionInfo(
     int scopeId,
     bool fromPrimaryBranch,
     int workspaceVersion,
     Checksum solutionChecksum,
     ProjectId?projectId)
 {
     ScopeId           = scopeId;
     FromPrimaryBranch = fromPrimaryBranch;
     WorkspaceVersion  = workspaceVersion;
     SolutionChecksum  = solutionChecksum;
     ProjectId         = projectId;
 }
Esempio n. 14
0
        private ImmutableArray <DiagnosticData> GetDiagnostics(
            Workspace workspace,
            ProjectId?projectId,
            DocumentId?documentId
            )
        {
            Assert.Equal(projectId, GetProjectId(workspace));
            Assert.Equal(documentId, GetDocumentId(workspace));

            return(_diagnostic == null
              ? ImmutableArray <DiagnosticData> .Empty
              : ImmutableArray.Create(_diagnostic));
        }
Esempio n. 15
0
 public Task <ImmutableArray <DiagnosticData> > GetCachedDiagnosticsAsync(
     Solution solution,
     ProjectId?projectId,
     DocumentId?documentId,
     bool includeSuppressedDiagnostics   = false,
     CancellationToken cancellationToken = default
     ) =>
 new IdeCachedDiagnosticGetter(
     this,
     solution,
     projectId,
     documentId,
     includeSuppressedDiagnostics
     ).GetDiagnosticsAsync(cancellationToken);
Esempio n. 16
0
 public ValueTask <ImmutableArray <DiagnosticData> > GetPushDiagnosticsAsync(
     Workspace workspace,
     ProjectId?projectId,
     DocumentId?documentId,
     object?id,
     bool includeSuppressedDiagnostics,
     Option2 <DiagnosticMode> diagnosticMode,
     CancellationToken cancellationToken
     )
 {
     return(new ValueTask <ImmutableArray <DiagnosticData> >(
                GetDiagnostics(workspace, projectId, documentId)
                ));
 }
Esempio n. 17
0
        private static Func <Project, bool> GetShouldFixInProjectDelegate(IVsHierarchyItemManager vsHierarchyItemManager, IHierarchyItemToProjectIdMap projectMap, IVsHierarchy?projectHierarchy)
        {
            ProjectId?projectIdToMatch = null;

            if (projectHierarchy != null)
            {
                var projectHierarchyItem = vsHierarchyItemManager.GetHierarchyItem(projectHierarchy, VSConstants.VSITEMID_ROOT);
                if (projectMap.TryGetProjectId(projectHierarchyItem, targetFrameworkMoniker: null, out var projectId))
                {
                    projectIdToMatch = projectId;
                }
            }

            return(p => projectHierarchy == null || p.Id == projectIdToMatch);
        }
Esempio n. 18
0
        /// <summary>
        /// Private helper method for comparing two nullable <see cref="ProjectId"/> values.
        /// </summary>
        /// <param name="a">First nullable value of <see cref="ProjectId"/></param>
        /// <param name="b">Second nullable value of <see cref="ProjectId"/></param>
        /// <returns>True if two <see cref="ProjectId"/> values are not equal. False otherwise.</returns>
        private static bool CompareNullableWithNullable(ProjectId?a, ProjectId?b)
        {
            // if neither has value, they are both null and therefore are equal.
            if (!a.HasValue && !b.HasValue)
            {
                return(true);
            }

            if (a.HasValue)
            {
                return(a.Value == b);
            }

            return(b.Value == a);
        }
Esempio n. 19
0
            public DiagnosticGetter(
                DiagnosticIncrementalAnalyzer owner,
                Solution solution,
                ProjectId?projectId,
                DocumentId?documentId,
                bool includeSuppressedDiagnostics)
            {
                Owner    = owner;
                Solution = solution;

                DocumentId = documentId;
                ProjectId  = projectId ?? documentId?.ProjectId;

                IncludeSuppressedDiagnostics = includeSuppressedDiagnostics;
            }
Esempio n. 20
0
 public Task <ImmutableArray <DiagnosticData> > GetProjectDiagnosticsForIdsAsync(
     Solution solution,
     ProjectId?projectId,
     ImmutableHashSet <string>?diagnosticIds,
     bool includeSuppressedDiagnostics   = false,
     CancellationToken cancellationToken = default
     ) =>
 new IdeLatestDiagnosticGetter(
     this,
     solution,
     projectId,
     documentId: null,
     diagnosticIds: diagnosticIds,
     includeSuppressedDiagnostics
     ).GetProjectDiagnosticsAsync(cancellationToken);
                    public NormalPriorityProcessor(
                        IAsynchronousOperationListener listener,
                        IncrementalAnalyzerProcessor processor,
                        Lazy <ImmutableArray <IIncrementalAnalyzer> > lazyAnalyzers,
                        IGlobalOperationNotificationService globalOperationNotificationService,
                        int backOffTimeSpanInMs,
                        CancellationToken shutdownToken)
                        : base(listener, processor, lazyAnalyzers, globalOperationNotificationService, backOffTimeSpanInMs, shutdownToken)
                    {
                        _running       = Task.CompletedTask;
                        _workItemQueue = new AsyncDocumentWorkItemQueue(processor._registration.ProgressReporter, processor._registration.Workspace);
                        _higherPriorityDocumentsNotProcessed = new ConcurrentDictionary <DocumentId, IDisposable?>(concurrencyLevel: 2, capacity: 20);

                        _currentProjectProcessing = null;

                        Start();
                    }
Esempio n. 22
0
        private DiagnosticsUpdatedArgs(
            object id,
            Workspace workspace,
            Solution?solution,
            ProjectId?projectId,
            DocumentId?documentId,
            ImmutableArray <DiagnosticData> diagnostics,
            DiagnosticsUpdatedKind kind
            ) : base(id, workspace, projectId, documentId)
        {
            // TODO: This assert fails for EditAndContinueDiagnosticUpdateSource. See https://github.com/dotnet/roslyn/issues/36246.
            // Debug.Assert(diagnostics.All(d => d.ProjectId == projectId && d.DocumentId == documentId));

            Debug.Assert(kind != DiagnosticsUpdatedKind.DiagnosticsRemoved || diagnostics.IsEmpty);

            Solution     = solution;
            Kind         = kind;
            _diagnostics = diagnostics;
        }
Esempio n. 23
0
        public async Task ForceAnalyzeAsync(
            Solution solution,
            Action <Project> onProjectAnalyzed,
            ProjectId?projectId = null,
            CancellationToken cancellationToken = default
            )
        {
            if (_map.TryGetValue(solution.Workspace, out var analyzer))
            {
                if (projectId != null)
                {
                    var project = solution.GetProject(projectId);
                    if (project != null)
                    {
                        await analyzer
                        .ForceAnalyzeProjectAsync(project, cancellationToken)
                        .ConfigureAwait(false);

                        onProjectAnalyzed(project);
                    }
                }
                else
                {
                    var tasks = new Task[solution.ProjectIds.Count];
                    var index = 0;
                    foreach (var project in solution.Projects)
                    {
                        tasks[index++] = Task.Run(
                            async() =>
                        {
                            await analyzer
                            .ForceAnalyzeProjectAsync(project, cancellationToken)
                            .ConfigureAwait(false);
                            onProjectAnalyzed(project);
                        },
                            cancellationToken
                            );
                    }

                    await Task.WhenAll(tasks).ConfigureAwait(false);
                }
            }
        }
Esempio n. 24
0
 public ImmutableArray <DiagnosticData> GetDiagnostics(
     Workspace workspace,
     ProjectId?projectId,
     DocumentId?documentId,
     object?id,
     bool includeSuppressedDiagnostics,
     CancellationToken cancellationToken
     ) =>
 GetPushDiagnosticsAsync(
     workspace,
     projectId,
     documentId,
     id,
     includeSuppressedDiagnostics,
     InternalDiagnosticsOptions.NormalDiagnosticMode,
     cancellationToken
     )
 .AsTask()
 .WaitAndGetResult_CanCallOnBackground(cancellationToken);
Esempio n. 25
0
        protected static LSP.TextDocumentIdentifier CreateTextDocumentIdentifier(
            Uri uri,
            ProjectId?projectContext = null
            )
        {
            var documentIdentifier = new LSP.VSTextDocumentIdentifier {
                Uri = uri
            };

            if (projectContext != null)
            {
                documentIdentifier.ProjectContext = new LSP.ProjectContext
                {
                    Id = ProtocolConversions.ProjectIdToProjectContextId(projectContext)
                };
            }

            return(documentIdentifier);
        }
Esempio n. 26
0
        public WorkspaceChangeEventArgs(
            WorkspaceChangeKind kind,
            Solution oldSolution,
            Solution newSolution,
            ProjectId?projectId   = null,
            DocumentId?documentId = null
            )
        {
            if (!kind.IsValid())
            {
                throw new ArgumentOutOfRangeException(nameof(kind));
            }

            this.Kind        = kind;
            this.OldSolution = oldSolution ?? throw new ArgumentNullException(nameof(oldSolution));
            this.NewSolution = newSolution ?? throw new ArgumentNullException(nameof(newSolution));
            this.ProjectId   = projectId;
            this.DocumentId  = documentId;
        }
Esempio n. 27
0
        public DiagnosticData(
            string id,
            string category,
            string?message,
            string?enuMessageForBingSearch,
            DiagnosticSeverity severity,
            DiagnosticSeverity defaultSeverity,
            bool isEnabledByDefault,
            int warningLevel,
            ImmutableArray <string> customTags,
            ImmutableDictionary <string, string?> properties,
            ProjectId?projectId,
            DiagnosticDataLocation?location = null,
            ImmutableArray <DiagnosticDataLocation> additionalLocations = default,
            string?language    = null,
            string?title       = null,
            string?description = null,
            string?helpLink    = null,
            bool isSuppressed  = false
            )
        {
            Id       = id;
            Category = category;
            Message  = message;
            ENUMessageForBingSearch = enuMessageForBingSearch;

            Severity           = severity;
            DefaultSeverity    = defaultSeverity;
            IsEnabledByDefault = isEnabledByDefault;
            WarningLevel       = warningLevel;
            CustomTags         = customTags;
            Properties         = properties;

            ProjectId           = projectId;
            DataLocation        = location;
            AdditionalLocations = additionalLocations.NullToEmpty();

            Language     = language;
            Title        = title;
            Description  = description;
            HelpLink     = helpLink;
            IsSuppressed = isSuppressed;
        }
Esempio n. 28
0
        private ImmutableArray <DiagnosticBucket> GetDiagnosticBuckets(
            Workspace workspace,
            ProjectId?projectId,
            DocumentId?documentId
            )
        {
            Assert.Equal(projectId, GetProjectId(workspace));
            Assert.Equal(documentId, GetDocumentId(workspace));

            return(_diagnostic == null
              ? ImmutableArray <DiagnosticBucket> .Empty
              : ImmutableArray.Create(
                       new DiagnosticBucket(
                           this,
                           workspace,
                           GetProjectId(workspace),
                           GetDocumentId(workspace)
                           )
                       ));
        }
                protected override bool TryTakeAnyWork_NoLock(
                    ProjectId?preferableProjectId, ProjectDependencyGraph dependencyGraph, IDiagnosticAnalyzerService?analyzerService,
                    out WorkItem workItem)
                {
                    // there must be at least one item in the map when this is called unless host is shutting down.
                    if (_projectWorkQueue.Count == 0)
                    {
                        workItem = default;
                        return(false);
                    }

                    var projectId = GetBestProjectId_NoLock(_projectWorkQueue, preferableProjectId, dependencyGraph, analyzerService);

                    if (TryTake_NoLock(projectId, out workItem))
                    {
                        return(true);
                    }

                    throw ExceptionUtilities.Unreachable;
                }
        private void ClearOpenFileCache(ProjectId?projectId = null)
        {
            lock (_gate)
            {
                var itemsToRemove = new List <DocumentId>();
                foreach (var(documentId, contextTask) in _openDocumentContexts)
                {
                    if (projectId is null || documentId.ProjectId == projectId)
                    {
                        itemsToRemove.Add(documentId);
                        ReleaseContext_NoLock(contextTask);
                    }
                }

                // If any items were released due to the Clear operation, we need to remove them from the map.
                foreach (var documentId in itemsToRemove)
                {
                    _openDocumentContexts.Remove(documentId);
                }
            }
        }