Skip to content

Commit

Permalink
refactor: move the survey command into its own file (#4017)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Jan 7, 2025
1 parent 098c5f0 commit a0e6728
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 84 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,30 +604,35 @@
},
{
"command": "cSpell.supportRequest",
"enablement": "config.cSpell.command.enableSupportRequest",
"category": "Spell",
"title": "Request Support with the Spell Checker",
"icon": "$(github)"
},
{
"command": "cSpell.reportIssue",
"enablement": "config.cSpell.command.reportIssue",
"category": "Spell",
"title": "Report an Issue with the Spell Checker",
"icon": "$(github)"
},
{
"command": "cSpell.about",
"enablement": "config.cSpell.command.about",
"category": "Spell",
"title": "About the Spell Checker",
"icon": "$(home)"
},
{
"command": "cSpell.releaseNotes",
"enablement": "config.cSpell.command.releaseNotes",
"category": "Spell",
"title": "Show Spell Checker Release Notes",
"icon": "$(heart)"
},
{
"command": "cSpell.sponsor",
"enablement": "config.cSpell.command.sponsor",
"category": "Spell",
"title": "Sponsor the Spell Checker",
"icon": "$(heart)"
Expand Down
4 changes: 4 additions & 0 deletions packages/client/src/di.mts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export function getIssueTracker(): IssueTracker {
return get('issueTracker');
}

export function getEventLogger(): EventLogger {
return get('eventLogger');
}

export function set<K extends keyof GlobalDependencies>(key: K, value: GlobalDependencies[K]): void {
Object.defineProperty(globals, key, {
value,
Expand Down
16 changes: 14 additions & 2 deletions packages/client/src/extension.mts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ let currLogLevel: CSpellSettings['logLevel'] = undefined;

modules.init();

/**
* Activate the extension
* NOTE: Do NOT make this an async function. It will cause errors in the extension host.
* @param context - The extension context from VS Code.
* @returns The extension API.
*/
export function activate(context: ExtensionContext): Promise<ExtensionApi> {
try {
performance.mark('cspell_activate_start');
Expand All @@ -61,7 +67,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionApi> {
activateFileIssuesViewer(context, pIssueTracker);

performance.mark('start_async_activate');
return _activate(context, eIssueTracker).catch((e) => {
return _activate({ context, eIssueTracker }).catch((e) => {
throw activationError(e);
});
} catch (e) {
Expand All @@ -73,7 +79,13 @@ function activationError(e: unknown) {
return new Error(`Failed to activate: (${performance.getLastEventName()}) ${e}`, { cause: e });
}

async function _activate(context: ExtensionContext, eIssueTracker: vscode.EventEmitter<IssueTracker>): Promise<ExtensionApi> {
interface ActivateOptions {
context: ExtensionContext;
eIssueTracker: vscode.EventEmitter<IssueTracker>;
}

async function _activate(options: ActivateOptions): Promise<ExtensionApi> {
const { context, eIssueTracker } = options;
const logOutput = vscode.window.createOutputChannel('Code Spell Checker', { log: true });
const dLogger = bindLoggerToOutput(logOutput);

Expand Down
8 changes: 8 additions & 0 deletions packages/client/src/storage/EventLogger.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ import { MementoFile } from './mementoFile.mjs';
export interface EventLogger {
readonly eventLog: readonly LogEntryBase[];
log(event: LogEntry): void;
/**
* Log that the extension was activated.
*/
logActivate(): void;
/**
* Log a word replacement.
* @param word - The word being replaced.
* @param suggestion - The suggestion being used.
*/
logReplace(word: string, suggestion: string): void;
flush(): Promise<void>;
}
Expand Down
81 changes: 1 addition & 80 deletions packages/client/src/support/commands.mts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { commands, Uri, window } from 'vscode';
import { commands, Uri } from 'vscode';

import { getExtensionContext } from '../di.mjs';
import { openExternalUrl } from '../util/openUrl.mjs';
import { openNegativeFeedbackIssue } from './openIssue.mjs';

export async function about(): Promise<void> {
const uriReadme = Uri.joinPath(getExtensionContext().extensionUri, 'resources/pages/About the Spell Checker.md');
Expand All @@ -21,84 +20,6 @@ export function sponsor(): Promise<boolean> {
return openExternalUrl('https://streetsidesoftware.com/sponsor/');
}

export async function rateTheSpellChecker(): Promise<void> {
const ratings = ['⭐️⭐️⭐️⭐️', '⭐️⭐️⭐️', '⭐️⭐️', '⭐️'];
const choice = await window.showInformationMessage('How would you rate the Spell Checker?', ...ratings);
if (!choice) {
// register that it was dismissed and reschedule.
return;
}
const idx = ratings.indexOf(choice);
const rating = 4 - idx;
if (rating === 1) {
const result = await window.showInformationMessage(
'Thank you for your feedback. Would you provide more detail on how the Spell Checker can be improved by opening an issue on GitHub?',
'Open Issue',
'Not Now',
);
if (result === 'Open Issue') {
return openNegativeFeedbackIssue();
}
return;
}
if (rating === 2) {
await window.showInformationMessage('Thank you for your feedback.', 'Close');
return;
}
const resultGTD = await window.showInformationMessage(
'Does the Spell Checker help you avoid spelling mistakes and get things done?',
'Yes',
'No',
);

switch (resultGTD) {
case 'Yes': {
const result = await window.showInformationMessage(
'Thank you for your feedback. The Spell Checker needs your support to continue to improve. Would you consider sponsoring the Spell Checker?',
'Open Sponsor Page',
'Ask me Later',
'No',
);
switch (result) {
case 'Open Sponsor Page':
await sponsor();
return;
case 'Ask me Later':
// register that it was dismissed and reschedule.
await window.showInformationMessage('Thank you. We will ask again in about a month.', 'Close');
return;
case 'No': {
const result = await window.showInformationMessage('Are you already a sponsor?', 'Yes', 'No');
if (result === 'Yes') {
// register response and do not ask again.
await window.showInformationMessage('Thank you for your support!', 'Close');
return;
}
await window.showInformationMessage(
'Thank you for your feedback. Would you provide more detail on how the Spell Checker can be improved by opening an issue on GitHub?',
'Open Issue',
'Not Now',
);
return;
}
}
return;
}
case 'No': {
const result = await window.showInformationMessage(
'Thank you for your feedback. Would you provide more detail on how the Spell Checker can be improved by opening an issue on GitHub?',
'Open Issue',
'Not Now',
);
if (result === 'Open Issue') {
return openNegativeFeedbackIssue();
}
return;
}
}
await window.showInformationMessage('Thank you for your feedback.', 'Close');
}

export function releaseNotes(): Promise<void> {
return openMarkdown('resources/pages/Spell Checker Release Notes.md');
}
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/support/index.mts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { about, rateTheSpellChecker, releaseNotes, reportIssue, sponsor, supportRequest } from './commands.mjs';
export { about, releaseNotes, reportIssue, sponsor, supportRequest } from './commands.mjs';
export { rateTheSpellChecker } from './rateTheSpellChecker.mjs';
82 changes: 82 additions & 0 deletions packages/client/src/support/rateTheSpellChecker.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { window } from 'vscode';

import { sponsor } from './commands.mjs';
import { openNegativeFeedbackIssue } from './openIssue.mjs';

export async function rateTheSpellChecker(): Promise<void> {
const ratings = ['⭐️⭐️⭐️⭐️', '⭐️⭐️⭐️', '⭐️⭐️', '⭐️'];
const choice = await window.showInformationMessage('How would you rate the Spell Checker?', ...ratings);
if (!choice) {
// register that it was dismissed and reschedule.
return;
}
const idx = ratings.indexOf(choice);
const rating = 4 - idx;
if (rating === 1) {
const result = await window.showInformationMessage(
'Thank you for your feedback. Would you provide more detail on how the Spell Checker can be improved by opening an issue on GitHub?',
'Open Issue',
'Not Now',
);
if (result === 'Open Issue') {
return openNegativeFeedbackIssue();
}
return;
}
if (rating === 2) {
await window.showInformationMessage('Thank you for your feedback.', 'Close');
return;
}
const resultGTD = await window.showInformationMessage(
'Does the Spell Checker help you avoid spelling mistakes and get things done?',
'Yes',
'No',
);

switch (resultGTD) {
case 'Yes': {
const result = await window.showInformationMessage(
'Thank you for your feedback. The Spell Checker needs your support to continue to improve. Would you consider sponsoring the Spell Checker?',
'Open Sponsor Page',
'Ask me Later',
'No',
);
switch (result) {
case 'Open Sponsor Page':
await sponsor();
return;
case 'Ask me Later':
// register that it was dismissed and reschedule.
await window.showInformationMessage('Thank you. We will ask again in about a month.', 'Close');
return;
case 'No': {
const result = await window.showInformationMessage('Are you already a sponsor?', 'Yes', 'No');
if (result === 'Yes') {
// register response and do not ask again.
await window.showInformationMessage('Thank you for your support!', 'Close');
return;
}
await window.showInformationMessage(
'Thank you for your feedback. Would you provide more detail on how the Spell Checker can be improved by opening an issue on GitHub?',
'Open Issue',
'Not Now',
);
return;
}
}
return;
}
case 'No': {
const result = await window.showInformationMessage(
'Thank you for your feedback. Would you provide more detail on how the Spell Checker can be improved by opening an issue on GitHub?',
'Open Issue',
'Not Now',
);
if (result === 'Open Issue') {
return openNegativeFeedbackIssue();
}
return;
}
}
await window.showInformationMessage('Thank you for your feedback.', 'Close');
}
2 changes: 1 addition & 1 deletion resources/pages/About the Spell Checker.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# About
# About the Spell Checker

0 comments on commit a0e6728

Please sign in to comment.