A Visual Studio Code extension to exclude some files when using "Go to Implementation" in Go projects.
This extension improves the default Go to Implementation behavior in Visual Studio Code for Go projects by filtering out some files (e.g., *_mock.go
, mocks/*
) from navigation results. It is ideal for projects using generators like uber-go/mock or vektra/mockery etc. Also useful for ignoring external packages (e.g., with adapters).
- ✅ Filters files based on customizable glob patterns (e.g.,
**/*_mock.go
,**/mocks/**/*.go
). - ✅ Customize mock file patterns via
settings.json
. - ✅ Displays a pick list if multiple valid implementations exist.
- ✅ Provides an enhanced Go to Implementation with
Ctrl+Alt+F12
(Cmd+Opt+F12
on Mac) while keeping the native command unchanged.
- Clone the repository:
$ git clone https://github.com/comerc/golang-go-to-impl.git
- Navigate to the directory:
$ cd golang-go-to-impl
- Install dependencies:
$ npm install
- Build the project:
$ npm run compile
- Run the extension in debug mode (for development):
- Open the folder in VS Code.
- Press
F5
to launch the extension host.
- Download
golang-go-to-impl-*.vsix
from latest release. - Open Command Palette
Ctrl+Shift+P
(Cmd+Shift+P
on Mac). - Type ">Extensions: Install from VSIX..." and select the downloaded file.
Also available on open-vsx.org
- Open a
.go
file in Visual Studio Code. - Click on an interface method or function signature.
- Press
Ctrl+Alt+F12
(Cmd+Opt+F12
on Mac) to trigger Go to Implementation. - The extension will:
- Fetch implementation locations from the language server (e.g.,
gopls
). - Filter out mock files based on configured patterns.
- Navigate to the result or show a pick list.
- Fetch implementation locations from the language server (e.g.,
- Easy navigation back with
Alt+F12
(Opt+F12
on Mac) to return to the previous location.
Customize mock file patterns in settings.json
:
{
"golangGoToImplementation.excludePatterns": [
"**/*_mock.go", // Files ending with _mock.go
"**/mock/**/*.go", // Files in mock directories
"**/mocks/**/*.go", // Files in mocks directories
"**/mock_*.go", // Files starting with mock_ followed by any characters
]
}
{
"golangGoToImplementation.excludePatterns": [
"**/test/**", // Files in test directories
"**/testdata/**", // Files in test directories
"**/stubs/**/*.go", // Files in stubs directories
"**/generated/*.go" // Auto-generated files
]
}
- gopls: Go language server supporting Go to Implementation.
Contributions are welcome! Here's how to get started:
- Fork this repository.
- Create a feature branch:
git checkout -b new-feature
. - Commit your changes:
git commit -am 'Add new feature'
. - Push to the branch:
git push origin new-feature
. - Submit a Pull Request.
MIT © comerc
Report bugs or request features at: https://github.com/comerc/golang-go-to-impl/issues
Go
, Golang
, VSCode
, Mock
, Go to Implementation
, gopls
, Mock Generator
, Interface Navigation
- Works only for Go files (
editorLangId == 'go'
). - Does not interfere with built-in commands for other languages.
interfaces.go:10: func DoSomething()
→ Implementations found:
- service.go
- mocks/mock_service.go
- testdata/fake_service.go
interfaces.go:10: func DoSomething()
→ Implementations found:
- service.go