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

Show a prompt asking user to upgrade Code runner to new version to keep using it #11395

Merged
merged 2 commits into from
May 4, 2020
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/1 Enhancements/11327.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Show a prompt asking user to upgrade Code runner to new version to keep using it when in Deprecate PythonPath experiment.
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
"InterpreterQuickPickList.enterPath.placeholder": "Enter path to a Python interpreter.",
"InterpreterQuickPickList.browsePath.label": "Find...",
"InterpreterQuickPickList.browsePath.detail": "Browse your file system to find a Python interpreter.",
"diagnostics.upgradeCodeRunner": "Please update the Code Runner extension for it to be compatible with the Python extension.",
"Common.bannerLabelYes": "Yes",
"Common.bannerLabelNo": "No",
"Common.doNotShowAgain": "Do not show again",
Expand Down
94 changes: 94 additions & 0 deletions src/client/application/diagnostics/checks/upgradeCodeRunner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import { inject, named } from 'inversify';
import { DiagnosticSeverity } from 'vscode';
import { IWorkspaceService } from '../../../common/application/types';
import { CODE_RUNNER_EXTENSION_ID } from '../../../common/constants';
import { DeprecatePythonPath } from '../../../common/experimentGroups';
import { IDisposableRegistry, IExperimentsManager, IExtensions, Resource } from '../../../common/types';
import { Common, 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 UpgradeCodeRunnerDiagnostic extends BaseDiagnostic {
constructor(message: string, resource: Resource) {
super(
DiagnosticCodes.UpgradeCodeRunnerDiagnostic,
message,
DiagnosticSeverity.Information,
DiagnosticScope.Global,
resource
);
}
}

export const UpgradeCodeRunnerDiagnosticServiceId = 'UpgradeCodeRunnerDiagnosticServiceId';

export class UpgradeCodeRunnerDiagnosticService extends BaseDiagnosticsService {
public _diagnosticReturned: boolean = false;
private workspaceService: IWorkspaceService;
constructor(
@inject(IServiceContainer) serviceContainer: IServiceContainer,
@inject(IDiagnosticHandlerService)
@named(DiagnosticCommandPromptHandlerServiceId)
protected readonly messageService: IDiagnosticHandlerService<MessageCommandPrompt>,
@inject(IDisposableRegistry) disposableRegistry: IDisposableRegistry,
@inject(IExtensions) private readonly extensions: IExtensions
) {
super([DiagnosticCodes.UpgradeCodeRunnerDiagnostic], serviceContainer, disposableRegistry, true);
this.workspaceService = this.serviceContainer.get<IWorkspaceService>(IWorkspaceService);
}
public async diagnose(resource: Resource): Promise<IDiagnostic[]> {
if (this._diagnosticReturned) {
return [];
}
const experiments = this.serviceContainer.get<IExperimentsManager>(IExperimentsManager);
experiments.sendTelemetryIfInExperiment(DeprecatePythonPath.control);
if (!experiments.inExperiment(DeprecatePythonPath.experiment)) {
return [];
}
const extension = this.extensions.getExtension(CODE_RUNNER_EXTENSION_ID);
if (!extension) {
return [];
}
const flagValue: boolean | undefined = extension.packageJSON?.featureFlags?.usingNewPythonInterpreterPathApi;
if (flagValue) {
// Using new version of Code runner already, no need to upgrade
return [];
}
const pythonExecutor = this.workspaceService
.getConfiguration('code-runner', resource)
.get<string>('executorMap.python');
if (pythonExecutor?.includes('$pythonPath')) {
this._diagnosticReturned = true;
return [new UpgradeCodeRunnerDiagnostic(Diagnostics.upgradeCodeRunner(), resource)];
}
return [];
}

protected async onHandle(diagnostics: IDiagnostic[]): Promise<void> {
if (diagnostics.length === 0 || !(await 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: Common.doNotShowAgain(),
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 @@ -17,5 +17,6 @@ export enum DiagnosticCodes {
PythonPathDeprecatedDiagnostic = 'PythonPathDeprecatedDiagnostic',
JustMyCodeDiagnostic = 'JustMyCodeDiagnostic',
ConsoleTypeDiagnostic = 'ConsoleTypeDiagnostic',
ConfigPythonPathDiagnostic = 'ConfigPythonPathDiagnostic'
ConfigPythonPathDiagnostic = 'ConfigPythonPathDiagnostic',
UpgradeCodeRunnerDiagnostic = 'UpgradeCodeRunnerDiagnostic'
}
7 changes: 7 additions & 0 deletions src/client/application/diagnostics/serviceRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
PythonPathDeprecatedDiagnosticService,
PythonPathDeprecatedDiagnosticServiceId
} from './checks/pythonPathDeprecated';
import { UpgradeCodeRunnerDiagnosticService, UpgradeCodeRunnerDiagnosticServiceId } from './checks/upgradeCodeRunner';
import { DiagnosticsCommandFactory } from './commands/factory';
import { IDiagnosticsCommandFactory } from './commands/types';
import { DiagnosticFilterService } from './filter';
Expand Down Expand Up @@ -85,6 +86,12 @@ export function registerTypes(serviceManager: IServiceManager, languageServerTyp
PythonPathDeprecatedDiagnosticService,
PythonPathDeprecatedDiagnosticServiceId
);

serviceManager.addSingleton<IDiagnosticsService>(
IDiagnosticsService,
UpgradeCodeRunnerDiagnosticService,
UpgradeCodeRunnerDiagnosticServiceId
);
serviceManager.addSingleton<IDiagnosticsCommandFactory>(IDiagnosticsCommandFactory, DiagnosticsCommandFactory);
serviceManager.addSingleton<IApplicationDiagnostics>(IApplicationDiagnostics, ApplicationDiagnostics);

Expand Down
4 changes: 4 additions & 0 deletions src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export namespace Diagnostics {
'diagnostics.lsNotSupported',
'Your operating system does not meet the minimum requirements of the Python Language Server. Reverting to the alternative autocompletion provider, Jedi.'
);
export const upgradeCodeRunner = localize(
'diagnostics.upgradeCodeRunner',
'Please update the Code Runner extension for it to be compatible with the Python extension.'
);
export const removePythonPathSettingsJson = localize(
'diagnostics.removePythonPathSettingsJson',
'The setting "python.pythonPath" defined in your workspace settings is now deprecated. Do you want us to delete it? This will only remove the "python.pythonPath" entry from your settings.json.'
Expand Down
Loading