Skip to content
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

Do not attempt to launch Jedi language server in case when selected Python interpreter is invalid #19449

Merged
merged 3 commits into from
Jul 11, 2022
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
10 changes: 7 additions & 3 deletions src/client/languageServer/jediLSExtensionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { IEnvironmentVariablesProvider } from '../common/variables/types';
import { IInterpreterService } from '../interpreter/contracts';
import { IServiceContainer } from '../ioc/types';
import { traceError } from '../logging';
import { PythonEnvironment } from '../pythonEnvironments/info';
import { LanguageServerCapabilities } from './languageServerCapabilities';
import { ILanguageServerExtensionManager } from './types';
Expand Down Expand Up @@ -78,10 +79,13 @@ export class JediLSExtensionManager extends LanguageServerCapabilities
}

// eslint-disable-next-line class-methods-use-this
canStartLanguageServer(): boolean {
// Return true for now since it's shipped with the extension.
canStartLanguageServer(interpreter: PythonEnvironment | undefined): boolean {
if (!interpreter) {
traceError('Unable to start Jedi language server as a valid interpreter is not selected');
return false;
}
// Otherwise return true for now since it's shipped with the extension.
// Update this when JediLSP is pulled in a separate extension.

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/languageServer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface ILanguageServerCapabilities extends ILanguageServer {
export interface ILanguageServerExtensionManager extends ILanguageServerCapabilities {
startLanguageServer(resource: Resource, interpreter?: PythonEnvironment): Promise<void>;
stopLanguageServer(): Promise<void>;
canStartLanguageServer(): boolean;
canStartLanguageServer(interpreter: PythonEnvironment | undefined): boolean;
languageServerNotAvailable(): Promise<void>;
dispose(): void;
}
2 changes: 1 addition & 1 deletion src/client/languageServer/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class LanguageServerWatcher
const languageServerExtensionManager = this.createLanguageServer(serverType);
this.workspaceLanguageServers.set(key, languageServerExtensionManager);

if (languageServerExtensionManager.canStartLanguageServer()) {
if (languageServerExtensionManager.canStartLanguageServer(interpreter)) {
// Start the language server.
await languageServerExtensionManager.startLanguageServer(lsResource, interpreter);

Expand Down
13 changes: 11 additions & 2 deletions src/test/languageServer/jediLSExtensionManager.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IEnvironmentVariablesProvider } from '../../client/common/variables/typ
import { IInterpreterService } from '../../client/interpreter/contracts';
import { IServiceContainer } from '../../client/ioc/types';
import { JediLSExtensionManager } from '../../client/languageServer/jediLSExtensionManager';
import { PythonEnvironment } from '../../client/pythonEnvironments/info';

suite('Language Server - Jedi LS extension manager', () => {
let manager: JediLSExtensionManager;
Expand Down Expand Up @@ -37,9 +38,17 @@ suite('Language Server - Jedi LS extension manager', () => {
assert.notStrictEqual(manager.serverProxy, undefined);
});

test('canStartLanguageServer should return true', () => {
const result = manager.canStartLanguageServer();
test('canStartLanguageServer should return true if an interpreter is passed in', () => {
const result = manager.canStartLanguageServer(({
path: 'path/to/interpreter',
} as unknown) as PythonEnvironment);

assert.strictEqual(result, true);
});

test('canStartLanguageServer should return false otherwise', () => {
const result = manager.canStartLanguageServer(undefined);

assert.strictEqual(result, false);
});
});