Skip to content

Displayed actionable message when LS is not supported #3864

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

Merged
merged 9 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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/1 Enhancements/3634.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Display actionable message when LS is not supported
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"diagnostics.disableSourceMaps": "Disable Source Map Support",
"diagnostics.warnBeforeEnablingSourceMaps": "Enabling source map support in the Python Extension will adversely impact performance of the extension.",
"diagnostics.enableSourceMapsAndReloadVSC": "Enable and reload Window",
"diagnostics.lsNotSupported": "Your operating system does not meet the minimum requirements of the Language Server. Reverting to the alternative, Jedi.",
"DataScience.interruptKernel": "Interrupt iPython Kernel",
"DataScience.exportingFormat": "Exporting {0}",
"DataScience.exportCancel": "Cancel",
Expand Down
12 changes: 8 additions & 4 deletions src/client/activation/activationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

import { inject, injectable } from 'inversify';
import {
ConfigurationChangeEvent, Disposable,
OutputChannel, Uri
ConfigurationChangeEvent,
Disposable, OutputChannel, Uri
} from 'vscode';
import { LSNotSupportedDiagnosticService } from '../application/diagnostics/checks/lsNotSupported';
import { IDiagnostic } from '../application/diagnostics/types';
import {
IApplicationShell, ICommandManager,
IWorkspaceService
Expand Down Expand Up @@ -36,13 +38,14 @@ export class ExtensionActivationService implements IExtensionActivationService,
private readonly workspaceService: IWorkspaceService;
private readonly output: OutputChannel;
private readonly appShell: IApplicationShell;
private readonly lsNotSupportedDiagnosticService: LSNotSupportedDiagnosticService;

constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer,
@inject(ILanguageServerCompatibilityService) private readonly lsCompatibility: ILanguageServerCompatibilityService) {
this.workspaceService = this.serviceContainer.get<IWorkspaceService>(IWorkspaceService);
this.output = this.serviceContainer.get<OutputChannel>(IOutputChannel, STANDARD_OUTPUT_CHANNEL);
this.appShell = this.serviceContainer.get<IApplicationShell>(IApplicationShell);

this.lsNotSupportedDiagnosticService = new LSNotSupportedDiagnosticService(serviceContainer);
const disposables = serviceContainer.get<IDisposableRegistry>(IDisposableRegistry);
disposables.push(this);
disposables.push(this.workspaceService.onDidChangeConfiguration(this.onDidChangeConfiguration.bind(this)));
Expand All @@ -55,8 +58,9 @@ export class ExtensionActivationService implements IExtensionActivationService,

let jedi = this.useJedi();
if (!jedi && !await this.lsCompatibility.isSupported()) {
this.appShell.showWarningMessage('The Python Language Server is not supported on your platform.');
sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_PLATFORM_NOT_SUPPORTED);
const diagnostic: IDiagnostic[] = await this.lsNotSupportedDiagnosticService.diagnose();
await this.lsNotSupportedDiagnosticService.handle(diagnostic);
jedi = true;
}

Expand Down
54 changes: 54 additions & 0 deletions src/client/application/diagnostics/checks/lsNotSupported.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import { inject } from 'inversify';
import { DiagnosticSeverity } from 'vscode';
import { Diagnostics } from '../../../common/utils/localize';
import { IServiceContainer } from '../../../ioc/types';
import { BaseDiagnostic, BaseDiagnosticsService } from '../base';
import { IDiagnosticsCommandFactory } from '../commands/types';
import { DiagnosticCodes } from '../constants';
import { DiagnosticCommandPromptHandlerServiceId, MessageCommandPrompt } from '../promptHandler';
import { DiagnosticScope, IDiagnostic, IDiagnosticHandlerService } from '../types';

export class LSNotSupportedDiagnostic extends BaseDiagnostic {
constructor(message) {
super(DiagnosticCodes.LSNotSupportedDiagnostic,
message, DiagnosticSeverity.Warning, DiagnosticScope.Global);
}
}

export class LSNotSupportedDiagnosticService extends BaseDiagnosticsService {
protected readonly messageService: IDiagnosticHandlerService<MessageCommandPrompt>;
constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) {
super([DiagnosticCodes.LSNotSupportedDiagnostic], serviceContainer);
this.messageService = serviceContainer.get<IDiagnosticHandlerService<MessageCommandPrompt>>(IDiagnosticHandlerService, DiagnosticCommandPromptHandlerServiceId);
}
public async diagnose(): Promise<IDiagnostic[]>{
return [new LSNotSupportedDiagnostic(Diagnostics.lsNotSupported())];
}
public async handle(diagnostics: IDiagnostic[]): Promise<void>{
if (diagnostics.length === 0 || !this.canHandle(diagnostics[0])) {
return;
}
const diagnostic = diagnostics[0];
if (await this.filterService.shouldIgnoreDiagnostic(diagnostic.code)) {
return;
}
const commandFactory = this.serviceContainer.get<IDiagnosticsCommandFactory>(IDiagnosticsCommandFactory);
const options = [
{
prompt: 'More Info',
command: commandFactory.createCommand(diagnostic, { type: 'launch', options: 'https://aka.ms/AA3qqka' })
},
{
prompt: 'Do not show again',
command: commandFactory.createCommand(diagnostic, { type: 'ignore', options: DiagnosticScope.Global })
}
];

await this.messageService.handle(diagnostic, { commandPrompts: options });
}
}
3 changes: 2 additions & 1 deletion src/client/application/diagnostics/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export enum DiagnosticCodes {
MacInterpreterSelectedAndHaveOtherInterpretersDiagnostic = 'MacInterpreterSelectedAndHaveOtherInterpretersDiagnostic',
InvalidPythonPathInDebuggerDiagnostic = 'InvalidPythonPathInDebuggerDiagnostic',
EnvironmentActivationInPowerShellWithBatchFilesNotSupportedDiagnostic = 'EnvironmentActivationInPowerShellWithBatchFilesNotSupportedDiagnostic',
NoCurrentlySelectedPythonInterpreterDiagnostic = 'InvalidPythonInterpreterDiagnostic'
NoCurrentlySelectedPythonInterpreterDiagnostic = 'InvalidPythonInterpreterDiagnostic',
LSNotSupportedDiagnostic = 'LSNotSupportedDiagnostic'
}
1 change: 1 addition & 0 deletions src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export namespace Diagnostics {
export const disableSourceMaps = localize('diagnostics.disableSourceMaps', 'Disable Source Map Support');
export const warnBeforeEnablingSourceMaps = localize('diagnostics.warnBeforeEnablingSourceMaps', 'Enabling source map support in the Python Extension will adversely impact performance of the extension.');
export const enableSourceMapsAndReloadVSC = localize('diagnostics.enableSourceMapsAndReloadVSC', 'Enable and reload Window.');
export const lsNotSupported = localize('diagnostics.lsNotSupported', 'Your operating system does not meet the minimum requirements of the Language Server. Reverting to the alternative, Jedi.');
}

export namespace Common {
Expand Down
14 changes: 13 additions & 1 deletion src/test/activation/activationService.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import {
ILanguageServerCompatibilityService,
ILanguageServerFolderService
} from '../../client/activation/types';
import { IDiagnosticsCommandFactory } from '../../client/application/diagnostics/commands/types';
import { DiagnosticCommandPromptHandlerServiceId, MessageCommandPrompt } from '../../client/application/diagnostics/promptHandler';
import { IDiagnosticFilterService, IDiagnosticHandlerService } from '../../client/application/diagnostics/types';
import {
IApplicationShell, ICommandManager,
IWorkspaceService
Expand All @@ -36,6 +39,9 @@ suite('Activation - ActivationService', () => {
let workspaceService: TypeMoq.IMock<IWorkspaceService>;
let platformService: TypeMoq.IMock<IPlatformService>;
let lanagueServerSupportedService: TypeMoq.IMock<ILanguageServerCompatibilityService>;
let filterService: TypeMoq.IMock<IDiagnosticFilterService>;
let commandFactory: TypeMoq.IMock<IDiagnosticsCommandFactory>;
let messageHandler: TypeMoq.IMock<IDiagnosticHandlerService<MessageCommandPrompt>>;
setup(() => {
serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>();
appShell = TypeMoq.Mock.ofType<IApplicationShell>();
Expand All @@ -50,6 +56,9 @@ suite('Activation - ActivationService', () => {
version: new SemVer('1.2.3')
};
lanagueServerSupportedService = TypeMoq.Mock.ofType<ILanguageServerCompatibilityService>();
filterService = TypeMoq.Mock.ofType<IDiagnosticFilterService>();
commandFactory = TypeMoq.Mock.ofType<IDiagnosticsCommandFactory>();
messageHandler = TypeMoq.Mock.ofType<IDiagnosticHandlerService<MessageCommandPrompt>>();
workspaceService.setup(w => w.hasWorkspaceFolders).returns(() => false);
workspaceService.setup(w => w.workspaceFolders).returns(() => []);
configService.setup(c => c.getSettings(TypeMoq.It.isAny())).returns(() => pythonSettings.object);
Expand All @@ -64,7 +73,10 @@ suite('Activation - ActivationService', () => {
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(ICommandManager))).returns(() => cmdManager.object);
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IPlatformService))).returns(() => platformService.object);
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(ILanguageServerFolderService))).returns(() => langFolderServiceMock.object);
});
serviceContainer.setup(s => s.get(TypeMoq.It.isValue(IDiagnosticFilterService))).returns(() => filterService.object);
serviceContainer.setup(s => s.get(TypeMoq.It.isValue(IDiagnosticsCommandFactory))).returns(() => commandFactory.object);
serviceContainer.setup(s => s.get(TypeMoq.It.isValue(IDiagnosticHandlerService), TypeMoq.It.isValue(DiagnosticCommandPromptHandlerServiceId))).returns(() => messageHandler.object);
});

async function testActivation(activationService: IExtensionActivationService, activator: TypeMoq.IMock<IExtensionActivator>, lsSupported: boolean = true) {
activator
Expand Down
101 changes: 101 additions & 0 deletions src/test/application/diagnostics/checks/lsNotSupported.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import { expect } from 'chai';
import * as TypeMoq from 'typemoq';
import { LSNotSupportedDiagnosticService } from '../../../../client/application/diagnostics/checks/lsNotSupported';
import { CommandOption, IDiagnosticsCommandFactory } from '../../../../client/application/diagnostics/commands/types';
import { DiagnosticCodes } from '../../../../client/application/diagnostics/constants';
import { DiagnosticCommandPromptHandlerServiceId, MessageCommandPrompt } from '../../../../client/application/diagnostics/promptHandler';
import { DiagnosticScope, IDiagnostic, IDiagnosticCommand, IDiagnosticFilterService, IDiagnosticHandlerService, IDiagnosticsService } from '../../../../client/application/diagnostics/types';
import { IServiceContainer } from '../../../../client/ioc/types';

suite('Application Diagnostics - Checks Env Path Variable', () => {
let serviceContainer: TypeMoq.IMock<IServiceContainer>;
let diagnosticService: IDiagnosticsService;
let filterService: TypeMoq.IMock<IDiagnosticFilterService>;
let commandFactory: TypeMoq.IMock<IDiagnosticsCommandFactory>;
let messageHandler: TypeMoq.IMock<IDiagnosticHandlerService<MessageCommandPrompt>>;
setup(() => {
serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>();
filterService = TypeMoq.Mock.ofType<IDiagnosticFilterService>();
commandFactory = TypeMoq.Mock.ofType<IDiagnosticsCommandFactory>();
messageHandler = TypeMoq.Mock.ofType<IDiagnosticHandlerService<MessageCommandPrompt>>();
serviceContainer.setup(s => s.get(TypeMoq.It.isValue(IDiagnosticFilterService))).returns(() => filterService.object);
serviceContainer.setup(s => s.get(TypeMoq.It.isValue(IDiagnosticsCommandFactory))).returns(() => commandFactory.object);
serviceContainer.setup(s => s.get(TypeMoq.It.isValue(IDiagnosticHandlerService), TypeMoq.It.isValue(DiagnosticCommandPromptHandlerServiceId))).returns(() => messageHandler.object);

diagnosticService = new LSNotSupportedDiagnosticService(serviceContainer.object);
});

test('Should display two options in message displayed with 2 commands', async () => {
let options: MessageCommandPrompt | undefined;
const diagnostic = TypeMoq.Mock.ofType<IDiagnostic>();
diagnostic.setup(d => d.code)
.returns(() => DiagnosticCodes.InvalidEnvironmentPathVariableDiagnostic)
.verifiable(TypeMoq.Times.atLeastOnce());
const launchBrowserCommand = TypeMoq.Mock.ofType<IDiagnosticCommand>();
commandFactory.setup(f => f.createCommand(TypeMoq.It.isAny(),
TypeMoq.It.isObjectWith<CommandOption<'launch', string>>({ type: 'launch' })))
.returns(() => launchBrowserCommand.object)
.verifiable(TypeMoq.Times.once());
const alwaysIgnoreCommand = TypeMoq.Mock.ofType<IDiagnosticCommand>();
commandFactory.setup(f => f.createCommand(TypeMoq.It.isAny(),
TypeMoq.It.isObjectWith<CommandOption<'ignore', DiagnosticScope>>({ type: 'ignore', options: DiagnosticScope.Global })))
.returns(() => alwaysIgnoreCommand.object)
.verifiable(TypeMoq.Times.once());
messageHandler.setup(m => m.handle(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.callback((_, opts: MessageCommandPrompt) => options = opts)
.verifiable(TypeMoq.Times.once());

await diagnosticService.handle([diagnostic.object]);

diagnostic.verifyAll();
commandFactory.verifyAll();
messageHandler.verifyAll();
expect(options!.commandPrompts).to.be.lengthOf(2);
expect(options!.commandPrompts[0].prompt).to.be.equal('More Info');
});
test('Should not display a message if the diagnostic code has been ignored', async () => {
const diagnostic = TypeMoq.Mock.ofType<IDiagnostic>();

filterService.setup(f => f.shouldIgnoreDiagnostic(TypeMoq.It.isValue(DiagnosticCodes.LSNotSupportedDiagnostic)))
.returns(() => Promise.resolve(true))
.verifiable(TypeMoq.Times.once());
diagnostic.setup(d => d.code)
.returns(() => DiagnosticCodes.LSNotSupportedDiagnostic)
.verifiable(TypeMoq.Times.atLeastOnce());
commandFactory.setup(f => f.createCommand(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.verifiable(TypeMoq.Times.never());
messageHandler.setup(m => m.handle(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.verifiable(TypeMoq.Times.never());

await diagnosticService.handle([diagnostic.object]);

filterService.verifyAll();
diagnostic.verifyAll();
commandFactory.verifyAll();
messageHandler.verifyAll();
});

test('LSNotSupportedDiagnosticService can handle LSNotSupported diagnostics', async () => {
const diagnostic = TypeMoq.Mock.ofType<IDiagnostic>();
diagnostic.setup(d => d.code)
.returns(() => DiagnosticCodes.LSNotSupportedDiagnostic)
.verifiable(TypeMoq.Times.atLeastOnce());
const canHandle = await diagnosticService.canHandle(diagnostic.object);
expect(canHandle).to.be.equal(true, 'Invalid value');
diagnostic.verifyAll();
});
test('LSNotSupportedDiagnosticService can not handle non-LSNotSupported diagnostics', async () => {
const diagnostic = TypeMoq.Mock.ofType<IDiagnostic>();
diagnostic.setup(d => d.code)
.returns(() => 'Something Else')
.verifiable(TypeMoq.Times.atLeastOnce());
const canHandle = await diagnosticService.canHandle(diagnostic.object);
expect(canHandle).to.be.equal(false, 'Invalid value');
diagnostic.verifyAll();
});
});