提交 9c6d6537 编写于 作者: T tmeschter

Add basic project system support for analyzers.

This change adds a new interface, IAnalyzerHost, implemented by the C# and VB project system shims.

A future change will update vbproj.dll and csproj.dll to call the methods in this interface to inform us of <Analyzer> and <RuleSet> items in project files.

There are a few missing pieces of functionality that will be filled in later:

1.) We end up loading the analyzer assemblies on the UI thread as soon as AddAnalyzerAssembly is called. This may cause undesirable pauses while loading a project or changing settings. Ideally we would just pass in information about the analyzers and the workspace layer would handle the actual assembly loading.

2.) We don't yet hook up file change listeners for the ruleset files. Ideally we would hook up a listener to the ruleset file and the transitive set of other ruleset files it includes, and reload the rules whenever one of them changes on disk.

3.) The information about analyzers is not currently being passed from the host to the workspace. (changeset 1210973)
上级 582b949a
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. 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.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.Diagnostics;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
......@@ -73,6 +74,11 @@ public sealed class ProjectInfo
/// </summary>
public IReadOnlyList<MetadataReference> MetadataReferences { get; private set; }
/// <summary>
/// The analyzers initially associated with this project.
/// </summary>
public IReadOnlyList<IDiagnosticAnalyzer> Analyzers { get; private set; }
/// <summary>
/// True if this is a submission project for interactive sessions.
/// </summary>
......@@ -96,6 +102,7 @@ public sealed class ProjectInfo
IEnumerable<DocumentInfo> documents,
IEnumerable<ProjectReference> projectReferences,
IEnumerable<MetadataReference> metadataReferences,
IEnumerable<IDiagnosticAnalyzer> analyzers,
bool isSubmission,
Type hostObjectType)
{
......@@ -131,6 +138,7 @@ public sealed class ProjectInfo
this.Documents = documents.ToImmutableListOrEmpty();
this.ProjectReferences = projectReferences.ToImmutableListOrEmpty();
this.MetadataReferences = metadataReferences.ToImmutableListOrEmpty();
this.Analyzers = analyzers.ToImmutableListOrEmpty();
this.IsSubmission = isSubmission;
this.HostObjectType = hostObjectType;
}
......@@ -151,6 +159,7 @@ public sealed class ProjectInfo
IEnumerable<DocumentInfo> documents = null,
IEnumerable<ProjectReference> projectReferences = null,
IEnumerable<MetadataReference> metadataReferences = null,
IEnumerable<IDiagnosticAnalyzer> analyzers = null,
bool isSubmission = false,
Type hostObjectType = null)
{
......@@ -167,6 +176,7 @@ public sealed class ProjectInfo
documents,
projectReferences,
metadataReferences,
analyzers,
isSubmission,
hostObjectType);
}
......@@ -184,6 +194,7 @@ public sealed class ProjectInfo
IEnumerable<DocumentInfo> documents = null,
IEnumerable<ProjectReference> projectReferences = null,
IEnumerable<MetadataReference> metadataReferences = null,
IEnumerable<IDiagnosticAnalyzer> analyzers = null,
Optional<bool> isSubmission = default(Optional<bool>),
Optional<Type> hostObjectType = default(Optional<Type>))
{
......@@ -199,6 +210,7 @@ public sealed class ProjectInfo
var newDocuments = documents ?? this.Documents;
var newProjectReferences = projectReferences ?? this.ProjectReferences;
var newMetadataReferences = metadataReferences ?? this.MetadataReferences;
var newAnalyzers = analyzers ?? this.Analyzers;
var newIsSubmission = isSubmission.HasValue ? isSubmission.Value : this.IsSubmission;
var newHostObjectType = hostObjectType.HasValue ? hostObjectType.Value : this.HostObjectType;
......@@ -214,6 +226,7 @@ public sealed class ProjectInfo
newDocuments == this.Documents &&
newProjectReferences == this.ProjectReferences &&
newMetadataReferences == this.MetadataReferences &&
newAnalyzers == this.Analyzers &&
newIsSubmission == this.IsSubmission &&
newHostObjectType == this.HostObjectType)
{
......@@ -233,6 +246,7 @@ public sealed class ProjectInfo
newDocuments,
newProjectReferences,
newMetadataReferences,
newAnalyzers,
newIsSubmission,
newHostObjectType);
}
......@@ -276,5 +290,10 @@ public ProjectInfo WithMetadataReferences(IEnumerable<MetadataReference> metadat
{
return this.With(metadataReferences: metadataReferences);
}
public ProjectInfo WithAnalyzers(IEnumerable<IDiagnosticAnalyzer> analyzers)
{
return this.With(analyzers: analyzers);
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册