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

feat: expand ${workspaceFolder} in nargoPath setting #91

Merged
merged 2 commits into from
Jan 8, 2025
Merged
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
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from 'vscode-languageclient/node';

import { extensionName, languageId } from './constants';
import findNargo from './find-nargo';
import { getNargoPath } from './find-nargo';

type NargoCapabilities = {
nargo?: {
Expand Down Expand Up @@ -90,7 +90,7 @@ function getLspCommand(uri: Uri) {
return;
}

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

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

Expand Down
11 changes: 3 additions & 8 deletions src/debugger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
debug,
window,
workspace,
DebugAdapterDescriptorFactory,
DebugSession,
DebugAdapterExecutable,
Expand All @@ -15,7 +14,7 @@ import {
} from 'vscode';

import { spawn } from 'child_process';
import findNargo from './find-nargo';
import { getNargoPath } from './find-nargo';
import findNearestPackageFrom from './find-nearest-package';

let outputChannel: OutputChannel;
Expand All @@ -37,10 +36,7 @@ export class NoirDebugAdapterDescriptorFactory implements DebugAdapterDescriptor
_session: DebugSession,
_executable: DebugAdapterExecutable,
): ProviderResult<DebugAdapterDescriptor> {
const config = workspace.getConfiguration('noir');

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

return new DebugAdapterExecutable(nargoPath, ['dap']);
}
Expand Down Expand Up @@ -84,8 +80,7 @@ class NoirDebugConfigurationProvider implements DebugConfigurationProvider {
config: DebugConfiguration,
_token?: CancellationToken,
): ProviderResult<DebugConfiguration> {
const workspaceConfig = workspace.getConfiguration('noir');
const nargoPath = workspaceConfig.get<string | undefined>('nargoPath') || findNargo();
const nargoPath = getNargoPath();

outputChannel.clear();

Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { activateDebugger } from './debugger';

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

Expand Down Expand Up @@ -113,7 +113,7 @@ function registerCommands(uri: Uri) {
const file = uri.toString();
const config = workspace.getConfiguration('noir', uri);

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

const nargoFlags = config.get<string | undefined>('nargoFlags') || [];

Expand Down
14 changes: 13 additions & 1 deletion src/find-nargo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
import fs from 'fs';
import which from 'which';
import { NargoNotFoundError } from './noir';
import { MarkdownString } from 'vscode';
import { MarkdownString, Uri, workspace } from 'vscode';

// List of possible nargo binaries to find on Path
// We prioritize 'nargo' as the more standard version.
Expand Down Expand Up @@ -64,3 +64,15 @@ export default function findNargo() {
throw new NargoNotFoundError(message);
}
}

export function getNargoPath(uri: Uri | undefined = undefined): string {
const config = workspace.getConfiguration('noir', uri);
let nargoPath = config.get<string | undefined>('nargoPath');
if (nargoPath === undefined) {
return findNargo();
}

nargoPath = nargoPath.replace(/\${workspaceFolder}/g, workspace.workspaceFolders[0].uri.fsPath);

return nargoPath;
}
Loading