@@ -42,9 +42,9 @@ public void Dispose()
42
42
[ Fact ]
43
43
public async Task LanguageServiceCompletesCommandInFile ( )
44
44
{
45
- CompletionResults completionResults =
45
+ CompletionResults completionResults = await RunWithTimeout ( async ( ) =>
46
46
await this . GetCompletionResults (
47
- CompleteCommandInFile . SourceDetails ) . RunWithTimeout ( ) ;
47
+ CompleteCommandInFile . SourceDetails ) ) ;
48
48
49
49
Assert . NotEqual ( 0 , completionResults . Completions . Length ) ;
50
50
Assert . Equal (
@@ -56,8 +56,8 @@ await this.GetCompletionResults(
56
56
public async Task LanguageServiceCompletesCommandFromModule ( )
57
57
{
58
58
CompletionResults completionResults =
59
- await this . GetCompletionResults (
60
- CompleteCommandFromModule . SourceDetails ) . RunWithTimeout ( ) ;
59
+ await RunWithTimeout ( async ( ) => await this . GetCompletionResults (
60
+ CompleteCommandFromModule . SourceDetails ) ) ;
61
61
62
62
Assert . NotEqual ( 0 , completionResults . Completions . Length ) ;
63
63
Assert . Equal (
@@ -69,8 +69,8 @@ await this.GetCompletionResults(
69
69
public async Task LanguageServiceCompletesVariableInFile ( )
70
70
{
71
71
CompletionResults completionResults =
72
- await this . GetCompletionResults (
73
- CompleteVariableInFile . SourceDetails ) . RunWithTimeout ( ) ;
72
+ await RunWithTimeout ( async ( ) => await this . GetCompletionResults (
73
+ CompleteVariableInFile . SourceDetails ) ) ;
74
74
75
75
Assert . Equal ( 1 , completionResults . Completions . Length ) ;
76
76
Assert . Equal (
@@ -82,8 +82,8 @@ await this.GetCompletionResults(
82
82
public async Task LanguageServiceCompletesAttributeValue ( )
83
83
{
84
84
CompletionResults completionResults =
85
- await this . GetCompletionResults (
86
- CompleteAttributeValue . SourceDetails ) . RunWithTimeout ( ) ;
85
+ await RunWithTimeout ( async ( ) => await this . GetCompletionResults (
86
+ CompleteAttributeValue . SourceDetails ) ) ;
87
87
88
88
Assert . NotEqual ( 0 , completionResults . Completions . Length ) ;
89
89
Assert . Equal (
@@ -95,8 +95,8 @@ await this.GetCompletionResults(
95
95
public async Task LanguageServiceCompletesFilePath ( )
96
96
{
97
97
CompletionResults completionResults =
98
- await this . GetCompletionResults (
99
- CompleteFilePath . SourceDetails ) . RunWithTimeout ( ) ;
98
+ await RunWithTimeout ( async ( ) => await this . GetCompletionResults (
99
+ CompleteFilePath . SourceDetails ) ) ;
100
100
101
101
Assert . NotEqual ( 0 , completionResults . Completions . Length ) ;
102
102
Assert . Equal (
@@ -108,8 +108,8 @@ await this.GetCompletionResults(
108
108
public async Task LanguageServiceFindsParameterHintsOnCommand ( )
109
109
{
110
110
ParameterSetSignatures paramSignatures =
111
- await this . GetParamSetSignatures (
112
- FindsParameterSetsOnCommand . SourceDetails ) . RunWithTimeout ( ) ;
111
+ await RunWithTimeout ( async ( ) => await this . GetParamSetSignatures (
112
+ FindsParameterSetsOnCommand . SourceDetails ) ) ;
113
113
114
114
Assert . NotNull ( paramSignatures ) ;
115
115
Assert . Equal ( "Get-Process" , paramSignatures . CommandName ) ;
@@ -120,8 +120,8 @@ await this.GetParamSetSignatures(
120
120
public async Task LanguageServiceFindsCommandForParamHintsWithSpaces ( )
121
121
{
122
122
ParameterSetSignatures paramSignatures =
123
- await this . GetParamSetSignatures (
124
- FindsParameterSetsOnCommandWithSpaces . SourceDetails ) . RunWithTimeout ( ) ;
123
+ await RunWithTimeout ( async ( ) => await this . GetParamSetSignatures (
124
+ FindsParameterSetsOnCommandWithSpaces . SourceDetails ) ) ;
125
125
126
126
Assert . NotNull ( paramSignatures ) ;
127
127
Assert . Equal ( "Write-Host" , paramSignatures . CommandName ) ;
@@ -132,8 +132,8 @@ await this.GetParamSetSignatures(
132
132
public async Task LanguageServiceFindsFunctionDefinition ( )
133
133
{
134
134
GetDefinitionResult definitionResult =
135
- await this . GetDefinition (
136
- FindsFunctionDefinition . SourceDetails ) . RunWithTimeout ( ) ;
135
+ await RunWithTimeout ( async ( ) => await this . GetDefinition (
136
+ FindsFunctionDefinition . SourceDetails ) ) ;
137
137
138
138
SymbolReference definition = definitionResult . FoundDefinition ;
139
139
Assert . Equal ( 1 , definition . ScriptRegion . StartLineNumber ) ;
@@ -145,8 +145,8 @@ await this.GetDefinition(
145
145
public async Task LanguageServiceFindsFunctionDefinitionInDotSourceReference ( )
146
146
{
147
147
GetDefinitionResult definitionResult =
148
- await this . GetDefinition (
149
- FindsFunctionDefinitionInDotSourceReference . SourceDetails ) . RunWithTimeout ( ) ;
148
+ await RunWithTimeout ( async ( ) => await this . GetDefinition (
149
+ FindsFunctionDefinitionInDotSourceReference . SourceDetails ) ) ;
150
150
151
151
SymbolReference definition = definitionResult . FoundDefinition ;
152
152
Assert . True (
@@ -162,12 +162,12 @@ await this.GetDefinition(
162
162
public async Task LanguageServiceFindsFunctionDefinitionInWorkspace ( )
163
163
{
164
164
var definitionResult =
165
- await this . GetDefinition (
165
+ await RunWithTimeout ( async ( ) => await this . GetDefinition (
166
166
FindsFunctionDefinitionInWorkspace . SourceDetails ,
167
167
new Workspace ( this . powerShellContext . LocalPowerShellVersion . Version , Logging . NullLogger )
168
168
{
169
169
WorkspacePath = Path . Combine ( baseSharedScriptPath , @"References" )
170
- } ) . RunWithTimeout ( ) ;
170
+ } ) ) ;
171
171
var definition = definitionResult . FoundDefinition ;
172
172
Assert . EndsWith ( "ReferenceFileE.ps1" , definition . FilePath ) ;
173
173
Assert . Equal ( "My-FunctionInFileE" , definition . SymbolName ) ;
@@ -177,8 +177,8 @@ await this.GetDefinition(
177
177
public async Task LanguageServiceFindsVariableDefinition ( )
178
178
{
179
179
GetDefinitionResult definitionResult =
180
- await this . GetDefinition (
181
- FindsVariableDefinition . SourceDetails ) . RunWithTimeout ( ) ;
180
+ await RunWithTimeout ( async ( ) => await this . GetDefinition (
181
+ FindsVariableDefinition . SourceDetails ) ) ;
182
182
183
183
SymbolReference definition = definitionResult . FoundDefinition ;
184
184
Assert . Equal ( 6 , definition . ScriptRegion . StartLineNumber ) ;
@@ -214,8 +214,8 @@ public void LanguageServiceFindsOccurrencesOnParameter()
214
214
public async Task LanguageServiceFindsReferencesOnCommandWithAlias ( )
215
215
{
216
216
FindReferencesResult refsResult =
217
- await this . GetReferences (
218
- FindsReferencesOnBuiltInCommandWithAlias . SourceDetails ) . RunWithTimeout ( ) ;
217
+ await RunWithTimeout ( async ( ) => await this . GetReferences (
218
+ FindsReferencesOnBuiltInCommandWithAlias . SourceDetails ) ) ;
219
219
220
220
Assert . Equal ( 6 , refsResult . FoundReferences . Count ( ) ) ;
221
221
Assert . Equal ( "Get-ChildItem" , refsResult . FoundReferences . Last ( ) . SymbolName ) ;
@@ -226,8 +226,8 @@ await this.GetReferences(
226
226
public async Task LanguageServiceFindsReferencesOnAlias ( )
227
227
{
228
228
FindReferencesResult refsResult =
229
- await this . GetReferences (
230
- FindsReferencesOnBuiltInCommandWithAlias . SourceDetails ) . RunWithTimeout ( ) ;
229
+ await RunWithTimeout ( async ( ) => await this . GetReferences (
230
+ FindsReferencesOnBuiltInCommandWithAlias . SourceDetails ) ) ;
231
231
232
232
Assert . Equal ( 6 , refsResult . FoundReferences . Count ( ) ) ;
233
233
Assert . Equal ( "Get-ChildItem" , refsResult . FoundReferences . Last ( ) . SymbolName ) ;
@@ -239,8 +239,8 @@ await this.GetReferences(
239
239
public async Task LanguageServiceFindsReferencesOnFileWithReferencesFileB ( )
240
240
{
241
241
FindReferencesResult refsResult =
242
- await this . GetReferences (
243
- FindsReferencesOnFunctionMultiFileDotSourceFileB . SourceDetails ) . RunWithTimeout ( ) ;
242
+ await RunWithTimeout ( async ( ) => await this . GetReferences (
243
+ FindsReferencesOnFunctionMultiFileDotSourceFileB . SourceDetails ) ) ;
244
244
245
245
Assert . Equal ( 4 , refsResult . FoundReferences . Count ( ) ) ;
246
246
}
@@ -249,19 +249,19 @@ await this.GetReferences(
249
249
public async Task LanguageServiceFindsReferencesOnFileWithReferencesFileC ( )
250
250
{
251
251
FindReferencesResult refsResult =
252
- await this . GetReferences (
253
- FindsReferencesOnFunctionMultiFileDotSourceFileC . SourceDetails ) . RunWithTimeout ( ) ;
252
+ await RunWithTimeout ( async ( ) => await this . GetReferences (
253
+ FindsReferencesOnFunctionMultiFileDotSourceFileC . SourceDetails ) ) ;
254
254
Assert . Equal ( 4 , refsResult . FoundReferences . Count ( ) ) ;
255
255
}
256
256
257
257
[ Fact ]
258
258
public async Task LanguageServiceFindsDetailsForBuiltInCommand ( )
259
259
{
260
260
SymbolDetails symbolDetails =
261
- await this . languageService . FindSymbolDetailsAtLocation (
261
+ await RunWithTimeout ( async ( ) => await this . languageService . FindSymbolDetailsAtLocation (
262
262
this . GetScriptFile ( FindsDetailsForBuiltInCommand . SourceDetails ) ,
263
263
FindsDetailsForBuiltInCommand . SourceDetails . StartLineNumber ,
264
- FindsDetailsForBuiltInCommand . SourceDetails . StartColumnNumber ) . RunWithTimeout ( ) ;
264
+ FindsDetailsForBuiltInCommand . SourceDetails . StartColumnNumber ) ) ;
265
265
266
266
Assert . NotNull ( symbolDetails . Documentation ) ;
267
267
Assert . NotEqual ( "" , symbolDetails . Documentation ) ;
@@ -341,19 +341,19 @@ private async Task<CompletionResults> GetCompletionResults(ScriptRegion scriptRe
341
341
{
342
342
// Run the completions request
343
343
return
344
- await this . languageService . GetCompletionsInFile (
344
+ await RunWithTimeout ( async ( ) => await this . languageService . GetCompletionsInFile (
345
345
GetScriptFile ( scriptRegion ) ,
346
346
scriptRegion . StartLineNumber ,
347
- scriptRegion . StartColumnNumber ) . RunWithTimeout ( ) ;
347
+ scriptRegion . StartColumnNumber ) ) ;
348
348
}
349
349
350
350
private async Task < ParameterSetSignatures > GetParamSetSignatures ( ScriptRegion scriptRegion )
351
351
{
352
352
return
353
- await this . languageService . FindParameterSetsInFile (
353
+ await RunWithTimeout ( async ( ) => await this . languageService . FindParameterSetsInFile (
354
354
GetScriptFile ( scriptRegion ) ,
355
355
scriptRegion . StartLineNumber ,
356
- scriptRegion . StartColumnNumber ) . RunWithTimeout ( ) ;
356
+ scriptRegion . StartColumnNumber ) ) ;
357
357
}
358
358
359
359
private async Task < GetDefinitionResult > GetDefinition ( ScriptRegion scriptRegion , Workspace workspace )
@@ -369,15 +369,15 @@ private async Task<GetDefinitionResult> GetDefinition(ScriptRegion scriptRegion,
369
369
Assert . NotNull ( symbolReference ) ;
370
370
371
371
return
372
- await this . languageService . GetDefinitionOfSymbol (
372
+ await RunWithTimeout ( async ( ) => await this . languageService . GetDefinitionOfSymbol (
373
373
scriptFile ,
374
374
symbolReference ,
375
- workspace ) . RunWithTimeout ( ) ;
375
+ workspace ) ) ;
376
376
}
377
377
378
378
private async Task < GetDefinitionResult > GetDefinition ( ScriptRegion scriptRegion )
379
379
{
380
- return await GetDefinition ( scriptRegion , this . workspace ) . RunWithTimeout ( ) ;
380
+ return await RunWithTimeout ( async ( ) => await GetDefinition ( scriptRegion , this . workspace ) ) ;
381
381
}
382
382
383
383
private async Task < FindReferencesResult > GetReferences ( ScriptRegion scriptRegion )
@@ -393,10 +393,10 @@ private async Task<FindReferencesResult> GetReferences(ScriptRegion scriptRegion
393
393
Assert . NotNull ( symbolReference ) ;
394
394
395
395
return
396
- await this . languageService . FindReferencesOfSymbol (
396
+ await RunWithTimeout ( async ( ) => await this . languageService . FindReferencesOfSymbol (
397
397
symbolReference ,
398
398
this . workspace . ExpandScriptReferences ( scriptFile ) ,
399
- this . workspace ) . RunWithTimeout ( ) ;
399
+ this . workspace ) ) ;
400
400
}
401
401
402
402
private FindOccurrencesResult GetOccurrences ( ScriptRegion scriptRegion )
@@ -414,17 +414,15 @@ private FindOccurrencesResult FindSymbolsInFile(ScriptRegion scriptRegion)
414
414
this . languageService . FindSymbolsInFile (
415
415
GetScriptFile ( scriptRegion ) ) ;
416
416
}
417
- }
418
417
419
- internal static class TaskExtensions
420
- {
421
- public static async Task < T > RunWithTimeout < T > ( this Task < T > task , int timeoutMillis = 10000 )
418
+ private static async Task < T > RunWithTimeout < T > ( Func < Task < T > > task , int timeoutMillis = 1000 )
422
419
{
423
- Task < T > newThreadTask = Task < T > . Run ( ( ) => task ) ;
420
+ Task < T > newThreadTask = Task . Run ( task ) ;
424
421
if ( ! ( ( IAsyncResult ) newThreadTask ) . AsyncWaitHandle . WaitOne ( timeoutMillis ) )
425
422
{
426
423
throw new TimeoutException ( ) ;
427
424
}
425
+
428
426
return await newThreadTask ;
429
427
}
430
428
}
0 commit comments