|
1 | 1 | /* eslint-disable @typescript-eslint/no-require-imports */ |
2 | 2 | import * as vscode from 'vscode' |
3 | 3 | import { defaultJsSupersetLangs } from '@zardoy/vscode-utils/build/langs' |
4 | | -import { extensionCtx, getExtensionSetting, getExtensionSettingId } from 'vscode-framework' |
| 4 | +import { Settings, extensionCtx, getExtensionSetting, getExtensionSettingId, registerExtensionCommand } from 'vscode-framework' |
5 | 5 | import { pickObj } from '@zardoy/utils' |
6 | 6 | import { watchExtensionSettings } from '@zardoy/vscode-utils/build/settings' |
| 7 | +import { ConditionalPick } from 'type-fest' |
7 | 8 | import webImports from './webImports' |
8 | 9 | import { sendCommand } from './sendCommand' |
9 | 10 | import { registerEmmet } from './emmet' |
@@ -90,6 +91,7 @@ export const activateTsPlugin = (tsApi: { configurePlugin; onCompletionAccepted |
90 | 91 | } |
91 | 92 |
|
92 | 93 | export const activate = async () => { |
| 94 | + registerDisableOptionalFeaturesCommand() |
93 | 95 | migrateSettings() |
94 | 96 |
|
95 | 97 | const possiblyActivateTsPlugin = async () => { |
@@ -138,3 +140,55 @@ export const activate = async () => { |
138 | 140 | }) |
139 | 141 | } |
140 | 142 | } |
| 143 | + |
| 144 | +const registerDisableOptionalFeaturesCommand = () => { |
| 145 | + registerExtensionCommand('disableAllOptionalFeatures', async () => { |
| 146 | + const config = vscode.workspace.getConfiguration(process.env.IDS_PREFIX, null) |
| 147 | + const toDisable: Array<[keyof Settings, any]> = [] |
| 148 | + for (const optionalExperience of optionalExperiences) { |
| 149 | + const desiredKey = Array.isArray(optionalExperience) ? optionalExperience[0] : optionalExperience |
| 150 | + const desiredValue = Array.isArray(optionalExperience) ? optionalExperience[1] : false |
| 151 | + if (config.get(desiredKey) !== desiredValue) toDisable.push([desiredKey, desiredValue]) |
| 152 | + } |
| 153 | + |
| 154 | + const action = await vscode.window.showInformationMessage( |
| 155 | + `${toDisable.length} features are going to be disabled`, |
| 156 | + { detail: '', modal: true }, |
| 157 | + 'Write to settings NOW', |
| 158 | + 'Copy settings', |
| 159 | + ) |
| 160 | + if (!action) return |
| 161 | + switch (action) { |
| 162 | + case 'Write to settings NOW': { |
| 163 | + for (const [key, value] of toDisable) { |
| 164 | + void config.update(key, value, vscode.ConfigurationTarget.Global) |
| 165 | + } |
| 166 | + |
| 167 | + break |
| 168 | + } |
| 169 | + |
| 170 | + case 'Copy settings': { |
| 171 | + await vscode.env.clipboard.writeText(JSON.stringify(Object.fromEntries(toDisable), undefined, 4)) |
| 172 | + break |
| 173 | + } |
| 174 | + } |
| 175 | + }) |
| 176 | +} |
| 177 | + |
| 178 | +/** Experiences that are enabled out of the box */ |
| 179 | +const optionalExperiences: Array<keyof ConditionalPick<Settings, boolean> | [keyof Settings, any]> = [ |
| 180 | + 'enableMethodSnippets', |
| 181 | + 'removeUselessFunctionProps.enable', |
| 182 | + 'patchToString.enable', |
| 183 | + ['suggestions.keywordsInsertText', 'none'], |
| 184 | + 'highlightNonFunctionMethods.enable', |
| 185 | + 'markTsCodeActions.enable', |
| 186 | + ['markTsCodeFixes.character', ''], |
| 187 | + 'removeCodeFixes.enable', |
| 188 | + 'removeDefinitionFromReferences', |
| 189 | + 'removeImportsFromReferences', |
| 190 | + 'miscDefinitionImprovement', |
| 191 | + 'improveJsxCompletions', |
| 192 | + 'objectLiteralCompletions.moreVariants', |
| 193 | + 'codeActions.extractTypeInferName', |
| 194 | +] |
0 commit comments