Skip to content

Commit

Permalink
support survey popup (#54)
Browse files Browse the repository at this point in the history
* support survey popup

* fix lint
  • Loading branch information
ms-henglu authored Mar 5, 2025
1 parent 2abcea6 commit 561b915
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 1 deletion.
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@
"type": "object",
"title": "Terraform",
"properties": {
"azapi.survey": {
"surveyPromptDate": {
"type": "string",
"default": "none",
"description": "Date of the AzAPI survey will be prompted to the user"
},
"surveyPromptIgnoredCount": {
"type": "number",
"default": 0,
"description": "Number of times the survey prompt has been ignored"
}
},
"azapi.languageServer": {
"type": "object",
"description": "Language Server settings",
Expand Down Expand Up @@ -121,6 +133,10 @@
{
"command": "azapi.disableLanguageServer",
"title": "Terraform AzApi Provider: Disable Language Server"
},
{
"command": "azapi.showSurvey",
"title": "Terraform AzApi Provider: Show Survey"
}
],
"menus": {},
Expand Down
10 changes: 9 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import TelemetryReporter from '@vscode/extension-telemetry';
import { ClientHandler } from './clientHandler';
import { ServerPath } from './serverPath';
import { config } from './vscodeUtils';
import { ShouldShowSurvey, ShowSurvey } from './survey';

const brand = `Terraform AzApi Provider`;
const outputChannel = vscode.window.createOutputChannel(brand);
Expand Down Expand Up @@ -42,6 +43,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
stopLanguageServer();
}
}),
vscode.commands.registerCommand('azapi.showSurvey', async () => {
ShowSurvey();
}),
vscode.workspace.onDidChangeTextDocument(async (event: vscode.TextDocumentChangeEvent) => {
if (event.document.languageId !== 'terraform') {
return;
Expand Down Expand Up @@ -90,7 +94,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
}
}),
vscode.workspace.onDidChangeConfiguration(async (event: vscode.ConfigurationChangeEvent) => {
if (event.affectsConfiguration('azapi')) {
if (event.affectsConfiguration('azapi.languageServer')) {
const reloadMsg = 'Reload VSCode window to apply language server changes';
const selected = await vscode.window.showInformationMessage(reloadMsg, 'Reload');
if (selected === 'Reload') {
Expand All @@ -103,6 +107,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
if (enabled()) {
startLanguageServer();
}

if (await ShouldShowSurvey()) {
ShowSurvey();
}
}

export async function deactivate(): Promise<void> {
Expand Down
74 changes: 74 additions & 0 deletions src/survey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import * as vscode from 'vscode';
import { config } from './vscodeUtils';

export async function ShouldShowSurvey(): Promise<boolean> {
let currentConfig: any = config('azapi').get('survey');

Check warning on line 5 in src/survey.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 5 in src/survey.ts

View workflow job for this annotation

GitHub Actions / test (stable, windows-latest)

Unexpected any. Specify a different type

Check warning on line 5 in src/survey.ts

View workflow job for this annotation

GitHub Actions / test (stable, ubuntu-latest)

Unexpected any. Specify a different type
if (
currentConfig == undefined ||
currentConfig.surveyPromptDate == undefined ||
currentConfig.surveyPromptDate == 'none'
) {
currentConfig = {};
// first time, remind after 10 days
const promptDate = new Date();
promptDate.setDate(promptDate.getDate() + 10);
currentConfig.surveyPromptDate = promptDate.toISOString();
currentConfig.surveyPromptIgnoredCount = 0;
await config('azapi').update('survey', currentConfig, vscode.ConfigurationTarget.Global);
return false;
}

if (currentConfig.surveyPromptDate == 'never') {
return false;
}

const currentDate = new Date();
const promptDate = new Date(currentConfig.surveyPromptDate);
if (currentDate >= promptDate) {
return true;
}

return false;
}

export async function ShowSurvey(): Promise<void> {
const reloadMsg =
'Looks like you are using Terraform AzAPI Provider. We’d love to hear from you! Could you help us improve product usability by filling out a 2-3 minute survey about your experience with it?';
const selected = await vscode.window.showInformationMessage(reloadMsg, 'Yes', 'Not Now', 'Never');
let currentConfig: any = config('azapi').get('survey');

Check warning on line 38 in src/survey.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 38 in src/survey.ts

View workflow job for this annotation

GitHub Actions / test (stable, windows-latest)

Unexpected any. Specify a different type

Check warning on line 38 in src/survey.ts

View workflow job for this annotation

GitHub Actions / test (stable, ubuntu-latest)

Unexpected any. Specify a different type
if (currentConfig == undefined) {
currentConfig = {};
currentConfig.surveyPromptDate = 'none';
currentConfig.surveyPromptIgnoredCount = 0;
}

const nextPromptDate = new Date();

switch (selected) {
case 'Yes':
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://aka.ms/AzAPI2025'));
// reset the survey prompt date and ignored count, remind after 180 days
currentConfig.surveyPromptIgnoredCount = 0;
nextPromptDate.setDate(nextPromptDate.getDate() + 180);
currentConfig.surveyPromptDate = nextPromptDate.toISOString();
break;
case 'Never':
currentConfig.surveyPromptDate = 'never';
currentConfig.surveyPromptIgnoredCount = 0;
break;
case 'Not Now':
case undefined:
currentConfig.surveyPromptIgnoredCount++;
if (currentConfig.surveyPromptIgnoredCount == 1) {
// first time ignore, remind after 7 days
nextPromptDate.setDate(nextPromptDate.getDate() + 7);
currentConfig.surveyPromptDate = nextPromptDate.toISOString();
} else {
// second time ignore, remind after 30 days
nextPromptDate.setDate(nextPromptDate.getDate() + 30);
currentConfig.surveyPromptDate = nextPromptDate.toISOString();
}
break;
}
await config('azapi').update('survey', currentConfig, vscode.ConfigurationTarget.Global);
}

0 comments on commit 561b915

Please sign in to comment.