@@ -25,6 +25,7 @@ internal class CompletionHandler : ICompletionHandler, ICompletionResolveHandler
25
25
{
26
26
const int DefaultWaitTimeoutMilliseconds = 5000 ;
27
27
private readonly SemaphoreSlim _completionLock = AsyncUtils . CreateSimpleLockingSemaphore ( ) ;
28
+ private readonly SemaphoreSlim _completionResolveLock = AsyncUtils . CreateSimpleLockingSemaphore ( ) ;
28
29
29
30
private readonly ILogger _logger ;
30
31
private readonly PowerShellContextService _powerShellContextService ;
@@ -67,7 +68,15 @@ public async Task<CompletionList> Handle(CompletionParams request, CancellationT
67
68
68
69
ScriptFile scriptFile = _workspaceService . GetFile ( request . TextDocument . Uri ) ;
69
70
70
- await _completionLock . WaitAsync ( ) . ConfigureAwait ( false ) ;
71
+ try
72
+ {
73
+ await _completionLock . WaitAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
74
+ }
75
+ catch ( OperationCanceledException )
76
+ {
77
+ _logger . LogDebug ( "Completion request canceled for file: {0}" , request . TextDocument . Uri ) ;
78
+ return Array . Empty < CompletionItem > ( ) ;
79
+ }
71
80
72
81
try
73
82
{
@@ -116,22 +125,39 @@ public async Task<CompletionItem> Handle(CompletionItem request, CancellationTok
116
125
return request ;
117
126
}
118
127
119
- // Get the documentation for the function
120
- CommandInfo commandInfo =
121
- await CommandHelpers . GetCommandInfoAsync (
122
- request . Label ,
123
- _powerShellContextService ) . ConfigureAwait ( false ) ;
128
+ try
129
+ {
130
+ await _completionResolveLock . WaitAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
131
+ }
132
+ catch ( OperationCanceledException )
133
+ {
134
+ _logger . LogDebug ( "CompletionItemResolve request canceled for item: {0}" , request . Label ) ;
135
+ return request ;
136
+ }
124
137
125
- if ( commandInfo != null )
138
+ try
126
139
{
127
- request . Documentation =
128
- await CommandHelpers . GetCommandSynopsisAsync (
129
- commandInfo ,
140
+ // Get the documentation for the function
141
+ CommandInfo commandInfo =
142
+ await CommandHelpers . GetCommandInfoAsync (
143
+ request . Label ,
130
144
_powerShellContextService ) . ConfigureAwait ( false ) ;
131
- }
132
145
133
- // Send back the updated CompletionItem
134
- return request ;
146
+ if ( commandInfo != null )
147
+ {
148
+ request . Documentation =
149
+ await CommandHelpers . GetCommandSynopsisAsync (
150
+ commandInfo ,
151
+ _powerShellContextService ) . ConfigureAwait ( false ) ;
152
+ }
153
+
154
+ // Send back the updated CompletionItem
155
+ return request ;
156
+ }
157
+ finally
158
+ {
159
+ _completionResolveLock . Release ( ) ;
160
+ }
135
161
}
136
162
137
163
public void SetCapability ( CompletionCapability capability )
0 commit comments