提交 b1bf7246 编写于 作者: J Jason Malinowski

Add an API to enumerate AnalyzerConfigDocuments

We had APIs for add/remove, but didn't actually add the collection
type yet.
上级 4da29aa6
*REMOVED*Microsoft.CodeAnalysis.Workspace.ClearOpenDocument(Microsoft.CodeAnalysis.DocumentId documentId, bool isSolutionClosing = false) -> void
Microsoft.CodeAnalysis.AnalyzerConfigDocument
Microsoft.CodeAnalysis.Project.AnalyzerConfigDocuments.get -> System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.AnalyzerConfigDocument>
Microsoft.CodeAnalysis.Project.ContainsAnalyzerConfigDocument(Microsoft.CodeAnalysis.DocumentId documentId) -> bool
Microsoft.CodeAnalysis.Project.GetAnalyzerConfigDocument(Microsoft.CodeAnalysis.DocumentId documentId) -> Microsoft.CodeAnalysis.AnalyzerConfigDocument
Microsoft.CodeAnalysis.ProjectInfo.AnalyzerConfigDocuments.get -> System.Collections.Generic.IReadOnlyList<Microsoft.CodeAnalysis.DocumentInfo>
Microsoft.CodeAnalysis.ProjectInfo.WithAnalyzerConfigDocuments(System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.DocumentInfo> analyzerConfigDocuments) -> Microsoft.CodeAnalysis.ProjectInfo
Microsoft.CodeAnalysis.Solution.AddAdditionalDocuments(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.DocumentInfo> documentInfos) -> Microsoft.CodeAnalysis.Solution
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Text;
namespace Microsoft.CodeAnalysis
{
public sealed class AnalyzerConfigDocument : TextDocument
{
internal AnalyzerConfigDocument(Project project, AnalyzerConfigDocumentState state)
: base(project, state)
{
}
}
}
......@@ -24,6 +24,7 @@ public partial class Project
private readonly ProjectState _projectState;
private ImmutableHashMap<DocumentId, Document> _idToDocumentMap = ImmutableHashMap<DocumentId, Document>.Empty;
private ImmutableHashMap<DocumentId, TextDocument> _idToAdditionalDocumentMap = ImmutableHashMap<DocumentId, TextDocument>.Empty;
private ImmutableHashMap<DocumentId, AnalyzerConfigDocument> _idToAnalyzerConfigDocumentMap = ImmutableHashMap<DocumentId, AnalyzerConfigDocument>.Empty;
internal Project(Solution solution, ProjectState projectState)
{
......@@ -169,6 +170,11 @@ internal Project(Solution solution, ProjectState projectState)
/// </summary>
public IEnumerable<TextDocument> AdditionalDocuments => _projectState.AdditionalDocumentIds.Select(GetAdditionalDocument);
/// <summary>
/// All the <see cref="AnalyzerConfigDocument"/>s associated with this project.
/// </summary>
public IEnumerable<AnalyzerConfigDocument> AnalyzerConfigDocuments => _projectState.AnalyzerConfigDocumentStates.Select(s => GetAnalyzerConfigDocument(s.Key));
/// <summary>
/// True if the project contains a document with the specified ID.
/// </summary>
......@@ -185,6 +191,14 @@ public bool ContainsAdditionalDocument(DocumentId documentId)
return _projectState.ContainsAdditionalDocument(documentId);
}
/// <summary>
/// True if the project contains an <see cref="AnalyzerConfigDocument"/> with the specified ID.
/// </summary>
public bool ContainsAnalyzerConfigDocument(DocumentId documentId)
{
return _projectState.ContainsAnalyzerConfigDocument(documentId);
}
/// <summary>
/// Get the documentId in this project with the specified syntax tree.
/// </summary>
......@@ -227,6 +241,19 @@ public TextDocument GetAdditionalDocument(DocumentId documentId)
return ImmutableHashMapExtensions.GetOrAdd(ref _idToAdditionalDocumentMap, documentId, s_createAdditionalDocumentFunction, this);
}
/// <summary>
/// Get the analyzer config document in this project with the specified document Id.
/// </summary>
public AnalyzerConfigDocument GetAnalyzerConfigDocument(DocumentId documentId)
{
if (!ContainsAnalyzerConfigDocument(documentId))
{
return null;
}
return ImmutableHashMapExtensions.GetOrAdd(ref _idToAnalyzerConfigDocumentMap, documentId, s_createAnalyzerConfigDocumentFunction, this);
}
internal DocumentState GetDocumentState(DocumentId documentId)
{
return _projectState.GetDocumentState(documentId);
......@@ -266,6 +293,12 @@ private static TextDocument CreateAdditionalDocument(DocumentId documentId, Proj
return new TextDocument(project, project._projectState.GetAdditionalDocumentState(documentId));
}
private static readonly Func<DocumentId, Project, AnalyzerConfigDocument> s_createAnalyzerConfigDocumentFunction = CreateAnalyzerConfigDocument;
private static AnalyzerConfigDocument CreateAnalyzerConfigDocument(DocumentId documentId, Project project)
{
return new AnalyzerConfigDocument(project, project._projectState.GetAnalyzerConfigDocumentState(documentId));
}
/// <summary>
/// Tries to get the cached <see cref="Compilation"/> for this project if it has already been created and is still cached. In almost all
/// cases you should call <see cref="GetCompilationAsync"/> which will either return the cached <see cref="Compilation"/>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册