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

support survey popup #54

Merged
merged 2 commits into from
Mar 5, 2025
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
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 { 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 All @@ -28,7 +29,7 @@
context.subscriptions.push(
vscode.commands.registerCommand('azapi.enableLanguageServer', async () => {
if (!enabled()) {
const currentConfig: any = config('azapi').get('languageServer');

Check warning on line 32 in src/extension.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 32 in src/extension.ts

View workflow job for this annotation

GitHub Actions / test (stable, windows-latest)

Unexpected any. Specify a different type

Check warning on line 32 in src/extension.ts

View workflow job for this annotation

GitHub Actions / test (stable, ubuntu-latest)

Unexpected any. Specify a different type
currentConfig.external = true;
await config('azapi').update('languageServer', currentConfig, vscode.ConfigurationTarget.Global);
startLanguageServer();
Expand All @@ -36,12 +37,15 @@
}),
vscode.commands.registerCommand('azapi.disableLanguageServer', async () => {
if (enabled()) {
const currentConfig: any = config('azapi').get('languageServer');

Check warning on line 40 in src/extension.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 40 in src/extension.ts

View workflow job for this annotation

GitHub Actions / test (stable, windows-latest)

Unexpected any. Specify a different type

Check warning on line 40 in src/extension.ts

View workflow job for this annotation

GitHub Actions / test (stable, ubuntu-latest)

Unexpected any. Specify a different type
currentConfig.external = false;
await config('azapi').update('languageServer', currentConfig, vscode.ConfigurationTarget.Global);
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 @@ -73,7 +77,7 @@
}

try {
const result: any = await lsClient.client.sendRequest('workspace/executeCommand', {

Check warning on line 80 in src/extension.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 80 in src/extension.ts

View workflow job for this annotation

GitHub Actions / test (stable, windows-latest)

Unexpected any. Specify a different type

Check warning on line 80 in src/extension.ts

View workflow job for this annotation

GitHub Actions / test (stable, ubuntu-latest)

Unexpected any. Specify a different type
command: 'azapi.convertJsonToAzapi',
arguments: [`jsonContent=${clipboardText}`],
});
Expand All @@ -90,7 +94,7 @@
}
}),
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 @@
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);
}
Loading