Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add option to set the aztec macros environment variable #53

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
"type": "string",
"description": "Space-separated list of flags to pass to the nargo CLI"
},
"noir.enableAztecMacro": {
"type": "boolean",
"default": true,
"description": "Enables the Aztec macro feature for compiling aztec contracts"
},
"noir.nargoPath": {
"scope": "resource",
"type": "string",
Expand Down
19 changes: 13 additions & 6 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ServerOptions,
TextDocumentFilter,
} from 'vscode-languageclient/node';
import { ChildProcess, spawn } from 'child_process';

import { extensionName, languageId } from './constants';
import findNargo from './find-nargo';
Expand Down Expand Up @@ -91,13 +92,13 @@ function getLspCommand(uri: Uri) {
}

const command = config.get<string | undefined>('nargoPath') || findNargo();

const aztecMacroEnabled = config.get<boolean>('enableAztecMacro');
const flags = config.get<string | undefined>('nargoFlags') || '';

// Remove empty strings from the flags list
const args = ['lsp', ...flags.split(' ')].filter((arg) => arg !== '');

return [command, args] as const;
return [command, args, aztecMacroEnabled] as const;
}

export default class Client extends LanguageClient {
Expand All @@ -114,7 +115,7 @@ export default class Client extends LanguageClient {
constructor(uri: Uri, workspaceFolder?: WorkspaceFolder) {
const outputChannel = window.createOutputChannel(extensionName, languageId);

const [command, args] = getLspCommand(uri);
const [command, args, aztecMacroEnabled] = getLspCommand(uri);

const documentSelector: TextDocumentFilter[] = [];
if (workspaceFolder) {
Expand All @@ -138,9 +139,15 @@ export default class Client extends LanguageClient {
outputChannel,
};

const serverOptions: ServerOptions = {
command,
args,
const serverOptions: ServerOptions = () => {
const env = aztecMacroEnabled ? { ...process.env, AZTEC_MACROS: 'true' } : { ...process.env };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please help me understand how this will affect LSP? Not obvious if this should affect version from master (I think yes, looking at the issue #52).

Also should this affect LSP only? If no, more lift is needed to support Command, Info and Profile commands.


// Return a function that spawns the process
return new Promise<ChildProcess>((resolve, reject) => {
const childProcess = spawn(command, args, { env });
childProcess.on('error', reject);
resolve(childProcess);
});
};

super(languageId, extensionName, serverOptions, clientOptions);
Expand Down