@@ -42,20 +42,27 @@ public async Task<CompletionItemWithDescription[]> Complete(Document document, s
4242 return cached ;
4343
4444 var completionService = CompletionService . GetService ( document ) ;
45- if ( completionService is null ) return Array . Empty < CompletionItemWithDescription > ( ) ;
45+ if ( completionService is null ) return [ ] ;
4646
47- var completions = await completionService
48- . GetCompletionsAsync ( document , caret )
49- . ConfigureAwait ( false ) ;
47+ try
48+ {
49+ var completions = await completionService
50+ . GetCompletionsAsync ( document , caret )
51+ . ConfigureAwait ( false ) ;
5052
51- var completionsWithDescriptions = completions ? . ItemsList
52- . Where ( item => ! ( item . IsComplexTextEdit && item . InlineDescription . Length > 0 ) ) //TODO https://github.com/waf/CSharpRepl/issues/236
53- . Select ( item => new CompletionItemWithDescription ( item , GetDisplayText ( item ) , cancellationToken => GetExtendedDescriptionAsync ( completionService , document , item , highlighter ) ) )
54- . ToArray ( ) ?? Array . Empty < CompletionItemWithDescription > ( ) ;
53+ var completionsWithDescriptions = completions ? . ItemsList
54+ . Where ( item => ! ( item . IsComplexTextEdit && item . InlineDescription . Length > 0 ) ) //TODO https://github.com/waf/CSharpRepl/issues/236
55+ . Select ( item => new CompletionItemWithDescription ( item , GetDisplayText ( item ) , cancellationToken => GetExtendedDescriptionAsync ( completionService , document , item , highlighter ) ) )
56+ . ToArray ( ) ?? [ ] ;
5557
56- cache . Set ( cacheKey , completionsWithDescriptions , DateTimeOffset . Now . AddMinutes ( 1 ) ) ;
58+ cache . Set ( cacheKey , completionsWithDescriptions , DateTimeOffset . Now . AddMinutes ( 1 ) ) ;
5759
58- return completionsWithDescriptions ;
60+ return completionsWithDescriptions ;
61+ }
62+ catch ( InvalidOperationException ) // handle crashes from roslyn completion API
63+ {
64+ return [ ] ;
65+ }
5966
6067 FormattedString GetDisplayText ( CompletionItem item )
6168 {
0 commit comments