@@ -7,7 +7,10 @@ import type {
77} from "vscode-languageclient" ;
88
99import type * as tr from "./telemetryReporting" ;
10- import { restartExtHostOnChangeIfNeeded } from "./util" ;
10+ import {
11+ getExplicitConfigTarget ,
12+ restartExtHostOnChangeIfNeeded ,
13+ } from "./util" ;
1114
1215export function registerEnablementCommands ( context : vscode . ExtensionContext , telemetryReporter : tr . TelemetryReporter ) : void {
1316 context . subscriptions . push ( vscode . commands . registerCommand ( "typescript.native-preview.enable" , ( ) => {
@@ -28,34 +31,34 @@ export function registerEnablementCommands(context: vscode.ExtensionContext, tel
2831 * Handles both `js/ts.experimental.useTsgo` and `typescript.experimental.useTsgo`.
2932 */
3033export async function updateUseTsgoSetting ( enable : boolean ) : Promise < void > {
31- const tsConfig = vscode . workspace . getConfiguration ( "typescript" ) ;
3234 const jsTsConfig = vscode . workspace . getConfiguration ( "js/ts" ) ;
35+ const tsConfig = vscode . workspace . getConfiguration ( "typescript" ) ;
3336
34- const tsTarget = getExplicitConfigTarget ( tsConfig , "experimental.useTsgo" ) ;
3537 const jsTsTarget = getExplicitConfigTarget ( jsTsConfig , "experimental.useTsgo" ) ;
38+ const tsTarget = getExplicitConfigTarget ( tsConfig , "experimental.useTsgo" ) ;
3639
37- const updates : Thenable < void > [ ] = [ ] ;
38- if ( jsTsTarget !== undefined ) {
39- updates . push ( jsTsConfig . update ( "experimental.useTsgo" , enable , jsTsTarget ) ) ;
40- }
41- if ( tsTarget !== undefined || jsTsTarget === undefined ) {
42- updates . push ( tsConfig . update ( "experimental.useTsgo" , enable , tsTarget ?? vscode . ConfigurationTarget . Global ) ) ;
43- }
44- await Promise . all ( updates ) ;
40+ // If any are defined, we'll use the most-specific target,
41+ // but we'll only set it through `js/ts`.
42+ if ( jsTsTarget !== undefined || tsTarget !== undefined ) {
43+ const updates = [ ] ;
4544
46- await restartExtHostOnChangeIfNeeded ( ) ;
47- }
45+ const mostSpecificTarget = Math . max (
46+ jsTsTarget ?? vscode . ConfigurationTarget . Global ,
47+ tsTarget ?? vscode . ConfigurationTarget . Global ,
48+ ) ;
49+ updates . push ( jsTsConfig . update ( "experimental.useTsgo" , enable , mostSpecificTarget ) ) ;
50+
51+ // If `typescript` had the most-specific target
52+ // (or shared the most-specific target), then
53+ // we'll erase that since we've just set `js/ts` above.
54+ if ( tsTarget === mostSpecificTarget ) {
55+ updates . push ( tsConfig . update ( "experimental.useTsgo" , undefined , mostSpecificTarget ) ) ;
56+ }
57+
58+ await Promise . all ( updates ) ;
59+ }
4860
49- function getExplicitConfigTarget (
50- config : vscode . WorkspaceConfiguration ,
51- key : string ,
52- ) : vscode . ConfigurationTarget | undefined {
53- const inspection = config . inspect ( key ) ;
54- if ( ! inspection ) return undefined ;
55- if ( inspection . workspaceFolderValue !== undefined ) return vscode . ConfigurationTarget . WorkspaceFolder ;
56- if ( inspection . workspaceValue !== undefined ) return vscode . ConfigurationTarget . Workspace ;
57- if ( inspection . globalValue !== undefined ) return vscode . ConfigurationTarget . Global ;
58- return undefined ;
61+ return restartExtHostOnChangeIfNeeded ( ) ;
5962}
6063
6164export const codeLensShowLocationsCommandName = "typescript.native-preview.codeLens.showLocations" ;
0 commit comments