77using System ;
88using System . Linq ;
99using System . Threading ;
10+ using System . Threading . Tasks ;
1011using Microsoft . CodeAnalysis . BraceMatching ;
1112using Microsoft . CodeAnalysis . Debugging ;
1213using Microsoft . CodeAnalysis . Editor ;
2930
3031namespace Microsoft . VisualStudio . LanguageServices . Implementation ;
3132
32- internal abstract class AbstractVsTextViewFilter : AbstractOleCommandTarget , IVsTextViewFilter
33+ internal abstract class AbstractVsTextViewFilter (
34+ IWpfTextView wpfTextView ,
35+ IComponentModel componentModel ) : AbstractOleCommandTarget ( wpfTextView , componentModel ) , IVsTextViewFilter
3336{
34- public AbstractVsTextViewFilter (
35- IWpfTextView wpfTextView ,
36- IComponentModel componentModel )
37- : base ( wpfTextView , componentModel )
38- {
39- }
40-
4137 int IVsTextViewFilter . GetDataTipText ( TextSpan [ ] pSpan , out string pbstrText )
4238 {
4339 try
@@ -144,41 +140,41 @@ protected int GetDataTipTextImpl(ITextBuffer subjectBuffer, TextSpan[] pSpan, ou
144140
145141 int IVsTextViewFilter . GetPairExtents ( int iLine , int iIndex , TextSpan [ ] pSpan )
146142 {
147- try
148- {
149- var result = VSConstants . S_OK ;
150- ComponentModel . GetService < IUIThreadOperationExecutor > ( ) . Execute (
151- "Intellisense" ,
152- defaultDescription : "" ,
153- allowCancellation : true ,
154- showProgress : false ,
155- action : c => result = GetPairExtentsWorker ( iLine , iIndex , pSpan , c . UserCancellationToken ) ) ;
156-
157- return result ;
158- }
159- catch ( Exception e ) when ( FatalError . ReportAndCatch ( e ) && false )
160- {
161- throw ExceptionUtilities . Unreachable ( ) ;
162- }
143+ return this . ThreadingContext . JoinableTaskFactory . Run ( ( ) => GetPairExtentsAsync ( iLine , iIndex , pSpan ) ) ;
163144 }
164145
165- private int GetPairExtentsWorker ( int iLine , int iIndex , TextSpan [ ] pSpan , CancellationToken cancellationToken )
146+ private async Task < int > GetPairExtentsAsync ( int iLine , int iIndex , TextSpan [ ] pSpan )
166147 {
148+ using var waitContext = ComponentModel . GetService < IUIThreadOperationExecutor > ( ) . BeginExecute (
149+ "Intellisense" ,
150+ defaultDescription : "" ,
151+ allowCancellation : true ,
152+ showProgress : false ) ;
153+
167154 var braceMatcher = ComponentModel . GetService < IBraceMatchingService > ( ) ;
168155 var globalOptions = ComponentModel . GetService < IGlobalOptionService > ( ) ;
169- return GetPairExtentsWorker (
156+
157+ return await GetPairExtentsAsync (
170158 WpfTextView ,
171159 braceMatcher ,
172160 globalOptions ,
173161 iLine ,
174162 iIndex ,
175163 pSpan ,
176164 ( VSConstants . VSStd2KCmdID ) this . CurrentlyExecutingCommand == VSConstants . VSStd2KCmdID . GOTOBRACE_EXT ,
177- cancellationToken ) ;
165+ waitContext . UserCancellationToken ) . ConfigureAwait ( true ) ;
178166 }
179167
180168 // Internal for testing purposes
181- internal static int GetPairExtentsWorker ( ITextView textView , IBraceMatchingService braceMatcher , IGlobalOptionService globalOptions , int iLine , int iIndex , TextSpan [ ] pSpan , bool extendSelection , CancellationToken cancellationToken )
169+ internal static async Task < int > GetPairExtentsAsync (
170+ ITextView textView ,
171+ IBraceMatchingService braceMatcher ,
172+ IGlobalOptionService globalOptions ,
173+ int iLine ,
174+ int iIndex ,
175+ TextSpan [ ] pSpan ,
176+ bool extendSelection ,
177+ CancellationToken cancellationToken )
182178 {
183179 pSpan [ 0 ] . iStartLine = pSpan [ 0 ] . iEndLine = iLine ;
184180 pSpan [ 0 ] . iStartIndex = pSpan [ 0 ] . iEndIndex = iIndex ;
@@ -202,7 +198,8 @@ internal static int GetPairExtentsWorker(ITextView textView, IBraceMatchingServi
202198 if ( document != null )
203199 {
204200 var options = globalOptions . GetBraceMatchingOptions ( document . Project . Language ) ;
205- var matchingSpan = braceMatcher . FindMatchingSpanAsync ( document , position , options , cancellationToken ) . WaitAndGetResult ( cancellationToken ) ;
201+ var matchingSpan = await braceMatcher . FindMatchingSpanAsync (
202+ document , position , options , cancellationToken ) . ConfigureAwait ( true ) ;
206203
207204 if ( matchingSpan . HasValue )
208205 {
@@ -236,7 +233,8 @@ internal static int GetPairExtentsWorker(ITextView textView, IBraceMatchingServi
236233 if ( extendSelection )
237234 {
238235 // case a.
239- var closingSpans = braceMatcher . FindMatchingSpanAsync ( document , matchingSpan . Value . Start , options , cancellationToken ) . WaitAndGetResult ( cancellationToken ) ;
236+ var closingSpans = await braceMatcher . FindMatchingSpanAsync (
237+ document , matchingSpan . Value . Start , options , cancellationToken ) . ConfigureAwait ( true ) ;
240238 var vsClosingSpans = textView . GetSpanInView ( closingSpans . Value . ToSnapshotSpan ( subjectBuffer . CurrentSnapshot ) ) . First ( ) . ToVsTextSpan ( ) ;
241239 pSpan [ 0 ] . iEndIndex = vsClosingSpans . iStartIndex ;
242240 }
@@ -255,7 +253,8 @@ internal static int GetPairExtentsWorker(ITextView textView, IBraceMatchingServi
255253 pSpan [ 0 ] . iEndIndex = vsTextSpan . iStartIndex ;
256254
257255 // case b.
258- var openingSpans = braceMatcher . FindMatchingSpanAsync ( document , matchingSpan . Value . End , options , cancellationToken ) . WaitAndGetResult ( cancellationToken ) ;
256+ var openingSpans = await braceMatcher . FindMatchingSpanAsync (
257+ document , matchingSpan . Value . End , options , cancellationToken ) . ConfigureAwait ( true ) ;
259258 var vsOpeningSpans = textView . GetSpanInView ( openingSpans . Value . ToSnapshotSpan ( subjectBuffer . CurrentSnapshot ) ) . First ( ) . ToVsTextSpan ( ) ;
260259 pSpan [ 0 ] . iStartIndex = vsOpeningSpans . iStartIndex ;
261260 }
0 commit comments