-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Make shift+enter work in DS and non-DS scenarios #9445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Shift+Enter can no longer send multiple lines to the interactive window. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Shift+Enter can no longer run code in the terminal. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
import '../../common/extensions'; | ||
|
||
import { inject, injectable } from 'inversify'; | ||
import * as path from 'path'; | ||
import { Range, TextEditor, Uri } from 'vscode'; | ||
|
||
import { IApplicationShell, IDocumentManager } from '../../common/application/types'; | ||
import { EXTENSION_ROOT_DIR, PYTHON_LANGUAGE } from '../../common/constants'; | ||
import '../../common/extensions'; | ||
import { traceError } from '../../common/logger'; | ||
import { IPythonExecutionFactory } from '../../common/process/types'; | ||
import { IProcessServiceFactory } from '../../common/process/types'; | ||
import { IInterpreterService } from '../../interpreter/contracts'; | ||
import { IServiceContainer } from '../../ioc/types'; | ||
import { ICodeExecutionHelper } from '../types'; | ||
|
||
@injectable() | ||
export class CodeExecutionHelper implements ICodeExecutionHelper { | ||
private readonly documentManager: IDocumentManager; | ||
private readonly applicationShell: IApplicationShell; | ||
private readonly pythonServiceFactory: IPythonExecutionFactory; | ||
private readonly processServiceFactory: IProcessServiceFactory; | ||
private readonly interpreterService: IInterpreterService; | ||
constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) { | ||
this.documentManager = serviceContainer.get<IDocumentManager>(IDocumentManager); | ||
this.applicationShell = serviceContainer.get<IApplicationShell>(IApplicationShell); | ||
this.pythonServiceFactory = serviceContainer.get<IPythonExecutionFactory>(IPythonExecutionFactory); | ||
this.processServiceFactory = serviceContainer.get<IProcessServiceFactory>(IProcessServiceFactory); | ||
this.interpreterService = serviceContainer.get<IInterpreterService>(IInterpreterService); | ||
} | ||
public async normalizeLines(code: string, resource?: Uri): Promise<string> { | ||
try { | ||
|
@@ -30,9 +34,10 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { | |
// On windows cr is not handled well by python when passing in/out via stdin/stdout. | ||
// So just remove cr from the input. | ||
code = code.replace(new RegExp('\\r', 'g'), ''); | ||
const interpreter = await this.interpreterService.getActiveInterpreter(resource); | ||
const processService = await this.processServiceFactory.create(resource); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getActiveIntepreter should be more up to date than the configuration service AFAIK. @DonJayamanne what do you think? |
||
const args = [path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'normalizeForInterpreter.py'), code]; | ||
const processService = await this.pythonServiceFactory.create({ resource }); | ||
const proc = await processService.exec(args, { throwOnStdErr: true }); | ||
const proc = await processService.exec(interpreter?.path || 'python', args, { throwOnStdErr: true }); | ||
|
||
return proc.stdout; | ||
} catch (ex) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.