VS Code Extension
Get enhanced IDE support with the official Go IoC VS Code extension for a better development experience.
Installation
From VS Code Marketplace
📦 Install from VS Code Marketplace
- Open VS Code
- Go to Extensions (Ctrl+Shift+X)
- Search for "Go IoC"
- Click Install
Command Line Installation
code --install-extension keva-dev.go-ioc
Features
🎨 Visual Decorators
IoC annotations are highlighted with emojis for better visual recognition:
⚙️Component markers (Component struct{})🔗Autowired dependencies (autowired:"true")🏷️Qualifiers (qualifier:"name"orvalue:"name")🔌Interface implementations (implements:"InterfaceName")❌Syntax errors and invalid annotations
💡 IntelliSense & Auto-completion
Smart code completion for IoC struct tags and annotations:
- Auto-completion for
autowired,qualifier,implementstags - Context-aware suggestions for component fields
- Syntax validation while typing
🔍 Hover Information
Get detailed documentation on hover:
- Component information showing dependencies and qualifiers
- Dependency analysis with autowiring status
- Lifecycle method explanations and usage examples
⚠️ Real-time Validation
Live validation of IoC components:
- Syntax validation for struct tags
- Dependency resolution checking
- Error highlighting with actionable messages
- Status bar integration showing validation status
- Problem panel integration for quick issue navigation
🔗 Interface Navigation
Navigate to interface definitions with ease:
- Go to Definition for interface names in
implementstags - Ctrl+Click (or Cmd+Click on Mac) navigation
- Workspace-wide search for interface definitions
- Multi-file support with intelligent package resolution
🎯 Commands
Access Go IoC commands from the Command Palette (Cmd+Shift+P / Ctrl+Shift+P):
- Go IoC: Generate Wire Files - Run
iocgento generate dependency injection code - Go IoC: Validate Components - Validate IoC configuration without generating files
- Go IoC: Analyze Dependencies - Run comprehensive dependency analysis
- Go IoC: Show Dependency Graph - Display visual dependency relationships
- Go IoC: List Components - Show all discovered IoC components
🔧 Code Snippets
Quick snippets for common IoC patterns:
Component Creation
ioc-component- Create basic IoC component structureioc-interface- Component with interface implementationioc-qualified- Component with qualifierioc-full- Complete component with all features
Dependency Injection
ioc-autowired- Add autowired dependencies
Lifecycle Methods
ioc-postconstruct- PostConstruct lifecycle methodioc-predestroy- PreDestroy lifecycle method
Configuration
Extension Settings
Configure the extension in VS Code settings:
{
"go-ioc.iocgenPath": "iocgen",
"go-ioc.autoGenerate": false,
"go-ioc.verboseOutput": false
}
Available Settings
go-ioc.iocgenPath: Path to the iocgen binary (default: "iocgen")go-ioc.autoGenerate: Automatically generate wire files on save (default: false)go-ioc.verboseOutput: Enable verbose output for iocgen commands (default: false)
Usage Examples
Creating IoC Components
- Type
ioc-componentand press Tab to create a basic component:
type ServiceName struct {
Component struct{} // IoC component marker
// Add fields here
}
- Type
ioc-interfacefor a component implementing an interface:
type ServiceName struct {
Component struct{}
Implements struct{} `implements:"InterfaceName"`
Qualifier struct{} `value:"qualifier"`
// Add fields here
}
- Type
ioc-autowiredto add dependencies:
FieldName InterfaceType `autowired:"true" qualifier:"value"`
Interface Navigation
- Ctrl+Click (or Cmd+Click on Mac) on interface names in
implementstags - Example: Click on
"UserService"inimplements:"UserService"to jump to the interface definition - Works across files in your workspace
Using Commands
- Command Palette (
Cmd+Shift+P/Ctrl+Shift+P): Type "Go IoC" to see available commands - Context Menu: Right-click in Go files for IoC-specific actions
- Status Bar: Click the IoC status indicator to validate components
Validation and Debugging
The extension automatically validates your IoC configuration:
- Green Status: All components valid ✅
- Warning Status: Issues detected ⚠️
- Error Status: Validation failed ❌
Hover over highlighted issues for detailed error information and suggested fixes.
Example Workflow
1. Create a Service Interface
type UserService interface {
GetUser(id string) (*User, error)
}
2. Implement the Service
Use the ioc-interface snippet:
type UserServiceImpl struct {
Component struct{}
Implements struct{} `implements:"UserService"`
DB DatabaseInterface `autowired:"true"`
}
3. Add Lifecycle Methods
Use the ioc-postconstruct snippet:
func (s *UserServiceImpl) PostConstruct() error {
// Initialization logic
return nil
}
4. Generate Wire Files
Use Command Palette → "Go IoC: Generate Wire Files"
Troubleshooting
Extension Not Working
-
Check Go IoC Installation:
go install github.com/tuhuynh27/go-ioc/cmd/iocgen@latest -
Verify PATH: Ensure
$GOPATH/binis in your PATH -
Check Extension Settings: Verify
go-ioc.iocgenPathpoints to the correct binary
Validation Issues
- Check Syntax: Ensure struct tags are properly formatted
- Run Manual Validation: Use
iocgen --dry-runin terminal - Check Dependencies: Ensure all interface implementations exist
Performance Issues
- Large Projects: The extension scans all Go files; consider excluding large vendor directories
- Auto-generation: Disable
go-ioc.autoGenerateif it impacts performance
Requirements
- Go IoC Framework: Install the
iocgenCLI tool - Go Language: Go 1.19 or later
- VS Code: Version 1.60.0 or later
Contributing
Issues and feature requests welcome! Visit the GitHub repository to contribute.
The VS Code extension source code is available in the go-ioc-vscode directory.