@@ -11,14 +11,14 @@ const SECURITY_SENSITIVE_CONFIG: string[] = [
11
11
'goroot' , 'gopath' , 'toolsGopath' , 'alternateTools' , 'inferGopath'
12
12
] ;
13
13
14
- let defaultConfig : Configuration = null ;
15
-
16
14
// Initialize the singleton defaultConfig and register related commands.
17
15
// Prompt if workspace configuration was found but had to be ignored until
18
16
// the user has to explicitly opt in to trust the workspace.
19
17
export async function initConfig ( ctx : vscode . ExtensionContext ) {
20
18
const isTrusted = getFromWorkspaceState ( WORKSPACE_IS_TRUSTED_KEY , false ) ;
21
- defaultConfig = new Configuration ( isTrusted , vscode . workspace . getConfiguration ) ;
19
+ if ( isTrusted !== defaultConfig . workspaceIsTrusted ) {
20
+ defaultConfig . toggleWorkspaceIsTrusted ( ) ;
21
+ }
22
22
ctx . subscriptions . push (
23
23
vscode . commands . registerCommand ( 'go.workspace.isTrusted.toggle' , toggleWorkspaceIsTrusted )
24
24
) ;
@@ -66,24 +66,35 @@ async function toggleWorkspaceIsTrusted() {
66
66
// Go extension configuration for a workspace.
67
67
export class Configuration {
68
68
constructor (
69
- private workspaceIsTrusted = false ,
69
+ private _workspaceIsTrusted = false ,
70
70
private getConfiguration = vscode . workspace . getConfiguration ) { }
71
71
72
72
public toggleWorkspaceIsTrusted ( ) {
73
- this . workspaceIsTrusted = ! this . workspaceIsTrusted ;
74
- return this . workspaceIsTrusted ;
73
+ this . _workspaceIsTrusted = ! this . _workspaceIsTrusted ;
74
+ return this . _workspaceIsTrusted ;
75
75
}
76
76
77
77
// returns a Proxied vscode.WorkspaceConfiguration, which prevents
78
78
// from using the workspace configuration if the workspace is untrusted.
79
79
public get < T > ( section : string , uri ?: vscode . Uri ) : vscode . WorkspaceConfiguration {
80
80
const cfg = this . getConfiguration ( section , uri ) ;
81
- if ( section !== 'go' || this . workspaceIsTrusted ) {
81
+ if ( section !== 'go' || this . _workspaceIsTrusted ) {
82
82
return cfg ;
83
83
}
84
84
85
85
return new WrappedConfiguration ( cfg ) ;
86
86
}
87
+
88
+ public workspaceIsTrusted ( ) : boolean {
89
+ return this . _workspaceIsTrusted ;
90
+ }
91
+ }
92
+
93
+ const defaultConfig = new Configuration ( ) ;
94
+
95
+ // Returns the workspace Configuration used by the extension.
96
+ export function DefaultConfig ( ) {
97
+ return defaultConfig ;
87
98
}
88
99
89
100
// wrappedConfiguration wraps vscode.WorkspaceConfiguration.
@@ -141,5 +152,5 @@ function getConfig(section: string, uri?: vscode.Uri) {
141
152
uri = null ;
142
153
}
143
154
}
144
- return defaultConfig ? defaultConfig . get ( section , uri ) : new Configuration ( ) . get ( section , uri ) ;
155
+ return defaultConfig . get ( section , uri ) ;
145
156
}
0 commit comments