diff --git a/package.json b/package.json index f799363db8..4106bb2255 100644 --- a/package.json +++ b/package.json @@ -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)" diff --git a/packages/client/src/di.mts b/packages/client/src/di.mts index 34167968a7..59e02595d9 100644 --- a/packages/client/src/di.mts +++ b/packages/client/src/di.mts @@ -65,6 +65,10 @@ export function getIssueTracker(): IssueTracker { return get('issueTracker'); } +export function getEventLogger(): EventLogger { + return get('eventLogger'); +} + export function set(key: K, value: GlobalDependencies[K]): void { Object.defineProperty(globals, key, { value, diff --git a/packages/client/src/extension.mts b/packages/client/src/extension.mts index 28594226ad..8be4f2def6 100644 --- a/packages/client/src/extension.mts +++ b/packages/client/src/extension.mts @@ -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 { try { performance.mark('cspell_activate_start'); @@ -61,7 +67,7 @@ export function activate(context: ExtensionContext): Promise { 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) { @@ -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): Promise { +interface ActivateOptions { + context: ExtensionContext; + eIssueTracker: vscode.EventEmitter; +} + +async function _activate(options: ActivateOptions): Promise { + const { context, eIssueTracker } = options; const logOutput = vscode.window.createOutputChannel('Code Spell Checker', { log: true }); const dLogger = bindLoggerToOutput(logOutput); diff --git a/packages/client/src/storage/EventLogger.mts b/packages/client/src/storage/EventLogger.mts index d9134bca91..4db4e6d856 100644 --- a/packages/client/src/storage/EventLogger.mts +++ b/packages/client/src/storage/EventLogger.mts @@ -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; } diff --git a/packages/client/src/support/commands.mts b/packages/client/src/support/commands.mts index f931fd10bb..9162b9bdd2 100644 --- a/packages/client/src/support/commands.mts +++ b/packages/client/src/support/commands.mts @@ -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 { const uriReadme = Uri.joinPath(getExtensionContext().extensionUri, 'resources/pages/About the Spell Checker.md'); @@ -21,84 +20,6 @@ export function sponsor(): Promise { return openExternalUrl('https://streetsidesoftware.com/sponsor/'); } -export async function rateTheSpellChecker(): Promise { - 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 { return openMarkdown('resources/pages/Spell Checker Release Notes.md'); } diff --git a/packages/client/src/support/index.mts b/packages/client/src/support/index.mts index 03d849354d..31ed87444f 100644 --- a/packages/client/src/support/index.mts +++ b/packages/client/src/support/index.mts @@ -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'; diff --git a/packages/client/src/support/rateTheSpellChecker.mts b/packages/client/src/support/rateTheSpellChecker.mts new file mode 100644 index 0000000000..1a572335c5 --- /dev/null +++ b/packages/client/src/support/rateTheSpellChecker.mts @@ -0,0 +1,82 @@ +import { window } from 'vscode'; + +import { sponsor } from './commands.mjs'; +import { openNegativeFeedbackIssue } from './openIssue.mjs'; + +export async function rateTheSpellChecker(): Promise { + 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'); +} diff --git a/resources/pages/About the Spell Checker.md b/resources/pages/About the Spell Checker.md index 4b51d644bd..9c12176e36 100644 --- a/resources/pages/About the Spell Checker.md +++ b/resources/pages/About the Spell Checker.md @@ -1 +1 @@ -# About +# About the Spell Checker