diff --git a/package.json b/package.json index 5a51e6c..d56a778 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/client.ts b/src/client.ts index f114fcf..b695b6e 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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'; @@ -91,13 +92,13 @@ function getLspCommand(uri: Uri) { } const command = config.get('nargoPath') || findNargo(); - + const aztecMacroEnabled = config.get('enableAztecMacro'); const flags = config.get('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 { @@ -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) { @@ -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 }; + + // Return a function that spawns the process + return new Promise((resolve, reject) => { + const childProcess = spawn(command, args, { env }); + childProcess.on('error', reject); + resolve(childProcess); + }); }; super(languageId, extensionName, serverOptions, clientOptions);