Skip to content

Commit 8033fa2

Browse files
committed
feat: add a command to disable all optional features after install (finally!)
1 parent 4f38362 commit 8033fa2

File tree

4 files changed

+77
-17
lines changed

4 files changed

+77
-17
lines changed

README.MD

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ TOC:
1616
- [Contributed Code Actions](#contributed-code-actions)
1717
- [Even Even More](#even-even-more)
1818

19-
> *Note* Visit website for list of recommended settings: <https://ts-plugin.zardoy.com/>
19+
> *Note*: You can disable all optional features with `> Disable All Optional Features` setting right after install.
20+
>
21+
> *Note*: Visit website for list of recommended settings: <https://ts-plugin.zardoy.com/>
2022
2123
## Top Features
2224

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
{
5959
"command": "pasteCodeWithImports",
6060
"title": "Paste Code with Imports"
61+
},
62+
{
63+
"command": "disableAllOptionalFeatures",
64+
"title": "Disable All Optional Features"
6165
}
6266
],
6367
"keybindings": [
@@ -90,7 +94,7 @@
9094
"keywords": [
9195
"ts",
9296
"javascript",
93-
"plugin",
97+
"pro",
9498
"webstorm",
9599
"typescript hero"
96100
],

src/configurationType.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export type Configuration = {
118118
/**
119119
* Will be `format-short` by default in future as super useful!
120120
* Requires TypeScript 5.0+
121+
* @recommended
121122
* @default disable
122123
*/
123124
'suggestions.displayImportedInfo': 'disable' | 'short-format' | 'long-format'
@@ -160,14 +161,15 @@ export type Configuration = {
160161
* */
161162
'correctSorting.enable': boolean
162163
/**
163-
* Try to restore suggestion sorting after `.`
164+
* Try to restore properties (not variables!) sorting as in source
164165
* Experimental and most probably will be changed in future
166+
* @recommended
165167
* @default false
166168
*/
167169
fixSuggestionsSorting: boolean
168-
// TODO
170+
// TODO-low
169171
/**
170-
* Mark QuickFixes & refactorings with 🔵
172+
* Mark refactorings with 🔵
171173
* @default true
172174
*/
173175
'markTsCodeActions.enable': boolean
@@ -205,6 +207,11 @@ export type Configuration = {
205207
* @default true
206208
* */
207209
'removeCodeFixes.enable': boolean
210+
/**
211+
* @default ["fixMissingFunctionDeclaration"]
212+
* @uniqueItems true
213+
* */
214+
'removeCodeFixes.codefixes': FixId[]
208215
/**
209216
* Also rename name of default or namespace import on refactor caused by file move / rename
210217
* Probably will be enabled by default in future
@@ -228,13 +235,8 @@ export type Configuration = {
228235
*/
229236
workspaceSymbolSearchExcludePatterns: string[]
230237
/**
231-
* @default ["fixMissingFunctionDeclaration"]
232-
* @uniqueItems true
233-
* */
234-
'removeCodeFixes.codefixes': FixId[]
235-
/**
236-
* Use full-blown emmet in jsx/tsx files!
237-
* Requires `jsxPseudoEmmet.enabled` to be disabled and `emmet.excludeLanguages` to have `javascriptreact` and `typescriptreact`
238+
* Use strict & precise emmet in jsx/tsx files! Doesn't annoy you everywhere!
239+
* Requires `jsxPseudoEmmet.enabled` to be disabled and `emmet.excludeLanguages` to have `javascriptreact` / `typescriptreact`
238240
* @default true
239241
* */
240242
'jsxEmmet.enable': boolean
@@ -443,11 +445,11 @@ export type Configuration = {
443445
*/
444446
// completionHelpers: boolean
445447
/**
446-
* Extend TypeScript outline!
447-
* Extend outline with:
448+
* Extend TypeScript outline with:
448449
* - JSX Elements
449450
* - Type Alias Declarations
450451
* Should be stable!
452+
* @recommended
451453
* @default false
452454
*/
453455
patchOutline: boolean
@@ -458,6 +460,7 @@ export type Configuration = {
458460
'outline.arraysTuplesNumberedItems': boolean
459461
/**
460462
* Exclude covered strings/enum cases in switch in completions
463+
* @deprecated Will be removed in next release
461464
* @default true
462465
*/
463466
switchExcludeCoveredCases: boolean
@@ -520,12 +523,12 @@ export type Configuration = {
520523
*/
521524
'figIntegration.enableWhenStartsWith': string[]
522525
/**
523-
* Propose additional completions in object. Just like `typescript.suggest.objectLiteralMethodSnippets.enabled`, but also for string, arrays and objects
526+
* Propose additional completions in object. Just like `typescript.suggest.objectLiteralMethodSnippets.enabled`, but also for strings, arrays and objects
524527
* @default true
525528
*/
526529
'objectLiteralCompletions.moreVariants': boolean
527530
/**
528-
* When `moreVariants` enabled, always add as fallback variant if other variant can't be derived
531+
* When `moreVariants` is enabled, always add fallback variant (`: `) if other variant can't be derived
529532
* @default false
530533
*/
531534
'objectLiteralCompletions.fallbackVariant': boolean

src/extension.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-require-imports */
22
import * as vscode from 'vscode'
33
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'
55
import { pickObj } from '@zardoy/utils'
66
import { watchExtensionSettings } from '@zardoy/vscode-utils/build/settings'
77
import webImports from './webImports'
@@ -16,6 +16,7 @@ import vueVolarSupport from './vueVolarSupport'
1616
import moreCompletions from './moreCompletions'
1717
import { mergeSettingsFromScopes } from './mergeSettings'
1818
import codeActionProvider from './codeActionProvider'
19+
import { ConditionalPick } from 'type-fest'
1920

2021
let isActivated = false
2122
// let erroredStatusBarItem: vscode.StatusBarItem | undefined
@@ -90,6 +91,7 @@ export const activateTsPlugin = (tsApi: { configurePlugin; onCompletionAccepted
9091
}
9192

9293
export const activate = async () => {
94+
registerDisableOptionalFeaturesCommand()
9395
migrateSettings()
9496

9597
const possiblyActivateTsPlugin = async () => {
@@ -138,3 +140,52 @@ export const activate = async () => {
138140
})
139141
}
140142
}
143+
144+
const registerDisableOptionalFeaturesCommand = () => {
145+
registerExtensionCommand('disableAllOptionalFeatures', async () => {
146+
const config = vscode.workspace.getConfiguration(process.env.IDS_PREFIX, null)
147+
const toDisable: [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+
const action = await vscode.window.showInformationMessage(
154+
`${toDisable.length} features are going to be disabled`,
155+
{ detail: '', modal: true },
156+
'Write to settings NOW',
157+
'Copy settings',
158+
)
159+
if (!action) return
160+
switch (action) {
161+
case 'Write to settings NOW': {
162+
for (const [key, value] of toDisable) {
163+
config.update(key, value, vscode.ConfigurationTarget.Global)
164+
}
165+
break
166+
}
167+
case 'Copy settings': {
168+
vscode.env.clipboard.writeText(JSON.stringify(Object.fromEntries(toDisable), undefined, 4))
169+
break
170+
}
171+
}
172+
})
173+
}
174+
175+
/** Experiences that are enabled out of the box */
176+
const optionalExperiences: (keyof ConditionalPick<Settings, boolean> | [keyof Settings, any])[] = [
177+
'enableMethodSnippets',
178+
'removeUselessFunctionProps.enable',
179+
'patchToString.enable',
180+
['suggestions.keywordsInsertText', 'none'],
181+
'highlightNonFunctionMethods.enable',
182+
'markTsCodeActions.enable',
183+
['markTsCodeFixes.character', ''],
184+
'removeCodeFixes.enable',
185+
'removeDefinitionFromReferences',
186+
'removeImportsFromReferences',
187+
'miscDefinitionImprovement',
188+
'improveJsxCompletions',
189+
'objectLiteralCompletions.moreVariants',
190+
'codeActions.extractTypeInferName',
191+
]

0 commit comments

Comments
 (0)