From fda0b508627da4ebfae1510553f35a6da4928211 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Thu, 30 Nov 2023 20:47:57 +0000 Subject: [PATCH 1/4] add setting option for aztec macro --- package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package.json b/package.json index d5b0274..4e981cd 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", From ab8dca04fbd2d062e10c38db9876644c0155e0eb Mon Sep 17 00:00:00 2001 From: kevaundray Date: Thu, 30 Nov 2023 20:48:14 +0000 Subject: [PATCH 2/4] add code to set the environment variable --- src/client.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index 9234337..2325e18 100644 --- a/src/client.ts +++ b/src/client.ts @@ -92,7 +92,10 @@ function getLspCommand(uri: Uri) { } let command = config.get("nargoPath") || findNargo(); - + let aztecMacroEnabled = config.get('enableAztecMacro'); + if (aztecMacroEnabled) { + command = "AZTEC_MACROS=true " + command; + } let flags = config.get("nargoFlags") || ""; // Remove empty strings from the flags list From d677d1c69f91f01bd402884f517776beceec2bdc Mon Sep 17 00:00:00 2001 From: kevaundray Date: Thu, 30 Nov 2023 22:07:41 +0000 Subject: [PATCH 3/4] use a child process --- src/client.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/client.ts b/src/client.ts index 2325e18..fb473d5 100644 --- a/src/client.ts +++ b/src/client.ts @@ -25,6 +25,7 @@ import { import { extensionName, languageId } from "./constants"; import findNargo from "./find-nargo"; +import { ChildProcess, spawn } from "child_process"; type NargoCapabilities = { nargo?: { @@ -93,15 +94,12 @@ function getLspCommand(uri: Uri) { let command = config.get("nargoPath") || findNargo(); let aztecMacroEnabled = config.get('enableAztecMacro'); - if (aztecMacroEnabled) { - command = "AZTEC_MACROS=true " + command; - } let flags = config.get("nargoFlags") || ""; // Remove empty strings from the flags list let args = ["lsp", ...flags.split(" ")].filter((arg) => arg !== ""); - return [command, args] as const; + return [command, args, aztecMacroEnabled] as const; } export default class Client extends LanguageClient { @@ -118,7 +116,7 @@ export default class Client extends LanguageClient { constructor(uri: Uri, workspaceFolder?: WorkspaceFolder) { let outputChannel = window.createOutputChannel(extensionName, languageId); - let [command, args] = getLspCommand(uri); + let [command, args, aztecMacroEnabled] = getLspCommand(uri); let documentSelector: TextDocumentFilter[] = []; if (workspaceFolder) { @@ -142,9 +140,15 @@ export default class Client extends LanguageClient { outputChannel, }; - let serverOptions: ServerOptions = { - command, - args, + let 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); From 7e09cab42dc59eaba2b3c2fa152308540713c2c9 Mon Sep 17 00:00:00 2001 From: Tom French Date: Mon, 11 Dec 2023 20:04:10 +0000 Subject: [PATCH 4/4] chore: fix broken merge --- src/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index 46d2d60..b695b6e 100644 --- a/src/client.ts +++ b/src/client.ts @@ -148,7 +148,7 @@ export default class Client extends LanguageClient { childProcess.on('error', reject); resolve(childProcess); }); - + }; super(languageId, extensionName, serverOptions, clientOptions);