Skip to content

Commit 9add1b8

Browse files
committed
always write patch after setting change, add ignoreMessages, create backup file, add a lot of draft work I guess
1 parent d17512f commit 9add1b8

File tree

8 files changed

+349
-83
lines changed

8 files changed

+349
-83
lines changed

README.MD

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,26 @@ And works in the same way for hovers, definitions and so on...
2626

2727
Hint: You can quickly enable/disable specific provider with keybinding with Setting Toggle extension.
2828

29-
Obviously you need to be careful with this power or you can blame yourself in future. Also it will never be supported in the web as **it makes VS Code installation patching**.
29+
Obviously you need to be careful with this power or you can blame yourself in future. Also it will never be supported in the web as **it makes VS Code installation patching**. On first patch it requires internet connection to download vscode sourcemaps.
30+
31+
#### Ignore Extension Messages
32+
33+
```json
34+
"extensionsControl.ignoreMessages": [
35+
// hide all extension messages that contains text "was updated"
36+
{
37+
"regex": "was updated"
38+
},
39+
],
40+
```
3041

3142
## Roadmap
3243

3344
- add filters to existing functionality (eg globs)
3445
- add a way to use middleware script
3546
- override ext activationEvents (easy) - motivation
36-
- disable messages (ext or regex)
37-
- disable diagnostics (ext or regex)
47+
- [x] disable messages (ext or regex)
48+
- ~~disable diagnostics (ext or regex)~~
3849
- add script to disable ext without reload
50+
51+
> Note: if vscode window crahes instantly, you can restore you can restore .backup file in *%localappdata%\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node*

package.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,29 @@
33
"displayName": "Extensions Control",
44
"description": "Control your extensions, don't let them control you.",
55
"publisher": "zardoy",
6+
"preview": true,
67
"version": "0.0.0-dev",
8+
"main": "main.js",
79
"license": "MIT",
810
"categories": [
911
"Other"
1012
],
11-
"contributes": {},
13+
"contributes": {
14+
"commands": [
15+
{
16+
"command": "forcePatch",
17+
"title": "Force apply patch again"
18+
},
19+
{
20+
"command": "removeAllPatches",
21+
"title": "Remove All Patches (clean)"
22+
},
23+
{
24+
"command": "logExtensionsActivationOrder",
25+
"title": "Log (print) Extensions Activation Order"
26+
}
27+
]
28+
},
1229
"extensionDependencies": [
1330
"lehni.vscode-fix-checksums"
1431
],
@@ -17,7 +34,7 @@
1734
"build": "tsc && vscode-framework build"
1835
},
1936
"activationEvents": [
20-
"*"
37+
"onStartupFinished"
2138
],
2239
"pnpm": {
2340
"overrides": {

src/configurationType.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,29 @@ export type Configuration = {
5252
* @default true
5353
*/
5454
autoApplyPatch: boolean
55+
/**
56+
* @default {}
57+
*/
5558
disableProviders: {
5659
[provider in ProviderType]?: string[]
5760
}
61+
/**
62+
* @default {}
63+
*/
64+
// overrideActivationEvents: {
65+
// [id: string]: string[]
66+
// }
67+
/**
68+
* @default []
69+
*/
70+
ignoreMessages: {
71+
regex?: string
72+
/** @default false */
73+
regexCaseInsensitive?: boolean
74+
/**
75+
* Full extension id to filter
76+
*/
77+
extension?: string
78+
severity?: 0 | 1 | 2 | 3
79+
}[]
5880
}

src/extension.ts

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,68 @@
11
import * as vscode from 'vscode'
2-
import { getExtensionSetting } from 'vscode-framework'
2+
import { extensionCtx, getExtensionSetting, registerExtensionCommand } from 'vscode-framework'
33
import { watchExtensionSettings } from '@zardoy/vscode-utils/build/settings'
4-
import { doPatch } from './patch'
4+
import { doPatch, removeAllPatches } from './patch'
55

66
export const activate = async () => {
7-
const upConfig = () => {
8-
process.env.VSC_CONTROL_EXT_CONFIG = JSON.stringify({ disableProviders: getExtensionSetting('disableProviders') })
7+
const getNewConfig = () => {
8+
return {
9+
disableProviders: getExtensionSetting('disableProviders'),
10+
ignoreMessages: getExtensionSetting('ignoreMessages'),
11+
version: extensionCtx.extension.packageJSON.version,
12+
}
13+
}
14+
const updateConfig = async (restartExtHost = false) => {
15+
const config = getNewConfig()
16+
process.env.VSC_CONTROL_EXT_CONFIG = JSON.stringify(config)
17+
await patchNow(config, restartExtHost)
918
}
1019

11-
watchExtensionSettings(['disableProviders'], upConfig)
20+
watchExtensionSettings(['disableProviders', 'ignoreMessages'], async () => {
21+
await updateConfig()
22+
})
23+
24+
// #region commands
25+
registerExtensionCommand('forcePatch', () => updateConfig())
26+
registerExtensionCommand('removeAllPatches', () => {
27+
removeAllPatches()
28+
})
29+
registerExtensionCommand('logExtensionsActivationOrder', () => {
30+
console.log(JSON.parse(process.env.VSC_EXT_ACT_ORDER ?? 'null'))
31+
})
32+
// #endregion
33+
34+
// Main activation actions
1235

13-
if (process.env.VSC_CONTROL_EXT_CONFIG) {
14-
upConfig()
36+
// todo continue impl
37+
// for (const [id, expected] of Object.entries(getExtensionSetting('overrideActivationEvents'))) {
38+
// }
39+
40+
const extVersion = extensionCtx.extension.packageJSON.version
41+
const currentLoadedConfig = process.env.VSC_CONTROL_EXT_CONFIG && JSON.parse(process.env.VSC_CONTROL_EXT_CONFIG)
42+
const patchedVersion = currentLoadedConfig?.version
43+
if (patchedVersion && patchedVersion === extVersion) {
44+
if (process.env.VSC_CONTROL_EXT_CONFIG !== JSON.stringify(getNewConfig())) await updateConfig()
1545
} else {
1646
if (
1747
!getExtensionSetting('autoApplyPatch') &&
1848
!(await vscode.window.showWarningMessage('Extensions Control needs to apply VS Code patch', 'Patch now'))
1949
) {
2050
return
2151
}
52+
if (patchedVersion && patchedVersion !== extVersion) {
53+
// force save unpatched version after update
54+
removeAllPatches()
55+
}
2256
vscode.window.showInformationMessage('Patching & restarting extension host...')
2357
setTimeout(async () => {
24-
try {
25-
await doPatch()
26-
await vscode.commands.executeCommand('fixChecksums.apply')
27-
await vscode.commands.executeCommand('workbench.action.restartExtensionHost')
28-
} catch (err) {
29-
vscode.window.showErrorMessage(`Failed to apply patch: ${err.message ?? err}`)
30-
throw err
31-
}
58+
await updateConfig(true)
3259
}, 0)
3360
}
3461
}
62+
63+
async function patchNow(config, restart: boolean) {
64+
await doPatch(config)
65+
await vscode.commands.executeCommand('fixChecksums.apply')
66+
if (!restart) return
67+
await vscode.commands.executeCommand('workbench.action.restartExtensionHost')
68+
}

src/mainLegacy.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const vscode = require('vscode')
2+
3+
exports.activate = () => {
4+
const config = vscode.workspace.getConfiguration('').get('extensionsControl')
5+
console.log('control: apply config', config)
6+
process.env.VSC_CONTROL_EXT_CONFIG = JSON.stringify(config)
7+
}

0 commit comments

Comments
 (0)