| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 678e5d9 commit 902b410
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Make cursor focus switch automatically to the terminal after launching a python process with configuration option. (Thanks [djplt](https://github.com/djplt)) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -945,6 +945,12 @@ | |||
| 945 | 945 | "scope": "resource", | |
| 946 | 946 | "type": "boolean" | |
| 947 | 947 | }, | |
| 948 | + "python.terminal.focusAfterLaunch": { | ||
| 949 | + "default": false, | ||
| 950 | + "description": "When launching a python process, whether to focus on the terminal.", | ||
| 951 | + "scope": "resource", | ||
| 952 | + "type": "boolean" | ||
| 953 | + }, | ||
| 948 | 954 | "python.terminal.launchArgs": { | |
| 949 | 955 | "default": [], | |
| 950 | 956 | "description": "Python launch arguments to use when executing a file in the terminal.", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,6 +27,7 @@ interface ICommandNameWithoutArgumentTypeMapping { | |||
| 27 | 27 | ['workbench.action.debug.stop']: []; | |
| 28 | 28 | ['workbench.action.reloadWindow']: []; | |
| 29 | 29 | ['workbench.action.closeActiveEditor']: []; | |
| 30 | + ['workbench.action.terminal.focus']: []; | ||
| 30 | 31 | ['editor.action.formatDocument']: []; | |
| 31 | 32 | ['editor.action.rename']: []; | |
| 32 | 33 | [Commands.ViewOutput]: []; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -465,6 +465,7 @@ export class PythonSettings implements IPythonSettings { | |||
| 465 | 465 | ? this.terminal | |
| 466 | 466 | : { | |
| 467 | 467 | executeInFileDir: true, | |
| 468 | + focusAfterLaunch: false, | ||
| 468 | 469 | launchArgs: [], | |
| 469 | 470 | activateEnvironment: true, | |
| 470 | 471 | activateEnvInCurrentTerminal: false, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -276,6 +276,7 @@ export interface IFormattingSettings { | |||
| 276 | 276 | ||
| 277 | 277 | export interface ITerminalSettings { | |
| 278 | 278 | readonly executeInFileDir: boolean; | |
| 279 | + readonly focusAfterLaunch: boolean; | ||
| 279 | 280 | readonly launchArgs: string[]; | |
| 280 | 281 | readonly activateEnvironment: boolean; | |
| 281 | 282 | readonly activateEnvInCurrentTerminal: boolean; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,11 +2,12 @@ | |||
| 2 | 2 | // Licensed under the MIT License. | |
| 3 | 3 | ||
| 4 | 4 | 'use strict'; | |
| 5 | - | ||
| 5 | + import { Uri } from 'vscode'; | ||
| 6 | 6 | import { inject, injectable } from 'inversify'; | |
| 7 | 7 | import { IExtensionSingleActivationService } from '../../../activation/types'; | |
| 8 | 8 | import { IDebugService } from '../../../common/application/types'; | |
| 9 | - import { IDisposableRegistry } from '../../../common/types'; | ||
| 9 | + import { IConfigurationService, IDisposableRegistry } from '../../../common/types'; | ||
| 10 | + import { ICommandManager } from '../../../common/application/types'; | ||
| 10 | 11 | import { DebuggerTypeName } from '../../constants'; | |
| 11 | 12 | import { IAttachProcessProviderFactory } from '../attachQuickPick/types'; | |
| 12 | 13 | import { IDebugAdapterDescriptorFactory, IDebugSessionLoggingFactory, IOutdatedDebuggerPromptFactory } from '../types'; | |
@@ -16,6 +17,8 @@ export class DebugAdapterActivator implements IExtensionSingleActivationService | |||
| 16 | 17 | public readonly supportedWorkspaceTypes = { untrustedWorkspace: false, virtualWorkspace: false }; | |
| 17 | 18 | constructor( | |
| 18 | 19 | @inject(IDebugService) private readonly debugService: IDebugService, | |
| 20 | + @inject(IConfigurationService) private readonly configSettings: IConfigurationService, | ||
| 21 | + @inject(ICommandManager) private commandManager: ICommandManager, | ||
| 19 | 22 | @inject(IDebugAdapterDescriptorFactory) private descriptorFactory: IDebugAdapterDescriptorFactory, | |
| 20 | 23 | @inject(IDebugSessionLoggingFactory) private debugSessionLoggingFactory: IDebugSessionLoggingFactory, | |
| 21 | 24 | @inject(IOutdatedDebuggerPromptFactory) private debuggerPromptFactory: IOutdatedDebuggerPromptFactory, | |
@@ -32,8 +35,19 @@ export class DebugAdapterActivator implements IExtensionSingleActivationService | |||
| 32 | 35 | this.disposables.push( | |
| 33 | 36 | this.debugService.registerDebugAdapterTrackerFactory(DebuggerTypeName, this.debuggerPromptFactory), | |
| 34 | 37 | ); | |
| 38 | + | ||
| 35 | 39 | this.disposables.push( | |
| 36 | 40 | this.debugService.registerDebugAdapterDescriptorFactory(DebuggerTypeName, this.descriptorFactory), | |
| 37 | 41 | ); | |
| 42 | + this.disposables.push( | ||
| 43 | + this.debugService.onDidStartDebugSession((debugSession) => { | ||
| 44 | + if (this.shouldTerminalFocusOnStart(debugSession.workspaceFolder?.uri)) | ||
| 45 | + this.commandManager.executeCommand('workbench.action.terminal.focus'); | ||
| 46 | + }), | ||
| 47 | + ); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + private shouldTerminalFocusOnStart(uri: Uri | undefined): boolean { | ||
| 51 | + return this.configSettings.getSettings(uri)?.terminal.focusAfterLaunch; | ||
| 38 | 52 | } | |
| 39 | 53 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ import { ICommandManager, IDocumentManager } from '../../common/application/type | |||
| 10 | 10 | import { Commands } from '../../common/constants'; | |
| 11 | 11 | import '../../common/extensions'; | |
| 12 | 12 | import { IFileSystem } from '../../common/platform/types'; | |
| 13 | - import { IDisposableRegistry, Resource } from '../../common/types'; | ||
| 13 | + import { IDisposableRegistry, IConfigurationService, Resource } from '../../common/types'; | ||
| 14 | 14 | import { noop } from '../../common/utils/misc'; | |
| 15 | 15 | import { IServiceContainer } from '../../ioc/types'; | |
| 16 | 16 | import { traceError } from '../../logging'; | |
@@ -26,6 +26,7 @@ export class CodeExecutionManager implements ICodeExecutionManager { | |||
| 26 | 26 | @inject(IDocumentManager) private documentManager: IDocumentManager, | |
| 27 | 27 | @inject(IDisposableRegistry) private disposableRegistry: Disposable[], | |
| 28 | 28 | @inject(IFileSystem) private fileSystem: IFileSystem, | |
| 29 | + @inject(IConfigurationService) private readonly configSettings: IConfigurationService, | ||
| 29 | 30 | @inject(IServiceContainer) private serviceContainer: IServiceContainer, | |
| 30 | 31 | ) {} | |
| 31 | 32 | ||
@@ -38,22 +39,32 @@ export class CodeExecutionManager implements ICodeExecutionManager { | |||
| 38 | 39 | this.disposableRegistry.push( | |
| 39 | 40 | this.commandManager.registerCommand(cmd as any, async (file: Resource) => { | |
| 40 | 41 | const trigger = cmd === Commands.Exec_In_Terminal ? 'command' : 'icon'; | |
| 41 | - await this.executeFileInTerminal(file, trigger).catch((ex) => | ||
| 42 | - traceError('Failed to execute file in terminal', ex), | ||
| 43 | - ); | ||
| 42 | + await this.executeFileInTerminal(file, trigger) | ||
| 43 | + .then(() => { | ||
| 44 | + if (this.shouldTerminalFocusOnStart(file)) | ||
| 45 | + this.commandManager.executeCommand('workbench.action.terminal.focus'); | ||
| 46 | + }) | ||
| 47 | + .catch((ex) => traceError('Failed to execute file in terminal', ex)); | ||
| 44 | 48 | }), | |
| 45 | 49 | ); | |
| 46 | 50 | }); | |
| 47 | 51 | this.disposableRegistry.push( | |
| 48 | - this.commandManager.registerCommand( | ||
| 49 | - Commands.Exec_Selection_In_Terminal, | ||
| 50 | - this.executeSelectionInTerminal.bind(this), | ||
| 51 | - ), | ||
| 52 | + this.commandManager.registerCommand(Commands.Exec_Selection_In_Terminal as any, async (file: Resource) => { | ||
| 53 | + await this.executeSelectionInTerminal().then(() => { | ||
| 54 | + if (this.shouldTerminalFocusOnStart(file)) | ||
| 55 | + this.commandManager.executeCommand('workbench.action.terminal.focus'); | ||
| 56 | + }); | ||
| 57 | + }), | ||
| 52 | 58 | ); | |
| 53 | 59 | this.disposableRegistry.push( | |
| 54 | 60 | this.commandManager.registerCommand( | |
| 55 | - Commands.Exec_Selection_In_Django_Shell, | ||
| 56 | - this.executeSelectionInDjangoShell.bind(this), | ||
| 61 | + Commands.Exec_Selection_In_Django_Shell as any, | ||
| 62 | + async (file: Resource) => { | ||
| 63 | + await this.executeSelectionInDjangoShell().then(() => { | ||
| 64 | + if (this.shouldTerminalFocusOnStart(file)) | ||
| 65 | + this.commandManager.executeCommand('workbench.action.terminal.focus'); | ||
| 66 | + }); | ||
| 67 | + }, | ||
| 57 | 68 | ), | |
| 58 | 69 | ); | |
| 59 | 70 | } | |
@@ -115,4 +126,8 @@ export class CodeExecutionManager implements ICodeExecutionManager { | |||
| 115 | 126 | ||
| 116 | 127 | await executionService.execute(normalizedCode, activeEditor!.document.uri); | |
| 117 | 128 | } | |
| 129 | + | ||
| 130 | + private shouldTerminalFocusOnStart(uri: Uri | undefined): boolean { | ||
| 131 | + return this.configSettings.getSettings(uri)?.terminal.focusAfterLaunch; | ||
| 132 | + } | ||
| 118 | 133 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,10 +6,11 @@ | |||
| 6 | 6 | import * as assert from 'assert'; | |
| 7 | 7 | import { anything, instance, mock, verify, when } from 'ts-mockito'; | |
| 8 | 8 | import { IExtensionSingleActivationService } from '../../../../client/activation/types'; | |
| 9 | + import { CommandManager } from '../../../../client/common/application/commandManager'; | ||
| 9 | 10 | import { DebugService } from '../../../../client/common/application/debugService'; | |
| 10 | - import { IDebugService } from '../../../../client/common/application/types'; | ||
| 11 | + import { ICommandManager, IDebugService } from '../../../../client/common/application/types'; | ||
| 11 | 12 | import { ConfigurationService } from '../../../../client/common/configuration/service'; | |
| 12 | - import { IDisposableRegistry, IPythonSettings } from '../../../../client/common/types'; | ||
| 13 | + import { IConfigurationService, IDisposableRegistry, IPythonSettings } from '../../../../client/common/types'; | ||
| 13 | 14 | import { DebugAdapterActivator } from '../../../../client/debugger/extension/adapter/activator'; | |
| 14 | 15 | import { DebugAdapterDescriptorFactory } from '../../../../client/debugger/extension/adapter/factory'; | |
| 15 | 16 | import { DebugSessionLoggingFactory } from '../../../../client/debugger/extension/adapter/logging'; | |
@@ -27,27 +28,36 @@ import { noop } from '../../../core'; | |||
| 27 | 28 | suite('Debugging - Adapter Factory and logger Registration', () => { | |
| 28 | 29 | let activator: IExtensionSingleActivationService; | |
| 29 | 30 | let debugService: IDebugService; | |
| 31 | + let commandManager: ICommandManager; | ||
| 30 | 32 | let descriptorFactory: IDebugAdapterDescriptorFactory; | |
| 31 | 33 | let loggingFactory: IDebugSessionLoggingFactory; | |
| 32 | 34 | let debuggerPromptFactory: IOutdatedDebuggerPromptFactory; | |
| 33 | 35 | let disposableRegistry: IDisposableRegistry; | |
| 34 | 36 | let attachFactory: IAttachProcessProviderFactory; | |
| 37 | + let configService: IConfigurationService; | ||
| 35 | 38 | ||
| 36 | 39 | setup(() => { | |
| 37 | - const configurationService = mock(ConfigurationService); | ||
| 40 | + attachFactory = mock(AttachProcessProviderFactory); | ||
| 41 | + | ||
| 42 | + debugService = mock(DebugService); | ||
| 43 | + when(debugService.onDidStartDebugSession).thenReturn(() => noop as any); | ||
| 44 | + | ||
| 45 | + commandManager = mock(CommandManager); | ||
| 38 | 46 | ||
| 39 | - when(configurationService.getSettings(undefined)).thenReturn(({ | ||
| 47 | + configService = mock(ConfigurationService); | ||
| 48 | + when(configService.getSettings(undefined)).thenReturn(({ | ||
| 40 | 49 | experiments: { enabled: true }, | |
| 41 | 50 | } as any) as IPythonSettings); | |
| 42 | - attachFactory = mock(AttachProcessProviderFactory); | ||
| 43 | 51 | ||
| 44 | - debugService = mock(DebugService); | ||
| 45 | 52 | descriptorFactory = mock(DebugAdapterDescriptorFactory); | |
| 46 | 53 | loggingFactory = mock(DebugSessionLoggingFactory); | |
| 47 | 54 | debuggerPromptFactory = mock(OutdatedDebuggerPromptFactory); | |
| 48 | 55 | disposableRegistry = []; | |
| 56 | + | ||
| 49 | 57 | activator = new DebugAdapterActivator( | |
| 50 | 58 | instance(debugService), | |
| 59 | + instance(configService), | ||
| 60 | + instance(commandManager), | ||
| 51 | 61 | instance(descriptorFactory), | |
| 52 | 62 | instance(loggingFactory), | |
| 53 | 63 | instance(debuggerPromptFactory), | |
@@ -72,9 +82,10 @@ suite('Debugging - Adapter Factory and logger Registration', () => { | |||
| 72 | 82 | const disposable = { dispose: noop }; | |
| 73 | 83 | when(debugService.registerDebugAdapterTrackerFactory(anything(), anything())).thenReturn(disposable); | |
| 74 | 84 | when(debugService.registerDebugAdapterDescriptorFactory(anything(), anything())).thenReturn(disposable); | |
| 85 | + when(debugService.onDidStartDebugSession).thenReturn(() => disposable); | ||
| 75 | 86 | ||
| 76 | 87 | await activator.activate(); | |
| 77 | 88 | ||
| 78 | - assert.deepEqual(disposableRegistry, [disposable, disposable, disposable]); | ||
| 89 | + assert.deepEqual(disposableRegistry, [disposable, disposable, disposable, disposable]); | ||
| 79 | 90 | }); | |
| 80 | 91 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ import { IFileSystem } from '../../../client/common/platform/types'; | |||
| 10 | 10 | import { IServiceContainer } from '../../../client/ioc/types'; | |
| 11 | 11 | import { CodeExecutionManager } from '../../../client/terminals/codeExecution/codeExecutionManager'; | |
| 12 | 12 | import { ICodeExecutionHelper, ICodeExecutionManager, ICodeExecutionService } from '../../../client/terminals/types'; | |
| 13 | + import { IConfigurationService } from '../../../client/common/types'; | ||
| 13 | 14 | ||
| 14 | 15 | suite('Terminal - Code Execution Manager', () => { | |
| 15 | 16 | let executionManager: ICodeExecutionManager; | |
@@ -18,6 +19,7 @@ suite('Terminal - Code Execution Manager', () => { | |||
| 18 | 19 | let disposables: Disposable[] = []; | |
| 19 | 20 | let serviceContainer: TypeMoq.IMock<IServiceContainer>; | |
| 20 | 21 | let documentManager: TypeMoq.IMock<IDocumentManager>; | |
| 22 | + let configService: TypeMoq.IMock<IConfigurationService>; | ||
| 21 | 23 | let fileSystem: TypeMoq.IMock<IFileSystem>; | |
| 22 | 24 | setup(() => { | |
| 23 | 25 | fileSystem = TypeMoq.Mock.ofType<IFileSystem>(); | |
@@ -33,11 +35,13 @@ suite('Terminal - Code Execution Manager', () => { | |||
| 33 | 35 | documentManager = TypeMoq.Mock.ofType<IDocumentManager>(); | |
| 34 | 36 | commandManager = TypeMoq.Mock.ofType<ICommandManager>(undefined, TypeMoq.MockBehavior.Strict); | |
| 35 | 37 | serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>(); | |
| 38 | + configService = TypeMoq.Mock.ofType<IConfigurationService>(); | ||
| 36 | 39 | executionManager = new CodeExecutionManager( | |
| 37 | 40 | commandManager.object, | |
| 38 | 41 | documentManager.object, | |
| 39 | 42 | disposables, | |
| 40 | 43 | fileSystem.object, | |
| 44 | + configService.object, | ||
| 41 | 45 | serviceContainer.object, | |
| 42 | 46 | ); | |
| 43 | 47 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments