Skip to content

Commit 1c75d3c

Browse files
authored
Stop running cohosting tests with and without FUSE (#11592)
Now that the source generator is in use, we don't ever actually use non-FUSE in cohosting, so we were just running all our tests twice for no reason. This fixes that. ~There is more to do to follow up here for formatting tests, and removing the `FORMAT_FUSE` preprocessor directive, but that will affect shipping product code so I'll do it serparately.~ Did it.
2 parents 2798396 + b229967 commit 1c75d3c

File tree

57 files changed

+414
-711
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+414
-711
lines changed

Directory.Build.props

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@
4747
<ExcludeFromSourceOnlyBuild>true</ExcludeFromSourceOnlyBuild>
4848

4949
<DefaultNetFxTargetFramework>net472</DefaultNetFxTargetFramework>
50-
51-
<!-- Uncomment this line to run formatting on runtime code-gen if FUSE is turned on -->
52-
<!-- <DefineConstants>$(DefineConstants);FORMAT_FUSE</DefineConstants> -->
5350
</PropertyGroup>
5451

5552
<!--

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/InlineCompletion/InlineCompletionEndPoint.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(VSInternalInlineCompleti
113113
var formattingContext = FormattingContext.Create(
114114
documentContext.Snapshot,
115115
codeDocument,
116-
options);
116+
options,
117+
// I don't think this makes a difference for inline completions, but it's better to be safe.
118+
useNewFormattingEngine: false);
117119
if (!SnippetFormatter.TryGetSnippetWithAdjustedIndentation(formattingContext, item.Text, hostDocumentIndex, out var newSnippetText))
118120
{
119121
continue;

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingContext.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,34 @@
1313
using Microsoft.AspNetCore.Razor.Language.Syntax;
1414
using Microsoft.AspNetCore.Razor.ProjectSystem;
1515
using Microsoft.CodeAnalysis;
16+
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
1617
using Microsoft.CodeAnalysis.Text;
1718
using Microsoft.VisualStudio.LanguageServer.Protocol;
1819

19-
#if !FORMAT_FUSE
20-
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
21-
#endif
22-
2320
namespace Microsoft.CodeAnalysis.Razor.Formatting;
2421

2522
internal sealed class FormattingContext
2623
{
2724
private IReadOnlyList<FormattingSpan>? _formattingSpans;
2825
private IReadOnlyDictionary<int, IndentationContext>? _indentations;
26+
private readonly bool _useNewFormattingEngine;
2927

3028
private FormattingContext(
3129
IDocumentSnapshot originalSnapshot,
3230
RazorCodeDocument codeDocument,
3331
RazorFormattingOptions options,
3432
bool automaticallyAddUsings,
3533
int hostDocumentIndex,
36-
char triggerCharacter)
34+
char triggerCharacter,
35+
bool useNewFormattingEngine)
3736
{
3837
OriginalSnapshot = originalSnapshot;
3938
CodeDocument = codeDocument;
4039
Options = options;
4140
AutomaticallyAddUsings = automaticallyAddUsings;
4241
HostDocumentIndex = hostDocumentIndex;
4342
TriggerCharacter = triggerCharacter;
43+
_useNewFormattingEngine = useNewFormattingEngine;
4444
}
4545

4646
public static bool SkipValidateComponents { get; set; }
@@ -229,13 +229,9 @@ public async Task<FormattingContext> WithTextAsync(SourceText changedText, Cance
229229
{
230230
var changedSnapshot = OriginalSnapshot.WithText(changedText);
231231

232-
#if !FORMAT_FUSE
233-
// Formatting always uses design time document
234-
var generator = (IDesignTimeCodeGenerator)changedSnapshot;
235-
var codeDocument = await generator.GenerateDesignTimeOutputAsync(cancellationToken).ConfigureAwait(false);
236-
#else
237-
var codeDocument = await changedSnapshot.GetGeneratedOutputAsync(cancellationToken).ConfigureAwait(false);
238-
#endif
232+
var codeDocument = !_useNewFormattingEngine && changedSnapshot is IDesignTimeCodeGenerator generator
233+
? await generator.GenerateDesignTimeOutputAsync(cancellationToken).ConfigureAwait(false)
234+
: await changedSnapshot.GetGeneratedOutputAsync(cancellationToken).ConfigureAwait(false);
239235

240236
DEBUG_ValidateComponents(CodeDocument, codeDocument);
241237

@@ -245,7 +241,8 @@ public async Task<FormattingContext> WithTextAsync(SourceText changedText, Cance
245241
Options,
246242
AutomaticallyAddUsings,
247243
HostDocumentIndex,
248-
TriggerCharacter);
244+
TriggerCharacter,
245+
_useNewFormattingEngine);
249246

250247
return newContext;
251248
}
@@ -282,20 +279,23 @@ public static FormattingContext CreateForOnTypeFormatting(
282279
options,
283280
automaticallyAddUsings,
284281
hostDocumentIndex,
285-
triggerCharacter);
282+
triggerCharacter,
283+
useNewFormattingEngine: false);
286284
}
287285

288286
public static FormattingContext Create(
289287
IDocumentSnapshot originalSnapshot,
290288
RazorCodeDocument codeDocument,
291-
RazorFormattingOptions options)
289+
RazorFormattingOptions options,
290+
bool useNewFormattingEngine)
292291
{
293292
return new FormattingContext(
294293
originalSnapshot,
295294
codeDocument,
296295
options,
297296
automaticallyAddUsings: false,
298297
hostDocumentIndex: 0,
299-
triggerCharacter: '\0');
298+
triggerCharacter: '\0',
299+
useNewFormattingEngine: useNewFormattingEngine);
300300
}
301301
}

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/RazorFormattingService.cs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ internal class RazorFormattingService : IRazorFormattingService
3434
private readonly ImmutableArray<IFormattingPass> _validationPasses;
3535
private readonly CSharpOnTypeFormattingPass _csharpOnTypeFormattingPass;
3636
private readonly HtmlOnTypeFormattingPass _htmlOnTypeFormattingPass;
37+
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions;
3738

3839
public RazorFormattingService(
3940
IDocumentMappingService documentMappingService,
@@ -49,7 +50,8 @@ public RazorFormattingService(
4950
new FormattingContentValidationPass(loggerFactory)
5051
];
5152

52-
_documentFormattingPasses = languageServerFeatureOptions.UseNewFormattingEngine
53+
_languageServerFeatureOptions = languageServerFeatureOptions;
54+
_documentFormattingPasses = _languageServerFeatureOptions.UseNewFormattingEngine
5355
? [
5456
new New.HtmlFormattingPass(loggerFactory),
5557
new RazorFormattingPass(languageServerFeatureOptions, loggerFactory),
@@ -71,13 +73,9 @@ public async Task<ImmutableArray<TextChange>> GetDocumentFormattingChangesAsync(
7173
RazorFormattingOptions options,
7274
CancellationToken cancellationToken)
7375
{
74-
#if !FORMAT_FUSE
75-
// Formatting always uses design time document
76-
var generator = (IDesignTimeCodeGenerator)documentContext.Snapshot;
77-
var codeDocument = await generator.GenerateDesignTimeOutputAsync(cancellationToken).ConfigureAwait(false);
78-
#else
79-
var codeDocument = await documentContext.Snapshot.GetGeneratedOutputAsync(cancellationToken).ConfigureAwait(false);
80-
#endif
76+
var codeDocument = !_languageServerFeatureOptions.UseNewFormattingEngine && documentContext.Snapshot is IDesignTimeCodeGenerator generator
77+
? await generator.GenerateDesignTimeOutputAsync(cancellationToken).ConfigureAwait(false)
78+
: await documentContext.Snapshot.GetGeneratedOutputAsync(cancellationToken).ConfigureAwait(false);
8179

8280
// Range formatting happens on every paste, and if there are Razor diagnostics in the file
8381
// that can make some very bad results. eg, given:
@@ -108,7 +106,8 @@ public async Task<ImmutableArray<TextChange>> GetDocumentFormattingChangesAsync(
108106
var context = FormattingContext.Create(
109107
documentSnapshot,
110108
codeDocument,
111-
options);
109+
options,
110+
_languageServerFeatureOptions.UseNewFormattingEngine);
112111
var originalText = context.SourceText;
113112

114113
var result = htmlChanges;
@@ -130,13 +129,9 @@ public async Task<ImmutableArray<TextChange>> GetCSharpOnTypeFormattingChangesAs
130129
{
131130
var documentSnapshot = documentContext.Snapshot;
132131

133-
#if !FORMAT_FUSE
134-
// Formatting always uses design time document
135-
var generator = (IDesignTimeCodeGenerator)documentSnapshot;
136-
var codeDocument = await generator.GenerateDesignTimeOutputAsync(cancellationToken).ConfigureAwait(false);
137-
#else
138-
var codeDocument = await documentSnapshot.GetGeneratedOutputAsync(cancellationToken).ConfigureAwait(false);
139-
#endif
132+
var codeDocument = documentContext.Snapshot is IDesignTimeCodeGenerator generator
133+
? await generator.GenerateDesignTimeOutputAsync(cancellationToken).ConfigureAwait(false)
134+
: await documentContext.Snapshot.GetGeneratedOutputAsync(cancellationToken).ConfigureAwait(false);
140135

141136
return await ApplyFormattedChangesAsync(
142137
documentSnapshot,
@@ -155,13 +150,8 @@ public async Task<ImmutableArray<TextChange>> GetHtmlOnTypeFormattingChangesAsyn
155150
{
156151
var documentSnapshot = documentContext.Snapshot;
157152

158-
#if !FORMAT_FUSE
159-
// Formatting always uses design time document
160-
var generator = (IDesignTimeCodeGenerator)documentSnapshot;
161-
var codeDocument = await generator.GenerateDesignTimeOutputAsync(cancellationToken).ConfigureAwait(false);
162-
#else
163-
var codeDocument = await documentSnapshot.GetGeneratedOutputAsync(cancellationToken).ConfigureAwait(false);
164-
#endif
153+
// Html formatting doesn't use the C# design time document
154+
var codeDocument = await documentContext.Snapshot.GetGeneratedOutputAsync(cancellationToken).ConfigureAwait(false);
165155

166156
return await ApplyFormattedChangesAsync(
167157
documentSnapshot,

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DocumentSnapshot.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111

1212
namespace Microsoft.CodeAnalysis.Razor.ProjectSystem;
1313

14-
internal sealed class DocumentSnapshot(ProjectSnapshot project, DocumentState state) : IDocumentSnapshot, ILegacyDocumentSnapshot
15-
#if !FORMAT_FUSE
16-
, IDesignTimeCodeGenerator
17-
#endif
14+
internal sealed class DocumentSnapshot(ProjectSnapshot project, DocumentState state) : IDocumentSnapshot, ILegacyDocumentSnapshot, IDesignTimeCodeGenerator
1815
{
1916
public ProjectSnapshot Project { get; } = project;
2017

@@ -65,10 +62,8 @@ async Task<SyntaxTree> GetCSharpSyntaxTreeCoreAsync(CancellationToken cancellati
6562
}
6663
}
6764

68-
#if !FORMAT_FUSE
6965
public Task<RazorCodeDocument> GenerateDesignTimeOutputAsync(CancellationToken cancellationToken)
7066
=> CompilationHelpers.GenerateDesignTimeCodeDocumentAsync(this, Project.ProjectEngine, cancellationToken);
71-
#endif
7267

7368
#region ILegacyDocumentSnapshot support
7469

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IDesignTimeCodeGenerator.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT license. See License.txt in the project root for license information.
33

4-
#if !FORMAT_FUSE
54
using System.Threading;
65
using System.Threading.Tasks;
76
using Microsoft.AspNetCore.Razor.Language;
@@ -12,4 +11,3 @@ internal interface IDesignTimeCodeGenerator
1211
{
1312
Task<RazorCodeDocument> GenerateDesignTimeOutputAsync(CancellationToken cancellationToken);
1413
}
15-
#endif

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Remote/RemoteClientInitializationOptions.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,18 @@ internal struct RemoteClientInitializationOptions
1616
[JsonPropertyName("htmlVirtualDocumentSuffix")]
1717
public required string HtmlVirtualDocumentSuffix { get; set; }
1818

19-
[JsonPropertyName("includeProjectKeyInGeneratedFilePath")]
20-
public required bool IncludeProjectKeyInGeneratedFilePath { get; set; }
21-
2219
[JsonPropertyName("returnCodeActionAndRenamePathsWithPrefixedSlash")]
2320
public required bool ReturnCodeActionAndRenamePathsWithPrefixedSlash { get; set; }
2421

25-
[JsonPropertyName("forceRuntimeCodeGeneration")]
26-
public required bool ForceRuntimeCodeGeneration { get; set; }
27-
2822
[JsonPropertyName("supportsFileManipulation")]
2923
public required bool SupportsFileManipulation { get; set; }
3024

3125
[JsonPropertyName("showAllCSharpCodeActions")]
3226
public required bool ShowAllCSharpCodeActions { get; set; }
3327

34-
[JsonPropertyName("useNewFormattingEngine")]
35-
public required bool UseNewFormattingEngine { get; set; }
36-
3728
[JsonPropertyName("supportsSoftSelectionInCompletion")]
3829
public required bool SupportsSoftSelectionInCompletion { get; set; }
3930

4031
[JsonPropertyName("useVSCodeCompletionTriggerCharacters")]
41-
public bool UseVsCodeCompletionTriggerCharacters { get; set; }
32+
public required bool UseVsCodeCompletionTriggerCharacters { get; set; }
4233
}

src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Initialization/RemoteLanguageServerFeatureOptions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ public void SetOptions(RemoteClientInitializationOptions options)
4242

4343
public override bool ReturnCodeActionAndRenamePathsWithPrefixedSlash => _options.ReturnCodeActionAndRenamePathsWithPrefixedSlash;
4444

45-
public override bool IncludeProjectKeyInGeneratedFilePath => _options.IncludeProjectKeyInGeneratedFilePath;
45+
public override bool IncludeProjectKeyInGeneratedFilePath => throw new InvalidOperationException("This option does not apply in cohosting.");
4646

4747
public override bool UseRazorCohostServer => _options.UseRazorCohostServer;
4848

49-
public override bool ForceRuntimeCodeGeneration => _options.ForceRuntimeCodeGeneration;
49+
public override bool ForceRuntimeCodeGeneration => true;
5050

51-
public override bool UseNewFormattingEngine => _options.UseNewFormattingEngine;
51+
public override bool UseNewFormattingEngine => true;
5252

5353
public override bool SupportsSoftSelectionInCompletion => _options.SupportsSoftSelectionInCompletion;
5454

src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/InlineCompletion/RemoteInlineCompletionService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected override IRemoteInlineCompletionService CreateService(in ServiceArgs a
7070

7171
var hostDocumentIndex = codeDocument.Source.Text.GetRequiredAbsoluteIndex(razorRange.End);
7272

73-
var formattingContext = FormattingContext.Create(context.Snapshot, codeDocument, options);
73+
var formattingContext = FormattingContext.Create(context.Snapshot, codeDocument, options, useNewFormattingEngine: false);
7474
if (!SnippetFormatter.TryGetSnippetWithAdjustedIndentation(formattingContext, text, hostDocumentIndex, out var newSnippetText))
7575
{
7676
return null;

src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteDocumentSnapshot.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88
using Microsoft.AspNetCore.Razor;
99
using Microsoft.AspNetCore.Razor.Language;
1010
using Microsoft.AspNetCore.Razor.ProjectSystem;
11-
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
1211
using Microsoft.CodeAnalysis.Text;
1312

1413
namespace Microsoft.CodeAnalysis.Remote.Razor.ProjectSystem;
1514

1615
internal sealed class RemoteDocumentSnapshot : IDocumentSnapshot
17-
#if !FORMAT_FUSE
18-
, IDesignTimeCodeGenerator
19-
#endif
2016
{
2117
public TextDocument TextDocument { get; }
2218
public RemoteProjectSnapshot ProjectSnapshot { get; }
@@ -80,17 +76,6 @@ public async ValueTask<RazorCodeDocument> GetGeneratedOutputAsync(CancellationTo
8076
return InterlockedOperations.Initialize(ref _codeDocument, document);
8177
}
8278

83-
#if !FORMAT_FUSE
84-
public async Task<RazorCodeDocument> GenerateDesignTimeOutputAsync(CancellationToken cancellationToken)
85-
{
86-
var projectEngine = await ProjectSnapshot.GetProjectEngineAsync(cancellationToken).ConfigureAwait(false);
87-
88-
return await CompilationHelpers
89-
.GenerateDesignTimeCodeDocumentAsync(this, projectEngine, cancellationToken)
90-
.ConfigureAwait(false);
91-
}
92-
#endif
93-
9479
public IDocumentSnapshot WithText(SourceText text)
9580
{
9681
var id = TextDocument.Id;

0 commit comments

Comments
 (0)