Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit 3e0ea5b

Browse files
committed
Don't save changed parse options
The formatter wasn't undoing the change to add the DOTNET_FORMATTER symbol to the parse options. The Workspace code tried to persist this to the project file and failed. Remove it after formatting the files so it isn't attempted to be persisted. closes #73
1 parent 3fd4df0 commit 3e0ea5b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Microsoft.DotNet.CodeFormatting/FormattingEngineImplementation.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private async Task FormatAsync(Workspace workspace, IReadOnlyList<DocumentId> do
102102
FormatLogger.WriteLine("Total time {0}", watch.Elapsed);
103103
}
104104

105-
internal Solution AddTablePreprocessorSymbol(Solution solution)
105+
private Solution AddTablePreprocessorSymbol(Solution solution)
106106
{
107107
var projectIds = solution.ProjectIds;
108108
foreach (var projectId in projectIds)
@@ -122,13 +122,32 @@ internal Solution AddTablePreprocessorSymbol(Solution solution)
122122
return solution;
123123
}
124124

125+
/// <summary>
126+
/// Remove the added table preprocessor symbol. Don't want that saved into the project
127+
/// file as a change.
128+
/// </summary>
129+
private Solution RemoveTablePreprocessorSymbol(Solution newSolution, Solution oldSolution)
130+
{
131+
var solution = newSolution;
132+
var projectIds = solution.ProjectIds;
133+
foreach (var projectId in projectIds)
134+
{
135+
var oldProject = oldSolution.GetProject(projectId);
136+
var newProject = newSolution.GetProject(projectId);
137+
solution = newProject.WithParseOptions(oldProject.ParseOptions).Solution;
138+
}
139+
140+
return solution;
141+
}
142+
125143
internal async Task<Solution> FormatCoreAsync(Solution originalSolution, IReadOnlyList<DocumentId> documentIds, CancellationToken cancellationToken)
126144
{
127145
var solution = originalSolution;
128146
solution = AddTablePreprocessorSymbol(originalSolution);
129147
solution = await RunSyntaxPass(solution, documentIds, cancellationToken);
130148
solution = await RunLocalSemanticPass(solution, documentIds, cancellationToken);
131149
solution = await RunGlobalSemanticPass(solution, documentIds, cancellationToken);
150+
solution = RemoveTablePreprocessorSymbol(solution, originalSolution);
132151
return solution;
133152
}
134153

0 commit comments

Comments
 (0)