提交 60e9b844 编写于 作者: H Heejae Chang

added MustRunInProc in IBuiltInAnalyzer and some clean up around serializing...

added MustRunInProc in IBuiltInAnalyzer and some clean up around serializing Solution/Project/DocumentId and how DocumentState is exposed.
上级 79d9ded8
......@@ -143,7 +143,7 @@ public async Task AnalyzerOptionsArePassedToAllAnalyzers()
var newSln = workspace.CurrentSolution.AddAdditionalDocument(additionalDocId, "add.config", SourceText.From("random text"));
currentProject = newSln.Projects.Single();
var additionalDocument = currentProject.GetAdditionalDocument(additionalDocId);
AdditionalText additionalStream = new AdditionalTextDocument(additionalDocument.GetDocumentState());
AdditionalText additionalStream = new AdditionalTextDocument(additionalDocument.State);
AnalyzerOptions options = new AnalyzerOptions(ImmutableArray.Create(additionalStream));
var analyzer = new OptionsDiagnosticAnalyzer<SyntaxKind>(expectedOptions: options);
......@@ -161,6 +161,8 @@ private void AccessSupportedDiagnostics(DiagnosticAnalyzer analyzer)
private class ThrowingDoNotCatchDiagnosticAnalyzer<TLanguageKindEnum> : ThrowingDiagnosticAnalyzer<TLanguageKindEnum>, IBuiltInAnalyzer where TLanguageKindEnum : struct
{
public bool MustRunInProc => true;
public DiagnosticAnalyzerCategory GetAnalyzerCategory()
{
return DiagnosticAnalyzerCategory.SyntaxAnalysis | DiagnosticAnalyzerCategory.SemanticDocumentAnalysis | DiagnosticAnalyzerCategory.ProjectAnalysis;
......
......@@ -18,13 +18,8 @@ internal sealed class RenameTrackingDiagnosticAnalyzer : DiagnosticAnalyzer, IBu
internal const string RenameFromPropertyKey = "RenameFrom";
internal const string RenameToPropertyKey = "RenameTo";
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
return ImmutableArray.Create(DiagnosticDescriptor);
}
}
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(DiagnosticDescriptor);
public bool MustRunInProc => true;
public override void Initialize(AnalysisContext context)
{
......
......@@ -135,6 +135,8 @@ internal class Analyzer : DiagnosticAnalyzer, IBuiltInAnalyzer
private readonly DiagnosticDescriptor _descriptor =
new DiagnosticDescriptor("TestId", "Test", "Test", "Test", DiagnosticSeverity.Warning, isEnabledByDefault: true);
public bool MustRunInProc => true;
public ImmutableArray<SyntaxNode> AllNodes { get; set; }
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
......
......@@ -499,7 +499,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.Diagnostics.UnitTests
Dim exceptionDiagnosticsSource = New TestHostDiagnosticUpdateSource(workspace)
' check reporting diagnostic to a project that doesn't exist
exceptionDiagnosticsSource.ReportAnalyzerDiagnostic(analyzer, expected, workspace, New ProjectId(Guid.NewGuid(), "dummy"))
exceptionDiagnosticsSource.ReportAnalyzerDiagnostic(analyzer, expected, workspace, ProjectId.CreateFromSerialized(Guid.NewGuid(), "dummy"))
Dim diagnostics = exceptionDiagnosticsSource.TestOnly_GetReportedDiagnostics(analyzer)
Assert.Equal(0, diagnostics.Count())
......
......@@ -92,7 +92,7 @@ End Class
currentProject = newSln.Projects.Single()
Dim additionalDocument = currentProject.GetAdditionalDocument(additionalDocId)
Dim additionalStream As AdditionalText = New AdditionalTextDocument(additionalDocument.GetDocumentState())
Dim additionalStream As AdditionalText = New AdditionalTextDocument(additionalDocument.State)
Dim options = New AnalyzerOptions(ImmutableArray.Create(additionalStream))
Dim analyzer = New OptionsDiagnosticAnalyzer(Of SyntaxKind)(expectedOptions:=options)
......
// 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.Collections.Immutable;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
......@@ -24,6 +26,8 @@ internal sealed class CSharpAddBracesDiagnosticAnalyzer : DiagnosticAnalyzer, IB
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(s_descriptor);
public bool MustRunInProc => false;
public override void Initialize(AnalysisContext context)
{
var syntaxKindsOfInterest =
......@@ -126,7 +130,7 @@ public void AnalyzeNode(SyntaxNodeAnalysisContext context)
}
}
private bool AnalyzeIfStatement(IfStatementSyntax ifStatement) =>
private bool AnalyzeIfStatement(IfStatementSyntax ifStatement) =>
!ifStatement.Statement.IsKind(SyntaxKind.Block);
private bool AnalyzeElseClause(ElseClauseSyntax elseClause) =>
......@@ -138,13 +142,13 @@ public void AnalyzeNode(SyntaxNodeAnalysisContext context)
private bool AnalyzeForEachStatement(ForEachStatementSyntax forEachStatement) =>
!forEachStatement.Statement.IsKind(SyntaxKind.Block);
private bool AnalyzeWhileStatement(WhileStatementSyntax whileStatement) =>
!whileStatement.Statement.IsKind(SyntaxKind.Block);
private bool AnalyzeDoStatement(DoStatementSyntax doStatement) =>
!doStatement.Statement.IsKind(SyntaxKind.Block);
private bool AnalyzeUsingStatement(UsingStatementSyntax usingStatement) =>
!usingStatement.Statement.IsKind(SyntaxKind.Block) &&
!usingStatement.Statement.IsKind(SyntaxKind.UsingStatement);
......
......@@ -15,13 +15,7 @@ internal sealed class CSharpRemoveUnnecessaryCastDiagnosticAnalyzer : RemoveUnne
{
private static readonly ImmutableArray<SyntaxKind> s_kindsOfInterest = ImmutableArray.Create(SyntaxKind.CastExpression);
public override ImmutableArray<SyntaxKind> SyntaxKindsOfInterest
{
get
{
return s_kindsOfInterest;
}
}
public override ImmutableArray<SyntaxKind> SyntaxKindsOfInterest => s_kindsOfInterest;
protected override bool IsUnnecessaryCast(SemanticModel model, SyntaxNode node, CancellationToken cancellationToken)
{
......
......@@ -56,8 +56,8 @@ public CSharpTypeStyleDiagnosticAnalyzerBase(string diagnosticId, LocalizableStr
ImmutableArray.Create(_noneDiagnosticDescriptor, _infoDiagnosticDescriptor,
_warningDiagnosticDescriptor, _errorDiagnosticDescriptor);
public DiagnosticAnalyzerCategory GetAnalyzerCategory() =>
DiagnosticAnalyzerCategory.SemanticSpanAnalysis;
public DiagnosticAnalyzerCategory GetAnalyzerCategory() => DiagnosticAnalyzerCategory.SemanticSpanAnalysis;
public bool MustRunInProc => true;
public override void Initialize(AnalysisContext context)
{
......@@ -79,7 +79,7 @@ private void HandleVariableDeclaration(SyntaxNodeAnalysisContext context)
State state = null;
var shouldAnalyze = false;
var declarationStatement = context.Node;
var optionSet = GetOptionSet(context.Options);
var optionSet = context.Options.GetOptionSet();
var semanticModel = context.SemanticModel;
var cancellationToken = context.CancellationToken;
......@@ -141,16 +141,5 @@ private bool ShouldAnalyzeVariableDeclaration(VariableDeclarationSyntax variable
variableDeclaration.Variables.Count == 1 &&
variableDeclaration.Variables.Single().Initializer.IsKind(SyntaxKind.EqualsValueClause);
}
private OptionSet GetOptionSet(AnalyzerOptions analyzerOptions)
{
var workspaceOptions = analyzerOptions as WorkspaceAnalyzerOptions;
if (workspaceOptions != null)
{
return workspaceOptions.Workspace.Options;
}
return null;
}
}
}
......@@ -27,7 +27,8 @@ internal class InvokeDelegateWithConditionalAccessAnalyzer : DiagnosticAnalyzer,
isEnabledByDefault: true,
customTags: DiagnosticCustomTags.Unnecessary);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(s_descriptor);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(s_descriptor);
public bool MustRunInProc => false;
public override void Initialize(AnalysisContext context)
{
......
......@@ -22,7 +22,7 @@ internal abstract class NamingStyleDiagnosticAnalyzerBase : DiagnosticAnalyzer,
// Applicable SymbolKind list is limited due to https://github.com/dotnet/roslyn/issues/8753.
// We would prefer to respond to the names of all symbols.
private static readonly ImmutableArray<SymbolKind> _symbolKinds = new[]
private static readonly ImmutableArray<SymbolKind> _symbolKinds = new[]
{
SymbolKind.Event,
SymbolKind.Field,
......@@ -33,6 +33,7 @@ internal abstract class NamingStyleDiagnosticAnalyzerBase : DiagnosticAnalyzer,
}.ToImmutableArray();
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(s_descriptorNamingStyle);
public bool MustRunInProc => true;
public override void Initialize(AnalysisContext context)
{
......@@ -68,7 +69,7 @@ private void SymbolAction(SymbolAnalysisContext context, NamingStylePreferencesI
if (preferences.TryGetApplicableRule(context.Symbol, categorizationService, out applicableRule))
{
string failureReason;
if (applicableRule.EnforcementLevel != DiagnosticSeverity.Hidden &&
if (applicableRule.EnforcementLevel != DiagnosticSeverity.Hidden &&
!applicableRule.IsNameCompliant(context.Symbol.Name, out failureReason))
{
var descriptor = new DiagnosticDescriptor(IDEDiagnosticIds.NamingRuleId,
......
......@@ -43,6 +43,8 @@ internal abstract class QualifyMemberAccessDiagnosticAnalyzerBase<TLanguageKindE
s_descriptorQualifyMemberAccessWarning,
s_descriptorQualifyMemberAccessError);
public bool MustRunInProc => true;
protected abstract bool IsAlreadyQualifiedMemberAccess(SyntaxNode node);
public override void Initialize(AnalysisContext context)
......
......@@ -23,13 +23,8 @@ internal abstract class RemoveUnnecessaryCastDiagnosticAnalyzerBase<TLanguageKin
#region Interface methods
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
return ImmutableArray.Create(s_descriptor);
}
}
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(s_descriptor);
public bool MustRunInProc => false;
public override void Initialize(AnalysisContext context)
{
......
......@@ -11,7 +11,7 @@
namespace Microsoft.CodeAnalysis.Diagnostics.RemoveUnnecessaryImports
{
internal abstract class RemoveUnnecessaryImportsDiagnosticAnalyzerBase :
internal abstract class RemoveUnnecessaryImportsDiagnosticAnalyzerBase :
DiagnosticAnalyzer, IBuiltInAnalyzer
{
// NOTE: This is a trigger diagnostic, which doesn't show up in the ruleset editor and hence doesn't need a conventional IDE Diagnostic ID string.
......@@ -48,19 +48,8 @@ private DiagnosticDescriptor GetClassificationIdDescriptor()
return _classificationIdDescriptor;
}
private ImmutableArray<DiagnosticDescriptor> _descriptors;
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
if (_descriptors == null)
{
_descriptors = ImmutableArray.Create(s_fixableIdDescriptor, GetClassificationIdDescriptor());
}
return _descriptors;
}
}
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(s_fixableIdDescriptor, GetClassificationIdDescriptor());
public bool MustRunInProc => true;
public override void Initialize(AnalysisContext context)
{
......
......@@ -13,13 +13,8 @@ namespace Microsoft.CodeAnalysis.EditAndContinue
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
internal class RudeEditDiagnosticAnalyzer : DocumentDiagnosticAnalyzer, IBuiltInAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
return RudeEditDiagnosticDescriptors.AllDescriptors;
}
}
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => RudeEditDiagnosticDescriptors.AllDescriptors;
public bool MustRunInProc => true;
public override Task<ImmutableArray<Diagnostic>> AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
{
......
......@@ -77,6 +77,8 @@ public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
}
}
public bool MustRunInProc => true;
protected abstract void AnalyzeNode(SyntaxNodeAnalysisContext context);
protected abstract bool CanSimplifyTypeNameExpressionCore(SemanticModel model, SyntaxNode node, OptionSet optionSet, out TextSpan issueSpan, out string diagnosticId, CancellationToken cancellationToken);
......
......@@ -19,13 +19,8 @@ internal abstract class UnboundIdentifiersDiagnosticAnalyzerBase<TLanguageKindEn
protected abstract ImmutableArray<TLanguageKindEnum> SyntaxKindsOfInterest { get; }
protected abstract bool ConstructorDoesNotExist(SyntaxNode node, SymbolInfo info, SemanticModel semanticModel);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
return ImmutableArray.Create(DiagnosticDescriptor, DiagnosticDescriptor2);
}
}
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(DiagnosticDescriptor, DiagnosticDescriptor2);
public bool MustRunInProc => false;
public override void Initialize(AnalysisContext context)
{
......
......@@ -8,6 +8,20 @@ namespace Microsoft.CodeAnalysis.Diagnostics
/// </summary>
internal interface IBuiltInAnalyzer
{
/// <summary>
/// This category will be used to run analyzer more efficiently by restricting scope of analysis
/// </summary>
DiagnosticAnalyzerCategory GetAnalyzerCategory();
/// <summary>
/// This indicates whether this builtin analyzer must run in proc or can be run on remote host such as service hub.
///
/// if the diagnostic analyzer can run in command line as it is, then it should be able to run in remote host.
/// otherwise, it won't unless diagnostic analyzer author make changes in remote host to provide whatever missing
/// data command line build doesn't provide such as workspace options/services/MEF and etc.
///
/// at this moment, remote host provide same context as command line build and only that context
/// </summary>
bool MustRunInProc { get; }
}
}
......@@ -11,7 +11,7 @@
namespace Microsoft.CodeAnalysis.PopulateSwitch
{
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
internal class PopulateSwitchDiagnosticAnalyzer : DiagnosticAnalyzer, IBuiltInAnalyzer
internal sealed class PopulateSwitchDiagnosticAnalyzer : DiagnosticAnalyzer, IBuiltInAnalyzer
{
private static readonly LocalizableString s_localizableTitle = new LocalizableResourceString(nameof(FeaturesResources.Add_missing_cases), FeaturesResources.ResourceManager, typeof(FeaturesResources));
private static readonly LocalizableString s_localizableMessage = new LocalizableResourceString(nameof(WorkspacesResources.Populate_switch), WorkspacesResources.ResourceManager, typeof(WorkspacesResources));
......@@ -26,6 +26,7 @@ internal class PopulateSwitchDiagnosticAnalyzer : DiagnosticAnalyzer, IBuiltInAn
#region Interface methods
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(s_descriptor);
public bool MustRunInProc => false;
public override void Initialize(AnalysisContext context)
{
......
......@@ -169,7 +169,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.EditAndContinue
Assert.Equal(Of UInteger)(0, mockVsBuffer._oldFlags) ' Editable
' the given project does not contain this document
Dim newDocumentId = New DocumentId(New ProjectId(New Guid(), "TestProject"), New Guid(), "TestDoc")
Dim newDocumentId = DocumentId.CreateFromSerialized(ProjectId.CreateFromSerialized(Guid.NewGuid(), "TestProject"), Guid.NewGuid(), "TestDoc")
readOnlyDocumentTracker.SetReadOnly(newDocumentId, False) ' Check no NRE
End Function
......
......@@ -35,6 +35,7 @@ static Microsoft.CodeAnalysis.Simplification.SimplificationOptions.QualifyEventA
static Microsoft.CodeAnalysis.Simplification.SimplificationOptions.QualifyFieldAccess.get -> Microsoft.CodeAnalysis.Options.PerLanguageOption<bool>
static Microsoft.CodeAnalysis.Simplification.SimplificationOptions.QualifyMethodAccess.get -> Microsoft.CodeAnalysis.Options.PerLanguageOption<bool>
static Microsoft.CodeAnalysis.Simplification.SimplificationOptions.QualifyPropertyAccess.get -> Microsoft.CodeAnalysis.Options.PerLanguageOption<bool>
static Microsoft.CodeAnalysis.SolutionId.CreateFromSerialized(System.Guid id, string debugName = null) -> Microsoft.CodeAnalysis.SolutionId
static readonly Microsoft.CodeAnalysis.CodeStyle.CodeStyleOptions.QualifyEventAccess -> Microsoft.CodeAnalysis.Options.PerLanguageOption<Microsoft.CodeAnalysis.CodeStyle.CodeStyleOption<bool>>
static readonly Microsoft.CodeAnalysis.CodeStyle.CodeStyleOptions.QualifyFieldAccess -> Microsoft.CodeAnalysis.Options.PerLanguageOption<Microsoft.CodeAnalysis.CodeStyle.CodeStyleOption<bool>>
static readonly Microsoft.CodeAnalysis.CodeStyle.CodeStyleOptions.QualifyMethodAccess -> Microsoft.CodeAnalysis.Options.PerLanguageOption<Microsoft.CodeAnalysis.CodeStyle.CodeStyleOption<bool>>
......
......@@ -23,32 +23,15 @@ namespace Microsoft.CodeAnalysis
[DebuggerDisplay("{GetDebuggerDisplay(),nq}")]
public partial class Document : TextDocument
{
private readonly DocumentState _state;
private WeakReference<SemanticModel> _model;
private Task<SyntaxTree> _syntaxTreeResultTask;
internal Document(Project project, DocumentState state)
{
Contract.ThrowIfNull(project);
Contract.ThrowIfNull(state);
this.Project = project;
_state = state;
}
internal DocumentState State
internal Document(Project project, DocumentState state) :
base(project, state)
{
get
{
return _state;
}
}
internal override TextDocumentState GetDocumentState()
{
return _state;
}
private DocumentState DocumentState => (DocumentState)State;
/// <summary>
/// The kind of source code this document contains.
......@@ -57,7 +40,7 @@ public SourceCodeKind SourceCodeKind
{
get
{
return _state.SourceCodeKind;
return DocumentState.SourceCodeKind;
}
}
......@@ -74,7 +57,7 @@ public bool TryGetSyntaxTree(out SyntaxTree syntaxTree)
syntaxTree = _syntaxTreeResultTask.Result;
}
if (!_state.TryGetSyntaxTree(out syntaxTree))
if (!DocumentState.TryGetSyntaxTree(out syntaxTree))
{
return false;
}
......@@ -114,7 +97,7 @@ public bool TryGetSyntaxVersion(out VersionStamp version)
/// </summary>
internal bool TryGetTopLevelChangeTextVersion(out VersionStamp version)
{
return _state.TryGetTopLevelChangeTextVersion(out version);
return DocumentState.TryGetTopLevelChangeTextVersion(out version);
}
/// <summary>
......@@ -138,7 +121,7 @@ public bool SupportsSyntaxTree
{
get
{
return this.State.SupportsSyntaxTree;
return DocumentState.SupportsSyntaxTree;
}
}
......@@ -210,7 +193,7 @@ public Task<SyntaxTree> GetSyntaxTreeAsync(CancellationToken cancellationToken =
// we can't cache this result, since internally it uses AsyncLazy which
// care about cancellation token
return _state.GetSyntaxTreeAsync(cancellationToken);
return DocumentState.GetSyntaxTreeAsync(cancellationToken);
}
internal SyntaxTree GetSyntaxTreeSynchronously(CancellationToken cancellationToken)
......@@ -229,7 +212,7 @@ internal SyntaxTree GetSyntaxTreeSynchronously(CancellationToken cancellationTok
}
// Otherwise defer to our state to get this value.
return _state.GetSyntaxTree(cancellationToken);
return DocumentState.GetSyntaxTree(cancellationToken);
}
/// <summary>
......
......@@ -19,14 +19,7 @@ public sealed class DocumentId : IEquatable<DocumentId>
private readonly string _debugName;
private DocumentId(ProjectId projectId, string debugName)
{
this.ProjectId = projectId;
this.Id = Guid.NewGuid();
_debugName = debugName;
}
internal DocumentId(ProjectId projectId, Guid guid, string debugName)
private DocumentId(ProjectId projectId, Guid guid, string debugName)
{
this.ProjectId = projectId;
this.Id = guid;
......@@ -45,7 +38,7 @@ public static DocumentId CreateNewId(ProjectId projectId, string debugName = nul
throw new ArgumentNullException(nameof(projectId));
}
return new DocumentId(projectId, debugName);
return new DocumentId(projectId, Guid.NewGuid(), debugName);
}
public static DocumentId CreateFromSerialized(ProjectId projectId, Guid id, string debugName = null)
......@@ -63,13 +56,13 @@ public static DocumentId CreateFromSerialized(ProjectId projectId, Guid id, stri
return new DocumentId(projectId, id, debugName);
}
internal string DebugName => _debugName;
internal string GetDebuggerDisplay()
{
return string.Format("({0}, #{1} - {2})", this.GetType().Name, this.Id, _debugName);
}
internal string DebugName { get { return _debugName; } }
public override string ToString()
{
return GetDebuggerDisplay();
......
......@@ -19,13 +19,7 @@ public sealed class ProjectId : IEquatable<ProjectId>
/// </summary>
public Guid Id { get; }
private ProjectId(string debugName)
{
this.Id = Guid.NewGuid();
_debugName = debugName;
}
internal ProjectId(Guid guid, string debugName)
private ProjectId(Guid guid, string debugName)
{
this.Id = guid;
_debugName = debugName;
......@@ -37,7 +31,7 @@ internal ProjectId(Guid guid, string debugName)
/// <param name="debugName">An optional name to make this id easier to recognize while debugging.</param>
public static ProjectId CreateNewId(string debugName = null)
{
return new ProjectId(debugName);
return new ProjectId(Guid.NewGuid(), debugName);
}
public static ProjectId CreateFromSerialized(Guid id, string debugName = null)
......@@ -50,16 +44,13 @@ public static ProjectId CreateFromSerialized(Guid id, string debugName = null)
return new ProjectId(id, debugName);
}
internal string DebugName => _debugName;
private string GetDebuggerDisplay()
{
return string.Format("({0}, #{1} - {2})", this.GetType().Name, this.Id, _debugName);
}
internal string DebugName
{
get { return _debugName; }
}
public override string ToString()
{
return GetDebuggerDisplay();
......
......@@ -1305,7 +1305,7 @@ private Solution AddDocument(Document document)
CheckNotContainsDocument(document.Id);
CheckContainsProject(document.Id.ProjectId);
return this.AddDocument(document.State);
return this.AddDocument((DocumentState)document.State);
}
/// <summary>
......@@ -1953,7 +1953,7 @@ internal async Task<Solution> WithFrozenPartialCompilationIncludingSpecificDocum
|| _documentIdOfLatestSolutionWithPartialCompilation != documentId)
{
var tracker = this.GetCompilationTracker(documentId.ProjectId);
var newTracker = tracker.FreezePartialStateWithTree(this, doc.State, tree, cancellationToken);
var newTracker = tracker.FreezePartialStateWithTree(this, (DocumentState)doc.State, tree, cancellationToken);
var newIdToProjectStateMap = _projectIdToProjectStateMap.SetItem(documentId.ProjectId, newTracker.ProjectState);
var newIdToTrackerMap = _projectIdToTrackerMap.SetItem(documentId.ProjectId, newTracker);
......
......@@ -19,9 +19,9 @@ public sealed class SolutionId : IEquatable<SolutionId>
private readonly string _debugName;
private SolutionId(string debugName)
private SolutionId(Guid id, string debugName)
{
this.Id = Guid.NewGuid();
this.Id = id;
_debugName = debugName;
}
......@@ -31,11 +31,23 @@ private SolutionId(string debugName)
/// <param name="debugName">An optional name to make this id easier to recognize while debugging.</param>
public static SolutionId CreateNewId(string debugName = null)
{
return CreateFromSerialized(Guid.NewGuid(), debugName);
}
public static SolutionId CreateFromSerialized(Guid id, string debugName = null)
{
if (id == Guid.Empty)
{
throw new ArgumentException(nameof(id));
}
debugName = debugName ?? "unsaved";
return new SolutionId(debugName);
return new SolutionId(id, debugName);
}
internal string DebugName => _debugName;
private string GetDebuggerDisplay()
{
return string.Format("({0}, #{1} - {2})", GetType().Name, this.Id, _debugName);
......
......@@ -10,12 +10,7 @@ namespace Microsoft.CodeAnalysis
{
public class TextDocument
{
private readonly TextDocumentState _state;
internal virtual TextDocumentState GetDocumentState()
{
return _state;
}
internal readonly TextDocumentState State;
/// <summary>
/// The project this document belongs to.
......@@ -32,7 +27,7 @@ internal TextDocument(Project project, TextDocumentState state)
Contract.ThrowIfNull(state);
this.Project = project;
_state = state;
State = state;
}
/// <summary>
......@@ -41,7 +36,7 @@ internal TextDocument(Project project, TextDocumentState state)
/// </summary>
public DocumentId Id
{
get { return this.GetDocumentState().Id; }
get { return State.Id; }
}
/// <summary>
......@@ -49,7 +44,7 @@ public DocumentId Id
/// </summary>
public string FilePath
{
get { return this.GetDocumentState().FilePath; }
get { return State.FilePath; }
}
/// <summary>
......@@ -59,7 +54,7 @@ public string Name
{
get
{
return this.GetDocumentState().Name;
return State.Name;
}
}
......@@ -70,7 +65,7 @@ public IReadOnlyList<string> Folders
{
get
{
return this.GetDocumentState().Folders;
return State.Folders;
}
}
......@@ -79,7 +74,7 @@ public IReadOnlyList<string> Folders
/// </summary>
public bool TryGetText(out SourceText text)
{
return this.GetDocumentState().TryGetText(out text);
return State.TryGetText(out text);
}
/// <summary>
......@@ -87,7 +82,7 @@ public bool TryGetText(out SourceText text)
/// </summary>
public bool TryGetTextVersion(out VersionStamp version)
{
return this.GetDocumentState().TryGetTextVersion(out version);
return State.TryGetTextVersion(out version);
}
/// <summary>
......@@ -95,7 +90,7 @@ public bool TryGetTextVersion(out VersionStamp version)
/// </summary>
public Task<SourceText> GetTextAsync(CancellationToken cancellationToken = default(CancellationToken))
{
return this.GetDocumentState().GetTextAsync(cancellationToken);
return State.GetTextAsync(cancellationToken);
}
/// <summary>
......@@ -103,7 +98,7 @@ public Task<SourceText> GetTextAsync(CancellationToken cancellationToken = defau
/// </summary>
public Task<VersionStamp> GetTextVersionAsync(CancellationToken cancellationToken = default(CancellationToken))
{
return this.GetDocumentState().GetTextVersionAsync(cancellationToken);
return State.GetTextVersionAsync(cancellationToken);
}
/// <summary>
......@@ -111,7 +106,7 @@ public Task<VersionStamp> GetTextVersionAsync(CancellationToken cancellationToke
/// </summary>
internal Task<VersionStamp> GetTopLevelChangeTextVersionAsync(CancellationToken cancellationToken = default(CancellationToken))
{
return this.GetDocumentState().GetTopLevelChangeTextVersionAsync(cancellationToken);
return State.GetTopLevelChangeTextVersionAsync(cancellationToken);
}
}
}
......@@ -435,7 +435,7 @@ private ISet<DocumentId> GetProjectOpenDocuments_NoLock(ProjectId project)
// Note: we pass along the newText here so that clients can easily get the text
// of an opened document just by calling TryGetText without any blocking.
currentSolution = oldSolution.WithDocumentTextLoader(documentId,
new ReuseVersionLoader(oldDocument.State, newText), newText, PreservationMode.PreserveIdentity);
new ReuseVersionLoader((DocumentState)oldDocument.State, newText), newText, PreservationMode.PreserveIdentity);
}
var newSolution = this.SetCurrentSolution(currentSolution);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册