Skip to content
6 changes: 6 additions & 0 deletions src/client/common/serviceRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { IProcessLogger } from './process/types';
import { TerminalActivator } from './terminal/activator';
import { PowershellTerminalActivationFailedHandler } from './terminal/activator/powershellFailedHandler';
import { Bash } from './terminal/environmentActivationProviders/bash';
import { Nushell } from './terminal/environmentActivationProviders/nushell';
import { CommandPromptAndPowerShell } from './terminal/environmentActivationProviders/commandPrompt';
import { CondaActivationCommandProvider } from './terminal/environmentActivationProviders/condaActivationProvider';
import { PipEnvActivationCommandProvider } from './terminal/environmentActivationProviders/pipEnvActivationProvider';
Expand Down Expand Up @@ -149,6 +150,11 @@ export function registerTypes(serviceManager: IServiceManager): void {
CommandPromptAndPowerShell,
TerminalActivationProviders.commandPromptAndPowerShell,
);
serviceManager.addSingleton<ITerminalActivationCommandProvider>(
ITerminalActivationCommandProvider,
Nushell,
TerminalActivationProviders.nushell,
);
serviceManager.addSingleton<ITerminalActivationCommandProvider>(
ITerminalActivationCommandProvider,
PyEnvActivationCommandProvider,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { injectable } from 'inversify';
import '../../extensions';
import { TerminalShellType } from '../types';
import { ActivationScripts, VenvBaseActivationCommandProvider } from './baseActivationProvider';

// For a given shell the scripts are in order of precedence.
const SCRIPTS: ActivationScripts = {
[TerminalShellType.nushell]: ['activate.nu'],
} as ActivationScripts;

export function getAllScripts(): string[] {
const scripts: string[] = [];
for (const key of Object.keys(SCRIPTS)) {
const shell = key as TerminalShellType;
for (const name of SCRIPTS[shell]) {
if (!scripts.includes(name)) {
scripts.push(name);
}
}
}
return scripts;
}

@injectable()
export class Nushell extends VenvBaseActivationCommandProvider {
protected readonly scripts = SCRIPTS;

public async getActivationCommandsForInterpreter(
pythonPath: string,
targetShell: TerminalShellType,
): Promise<string[] | undefined> {
const scriptFile = await this.findScriptFile(pythonPath, targetShell);
if (!scriptFile) {
return;
}
return [`overlay activate ${scriptFile.fileToCommandArgumentForPythonExt()}`];
}
}
7 changes: 5 additions & 2 deletions src/client/common/terminal/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export class TerminalHelper implements ITerminalHelper {
@named(TerminalActivationProviders.commandPromptAndPowerShell)
private readonly commandPromptAndPowerShell: ITerminalActivationCommandProvider,
@inject(ITerminalActivationCommandProvider)
@named(TerminalActivationProviders.nushell)
private readonly nushell: ITerminalActivationCommandProvider,
@inject(ITerminalActivationCommandProvider)
@named(TerminalActivationProviders.pyenv)
private readonly pyenv: ITerminalActivationCommandProvider,
@inject(ITerminalActivationCommandProvider)
Expand Down Expand Up @@ -72,7 +75,7 @@ export class TerminalHelper implements ITerminalHelper {
resource?: Uri,
interpreter?: PythonEnvironment,
): Promise<string[] | undefined> {
const providers = [this.pipenv, this.pyenv, this.bashCShellFish, this.commandPromptAndPowerShell];
const providers = [this.pipenv, this.pyenv, this.bashCShellFish, this.commandPromptAndPowerShell, this.nushell];
const promise = this.getActivationCommands(resource || undefined, interpreter, terminalShellType, providers);
this.sendTelemetry(
terminalShellType,
Expand All @@ -90,7 +93,7 @@ export class TerminalHelper implements ITerminalHelper {
if (this.platform.osType === OSType.Unknown) {
return;
}
const providers = [this.bashCShellFish, this.commandPromptAndPowerShell];
const providers = [this.bashCShellFish, this.commandPromptAndPowerShell, this.nushell];
const promise = this.getActivationCommands(resource, interpreter, shell, providers);
this.sendTelemetry(
shell,
Expand Down
2 changes: 2 additions & 0 deletions src/client/common/terminal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { IDisposable, Resource } from '../types';
export enum TerminalActivationProviders {
bashCShellFish = 'bashCShellFish',
commandPromptAndPowerShell = 'commandPromptAndPowerShell',
nushell = 'nushell',
pyenv = 'pyenv',
conda = 'conda',
pipenv = 'pipenv',
Expand All @@ -26,6 +27,7 @@ export enum TerminalShellType {
fish = 'fish',
cshell = 'cshell',
tcshell = 'tshell',
nushell = 'nushell',
wsl = 'wsl',
xonsh = 'xonsh',
other = 'other',
Expand Down