Skip to content

Commit 86ff691

Browse files
authored
Merge branch 'master' into trace-env
2 parents 3b2c9cf + 2559cae commit 86ff691

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@
144144
"default": "",
145145
"markdownDescription": "Pass additional arguments to the language server."
146146
},
147+
"haskell.serverEnvironment": {
148+
"scope": "resource",
149+
"type": "object",
150+
"default": {},
151+
"markdownDescription": "Define environment variables for the language server."
152+
},
147153
"haskell.updateBehavior": {
148154
"scope": "machine",
149155
"type": "string",

src/extension.ts

+13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ import { DocsBrowser } from './docsBrowser';
2525
import { downloadHaskellLanguageServer } from './hlsBinaries';
2626
import { directoryExists, executableExists, ExtensionLogger, resolvePathPlaceHolders } from './utils';
2727

28+
// Used for environment variables later on
29+
interface IEnvVars {
30+
[key: string]: string;
31+
}
32+
2833
// The current map of documents & folders to language servers.
2934
// It may be null to indicate that we are in the process of launching a server,
3035
// in which case don't try to launch another one for that uri
@@ -218,8 +223,10 @@ async function activateServerForFolder(context: ExtensionContext, uri: Uri, fold
218223
logger.info(`Activating the language server in the parent dir of the file: ${uri.fsPath}`);
219224
}
220225

226+
const serverEnvironment: IEnvVars = workspace.getConfiguration('haskell', uri).serverEnvironment;
221227
const exeOptions: ExecutableOptions = {
222228
cwd: folder ? undefined : path.dirname(uri.fsPath),
229+
env: Object.assign(process.env, serverEnvironment),
223230
};
224231

225232
// We don't want empty strings in our args
@@ -237,6 +244,12 @@ async function activateServerForFolder(context: ExtensionContext, uri: Uri, fold
237244
if (exeOptions.cwd) {
238245
logger.info(`server cwd: ${exeOptions.cwd}`);
239246
}
247+
if (serverEnvironment) {
248+
logger.info('server environment variables:');
249+
Object.entries(serverEnvironment).forEach(([key, val]: [string, string | undefined]) => {
250+
logger.info(` ${key}=${val}`);
251+
});
252+
}
240253

241254
const pat = folder ? `${folder.uri.fsPath}/**/*` : '**/*';
242255
logger.info(`document selector patten: ${pat}`);

test/suite/extension.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ suite('Extension Test Suite', () => {
6565
await getHaskellConfig().update('logFile', 'hls.log');
6666
await getHaskellConfig().update('trace.server', 'messages');
6767
await getHaskellConfig().update('releasesDownloadStoragePath', path.normalize(getWorkspaceFile('bin').fsPath));
68+
await getHaskellConfig().update('serverEnvironment', { XDG_CACHE_HOME: path.normalize(getWorkspaceFile('cache-test').fsPath) });
6869
const contents = new TextEncoder().encode('main = putStrLn "hi vscode tests"');
6970
await vscode.workspace.fs.writeFile(getWorkspaceFile('Main.hs'), contents);
7071
});
@@ -99,6 +100,15 @@ suite('Extension Test Suite', () => {
99100
assert.ok(await withTimeout(30, existsWorkspaceFile('hls.log')), 'Server log not created in 30 seconds');
100101
});
101102

103+
test('Server should inherit environment variables defined in the settings', async () => {
104+
await vscode.workspace.openTextDocument(getWorkspaceFile('Main.hs'));
105+
assert.ok(
106+
// Folder will have already been created by this point, so it will not trigger watcher in existsWorkspaceFile()
107+
vscode.workspace.getWorkspaceFolder(getWorkspaceFile('cache-test')),
108+
'Server did not inherit XDG_CACHE_DIR from environment variables set in the settings'
109+
);
110+
});
111+
102112
suiteTeardown(async () => {
103113
disposables.forEach((d) => d.dispose());
104114
await vscode.commands.executeCommand(CommandNames.StopServerCommandName);

0 commit comments

Comments
 (0)