@@ -35,106 +35,96 @@ internal abstract class AbstractVsTextViewFilter(
3535 IComponentModel componentModel ) : AbstractOleCommandTarget ( wpfTextView , componentModel ) , IVsTextViewFilter
3636{
3737 int IVsTextViewFilter . GetDataTipText ( TextSpan [ ] pSpan , out string pbstrText )
38+ {
39+ ( pbstrText , var result ) = this . ThreadingContext . JoinableTaskFactory . Run ( ( ) => GetDataTipTextAsync ( pSpan ) ) ;
40+ return result ;
41+ }
42+
43+ private async Task < ( string pbstrText , int result ) > GetDataTipTextAsync ( TextSpan [ ] pSpan )
3844 {
3945 try
4046 {
4147 if ( pSpan == null || pSpan . Length != 1 )
42- {
43- pbstrText = null ;
44- return VSConstants . E_INVALIDARG ;
45- }
48+ return ( null , VSConstants . E_INVALIDARG ) ;
4649
47- return GetDataTipTextImpl ( pSpan , out pbstrText ) ;
50+ return await GetDataTipTextImplAsync ( pSpan ) . ConfigureAwait ( true ) ;
4851 }
4952 catch ( Exception e ) when ( FatalError . ReportAndCatch ( e ) && false )
5053 {
5154 throw ExceptionUtilities . Unreachable ( ) ;
5255 }
5356 }
5457
55- protected virtual int GetDataTipTextImpl ( TextSpan [ ] pSpan , out string pbstrText )
58+ protected virtual async Task < ( string pbstrText , int result ) > GetDataTipTextImplAsync ( TextSpan [ ] pSpan )
5659 {
5760 var subjectBuffer = WpfTextView . GetBufferContainingCaret ( ) ;
5861 if ( subjectBuffer == null )
59- {
60- pbstrText = null ;
61- return VSConstants . E_FAIL ;
62- }
62+ return ( null , VSConstants . E_FAIL ) ;
6363
64- return GetDataTipTextImpl ( subjectBuffer , pSpan , out pbstrText ) ;
64+ return await GetDataTipTextImplAsync ( subjectBuffer , pSpan ) . ConfigureAwait ( true ) ;
6565 }
6666
67- protected int GetDataTipTextImpl ( ITextBuffer subjectBuffer , TextSpan [ ] pSpan , out string pbstrText )
67+ protected async Task < ( string pbstrText , int result ) > GetDataTipTextImplAsync ( ITextBuffer subjectBuffer , TextSpan [ ] pSpan )
6868 {
69- pbstrText = null ;
70-
7169 var vsBuffer = EditorAdaptersFactory . GetBufferAdapter ( subjectBuffer ) ;
7270
7371 // TODO: broken in REPL
7472 if ( vsBuffer == null )
75- {
76- return VSConstants . E_FAIL ;
77- }
73+ return ( null , VSConstants . E_FAIL ) ;
7874
7975 using ( Logger . LogBlock ( FunctionId . Debugging_VsLanguageDebugInfo_GetDataTipText , CancellationToken . None ) )
8076 {
81- pbstrText = null ;
8277 if ( pSpan == null || pSpan . Length != 1 )
83- {
84- return VSConstants . E_INVALIDARG ;
85- }
78+ return ( null , VSConstants . E_INVALIDARG ) ;
8679
8780 var result = VSConstants . E_FAIL ;
88- string pbstrTextInternal = null ;
81+ string pbstrText = null ;
8982
9083 var uiThreadOperationExecutor = ComponentModel . GetService < IUIThreadOperationExecutor > ( ) ;
91- uiThreadOperationExecutor . Execute (
84+ using var context = uiThreadOperationExecutor . BeginExecute (
9285 title : ServicesVSResources . Debugger ,
9386 defaultDescription : ServicesVSResources . Getting_DataTip_text ,
9487 allowCancellation : true ,
95- showProgress : false ,
96- action : context =>
97- {
98- IServiceProvider serviceProvider = ComponentModel . GetService < SVsServiceProvider > ( ) ;
99- var debugger = ( IVsDebugger ) serviceProvider . GetService ( typeof ( SVsShellDebugger ) ) ;
100- var debugMode = new DBGMODE [ 1 ] ;
88+ showProgress : false ) ;
10189
102- var cancellationToken = context . UserCancellationToken ;
103- if ( ErrorHandler . Succeeded ( debugger . GetMode ( debugMode ) ) && debugMode [ 0 ] != DBGMODE . DBGMODE_Design )
104- {
105- var textSpan = pSpan [ 0 ] ;
90+ IServiceProvider serviceProvider = ComponentModel . GetService < SVsServiceProvider > ( ) ;
91+ var debugger = ( IVsDebugger ) serviceProvider . GetService ( typeof ( SVsShellDebugger ) ) ;
92+ var debugMode = new DBGMODE [ 1 ] ;
93+
94+ var cancellationToken = context . UserCancellationToken ;
95+ if ( ErrorHandler . Succeeded ( debugger . GetMode ( debugMode ) ) && debugMode [ 0 ] != DBGMODE . DBGMODE_Design )
96+ {
97+ var textSpan = pSpan [ 0 ] ;
10698
107- var textSnapshot = subjectBuffer . CurrentSnapshot ;
108- var document = textSnapshot . GetOpenDocumentInCurrentContextWithChanges ( ) ;
99+ var textSnapshot = subjectBuffer . CurrentSnapshot ;
100+ var document = textSnapshot . GetOpenDocumentInCurrentContextWithChanges ( ) ;
109101
110- if ( document != null )
102+ if ( document != null )
103+ {
104+ var languageDebugInfo = document . Project . Services . GetService < ILanguageDebugInfoService > ( ) ;
105+ if ( languageDebugInfo != null )
111106 {
112- var languageDebugInfo = document . Project . Services . GetService < ILanguageDebugInfoService > ( ) ;
113- if ( languageDebugInfo != null )
107+ var spanOpt = textSnapshot . TryGetSpan ( textSpan ) ;
108+ if ( spanOpt . HasValue )
114109 {
115- var spanOpt = textSnapshot . TryGetSpan ( textSpan ) ;
116- if ( spanOpt . HasValue )
110+ // 'kind' is an lsp-only concept, so we don't want/need to include it here (especially
111+ // as it can be expensive to compute, and we don't want to block the UI thread).
112+ var dataTipInfo = await languageDebugInfo . GetDataTipInfoAsync (
113+ document , spanOpt . Value . Start , includeKind : false , cancellationToken ) . ConfigureAwait ( true ) ;
114+ if ( ! dataTipInfo . IsDefault )
117115 {
118- // 'kind' is an lsp-only concept, so we don't want/need to include it here (especially
119- // as it can be expensive to compute, and we don't want to block the UI thread).
120- var dataTipInfo = languageDebugInfo . GetDataTipInfoAsync (
121- document , spanOpt . Value . Start , includeKind : false , cancellationToken ) . WaitAndGetResult ( cancellationToken ) ;
122- if ( ! dataTipInfo . IsDefault )
123- {
124- var resultSpan = dataTipInfo . Span . ToSnapshotSpan ( textSnapshot ) ;
125- var textOpt = dataTipInfo . Text ;
116+ var resultSpan = dataTipInfo . Span . ToSnapshotSpan ( textSnapshot ) ;
117+ var textOpt = dataTipInfo . Text ;
126118
127- pSpan [ 0 ] = resultSpan . ToVsTextSpan ( ) ;
128- result = debugger . GetDataTipValue ( ( IVsTextLines ) vsBuffer , pSpan , textOpt , out pbstrTextInternal ) ;
129- }
119+ pSpan [ 0 ] = resultSpan . ToVsTextSpan ( ) ;
120+ result = debugger . GetDataTipValue ( ( IVsTextLines ) vsBuffer , pSpan , textOpt , out pbstrText ) ;
130121 }
131122 }
132123 }
133124 }
134- } ) ;
125+ }
135126
136- pbstrText = pbstrTextInternal ;
137- return result ;
127+ return ( pbstrText , result ) ;
138128 }
139129 }
140130
0 commit comments