Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store and display the times when files were generated. #72724

Merged
merged 8 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/VisualStudio/Core/Def/ServicesVSResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1382,8 +1382,8 @@ Additional information: {1}</value>
<data name="Extract_Base_Class" xml:space="preserve">
<value>Extract Base Class</value>
</data>
<data name="This_file_is_autogenerated_by_0_and_cannot_be_edited" xml:space="preserve">
<value>This file is auto-generated by the generator '{0}' and cannot be edited.</value>
<data name="This_file_was_generated_by_0_at_1_and_cannot_be_edited" xml:space="preserve">
<value>This file was generated by '{0}' at {1} and cannot be edited.</value>
</data>
<data name="generated_by_0_suffix" xml:space="preserve">
<value>[generated by {0}]</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ public async ValueTask RefreshFileAsync(CancellationToken cancellationToken)
generatedDocument = await project.GetSourceGeneratedDocumentAsync(_documentIdentity.DocumentId, cancellationToken).ConfigureAwait(false);
if (generatedDocument != null)
{
windowFrameMessageToShow = string.Format(ServicesVSResources.This_file_is_autogenerated_by_0_and_cannot_be_edited, GeneratorDisplayName);
windowFrameMessageToShow = string.Format(
ServicesVSResources.This_file_was_generated_by_0_at_1_and_cannot_be_edited,
GeneratorDisplayName,
generatedDocument.GenerationDateTime.ToLocalTime());
windowFrameImageMonikerToShow = default;
generatedSource = await generatedDocument.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
}
Expand Down
6 changes: 3 additions & 3 deletions src/VisualStudio/Core/Def/xlf/ServicesVSResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/VisualStudio/Core/Def/xlf/ServicesVSResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/VisualStudio/Core/Def/xlf/ServicesVSResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/VisualStudio/Core/Def/xlf/ServicesVSResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/VisualStudio/Core/Def/xlf/ServicesVSResources.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/VisualStudio/Core/Def/xlf/ServicesVSResources.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/VisualStudio/Core/Def/xlf/ServicesVSResources.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/VisualStudio/Core/Def/xlf/ServicesVSResources.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/VisualStudio/Core/Def/xlf/ServicesVSResources.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/VisualStudio/Core/Def/xlf/ServicesVSResources.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/VisualStudio/Core/Def/xlf/ServicesVSResources.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public async Task TestFrozenSourceGeneratedDocument()
// Now freeze with some content
var documentIdentity = (await solution.Projects.Single().GetSourceGeneratedDocumentsAsync()).First().Identity;
var frozenText1 = SourceText.From("// Hello, World!");
var frozenSolution1 = solution.WithFrozenSourceGeneratedDocument(documentIdentity, frozenText1).Project.Solution;
var frozenSolution1 = solution.WithFrozenSourceGeneratedDocument(documentIdentity, DateTime.Now, frozenText1).Project.Solution;

assetProvider = await GetAssetProviderAsync(workspace, remoteWorkspace, frozenSolution1);
solutionChecksum = await frozenSolution1.CompilationState.GetChecksumAsync(CancellationToken.None);
Expand All @@ -457,7 +457,7 @@ public async Task TestFrozenSourceGeneratedDocument()

// Try freezing with some different content from the original solution
var frozenText2 = SourceText.From("// Hello, World! A second time!");
var frozenSolution2 = solution.WithFrozenSourceGeneratedDocument(documentIdentity, frozenText2).Project.Solution;
var frozenSolution2 = solution.WithFrozenSourceGeneratedDocument(documentIdentity, DateTime.Now, frozenText2).Project.Solution;

assetProvider = await GetAssetProviderAsync(workspace, remoteWorkspace, frozenSolution2);
solutionChecksum = await frozenSolution2.CompilationState.GetChecksumAsync(CancellationToken.None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Immutable;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Text;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.SourceGeneration;
Expand All @@ -28,7 +29,7 @@ internal interface IRemoteSourceGenerationService
/// Should only be called by the host for documents it does not know about, or documents whose checksum contents are
/// different than the last time the document was queried.
/// </summary>
ValueTask<ImmutableArray<string>> GetContentsAsync(
ValueTask<ImmutableArray<(string contents, DateTime generationDateTime)>> GetContentsAsync(
Checksum solutionChecksum, ProjectId projectId, ImmutableArray<DocumentId> documentIds, CancellationToken cancellationToken);
}

Expand Down
8 changes: 5 additions & 3 deletions src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1586,9 +1586,10 @@ public Solution WithDocumentText(IEnumerable<DocumentId?> documentIds, SourceTex
/// implementation of <see cref="TextExtensions.GetOpenDocumentInCurrentContextWithChanges"/> where if a user has a source
/// generated file open, we need to make sure everything lines up.
/// </summary>
internal Document WithFrozenSourceGeneratedDocument(SourceGeneratedDocumentIdentity documentIdentity, SourceText text)
internal Document WithFrozenSourceGeneratedDocument(
SourceGeneratedDocumentIdentity documentIdentity, DateTime generationDateTime, SourceText text)
{
var newCompilationState = _compilationState.WithFrozenSourceGeneratedDocuments([(documentIdentity, text)]);
var newCompilationState = _compilationState.WithFrozenSourceGeneratedDocuments([(documentIdentity, generationDateTime, text)]);
var newSolution = newCompilationState != _compilationState
? new Solution(newCompilationState)
: this;
Expand All @@ -1600,7 +1601,8 @@ internal Document WithFrozenSourceGeneratedDocument(SourceGeneratedDocumentIdent
return newProject.GetOrCreateSourceGeneratedDocument(newDocumentState);
}

internal Solution WithFrozenSourceGeneratedDocuments(ImmutableArray<(SourceGeneratedDocumentIdentity documentIdentity, SourceText text)> documents)
internal Solution WithFrozenSourceGeneratedDocuments(
ImmutableArray<(SourceGeneratedDocumentIdentity documentIdentity, DateTime generationDateTime, SourceText text)> documents)
{
var newCompilationState = _compilationState.WithFrozenSourceGeneratedDocuments(documents);
return newCompilationState != _compilationState
Expand Down
Loading
Loading