Skip to content

Commit bab8887

Browse files
committed
Merge branch 'topic/vscode-env' into 'master'
Improve logging of environment in vscode See merge request eng/ide/ada_language_server!1426
2 parents 0afed14 + 90ed2e2 commit bab8887

File tree

4 files changed

+70
-47
lines changed

4 files changed

+70
-47
lines changed

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// "${workspaceFolder}/../als-rt"
2929
// "${workspaceFolder}/integration/vscode/ada/test/TestWorkspace"
3030
],
31-
"preLaunchTask": "npm: compile",
31+
"preLaunchTask": "npm: watch - integration/vscode/ada",
3232
"env": {
3333
// This is necessary to make the "child" vscode inherit the PATH
3434
// variable set in the workspace settings. Without it in some setups
@@ -69,7 +69,7 @@
6969
"MOCHA_TIMEOUT": "0",
7070
"MOCHA_ALS_UPDATE": "${input:updateTestRefs}"
7171
},
72-
"preLaunchTask": "npm: pretest",
72+
"preLaunchTask": "npm: pretest - integration/vscode/ada",
7373
"internalConsoleOptions": "openOnSessionStart"
7474
},
7575
{
@@ -103,7 +103,7 @@
103103
"MOCHA_TIMEOUT": "0",
104104
"MOCHA_ALS_UPDATE": "${input:updateTestRefs}"
105105
},
106-
"preLaunchTask": "npm: pretest",
106+
"preLaunchTask": "npm: pretest - integration/vscode/ada",
107107
// Switch to Debug Console to see test results
108108
"internalConsoleOptions": "openOnSessionStart"
109109
},

.vscode/tasks.json

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,6 @@
1919
"problemMatcher": ["$ada"],
2020
"group": "test"
2121
},
22-
{
23-
"type": "npm",
24-
"script": "compile",
25-
"path": "integration/vscode/ada",
26-
"group": "build",
27-
"problemMatcher": ["$tsc"],
28-
"label": "npm: compile",
29-
"detail": "node ./node_modules/typescript/bin/tsc",
30-
"presentation": {
31-
"echo": true,
32-
"reveal": "silent",
33-
"focus": false,
34-
"panel": "shared",
35-
"showReuseMessage": true,
36-
"clear": false
37-
}
38-
},
39-
{
40-
"type": "npm",
41-
"script": "pretest",
42-
"path": "integration/vscode/ada",
43-
"problemMatcher": [],
44-
"label": "npm: pretest",
45-
"detail": "npm run compile",
46-
"presentation": {
47-
"echo": true,
48-
"reveal": "silent",
49-
"focus": false,
50-
"panel": "shared",
51-
"showReuseMessage": true,
52-
"clear": false
53-
}
54-
},
5522
{
5623
"type": "shell",
5724
"label": "ada: Compile current file",
@@ -79,8 +46,25 @@
7946
}
8047
},
8148
{
82-
"type": "gnat",
83-
"taskKind": "checkFile",
49+
// This task starts a background npm process that monitors changes to
50+
// TS files and recompiles them as needed. It is configured to be run
51+
// before the (vscode)-based launch configurations to make sure the TS
52+
// files are compiled and re-compiled upon changes.
53+
"type": "npm",
54+
"script": "watch",
55+
"path": "integration/vscode/ada",
56+
"group": "build",
57+
"problemMatcher": ["$tsc-watch"],
58+
"label": "npm: watch - integration/vscode/ada",
59+
"detail": "node ./node_modules/typescript/bin/tsc -watch",
60+
"isBackground": true
61+
},
62+
{
63+
"type": "ada",
64+
"configuration": {
65+
"kind": "checkFile",
66+
"projectFile": "${config:ada.projectFile}"
67+
},
8468
"problemMatcher": ["$ada"],
8569
"group": "build",
8670
"label": "ada: Check current file"

integration/vscode/ada/src/clients.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,21 @@ export function createClient(
5050
}
5151
}
5252

53-
logger.debug(`Using ALS at: ${serverExecPath}`);
53+
logger.info(`Using ALS at: ${serverExecPath}`);
5454

5555
// Copy this process's environment
5656
const serverEnv: NodeJS.ProcessEnv = { ...process.env };
5757
// Set custom environment
5858
setCustomEnvironment(serverEnv);
5959

60+
logger.debug(`Environment for ${name}:`);
61+
for (const key in serverEnv) {
62+
const value = serverEnv[key];
63+
if (value) {
64+
logger.debug(`${key}=${value}`);
65+
}
66+
}
67+
6068
// Options to control the server
6169
const serverOptions: ServerOptions = {
6270
run: { command: serverExecPath, args: extra, options: { env: serverEnv } },

integration/vscode/ada/src/extension.ts

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class VSCodeOutputChannelTransport extends Transport {
110110
}
111111

112112
export 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

223254
export async function deactivate() {

0 commit comments

Comments
 (0)