Go Local Imports is a Visual Studio Code extension that automates the configuration of local import grouping for Go projects.
When working on Go projects, it's a common practice to separate standard library imports, third-party imports, and local project imports into distinct groups. This is typically handled by goimports via the local flag. This extension automates setting that flag for gopls based on your project's go.mod file.
Features
Automatic Module Detection: Scans your workspace's go.mod file to identify the module name.
Seamless Configuration: Automatically updates the workspace gopls settings (formatting.local) to include your module name.
Standardized Formatting: Ensures that when you save or format your Go files, imports from your current project are grouped separately from third-party dependencies.
How It Works
Open a Go project in VS Code that contains a go.mod file.
The extension activates and reads the module name from go.mod.
It checks your workspace settings for gopls.
If formatting.local is not already configured, it updates your .vscode/settings.json (Workspace Settings) to set formatting.local to your module name.
Example Result:
Before (mixed imports):
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/my-org/my-project/utils" // Local import mixed with 3rd party
"net/http"
)