Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
feat: add vscode binding for the solidity dap
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtekgrinder committed Mar 18, 2024
1 parent 8bdd02c commit 7b1de7b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
50 changes: 50 additions & 0 deletions toolchains/solidity/extension/src/debugger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as path from 'path';
import {
debug,
window,
DebugAdapterDescriptorFactory,
DebugSession,
DebugAdapterExecutable,
DebugAdapterDescriptor,
ExtensionContext,
OutputChannel,
ProviderResult,
} from 'vscode';
import * as os from 'os';

let outputChannel: OutputChannel;

export function registerDebugger(context: ExtensionContext) {
outputChannel = window.createOutputChannel('SolidityDebugger');

context.subscriptions.push(
debug.registerDebugAdapterDescriptorFactory('solidity', new SolidityDebugAdapterDescriptorFactory(context)),
debug.onDidTerminateDebugSession(() => {
outputChannel.appendLine(`Debug session ended.`);
}),
);
}

export class SolidityDebugAdapterDescriptorFactory implements DebugAdapterDescriptorFactory {
context: ExtensionContext;

constructor(context: ExtensionContext) {
this.context = context;
}

async createDebugAdapterDescriptor(
_session: DebugSession,
_executable: DebugAdapterExecutable,
): Promise<ProviderResult<DebugAdapterDescriptor>> {
const serverBinary = this.context.asAbsolutePath(
path.join('dist',
os.platform().startsWith("win") ? 'foundry-dap-server.exe' : 'foundry-dap-server')
);

if (!serverBinary) {
throw new Error('Could not find Solidity debugger server');
}

return new DebugAdapterExecutable(serverBinary, []);
}
}
2 changes: 2 additions & 0 deletions toolchains/solidity/extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { createTestsPositionsClient } from './tests-positions';
import { registerGasEstimation } from './gas-estimation';
import registerForgeFmtLinter from "./fmt-wrapper";
import { TestManager } from './tests/test-manager';
import { registerDebugger } from './debugger';

let slitherClient: LanguageClient;
let linterClient: LanguageClient;
Expand All @@ -28,6 +29,7 @@ export async function activate(context: ExtensionContext) {
context.subscriptions.push(linterClient, foundryCompilerClient, slitherClient, testsPositionsClient, testManager.testController);

registerForgeFmtLinter(context);
registerDebugger(context);
registerGasEstimation();

const folders = workspace.workspaceFolders;
Expand Down

0 comments on commit 7b1de7b

Please sign in to comment.