private static async Task <VersionStamp> ComputeLatestDocumentVersionAsync(TextDocumentStates <DocumentState> documentStates, TextDocumentStates <TextDocumentState> additionalDocumentStates, CancellationToken cancellationToken) { // this may produce a version that is out of sync with the actual Document versions. var latestVersion = VersionStamp.Default; foreach (var state in documentStates.States) { cancellationToken.ThrowIfCancellationRequested(); if (!state.IsGenerated) { var version = await state.GetTextVersionAsync(cancellationToken).ConfigureAwait(false); latestVersion = version.GetNewerVersion(latestVersion); } } foreach (var state in additionalDocumentStates.States) { cancellationToken.ThrowIfCancellationRequested(); var version = await state.GetTextVersionAsync(cancellationToken).ConfigureAwait(false); latestVersion = version.GetNewerVersion(latestVersion); } return(latestVersion); }
private ProjectState( ProjectInfo projectInfo, HostLanguageServices languageServices, SolutionServices solutionServices, TextDocumentStates <DocumentState> documentStates, TextDocumentStates <TextDocumentState> additionalDocumentStates, TextDocumentStates <AnalyzerConfigDocumentState> analyzerConfigDocumentStates, AsyncLazy <VersionStamp> lazyLatestDocumentVersion, AsyncLazy <VersionStamp> lazyLatestDocumentTopLevelChangeVersion, ValueSource <CachingAnalyzerConfigSet> lazyAnalyzerConfigSet) { _solutionServices = solutionServices; _languageServices = languageServices; DocumentStates = documentStates; AdditionalDocumentStates = additionalDocumentStates; AnalyzerConfigDocumentStates = analyzerConfigDocumentStates; _lazyLatestDocumentVersion = lazyLatestDocumentVersion; _lazyLatestDocumentTopLevelChangeVersion = lazyLatestDocumentTopLevelChangeVersion; _lazyAnalyzerConfigSet = lazyAnalyzerConfigSet; // ownership of information on document has moved to project state. clear out documentInfo the state is // holding on. otherwise, these information will be held onto unnecessarily by projectInfo even after // the info has changed by DocumentState. _projectInfo = ClearAllDocumentsFromProjectInfo(projectInfo); _lazyChecksums = new AsyncLazy <ProjectStateChecksums>(ComputeChecksumsAsync, cacheResult: true); }
private AsyncLazy <VersionStamp> CreateLazyLatestDocumentTopLevelChangeVersion( TextDocumentState newDocument, TextDocumentStates <DocumentState> newDocumentStates, TextDocumentStates <TextDocumentState> newAdditionalDocumentStates ) { if (_lazyLatestDocumentTopLevelChangeVersion.TryGetValue(out var oldVersion)) { return(new AsyncLazy <VersionStamp>( c => ComputeTopLevelChangeTextVersionAsync(oldVersion, newDocument, c), cacheResult: true )); } else { return(new AsyncLazy <VersionStamp>( c => ComputeLatestDocumentTopLevelChangeVersionAsync( newDocumentStates, newAdditionalDocumentStates, c ), cacheResult: true )); } }
public static State Create( Compilation compilation, TextDocumentStates <SourceGeneratedDocumentState> generatedDocuments, ImmutableArray < ValueTuple <ProjectState, CompilationAndGeneratorDriverTranslationAction> > intermediateProjects ) { Contract.ThrowIfTrue(intermediateProjects.IsDefault); // If we don't have any intermediate projects to process, just initialize our // DeclarationState now. We'll pass false for generatedDocumentsAreFinal because this is being called // if our referenced projects are changing, so we'll have to rerun to consume changes. return(intermediateProjects.Length == 0 ? new FullDeclarationState( compilation, generatedDocuments, generatedDocumentsAreFinal: false ) : (State) new InProgressState( compilation, generatedDocuments, intermediateProjects )); }
public CompilationTrackerGeneratorInfo( TextDocumentStates <SourceGeneratedDocumentState> documents, GeneratorDriver?driver, bool documentsAreFinal) { Documents = documents; Driver = driver; DocumentsAreFinal = documentsAreFinal; }
public CompilationTrackerGeneratorInfo( TextDocumentStates <SourceGeneratedDocumentState> documents, GeneratorDriver?driver, bool documentsAreFinal, bool documentsAreFinalAndFrozen = false) { Documents = documents; Driver = driver; DocumentsAreFinal = documentsAreFinal; DocumentsAreFinalAndFrozen = documentsAreFinalAndFrozen; // If we're frozen, that implies final as well Contract.ThrowIfTrue(documentsAreFinalAndFrozen && !documentsAreFinal); }
protected State( ValueSource <Optional <Compilation> >?compilationWithoutGeneratedDocuments, Compilation?declarationOnlyCompilation, TextDocumentStates <SourceGeneratedDocumentState> generatedDocuments, bool generatedDocumentsAreFinal) { // Declaration-only compilations should never have any references Contract.ThrowIfTrue(declarationOnlyCompilation != null && declarationOnlyCompilation.ExternalReferences.Any()); CompilationWithoutGeneratedDocuments = compilationWithoutGeneratedDocuments; DeclarationOnlyCompilation = declarationOnlyCompilation; GeneratedDocuments = generatedDocuments; GeneratedDocumentsAreFinal = generatedDocumentsAreFinal; }
public ProjectState(ProjectInfo projectInfo, HostLanguageServices languageServices, SolutionServices solutionServices) { Contract.ThrowIfNull(projectInfo); Contract.ThrowIfNull(languageServices); Contract.ThrowIfNull(solutionServices); _languageServices = languageServices; _solutionServices = solutionServices; var projectInfoFixed = FixProjectInfo(projectInfo); // We need to compute our AnalyerConfigDocumentStates first, since we use those to produce our DocumentStates AnalyzerConfigDocumentStates = new TextDocumentStates <AnalyzerConfigDocumentState>(projectInfoFixed.AnalyzerConfigDocuments, info => new AnalyzerConfigDocumentState(info, solutionServices)); _lazyAnalyzerConfigSet = ComputeAnalyzerConfigSetValueSource(AnalyzerConfigDocumentStates); // Add analyzer config information to the compilation options if (projectInfoFixed.CompilationOptions != null) { projectInfoFixed = projectInfoFixed.WithCompilationOptions( projectInfoFixed.CompilationOptions.WithSyntaxTreeOptionsProvider( new WorkspaceSyntaxTreeOptionsProvider(_lazyAnalyzerConfigSet))); } var parseOptions = projectInfoFixed.ParseOptions; DocumentStates = new TextDocumentStates <DocumentState>(projectInfoFixed.Documents, info => CreateDocument(info, parseOptions)); AdditionalDocumentStates = new TextDocumentStates <TextDocumentState>(projectInfoFixed.AdditionalDocuments, info => new TextDocumentState(info, solutionServices)); _lazyLatestDocumentVersion = new AsyncLazy <VersionStamp>(c => ComputeLatestDocumentVersionAsync(DocumentStates, AdditionalDocumentStates, c), cacheResult: true); _lazyLatestDocumentTopLevelChangeVersion = new AsyncLazy <VersionStamp>(c => ComputeLatestDocumentTopLevelChangeVersionAsync(DocumentStates, AdditionalDocumentStates, c), cacheResult: true); // ownership of information on document has moved to project state. clear out documentInfo the state is // holding on. otherwise, these information will be held onto unnecessarily by projectInfo even after // the info has changed by DocumentState. // we hold onto the info so that we don't need to duplicate all information info already has in the state _projectInfo = ClearAllDocumentsFromProjectInfo(projectInfoFixed); _lazyChecksums = new AsyncLazy <ProjectStateChecksums>(ComputeChecksumsAsync, cacheResult: true); }
public InProgressState( Compilation inProgressCompilation, TextDocumentStates <SourceGeneratedDocumentState> generatedDocuments, Compilation?compilationWithGeneratedDocuments, ImmutableArray <(ProjectState state, CompilationAndGeneratorDriverTranslationAction action)> intermediateProjects)