You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would you be interested in adding a vscode extension or should that be somewhere else?
Here is a starter snippet for how it could work, it would get as much context as it could and then ask for the struct and interface name from the user and output the file in the same directory.
import*asvscodefrom'vscode';import{exec}from'child_process';import*aspathfrom'path';import*asfsfrom'fs';functioninstallIfacemaker(){constcmd='go install github.com/vburenin/ifacemaker@latest';exec(cmd,(error,stdout,stderr)=>{if(error){vscode.window.showErrorMessage(`Error installing ifacemaker: ${error.message}`);return;}if(stderr){vscode.window.showErrorMessage(`Error: ${stderr}`);return;}vscode.window.showInformationMessage('ifacemaker installed successfully');});}exportfunctionactivate(context: vscode.ExtensionContext){letdisposable=vscode.commands.registerCommand('extension.useIfacemaker',async()=>{consteditor=vscode.window.activeTextEditor;if(!editor){vscode.window.showErrorMessage('No active Go file.');return;}constfilePath=editor.document.fileName;if(path.extname(filePath)!=='.go'){vscode.window.showErrorMessage('Active file is not a Go file.');return;}// Get struct name from userconststructName=awaitvscode.window.showInputBox({prompt: 'Enter Struct Name'});if(!structName){vscode.window.showErrorMessage('Struct name is required.');return;}// Get interface name from userconstinterfaceName=awaitvscode.window.showInputBox({prompt: 'Enter Interface Name'});if(!interfaceName){vscode.window.showErrorMessage('Interface name is required.');return;}// Try to parse the package name from the fileconstcontent=fs.readFileSync(filePath,'utf8');constpackageMatch=content.match(/^package(\w+)/m);if(!packageMatch){vscode.window.showErrorMessage('Could not determine the package name from the file.');return;}constpackageName=packageMatch[1];// Construct and execute the commandconstoutputFilePath=`${filePath.replace('.go','')}_${interfaceName}.go`;constcmd=`ifacemaker -f ${filePath} -s ${structName} -i ${interfaceName} -p ${packageName} > ${outputFilePath}`;exec(cmd,(error,stdout,stderr)=>{if(error){vscode.window.showErrorMessage(`Error: ${error.message}`);return;}if(stderr){vscode.window.showErrorMessage(`Error: ${stderr}`);return;}vscode.window.showInformationMessage('Interface generated successfully');});});context.subscriptions.push(disposable);}
The text was updated successfully, but these errors were encountered:
Would you be interested in adding a vscode extension or should that be somewhere else?
Here is a starter snippet for how it could work, it would get as much context as it could and then ask for the struct and interface name from the user and output the file in the same directory.
The text was updated successfully, but these errors were encountered: