@@ -76,13 +76,10 @@ public static async Task<CommandCompletion> GetCompletionsAsync(
7676 CancellationToken cancellationToken )
7777 {
7878 IScriptPosition cursorPosition = s_clonePositionWithNewOffset ( scriptAst . Extent . StartScriptPosition , fileOffset ) ;
79-
80- logger . LogTrace ( $ "Getting completions at offset { fileOffset } (line: { cursorPosition . LineNumber } , column: { cursorPosition . ColumnNumber } )") ;
81-
8279 Stopwatch stopwatch = new ( ) ;
80+ logger . LogTrace ( $ "Getting completions at offset { fileOffset } (line: { cursorPosition . LineNumber } , column: { cursorPosition . ColumnNumber } )") ;
8381
84- CommandCompletion commandCompletion = null ;
85- await executionService . ExecuteDelegateAsync (
82+ CommandCompletion commandCompletion = await executionService . ExecuteDelegateAsync (
8683 representation : "CompleteInput" ,
8784 new ExecutionOptions { Priority = ExecutionPriority . Next } ,
8885 ( pwsh , _ ) =>
@@ -108,35 +105,41 @@ await executionService.ExecuteDelegateAsync(
108105
109106 if ( completionResults is { Count : > 0 } )
110107 {
111- commandCompletion = completionResults [ 0 ] ;
108+ return completionResults [ 0 ] ;
112109 }
113110
114- return ;
111+ return null ;
115112 }
116113
117114 // If the current runspace is out of process, we can't call TabExpansion2
118115 // because the output will be serialized.
119- commandCompletion = CommandCompletion . CompleteInput (
116+ return CommandCompletion . CompleteInput (
120117 scriptAst ,
121118 currentTokens ,
122119 cursorPosition ,
123120 options : null ,
124121 powershell : pwsh ) ;
125122 } ,
126- cancellationToken )
127- . ConfigureAwait ( false ) ;
123+ cancellationToken ) . ConfigureAwait ( false ) ;
128124
129125 stopwatch . Stop ( ) ;
130- logger . LogTrace (
131- "IntelliSense completed in {elapsed}ms - WordToComplete: \" {word}\" MatchCount: {count}" ,
132- stopwatch . ElapsedMilliseconds ,
133- commandCompletion . ReplacementLength > 0
134- ? scriptAst . Extent . StartScriptPosition . GetFullScript ( ) ? . Substring (
135- commandCompletion . ReplacementIndex ,
136- commandCompletion . ReplacementLength )
137- : null ,
138- commandCompletion . CompletionMatches . Count ) ;
139126
127+ if ( commandCompletion is null )
128+ {
129+ logger . LogError ( "Error Occurred in TabExpansion2" ) ;
130+ }
131+ else
132+ {
133+ logger . LogTrace (
134+ "IntelliSense completed in {elapsed}ms - WordToComplete: \" {word}\" MatchCount: {count}" ,
135+ stopwatch . ElapsedMilliseconds ,
136+ commandCompletion . ReplacementLength > 0
137+ ? scriptAst . Extent . StartScriptPosition . GetFullScript ( ) ? . Substring (
138+ commandCompletion . ReplacementIndex ,
139+ commandCompletion . ReplacementLength )
140+ : null ,
141+ commandCompletion . CompletionMatches . Count ) ;
142+ }
140143 return commandCompletion ;
141144 }
142145
0 commit comments