@@ -97,65 +97,69 @@ static public async Task<CommandCompletion> GetCompletionsAsync(
97
97
98
98
var stopwatch = new Stopwatch ( ) ;
99
99
100
- stopwatch . Start ( ) ;
101
-
102
- try
103
- {
104
- return CommandCompletion . CompleteInput (
105
- scriptAst ,
106
- currentTokens ,
107
- cursorPosition ,
108
- options : null ,
109
- powershell : pwsh ) ;
110
- }
111
- finally
100
+ if ( powerShellContext . IsPSReadLineEnabled )
112
101
{
113
- stopwatch . Stop ( ) ;
114
- logger . Write ( LogLevel . Verbose , $ "IntelliSense completed in { stopwatch . ElapsedMilliseconds } ms.") ;
102
+ stopwatch . Start ( ) ;
103
+
104
+ try
105
+ {
106
+ return CommandCompletion . CompleteInput (
107
+ scriptAst ,
108
+ currentTokens ,
109
+ cursorPosition ,
110
+ options : null ,
111
+ powershell : pwsh ) ;
112
+ }
113
+ finally
114
+ {
115
+ stopwatch . Stop ( ) ;
116
+ logger . Write ( LogLevel . Verbose , $ "IntelliSense completed in { stopwatch . ElapsedMilliseconds } ms.") ;
117
+ }
115
118
}
119
+
116
120
// If the current runspace is out of process we can use
117
121
// CommandCompletion.CompleteInput because PSReadLine won't be taking up the
118
122
// main runspace.
119
- // if (powerShellContext.IsCurrentRunspaceOutOfProcess())
120
- // {
121
- // using (RunspaceHandle runspaceHandle = await powerShellContext.GetRunspaceHandleAsync(cancellationToken))
122
- // using (PowerShell powerShell = PowerShell.Create())
123
- // {
124
- // powerShell.Runspace = runspaceHandle.Runspace;
125
- // stopwatch.Start();
126
- // try
127
- // {
128
- // return CommandCompletion.CompleteInput(
129
- // scriptAst,
130
- // currentTokens,
131
- // cursorPosition,
132
- // options: null,
133
- // powershell: powerShell);
134
- // }
135
- // finally
136
- // {
137
- // stopwatch.Stop();
138
- // logger.Write(LogLevel.Verbose, $"IntelliSense completed in {stopwatch.ElapsedMilliseconds}ms.");
139
- // }
140
- // }
141
- // }
142
-
143
- // CommandCompletion commandCompletion = null;
144
- // await powerShellContext.InvokeOnPipelineThreadAsync(
145
- // pwsh =>
146
- // {
147
- // stopwatch.Start();
148
- // commandCompletion = CommandCompletion.CompleteInput(
149
- // scriptAst,
150
- // currentTokens,
151
- // cursorPosition,
152
- // options: null,
153
- // powershell: pwsh);
154
- // });
155
- // stopwatch.Stop();
156
- // logger.Write(LogLevel.Verbose, $"IntelliSense completed in {stopwatch.ElapsedMilliseconds}ms.");
157
-
158
- // return commandCompletion;
123
+ if ( powerShellContext . IsCurrentRunspaceOutOfProcess ( ) )
124
+ {
125
+ using ( RunspaceHandle runspaceHandle = await powerShellContext . GetRunspaceHandleAsync ( cancellationToken ) )
126
+ using ( PowerShell powerShell = PowerShell . Create ( ) )
127
+ {
128
+ powerShell . Runspace = runspaceHandle . Runspace ;
129
+ stopwatch . Start ( ) ;
130
+ try
131
+ {
132
+ return CommandCompletion . CompleteInput (
133
+ scriptAst ,
134
+ currentTokens ,
135
+ cursorPosition ,
136
+ options : null ,
137
+ powershell : powerShell ) ;
138
+ }
139
+ finally
140
+ {
141
+ stopwatch . Stop ( ) ;
142
+ logger . Write ( LogLevel . Verbose , $ "IntelliSense completed in { stopwatch . ElapsedMilliseconds } ms.") ;
143
+ }
144
+ }
145
+ }
146
+
147
+ CommandCompletion commandCompletion = null ;
148
+ await powerShellContext . InvokeOnPipelineThreadAsync (
149
+ pwsh =>
150
+ {
151
+ stopwatch . Start ( ) ;
152
+ commandCompletion = CommandCompletion . CompleteInput (
153
+ scriptAst ,
154
+ currentTokens ,
155
+ cursorPosition ,
156
+ options : null ,
157
+ powershell : pwsh ) ;
158
+ } ) ;
159
+ stopwatch . Stop ( ) ;
160
+ logger . Write ( LogLevel . Verbose , $ "IntelliSense completed in { stopwatch . ElapsedMilliseconds } ms.") ;
161
+
162
+ return commandCompletion ;
159
163
}
160
164
finally
161
165
{
0 commit comments