@@ -110,7 +110,7 @@ class VSCodeOutputChannelTransport extends Transport {
110110}
111111
112112export async function activate ( context : vscode . ExtensionContext ) : Promise < void > {
113- setUpLogging ( ) ;
113+ setUpLogging ( context ) ;
114114
115115 logger . info ( 'Starting Ada extension' ) ;
116116
@@ -130,7 +130,7 @@ async function activateExtension(context: vscode.ExtensionContext) {
130130 // Log the environment that the extension (and all VS Code) will be using
131131 const customEnv = getEvaluatedCustomEnv ( ) ;
132132 if ( customEnv && Object . keys ( customEnv ) . length > 0 ) {
133- logger . info ( ' Custom environment variables:' ) ;
133+ logger . info ( ` Custom environment variables from ${ getCustomEnvSettingName ( ) } ` ) ;
134134 for ( const varName in customEnv ) {
135135 const varValue : string = customEnv [ varName ] ;
136136 logger . info ( `${ varName } =${ varValue } ` ) ;
@@ -155,22 +155,27 @@ async function activateExtension(context: vscode.ExtensionContext) {
155155 vscode . workspace . onDidChangeConfiguration ( adaExtState . configChanged )
156156 ) ;
157157
158+ /**
159+ * Register commands first so that commands such as displaying the extension
160+ * Output become available even if the language servers fail to start.
161+ */
162+ registerCommands ( context , adaExtState ) ;
163+
158164 await Promise . all ( [ adaExtState . adaClient . onReady ( ) , adaExtState . gprClient . onReady ( ) ] ) ;
159165
160166 await vscode . commands . executeCommand ( 'setContext' , ADA_CONTEXT , true ) ;
161167
162- await checkSrcDirectories ( adaExtState . adaClient ) ;
163-
164168 await initializeTestView ( context , adaExtState ) ;
165169
166- await Promise . all ( [ adaExtState . adaClient . onReady ( ) , adaExtState . gprClient . onReady ( ) ] ) ;
167-
168170 initializeDebugging ( context ) ;
169171
170- registerCommands ( context , adaExtState ) ;
172+ /**
173+ * This can display a dialog to the User so don't wait on the result.
174+ */
175+ void checkSrcDirectories ( adaExtState . adaClient ) ;
171176}
172177
173- function setUpLogging ( ) {
178+ function setUpLogging ( context : vscode . ExtensionContext ) {
174179 // Create an output channel for the extension. There are dedicated channels
175180 // for the Ada and Gpr language servers, and this one is a general channel
176181 // for non-LSP features of the extension.
@@ -204,6 +209,21 @@ function setUpLogging() {
204209 } )
205210 ) ;
206211
212+ /**
213+ * Set logging level according to configuration
214+ */
215+ updateLogLevel ( ) ;
216+ /**
217+ * Listen to configuration changes and update the transport level
218+ */
219+ context . subscriptions . push (
220+ vscode . workspace . onDidChangeConfiguration ( ( e ) => {
221+ if ( e . affectsConfiguration ( 'ada.trace.server' ) ) {
222+ updateLogLevel ( ) ;
223+ }
224+ } )
225+ ) ;
226+
207227 if ( startedInDebugMode ( ) ) {
208228 // In debug mode, print log messages to the console with colors. Use
209229 // level 'debug' for more verbosity.
@@ -218,6 +238,17 @@ function setUpLogging() {
218238 } )
219239 ) ;
220240 }
241+
242+ function updateLogLevel ( ) {
243+ /**
244+ * Decide the log level from configuration.
245+ */
246+ const adaTraceServer : 'off' | 'messages' | 'verbose' =
247+ vscode . workspace . getConfiguration ( 'ada' ) . get ( 'trace.server' ) ?? 'off' ;
248+ const logLevel : 'info' | 'debug' = adaTraceServer == 'off' ? 'info' : 'debug' ;
249+ logger . transports . forEach ( ( t ) => ( t . level = logLevel ) ) ;
250+ logger . info ( 'Setting log level to: ' + logLevel ) ;
251+ }
221252}
222253
223254export async function deactivate ( ) {
0 commit comments