Skip to content

Visual Studio Code extension to automatically implement interface methods for Golang

License

Notifications You must be signed in to change notification settings

ricardoerikson/vscode-go-impl-methods

Repository files navigation

Implement Method Stubs for Golang Interfaces - Visual Studio Code Extension

GitHub Workflow Status (branch) GitHub release (latest SemVer) semantic-release GitHub Version Installs

VS Code extension that automatically generates method stubs for Golang interfaces. Just inform the receiver and the interface. The extension will generate the method stubs.

Usage

Requirements

First, you will need to have your Go environment correctly configured. The path folder for your Go binaries must also be added to the environment variable $PATH in your operating system. Please, find below some guidelines on how to do that in your operating system:

Then, you will need to install the impl package as follows:

go get -u github.com/josharian/impl

Obs: make sure your $GOPATH/bin is in your $PATH so that you can access the impl binary.

Usage

  • Inform the receiver as a comment (see some examples below):
    • // mt MyType
    • // mp *MyPointer
  • Open the Command Palette
    • Ctrl+Shift+P (Linux and Windows)
    • Shift+Command+P (macOS)
  • Look for Go: Implement Interface Methods
  • Start typing the name of the interface and pick it from the list (ex: io.Reader)
  • Hit Enter!

Author

Ricardo Erikson

Comments

The extension is working, but there are a few things to improve. Any suggestions are welcomed. Please, feel free to contribute.

Enjoy!