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 3 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 @@ -25,6 +25,7 @@ import {

import { extensionName, languageId } from "./constants";
import findNargo from "./find-nargo";
import { ChildProcess, spawn } from "child_process";

type NargoCapabilities = {
nargo?: {
Expand Down Expand Up @@ -92,13 +93,13 @@ function getLspCommand(uri: Uri) {
}

let command = config.get<string | undefined>("nargoPath") || findNargo();

let aztecMacroEnabled = config.get<boolean>('enableAztecMacro');
let flags = config.get<string | undefined>("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 {
Expand All @@ -115,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) {
Expand All @@ -139,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 };
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