go-imports-sorter
VSCode extension for separating imports in Go files into following groups:
- Standard library imports
- Third party imports
- Own library (belonging to the organization) imports.
- Self imports (import current project packages).
Extension Settings
groupImports.onSave: automatically group imports on save. Default value is true.
Modernization & Refactor (v1.2.0)
This extension has undergone a complete architectural refactor to improve performance, stability, and maintainability.
Key Improvements
- Performance: Integrated
esbuild for optimized extension bundling, resulting in faster startup and smaller package size.
- Architecture: Complete rewrite in TypeScript 5.0 with strict type safety and SOLID principles.
- Testing: New unit testing architecture running 99% faster (checking domain logic without needing a VS Code instance).
- Reliability: Decoupled file system logic for more robust path handling across different OS environments.
Development
This project uses modern tooling for development:
- Build:
npm run esbuild (Bundles the extension)
- Watch:
npm run esbuild-watch (Rebuilds on change)
- Test:
npm test (Runs unit tests via Mocha)
- Lint:
npm run lint
Notes
Recent Updates
- Parsing: Added robust parser for single-line imports (
import "fmt") and comment preservation.
- Resolution: Enhanced project root detection with recursive
go.mod search and go env GOPATH fallback.
- Safety: Added timeout protection for
onWillSave to prevent editor blocking.
- Refactor: Implemented Clean Architecture (Domain/Service/Controller separation).
- Build: Added
esbuild integration for production-grade bundling.
- Core: Rewrote
ImportProcessor and GoProjectService for better testability.
- Cleanup: Removed legacy dependencies and improved code quality.
- Fix: Resolved issue where import groups lacked a trailing newline, causing formatting errors.
| |