11import * as vscode from 'vscode'
22import { setTsPath } from './tsUtil'
3-
4- const configKeys = [
5- 'typescript-path' ,
6- 'typescript-path-mode' ,
7- 'benchmarkIterations' ,
8- 'restartTsserverOnIteration' ,
9- 'allIdentifiers' ,
10- 'traceCmd' ,
11- ] as const
12-
13- type ConfigKey = typeof configKeys [ number ]
14- const configKey = 'tsperf.tracer'
3+ import type { ConfigKey } from './constants'
4+ import { configKeys , extPrefix } from './constants'
155
166const currentConfig = {
17- 'typescript-path' : '' ,
18- 'typescript-path-mode' : 'vscode-builtin' ,
19- ' benchmarkIterations' : 3 ,
20- ' restartTsserverOnIteration' : false ,
21- ' allIdentifiers' : false ,
7+ typescriptPath : '' ,
8+ typescriptPathMode : 'vscode-builtin' ,
9+ benchmarkIterations : 3 ,
10+ restartTsserverOnIteration : false ,
11+ allIdentifiers : false ,
2212 // eslint-disable-next-line no-template-curly-in-string
23- ' traceCmd' : 'npx tsc --generateTrace ${traceDir}' ,
13+ traceCmd : 'npx tsc --generateTrace ${traceDir}' ,
2414} satisfies Record < ConfigKey , any >
2515
2616export function getCurrentConfig ( ) {
@@ -40,35 +30,36 @@ function isBoolean(x: unknown): x is boolean {
4030}
4131
4232const configValidate = {
43- 'typescript-path' : isString ,
44- 'typescript-path-mode' : isString ,
45- ' benchmarkIterations' : isNumber ,
46- ' restartTsserverOnIteration' : isBoolean ,
47- ' allIdentifiers' : isBoolean ,
48- ' traceCmd' : isString ,
33+ typescriptPath : isString ,
34+ typescriptPathMode : isString ,
35+ benchmarkIterations : isNumber ,
36+ restartTsserverOnIteration : isBoolean ,
37+ allIdentifiers : isBoolean ,
38+ traceCmd : isString ,
4939} satisfies Record < ConfigKey , any >
5040
5141function noop ( ) {
5242}
5343
5444const configHandlers = {
55- 'typescript-path' : ( _value : string ) => { currentConfig [ 'typescript-path-mode' ] = '!ForceUpdate' } ,
56- 'typescript-path-mode' : ( value : string ) => { setTsPath ( value , currentConfig [ 'typescript-path' ] ) } ,
57- ' benchmarkIterations' : noop ,
58- ' restartTsserverOnIteration' : noop ,
59- ' allIdentifiers' : noop ,
60- ' traceCmd' : noop ,
45+ typescriptPath : ( _value : string ) => { currentConfig . typescriptPathMode = '!ForceUpdate' } ,
46+ typescriptPathMode : ( value : string ) => { setTsPath ( value , currentConfig . typescriptPath ) } ,
47+ benchmarkIterations : noop ,
48+ restartTsserverOnIteration : noop ,
49+ allIdentifiers : noop ,
50+ traceCmd : noop ,
6151} satisfies Record < ConfigKey , any >
6252
63- let configuration = vscode . workspace . getConfiguration ( configKey )
53+ let configuration = vscode . workspace . getConfiguration ( extPrefix )
6454
6555const afterConfigHandlers : [ keys : ConfigKey [ ] , handler : ( config : typeof currentConfig ) => void ] [ ] = [ ]
6656
67- export function updateConfig ( ) {
57+ export function updateConfig ( opts ?: { force ?: ConfigKey [ ] } ) {
6858 const changedKeys : ConfigKey [ ] = [ ]
6959 for ( const key of configKeys ) {
70- const newValue = configuration . get ( key )
71- if ( newValue !== undefined && newValue !== currentConfig [ key ] ) {
60+ let newValue = configuration . get ( key )
61+ if ( opts ?. force ?. includes ( key ) || ( newValue !== undefined && newValue !== currentConfig [ key ] ) ) {
62+ newValue ??= currentConfig [ key ]
7263 changedKeys . push ( key )
7364 if ( ! configValidate [ key ] ( newValue ) ) {
7465 vscode . window . showErrorMessage ( `wrong type received for configuration item ${ key } : ${ newValue } ` )
@@ -86,8 +77,8 @@ export function updateConfig() {
8677}
8778
8879vscode . workspace . onDidChangeConfiguration ( ( change ) => {
89- if ( change . affectsConfiguration ( configKey ) ) {
90- configuration = vscode . workspace . getConfiguration ( configKey )
80+ if ( change . affectsConfiguration ( extPrefix ) ) {
81+ configuration = vscode . workspace . getConfiguration ( extPrefix )
9182 updateConfig ( )
9283 }
9384} )
0 commit comments