@@ -19,6 +19,13 @@ namespace Microsoft.VisualStudio.Extensibility.Testing;
19
19
[ TestService ]
20
20
internal partial class RazorProjectSystemInProcess
21
21
{
22
+ public async Task < bool > IsCohostingActiveAsync ( CancellationToken cancellationToken )
23
+ {
24
+ var options = await TestServices . Shell . GetComponentModelServiceAsync < LanguageServerFeatureOptions > ( cancellationToken ) ;
25
+ Assert . NotNull ( options ) ;
26
+ return options . UseRazorCohostServer ;
27
+ }
28
+
22
29
public async Task WaitForLSPServerActivatedAsync ( CancellationToken cancellationToken )
23
30
{
24
31
await WaitForLSPServerActivationStatusAsync ( active : true , cancellationToken ) ;
@@ -31,6 +38,11 @@ public async Task WaitForLSPServerDeactivatedAsync(CancellationToken cancellatio
31
38
32
39
private async Task WaitForLSPServerActivationStatusAsync ( bool active , CancellationToken cancellationToken )
33
40
{
41
+ if ( await IsCohostingActiveAsync ( cancellationToken ) )
42
+ {
43
+ return ;
44
+ }
45
+
34
46
var tracker = await TestServices . Shell . GetComponentModelServiceAsync < ILspServerActivationTracker > ( cancellationToken ) ;
35
47
await Helper . RetryAsync ( ct =>
36
48
{
@@ -40,6 +52,11 @@ await Helper.RetryAsync(ct =>
40
52
41
53
public async Task WaitForProjectFileAsync ( string projectFilePath , CancellationToken cancellationToken )
42
54
{
55
+ if ( await IsCohostingActiveAsync ( cancellationToken ) )
56
+ {
57
+ return ;
58
+ }
59
+
43
60
var projectManager = await TestServices . Shell . GetComponentModelServiceAsync < ProjectSnapshotManager > ( cancellationToken ) ;
44
61
Assert . NotNull ( projectManager ) ;
45
62
await Helper . RetryAsync ( ct =>
@@ -54,6 +71,11 @@ await Helper.RetryAsync(ct =>
54
71
55
72
public async Task WaitForComponentTagNameAsync ( string projectName , string componentName , CancellationToken cancellationToken )
56
73
{
74
+ if ( await IsCohostingActiveAsync ( cancellationToken ) )
75
+ {
76
+ return ;
77
+ }
78
+
57
79
var projectFilePath = await TestServices . SolutionExplorer . GetProjectFileNameAsync ( projectName , cancellationToken ) ;
58
80
var projectManager = await TestServices . Shell . GetComponentModelServiceAsync < ProjectSnapshotManager > ( cancellationToken ) ;
59
81
Assert . NotNull ( projectManager ) ;
@@ -73,6 +95,11 @@ await Helper.RetryAsync(async ct =>
73
95
74
96
public async Task WaitForRazorFileInProjectAsync ( string projectFilePath , string filePath , CancellationToken cancellationToken )
75
97
{
98
+ if ( await IsCohostingActiveAsync ( cancellationToken ) )
99
+ {
100
+ return ;
101
+ }
102
+
76
103
var projectManager = await TestServices . Shell . GetComponentModelServiceAsync < ProjectSnapshotManager > ( cancellationToken ) ;
77
104
Assert . NotNull ( projectManager ) ;
78
105
@@ -88,6 +115,11 @@ await Helper.RetryAsync(ct =>
88
115
89
116
public async Task < ImmutableArray < string > > GetProjectKeyIdsForProjectAsync ( string projectFilePath , CancellationToken cancellationToken )
90
117
{
118
+ if ( await IsCohostingActiveAsync ( cancellationToken ) )
119
+ {
120
+ throw new InvalidOperationException ( "This method makes no sense in cohosting, as there are no project keys." ) ;
121
+ }
122
+
91
123
var projectManager = await TestServices . Shell . GetComponentModelServiceAsync < ProjectSnapshotManager > ( cancellationToken ) ;
92
124
Assert . NotNull ( projectManager ) ;
93
125
@@ -96,6 +128,11 @@ public async Task<ImmutableArray<string>> GetProjectKeyIdsForProjectAsync(string
96
128
97
129
public async Task WaitForCSharpVirtualDocumentAsync ( string razorFilePath , CancellationToken cancellationToken )
98
130
{
131
+ if ( await IsCohostingActiveAsync ( cancellationToken ) )
132
+ {
133
+ return ;
134
+ }
135
+
99
136
var documentManager = await TestServices . Shell . GetComponentModelServiceAsync < LSPDocumentManager > ( cancellationToken ) ;
100
137
101
138
var uri = new Uri ( razorFilePath , UriKind . Absolute ) ;
@@ -118,6 +155,11 @@ await Helper.RetryAsync(ct =>
118
155
119
156
public async Task WaitForCSharpVirtualDocumentUpdateAsync ( string projectName , string relativeFilePath , Func < Task > updater , CancellationToken cancellationToken )
120
157
{
158
+ if ( await IsCohostingActiveAsync ( cancellationToken ) )
159
+ {
160
+ return ;
161
+ }
162
+
121
163
var filePath = await TestServices . SolutionExplorer . GetAbsolutePathForProjectRelativeFilePathAsync ( projectName , relativeFilePath , cancellationToken ) ;
122
164
123
165
var documentManager = await TestServices . Shell . GetComponentModelServiceAsync < LSPDocumentManager > ( cancellationToken ) ;
0 commit comments