(private logger: ILogger)
| 195 | private handlers: vscode.Disposable[] = []; |
| 196 | |
| 197 | constructor(private logger: ILogger) { |
| 198 | super(); |
| 199 | this.commands = [ |
| 200 | vscode.commands.registerCommand( |
| 201 | "PowerShell.RunSelection", |
| 202 | async () => { |
| 203 | if ( |
| 204 | vscode.window.activeTerminal && |
| 205 | vscode.window.activeTerminal.name !== |
| 206 | "PowerShell Extension" |
| 207 | ) { |
| 208 | this.logger.write( |
| 209 | "PowerShell Extension Terminal is not active! Running in current terminal using 'runSelectedText'.", |
| 210 | ); |
| 211 | await vscode.commands.executeCommand( |
| 212 | "workbench.action.terminal.runSelectedText", |
| 213 | ); |
| 214 | |
| 215 | // We need to honor the focusConsoleOnExecute setting here too. However, the boolean that `show` |
| 216 | // takes is called `preserveFocus` which when `true` the terminal will not take focus. |
| 217 | // This is the inverse of focusConsoleOnExecute so we have to inverse the boolean. |
| 218 | vscode.window.activeTerminal.show( |
| 219 | !getSettings().integratedConsole |
| 220 | .focusConsoleOnExecute, |
| 221 | ); |
| 222 | await vscode.commands.executeCommand( |
| 223 | "workbench.action.terminal.scrollToBottom", |
| 224 | ); |
| 225 | |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | const editor = vscode.window.activeTextEditor; |
| 230 | if (editor === undefined) { |
| 231 | return; |
| 232 | } |
| 233 | |
| 234 | let selectionRange: vscode.Range; |
| 235 | |
| 236 | if (!editor.selection.isEmpty) { |
| 237 | selectionRange = new vscode.Range( |
| 238 | editor.selection.start, |
| 239 | editor.selection.end, |
| 240 | ); |
| 241 | } else { |
| 242 | selectionRange = editor.document.lineAt( |
| 243 | editor.selection.start.line, |
| 244 | ).range; |
| 245 | } |
| 246 | const client = |
| 247 | await LanguageClientConsumer.getLanguageClient(); |
| 248 | await client.sendRequest(EvaluateRequestType, { |
| 249 | expression: editor.document.getText(selectionRange), |
| 250 | }); |
| 251 | |
| 252 | // Show the Extension Terminal if it isn't already visible and |
| 253 | // scroll terminal to bottom so new output is visible |
| 254 | await vscode.commands.executeCommand( |
nothing calls this directly
no test coverage detected