@@ -102,23 +102,33 @@ await this.powerShellContext.GetRunspaceHandle(
102
102
103
103
if ( commandCompletion != null )
104
104
{
105
- CompletionResults completionResults =
106
- CompletionResults . Create (
107
- scriptFile ,
108
- commandCompletion ) ;
109
-
110
- // save state of most recent completion
111
- mostRecentCompletions = completionResults ;
112
- mostRecentRequestFile = scriptFile . Id ;
113
- mostRecentRequestLine = lineNumber ;
114
- mostRecentRequestOffest = columnNumber ;
115
-
116
- return completionResults ;
117
- }
118
- else
119
- {
120
- return new CompletionResults ( ) ;
105
+ try
106
+ {
107
+ CompletionResults completionResults =
108
+ CompletionResults . Create (
109
+ scriptFile ,
110
+ commandCompletion ) ;
111
+
112
+ // save state of most recent completion
113
+ mostRecentCompletions = completionResults ;
114
+ mostRecentRequestFile = scriptFile . Id ;
115
+ mostRecentRequestLine = lineNumber ;
116
+ mostRecentRequestOffest = columnNumber ;
117
+
118
+ return completionResults ;
119
+ }
120
+ catch ( ArgumentException e )
121
+ {
122
+ // Bad completion results could return an invalid
123
+ // replacement range, catch that here
124
+ Logger . Write (
125
+ LogLevel . Error ,
126
+ $ "Caught exception while trying to create CompletionResults:\n \n { e . ToString ( ) } ") ;
127
+ }
121
128
}
129
+
130
+ // If all else fails, return empty results
131
+ return new CompletionResults ( ) ;
122
132
}
123
133
124
134
/// <summary>
0 commit comments