Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2 Fixes/15439.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix for missing pyenv virtual environments from selectable environments.
1 change: 1 addition & 0 deletions news/2 Fixes/15452.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Register Jedi regardless of what language server is configured.
1 change: 1 addition & 0 deletions src/client/activation/activationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ export class LanguageServerExtensionActivationService
if (serverType === LanguageServerType.Jedi) {
throw ex;
}
traceError(ex);
this.output.appendLine(LanguageService.lsFailedToStart());
serverType = LanguageServerType.Jedi;
server = this.serviceContainer.get<ILanguageServerActivator>(ILanguageServerActivator, serverType);
Expand Down
11 changes: 5 additions & 6 deletions src/client/activation/serviceRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ export function registerTypes(serviceManager: IServiceManager, languageServerTyp
ILanguageServerFolderService,
NodeLanguageServerFolderService,
);
} else if (languageServerType === LanguageServerType.Jedi) {
serviceManager.add<ILanguageServerActivator>(
ILanguageServerActivator,
JediExtensionActivator,
LanguageServerType.Jedi,
);
} else if (languageServerType === LanguageServerType.JediLSP) {
serviceManager.add<ILanguageServerActivator>(
ILanguageServerActivator,
Expand All @@ -165,6 +159,11 @@ export function registerTypes(serviceManager: IServiceManager, languageServerTyp
LanguageServerType.None,
);
}
serviceManager.add<ILanguageServerActivator>(
ILanguageServerActivator,
JediExtensionActivator,
LanguageServerType.Jedi,
); // We fallback to Jedi if for some reason we're unable to use other language servers, hence register this always.

serviceManager.addSingleton<IDownloadChannelRule>(
IDownloadChannelRule,
Expand Down
32 changes: 22 additions & 10 deletions src/client/pythonEnvironments/common/externalDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,35 @@ export async function getFileInfo(filePath: string): Promise<{ ctime: number; mt
}
}

export async function resolveSymbolicLink(filepath: string): Promise<string> {
const stats = await fsapi.lstat(filepath);
export async function resolveSymbolicLink(absPath: string): Promise<string> {
const stats = await fsapi.lstat(absPath);
if (stats.isSymbolicLink()) {
const link = await fsapi.readlink(filepath);
const link = await fsapi.readlink(absPath);
return resolveSymbolicLink(link);
}
return filepath;
return absPath;
}

export async function* getSubDirs(root: string): AsyncIterableIterator<string> {
const dirContents = await fsapi.readdir(root);
/**
* Returns full path to sub directories of a given directory.
* @param root
* @param resolveSymlinks
*/
export async function* getSubDirs(root: string, resolveSymlinks: boolean): AsyncIterableIterator<string> {
const dirContents = await fsapi.promises.readdir(root, { withFileTypes: true });
const generators = dirContents.map((item) => {
async function* generator() {
const stat = await fsapi.lstat(path.join(root, item));

if (stat.isDirectory()) {
yield item;
const fullPath = path.join(root, item.name);
if (item.isDirectory()) {
yield fullPath;
} else if (resolveSymlinks && item.isSymbolicLink()) {
// The current FS item is a symlink. It can potentially be a file
// or a directory. Resolve it first and then check if it is a directory.
const resolvedPath = await resolveSymbolicLink(fullPath);
const resolvedPathStat = await fsapi.lstat(resolvedPath);
if (resolvedPathStat.isDirectory()) {
yield resolvedPath;
}
}
}

Expand Down
23 changes: 2 additions & 21 deletions src/client/pythonEnvironments/discovery/locators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
CURRENT_PATH_SERVICE,
GetInterpreterLocatorOptions,
GLOBAL_VIRTUAL_ENV_SERVICE,
IComponentAdapter,
IInterpreterLocatorHelper,
IInterpreterLocatorService,
KNOWN_PATH_SERVICE,
Expand Down Expand Up @@ -182,12 +181,6 @@ export class WorkspaceLocators extends LazyResourceBasedLocator {
}
}

// The parts of IComponentAdapter used here.
interface IComponent {
hasInterpreters: Promise<boolean | undefined>;
getInterpreters(resource?: Uri, options?: GetInterpreterLocatorOptions): Promise<PythonEnvironment[] | undefined>;
}

/**
* Facilitates locating Python interpreters.
*/
Expand All @@ -207,10 +200,7 @@ export class PythonInterpreterLocatorService implements IInterpreterLocatorServi
Promise<PythonEnvironment[]>
>();

constructor(
@inject(IServiceContainer) private serviceContainer: IServiceContainer,
@inject(IComponentAdapter) private readonly pyenvs: IComponent,
) {
constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer) {
this._hasInterpreters = createDeferred<boolean>();
serviceContainer.get<Disposable[]>(IDisposableRegistry).push(this);
this.platform = serviceContainer.get<IPlatformService>(IPlatformService);
Expand All @@ -231,12 +221,7 @@ export class PythonInterpreterLocatorService implements IInterpreterLocatorServi
}

public get hasInterpreters(): Promise<boolean> {
return this.pyenvs.hasInterpreters.then((res) => {
if (res !== undefined) {
return res;
}
return this._hasInterpreters.completed ? this._hasInterpreters.promise : Promise.resolve(false);
});
return this._hasInterpreters.completed ? this._hasInterpreters.promise : Promise.resolve(false);
}

/**
Expand All @@ -256,10 +241,6 @@ export class PythonInterpreterLocatorService implements IInterpreterLocatorServi
*/
@traceDecorators.verbose('Get Interpreters')
public async getInterpreters(resource?: Uri, options?: GetInterpreterLocatorOptions): Promise<PythonEnvironment[]> {
const envs = await this.pyenvs.getInterpreters(resource, options);
if (envs !== undefined) {
return envs;
}
const locators = this.getLocators(options);
const promises = locators.map(async (provider) => provider.getInterpreters(resource));
locators.forEach((locator) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,15 @@ export function parsePyenvVersion(str: string): Promise<IPyenvVersionStrings | u
async function* getPyenvEnvironments(): AsyncIterableIterator<PythonEnvInfo> {
const pyenvVersionDir = getPyenvVersionsDir();

const subDirs = getSubDirs(pyenvVersionDir);
for await (const subDir of subDirs) {
const envDir = path.join(pyenvVersionDir, subDir);
const interpreterPath = await getInterpreterPathFromDir(envDir);
const subDirs = getSubDirs(pyenvVersionDir, true);
for await (const subDirPath of subDirs) {
const envDirName = path.basename(subDirPath);
const interpreterPath = await getInterpreterPathFromDir(subDirPath);

if (interpreterPath) {
// The sub-directory name sometimes can contain distro and python versions.
// here we attempt to extract the texts out of the name.
const versionStrings = await parsePyenvVersion(subDir);
const versionStrings = await parsePyenvVersion(envDirName);

// Here we look for near by files, or config files to see if we can get python version info
// without running python itself.
Expand All @@ -290,7 +290,7 @@ async function* getPyenvEnvironments(): AsyncIterableIterator<PythonEnvInfo> {
// `pyenv local|global <env-name>` or `pyenv shell <env-name>`
//
// For the display name we are going to treat these as `pyenv` environments.
const display = `${subDir}:pyenv`;
const display = `${envDirName}:pyenv`;

const org = versionStrings && versionStrings.distro ? versionStrings.distro : '';

Expand All @@ -299,14 +299,14 @@ async function* getPyenvEnvironments(): AsyncIterableIterator<PythonEnvInfo> {
const envInfo = buildEnvInfo({
kind: PythonEnvKind.Pyenv,
executable: interpreterPath,
location: envDir,
location: subDirPath,
version: pythonVersion,
source: [PythonEnvSource.Pyenv],
display,
org,
fileInfo,
});
envInfo.name = subDir;
envInfo.name = envDirName;

yield envInfo;
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/activation/serviceRegistry.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DownloadBetaChannelRule, DownloadDailyChannelRule } from '../../client/
import { LanguageServerDownloader } from '../../client/activation/common/downloader';
import { LanguageServerDownloadChannel } from '../../client/activation/common/packageRepository';
import { ExtensionSurveyPrompt } from '../../client/activation/extensionSurvey';
import { JediExtensionActivator } from '../../client/activation/jedi';
import { DotNetLanguageServerActivator } from '../../client/activation/languageServer/activator';
import { DotNetLanguageServerAnalysisOptions } from '../../client/activation/languageServer/analysisOptions';
import { DotNetLanguageClientFactory } from '../../client/activation/languageServer/languageClientFactory';
Expand Down Expand Up @@ -161,6 +162,13 @@ suite('Unit Tests - Language Server Activation Service Registry', () => {
LanguageServerType.Microsoft,
),
).once();
verify(
serviceManager.add<ILanguageServerActivator>(
ILanguageServerActivator,
JediExtensionActivator,
LanguageServerType.Jedi,
),
).once();
verify(serviceManager.add<ILanguageServerProxy>(ILanguageServerProxy, DotNetLanguageServerProxy)).once();
verify(serviceManager.add<ILanguageServerManager>(ILanguageServerManager, DotNetLanguageServerManager)).once();
verify(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
CONDA_ENV_SERVICE,
CURRENT_PATH_SERVICE,
GLOBAL_VIRTUAL_ENV_SERVICE,
IComponentAdapter,
IInterpreterLocatorHelper,
IInterpreterLocatorService,
KNOWN_PATH_SERVICE,
Expand Down Expand Up @@ -785,21 +784,18 @@ suite('Interpreters - Locators Index', () => {
let serviceContainer: TypeMoq.IMock<IServiceContainer>;
let platformSvc: TypeMoq.IMock<IPlatformService>;
let helper: TypeMoq.IMock<IInterpreterLocatorHelper>;
let pyenvs: TypeMoq.IMock<IComponentAdapter>;
let locator: IInterpreterLocatorService;
setup(() => {
serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>();
platformSvc = TypeMoq.Mock.ofType<IPlatformService>();
helper = TypeMoq.Mock.ofType<IInterpreterLocatorHelper>();
pyenvs = TypeMoq.Mock.ofType<IComponentAdapter>();
serviceContainer.setup((c) => c.get(TypeMoq.It.isValue(IDisposableRegistry))).returns(() => []);
serviceContainer.setup((c) => c.get(TypeMoq.It.isValue(IPlatformService))).returns(() => platformSvc.object);
serviceContainer.setup((c) => c.get(TypeMoq.It.isValue(IComponentAdapter))).returns(() => pyenvs.object);
serviceContainer
.setup((c) => c.get(TypeMoq.It.isValue(IInterpreterLocatorHelper)))
.returns(() => helper.object);

locator = new PythonInterpreterLocatorService(serviceContainer.object, pyenvs.object);
locator = new PythonInterpreterLocatorService(serviceContainer.object);
});
[undefined, Uri.file('Something')].forEach((resource) => {
getNamesAndValues<OSType>(OSType).forEach((osType) => {
Expand Down