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 package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"ExtensionSurveyBanner.bannerLabelYes": "Yes, take survey now",
"ExtensionSurveyBanner.bannerLabelNo": "No, thanks",
"ExtensionSurveyBanner.maybeLater": "Maybe later",
"ExtensionSurveyBanner.mplsMessage": "Can you please take 2 minutes to tell us about your experience using the Microsoft Python Language Server?",
"ExtensionChannels.installingInsidersMessage": "Installing Insiders... ",
"ExtensionChannels.installingStableMessage": "Installing Stable... ",
"ExtensionChannels.installationCompleteMessage": "complete.",
Expand Down
10 changes: 10 additions & 0 deletions src/client/activation/serviceRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ import {
LanguageServerType,
} from './types';
import { JediLanguageServerActivator } from './jedi/activator';
import { IDiagnosticsService } from '../application/diagnostics/types';
import {
MPLSSurveyDiagnosticService,
MPLSSurveyDiagnosticServiceId,
} from '../application/diagnostics/checks/mplsSurvey';

export function registerTypes(serviceManager: IServiceManager, languageServerType: LanguageServerType): void {
serviceManager.addSingleton<ILanguageServerCache>(ILanguageServerCache, LanguageServerExtensionActivationService);
Expand Down Expand Up @@ -117,6 +122,11 @@ export function registerTypes(serviceManager: IServiceManager, languageServerTyp
DotNetLanguageServerPackageService,
);
registerDotNetTypes(serviceManager);
serviceManager.addSingleton<IDiagnosticsService>(
IDiagnosticsService,
MPLSSurveyDiagnosticService,
MPLSSurveyDiagnosticServiceId,
);
} else if (languageServerType === LanguageServerType.Node) {
serviceManager.add<ILanguageServerAnalysisOptions>(
ILanguageServerAnalysisOptions,
Expand Down
102 changes: 102 additions & 0 deletions src/client/application/diagnostics/checks/mplsSurvey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// eslint-disable-next-line max-classes-per-file
import { inject, named } from 'inversify';
import { DiagnosticSeverity, UIKind } from 'vscode';
import * as querystring from 'querystring';
import { IDisposableRegistry, Resource } from '../../../common/types';
import { ExtensionSurveyBanner } from '../../../common/utils/localize';
import { IServiceContainer } from '../../../ioc/types';
import { BaseDiagnostic, BaseDiagnosticsService } from '../base';
import { DiagnosticCodes } from '../constants';
import { DiagnosticCommandPromptHandlerServiceId, MessageCommandPrompt } from '../promptHandler';
import { DiagnosticScope, IDiagnostic, IDiagnosticHandlerService } from '../types';
import { IApplicationEnvironment } from '../../../common/application/types';
import { IPlatformService } from '../../../common/platform/types';
import { IDiagnosticsCommandFactory } from '../commands/types';

export class MPLSSurveyDiagnostic extends BaseDiagnostic {
constructor(message: string, resource: Resource) {
super(
DiagnosticCodes.MPLSSurveyDiagnostic,
message,
DiagnosticSeverity.Information,
DiagnosticScope.Global,
resource,
);
}
}

export const MPLSSurveyDiagnosticServiceId = 'MPLSSurveyDiagnosticServiceId';

export class MPLSSurveyDiagnosticService extends BaseDiagnosticsService {
constructor(
@inject(IServiceContainer) serviceContainer: IServiceContainer,
@inject(IDiagnosticHandlerService)
@named(DiagnosticCommandPromptHandlerServiceId)
protected readonly messageService: IDiagnosticHandlerService<MessageCommandPrompt>,
@inject(IDisposableRegistry) disposableRegistry: IDisposableRegistry,
@inject(IApplicationEnvironment) private appEnvironment: IApplicationEnvironment,
@inject(IPlatformService) private platformService: IPlatformService,
) {
super([DiagnosticCodes.MPLSSurveyDiagnostic], serviceContainer, disposableRegistry, true);
}

public async diagnose(resource: Resource): Promise<IDiagnostic[]> {
if (this.appEnvironment.uiKind === UIKind?.Web) {
return [];
}

return [new MPLSSurveyDiagnostic(ExtensionSurveyBanner.mplsMessage(), resource)];
}

protected async onHandle(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;
Comment thread
karrtikr marked this conversation as resolved.
}

const commandFactory = this.serviceContainer.get<IDiagnosticsCommandFactory>(IDiagnosticsCommandFactory);

await this.messageService.handle(diagnostic, {
commandPrompts: [
{
prompt: ExtensionSurveyBanner.bannerLabelYes(),
command: {
diagnostic,
invoke: () => this.launchSurvey(diagnostic),
},
},
{
prompt: ExtensionSurveyBanner.maybeLater(),
},
{
prompt: ExtensionSurveyBanner.bannerLabelNo(),
command: commandFactory.createCommand(diagnostic, {
type: 'ignore',
options: DiagnosticScope.Global,
}),
},
],
});
}

private async launchSurvey(diagnostic: IDiagnostic) {
const query = querystring.stringify({
o: encodeURIComponent(this.platformService.osType), // platform
v: encodeURIComponent(this.appEnvironment.vscodeVersion),
e: encodeURIComponent(this.appEnvironment.packageJson.version), // extension version
m: encodeURIComponent(this.appEnvironment.sessionId),
});
const url = `https://aka.ms/mpls-experience-survey?${query}`;

const commandFactory = this.serviceContainer.get<IDiagnosticsCommandFactory>(IDiagnosticsCommandFactory);
await commandFactory.createCommand(diagnostic, { type: 'ignore', options: DiagnosticScope.Global }).invoke();
await commandFactory.createCommand(diagnostic, { type: 'launch', options: url }).invoke();
}
}
1 change: 1 addition & 0 deletions src/client/application/diagnostics/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export enum DiagnosticCodes {
ConfigPythonPathDiagnostic = 'ConfigPythonPathDiagnostic',
UpgradeCodeRunnerDiagnostic = 'UpgradeCodeRunnerDiagnostic',
PylanceDefaultDiagnostic = 'PylanceDefaultDiagnostic',
MPLSSurveyDiagnostic = 'MPLSSurveyDiagnostic',
}
4 changes: 4 additions & 0 deletions src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ export namespace ExtensionSurveyBanner {
export const bannerLabelYes = localize('ExtensionSurveyBanner.bannerLabelYes', 'Yes, take survey now');
export const bannerLabelNo = localize('ExtensionSurveyBanner.bannerLabelNo', 'No, thanks');
export const maybeLater = localize('ExtensionSurveyBanner.maybeLater', 'Maybe later');
export const mplsMessage = localize(
'ExtensionSurveyBanner.mplsMessage',
'Can you please take 2 minutes to tell us about your experience using the Microsoft Python Language Server?',
);
}

export namespace Products {
Expand Down
Loading