Skip to content

Commit

Permalink
Merge branch 'master' into dap-support
Browse files Browse the repository at this point in the history
  • Loading branch information
mverzilli committed Mar 13, 2024
2 parents 9d06ca1 + a03b2ef commit 6fc14b7
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 68 deletions.
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
needs: release-please
if: ${{ needs.release-please.outputs.tag-name }}
runs-on: ubuntu-latest
environment: marketplace
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.0.8"
".": "0.0.11"
}
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Changelog

## [0.0.11](https://github.com/noir-lang/vscode-noir/compare/v0.0.10...v0.0.11) (2024-03-04)


### Bug Fixes

* update tooltip when selecting nargo binary ([#73](https://github.com/noir-lang/vscode-noir/issues/73)) ([daf62f4](https://github.com/noir-lang/vscode-noir/commit/daf62f4bd9012d9a47f32fae1a37dfdf05467ca3))

## [0.0.10](https://github.com/noir-lang/vscode-noir/compare/v0.0.9...v0.0.10) (2024-03-04)


### Features

* add `unchecked` keyword highlighting ([#72](https://github.com/noir-lang/vscode-noir/issues/72)) ([47e5b3c](https://github.com/noir-lang/vscode-noir/commit/47e5b3c22ef2994ee4028fec93d0fbcc2db5b383))
* add keyword highlighting for databus visibility keywords ([#68](https://github.com/noir-lang/vscode-noir/issues/68)) ([fe14627](https://github.com/noir-lang/vscode-noir/commit/fe14627ed4ea6dc7c81ebb96eecd4256652ddb1d))
* **aztec:** search for aztec-nargo on top of nargo bin ([#67](https://github.com/noir-lang/vscode-noir/issues/67)) ([0be02a5](https://github.com/noir-lang/vscode-noir/commit/0be02a573bb48435f36e9517c4b69a2d7b633f96))
* introduce setting to disable Code Lens feature ([#64](https://github.com/noir-lang/vscode-noir/issues/64)) ([2ef2925](https://github.com/noir-lang/vscode-noir/commit/2ef2925ca9d9d2e3002f0d862a1f3f0c9fb8ef90))

## [0.0.9](https://github.com/noir-lang/vscode-noir/compare/v0.0.8...v0.0.9) (2023-12-13)


### Features

* Added format configuration defaults for noir ([#55](https://github.com/noir-lang/vscode-noir/issues/55)) ([5152918](https://github.com/noir-lang/vscode-noir/commit/51529189194d955785b70335061c4d121c851a98))

## [0.0.8](https://github.com/noir-lang/vscode-noir/compare/v0.0.7...v0.0.8) (2023-11-29)


Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This extension helps developers write, understand, and improve Noir code by prov
- Compile errors and warnings on file save
- Run tests via codelens above each test
- Useful snippets for common code patterns
- Auto-format on save

## Requirements

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-noir",
"displayName": "Noir Language Support",
"description": "Noir support for Visual Studio Code",
"version": "0.0.8",
"version": "0.0.11",
"publisher": "noir-lang",
"keywords": [
"noir",
Expand Down Expand Up @@ -178,6 +178,12 @@
"default": true,
"description": "Enable the language server"
},
"noir.enableCodeLens": {
"scope": "resource",
"type": "boolean",
"default": true,
"description": "Enable the Code Lens feature of language server. (Compile, Execute, Info, Profile, Run Test links above entry functions and tests)"
},
"noir.trace.server": {
"scope": "resource",
"type": "string",
Expand All @@ -190,6 +196,11 @@
"description": "Traces the communication between VS Code and the language server."
}
}
},
"configurationDefaults": {
"[noir]": {
"editor.defaultFormatter": "noir-lang.vscode-noir"
}
}
},
"scripts": {
Expand Down
11 changes: 11 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,17 @@ export default class Client extends LanguageClient {
});
}

const config = workspace.getConfiguration('noir', uri);

const enableCodeLens = config.get<boolean>('enableCodeLens');

const clientOptions: LanguageClientOptions = {
documentSelector,
workspaceFolder,
outputChannel,
initializationOptions: {
enableCodeLens,
},
};

const serverOptions: ServerOptions = {
Expand Down Expand Up @@ -199,6 +206,10 @@ export default class Client extends LanguageClient {
});
}

get command(): string {
return this.#command;
}

async refreshProfileInfo() {
const response = await this.sendRequest<NargoProfileRunResult>('nargo/profile/run', { package: '' });

Expand Down
141 changes: 85 additions & 56 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ import {
ProcessExecution,
ProgressLocation,
} from 'vscode';
import os from 'os';

import { activateDebugger } from './debugger';

import { languageId } from './constants';
import Client from './client';
import findNargo from './find-nargo';
import findNargo, { findNargoBinaries } from './find-nargo';
import { lspClients, editorLineDecorationManager } from './noir';
import { getNoirStatusBarItem, handleClientStartError } from './noir';

const activeCommands: Map<string, Disposable> = new Map();

Expand Down Expand Up @@ -170,6 +172,17 @@ function registerCommands(uri: Uri) {
});
commands$.push(hideProfileInformationCommand$);

const selectNargoPathCommand$ = commands.registerCommand('nargo.config.path.select', async (..._args) => {
const homeDir = os.homedir();
const foundNargoBinaries = findNargoBinaries(homeDir);
const result = await window.showQuickPick(foundNargoBinaries, { placeHolder: 'Select the Nargo binary to use' });
const config = workspace.getConfiguration('noir', uri);
config.update('nargoPath', result);
const statusBarItem = getNoirStatusBarItem();
statusBarItem.tooltip = result;
});
commands$.push(selectNargoPathCommand$);

activeCommands.set(file, Disposable.from(...commands$));
}

Expand Down Expand Up @@ -248,67 +261,83 @@ async function didOpenTextDocument(document: TextDocument): Promise<Disposable>
const uri = document.uri;
let folder = workspace.getWorkspaceFolder(uri);
let configHandler;
if (folder) {
// If we have nested workspace folders we only start a server on the outer most workspace folder.
folder = getOuterMostWorkspaceFolder(folder);

await addWorkspaceClient(folder);
registerWorkspaceCommands(folder);

configHandler = mutex(folder.uri.toString(), async (e: ConfigurationChangeEvent) => {
if (e.affectsConfiguration('noir.nargoFlags', folder.uri)) {
disposeWorkspaceCommands(folder);
await removeWorkspaceClient(folder);
await addWorkspaceClient(folder);
registerWorkspaceCommands(folder);
}

if (e.affectsConfiguration('noir.nargoPath', folder.uri)) {
disposeWorkspaceCommands(folder);
await removeWorkspaceClient(folder);
await addWorkspaceClient(folder);
registerWorkspaceCommands(folder);
try {
if (folder) {
// If we have nested workspace folders we only start a server on the outer most workspace folder.
folder = getOuterMostWorkspaceFolder(folder);

await addWorkspaceClient(folder);

const currentLspClient = lspClients.get(folder.uri.toString());
const statusBarItem = getNoirStatusBarItem();
statusBarItem.tooltip = currentLspClient.command;
statusBarItem.show();

registerWorkspaceCommands(folder);

configHandler = mutex(folder.uri.toString(), async (e: ConfigurationChangeEvent) => {
if (e.affectsConfiguration('noir.nargoFlags', folder.uri)) {
disposeWorkspaceCommands(folder);
await removeWorkspaceClient(folder);
await addWorkspaceClient(folder);
registerWorkspaceCommands(folder);
}

if (e.affectsConfiguration('noir.nargoPath', folder.uri)) {
disposeWorkspaceCommands(folder);
await removeWorkspaceClient(folder);
await addWorkspaceClient(folder);
registerWorkspaceCommands(folder);
}

if (e.affectsConfiguration('noir.enableLSP', folder.uri)) {
await removeWorkspaceClient(folder);
await addWorkspaceClient(folder);
}

if (e.affectsConfiguration('noir.enableCodeLens', folder.uri)) {
await removeWorkspaceClient(folder);
await addWorkspaceClient(folder);
}
});
} else {
// We only want to handle `file:` and `untitled:` schemes because
// vscode sends `output:` schemes for markdown responses from our LSP
if (uri.scheme !== 'file' && uri.scheme !== 'untitled') {
return Disposable.from();
}

if (e.affectsConfiguration('noir.enableLSP', folder.uri)) {
await removeWorkspaceClient(folder);
await addWorkspaceClient(folder);
}
});
} else {
// We only want to handle `file:` and `untitled:` schemes because
// vscode sends `output:` schemes for markdown responses from our LSP
if (uri.scheme !== 'file' && uri.scheme !== 'untitled') {
return Disposable.from();
// Each file outside of a workspace gets it's own client
await addFileClient(uri);
registerFileCommands(uri);

configHandler = mutex(uri.toString(), async (e: ConfigurationChangeEvent) => {
if (e.affectsConfiguration('noir.nargoFlags', uri)) {
disposeFileCommands(uri);
await removeFileClient(uri);
await addFileClient(uri);
registerFileCommands(uri);
}

if (e.affectsConfiguration('noir.nargoPath', uri)) {
disposeFileCommands(uri);
await removeFileClient(uri);
await addFileClient(uri);
registerFileCommands(uri);
}

if (e.affectsConfiguration('noir.enableLSP', uri)) {
await removeFileClient(uri);
await addFileClient(uri);
}
});
}

// Each file outside of a workspace gets it's own client
await addFileClient(uri);
registerFileCommands(uri);

configHandler = mutex(uri.toString(), async (e: ConfigurationChangeEvent) => {
if (e.affectsConfiguration('noir.nargoFlags', uri)) {
disposeFileCommands(uri);
await removeFileClient(uri);
await addFileClient(uri);
registerFileCommands(uri);
}

if (e.affectsConfiguration('noir.nargoPath', uri)) {
disposeFileCommands(uri);
await removeFileClient(uri);
await addFileClient(uri);
registerFileCommands(uri);
}

if (e.affectsConfiguration('noir.enableLSP', uri)) {
await removeFileClient(uri);
await addFileClient(uri);
}
});
return workspace.onDidChangeConfiguration(configHandler);
} catch (e) {
handleClientStartError(e);
}

return workspace.onDidChangeConfiguration(configHandler);
}

async function didChangeWorkspaceFolders(event: WorkspaceFoldersChangeEvent) {
Expand Down
62 changes: 56 additions & 6 deletions src/find-nargo.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,66 @@
import os from 'os';
import path from 'path';
import fs from 'fs';
import which from 'which';
import { NargoNotFoundError } from './noir';
import { MarkdownString } from 'vscode';

const nargoBinaries = ['nargo'];
// List of possible nargo binaries to find on Path
// We prioritize 'nargo' as the more standard version.
const NARGO_BINARIES = ['nargo', 'aztec-nargo'];
// List of possible default installations in users folder
const NARGO_INSTALL_LOCATION_POSTFIXES = ['.nargo/bin/nargo', '.aztec/bin/aztec-nargo'];

export default function findNargo() {
for (const bin of nargoBinaries) {
function absoluteInstallLocationPaths(homeDir: string): string[] {
return NARGO_INSTALL_LOCATION_POSTFIXES.map((postfix) => path.join(homeDir, postfix)).filter((filePath) =>
fs.existsSync(filePath),
);
}

export function findNargoBinaries(homeDir: string): string[] {
// Note that JS sets maintain insertion order.
const nargoBinaryPaths: Set<string> = new Set();

for (const bin of NARGO_BINARIES) {
try {
const nargo = which.sync(bin);
const path = which.sync(bin);
// If it didn't throw, we found a nargo binary
return nargo;
nargoBinaryPaths.add(path);
} catch (err) {
// Not found
}
}
throw new Error('Unable to locate any nargo binary. Did you install it?');

// So far we have not found installations on path
// Let's check default installation locations
for (const filePath of absoluteInstallLocationPaths(homeDir)) {
nargoBinaryPaths.add(filePath);
}

return [...nargoBinaryPaths];
}

export default function findNargo() {
const homeDir = os.homedir();
const nargoBinaryPaths = findNargoBinaries(homeDir);

if (nargoBinaryPaths.length > 0) {
return nargoBinaryPaths[0];
} else {
const message = new MarkdownString();
message.appendText(`Could not locate any of\n`);
for (const nargoBinary of NARGO_BINARIES) {
message.appendMarkdown(`\`${nargoBinary}\``);
message.appendText(`\n`);
}

message.appendText(`on \`$PATH\`, or one of default installation locations\n`);
for (const postfix of NARGO_INSTALL_LOCATION_POSTFIXES) {
const filePath = path.join(homeDir, postfix);
message.appendMarkdown(`\`${filePath}\``);
message.appendText(`\n`);
}

throw new NargoNotFoundError(message);
}
}
Loading

0 comments on commit 6fc14b7

Please sign in to comment.