A Visual Studio Code extension to exclude mock 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 mock files (e.g., *_mock.go
, mocks/*
) from navigation results. It is ideal for projects using mock generators like gomock or custom mock directories.
- ✅ 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.
- ✅ Replaces the native
Go to Implementation
command (ctrl+f12
orcmd+f12
for mac) without disrupting normal usage.
- Open Visual Studio Code.
- Open the Extensions Panel (
Ctrl + Shift + X
orCmd + Shift + X
). - Search for
Exclude Mocks in Go to Implementation
. - Click Install.
- Clone the repository:
git clone https://github.com/ZihxS/exclude-mocks-go-to-impl.git
- Navigate to the directory:
cd exclude-mocks-go-to-impl
- Install dependencies:
npm install
- Build the project:
npm run compile
- Run the extension in debug mode:
- Open the folder in VS Code.
- Press
F5
to launch the extension host.
- Open a
.go
file in Visual Studio Code. - Click on an interface method or function signature.
- Press (
ctrl+f12
orcmd+f12
for 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.,
Customize mock file patterns in settings.json
:
{
"excludeMockFiles.patterns": [
"**/*_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
]
}
{
"excludeMockFiles.patterns": [
"**/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
. - minimatch: For flexible glob pattern matching.
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 © Muhammad Saleh Solahudin
Report bugs or request features at: https://github.com/ZihxS/exclude-mocks-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