|
5 | 5 |
|
6 | 6 | import { inject, injectable } from 'inversify'; |
7 | 7 | import * as path from 'path'; |
8 | | -import { Disposable, Uri } from 'vscode'; |
| 8 | +import { Disposable, TerminalShellExecutionStartEvent, Uri } from 'vscode'; |
9 | 9 | import { IApplicationShell, ICommandManager, IWorkspaceService } from '../../common/application/types'; |
10 | 10 | import '../../common/extensions'; |
11 | 11 | import { IPlatformService } from '../../common/platform/types'; |
12 | 12 | import { ITerminalService, ITerminalServiceFactory } from '../../common/terminal/types'; |
13 | 13 | import { IConfigurationService, IDisposable, IDisposableRegistry, Resource } from '../../common/types'; |
14 | | -import { Diagnostics, Repl } from '../../common/utils/localize'; |
15 | | -import { showWarningMessage } from '../../common/vscodeApis/windowApis'; |
| 14 | +import { Common, Diagnostics, Repl } from '../../common/utils/localize'; |
| 15 | +import { onDidStartTerminalShellExecution, showWarningMessage } from '../../common/vscodeApis/windowApis'; |
16 | 16 | import { IInterpreterService } from '../../interpreter/contracts'; |
17 | 17 | import { traceInfo } from '../../logging'; |
18 | 18 | import { buildPythonExecInfo, PythonExecInfo } from '../../pythonEnvironments/exec'; |
19 | 19 | import { ICodeExecutionService } from '../../terminals/types'; |
20 | 20 | import { EventName } from '../../telemetry/constants'; |
21 | 21 | import { sendTelemetryEvent } from '../../telemetry'; |
| 22 | +import { getActiveInterpreter } from '../../repl/replUtils'; |
| 23 | +import { getNativeRepl } from '../../repl/nativeRepl'; |
| 24 | +import { checkREPLCommand } from './terminalReplWatcher'; |
22 | 25 |
|
23 | 26 | @injectable() |
24 | 27 | export class TerminalCodeExecutionProvider implements ICodeExecutionService { |
@@ -63,11 +66,43 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { |
63 | 66 | } |
64 | 67 | } |
65 | 68 |
|
| 69 | + public suggestNativeRepl(resource: Resource) { |
| 70 | + this.disposables.push( |
| 71 | + onDidStartTerminalShellExecution(async (e: TerminalShellExecutionStartEvent) => { |
| 72 | + if (e.execution.commandLine.isTrusted && checkREPLCommand(e.execution.commandLine.value)) { |
| 73 | + sendTelemetryEvent(EventName.REPL, undefined, { replType: 'manualTerminal' }); |
| 74 | + const selection = await showWarningMessage( |
| 75 | + Repl.terminalSuggestNativeReplPrompt, |
| 76 | + Common.doNotShowAgain, |
| 77 | + ); |
| 78 | + if (selection === Repl.terminalSuggestNativeReplPrompt) { |
| 79 | + sendTelemetryEvent(EventName.REPL, undefined, { replType: 'Native' }); |
| 80 | + const interpreter = await getActiveInterpreter(resource as Uri, this.interpreterService); |
| 81 | + if (interpreter) { |
| 82 | + const nativeRepl = await getNativeRepl(interpreter, this.disposables); |
| 83 | + await nativeRepl.sendToNativeRepl(undefined, false); |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + }), |
| 88 | + ); |
| 89 | + } |
| 90 | + |
66 | 91 | public async initializeRepl(resource: Resource) { |
67 | 92 | const terminalService = this.getTerminalService(resource); |
| 93 | + if (!this.replActive) { |
| 94 | + this.suggestNativeRepl(resource); |
| 95 | + } |
68 | 96 | if (this.replActive && (await this.replActive)) { |
69 | 97 | await terminalService.show(); |
70 | 98 | return; |
| 99 | + } else { |
| 100 | + // Suggest launch of Native REPL |
| 101 | + const interpreter = await getActiveInterpreter(resource!, this.interpreterService); |
| 102 | + if (interpreter) { |
| 103 | + const nativeRepl = await getNativeRepl(interpreter, this.disposables); |
| 104 | + await nativeRepl.sendToNativeRepl(undefined, false); |
| 105 | + } |
71 | 106 | } |
72 | 107 | sendTelemetryEvent(EventName.REPL, undefined, { replType: 'Terminal' }); |
73 | 108 | this.replActive = new Promise<boolean>(async (resolve) => { |
|
0 commit comments