docs(impl): write docs

This commit is contained in:
Smirnov Oleksandr 2024-04-02 17:05:38 +03:00
parent 1969241122
commit dba618d387
2 changed files with 62 additions and 0 deletions

View file

@ -11,6 +11,7 @@ Table of Contents
Setup....................................................|gopher.nvim-setup| Setup....................................................|gopher.nvim-setup|
Install dependencies..............................|gopher.nvim-install-deps| Install dependencies..............................|gopher.nvim-install-deps|
Configuration...........................................|gopher.nvim-config| Configuration...........................................|gopher.nvim-config|
Auto implementation of interface methods..................|gopher.nvim-impl|
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*gopher.nvim-setup* *gopher.nvim-setup*
@ -82,4 +83,35 @@ Parameters ~
{user_config} `(optional)` gopher.Config {user_config} `(optional)` gopher.Config
==============================================================================
------------------------------------------------------------------------------
*gopher.nvim-impl*
impl is utilizing the `impl` tool to generate method stubs for interfaces.
Usage ~
1. put your coursor on the struct on which you want implement the interface
and run `:GoImpl io.Reader`
which will automatically choose the reciver for the methods and
implement the `io.Reader` interface
2. same as previous but with custom receiver, so put your coursor on the struct
run `:GoImpl w io.Writer`
where `w` is the receiver and `io.Writer` is the interface
3. specift receiver, struct, and interface
there's no need to put your coursor on the struct if you specify all arguments
`:GoImpl r RequestReader io.Reader`
where `r` is the receiver, `RequestReader` is the struct and `io.Reader` is the interface
simple example:
>go
type BytesReader struct{}
// ^ put your cursor here
// run `:GoImpl b io.Reader`
// this is what you will get
func (b *BytesReader) Read(p []byte) (n int, err error) {
panic("not implemented") // TODO: Implement
}
<
vim:tw=78:ts=8:noet:ft=help:norl: vim:tw=78:ts=8:noet:ft=help:norl:

View file

@ -1,3 +1,32 @@
---@toc_entry Auto implementation of interface methods
---@tag gopher.nvim-impl
---@text impl is utilizing the `impl` tool to generate method stubs for interfaces.
---@usage
--- 1. put your coursor on the struct on which you want implement the interface
--- and run `:GoImpl io.Reader`
--- which will automatically choose the reciver for the methods and
--- implement the `io.Reader` interface
--- 2. same as previous but with custom receiver, so put your coursor on the struct
--- run `:GoImpl w io.Writer`
--- where `w` is the receiver and `io.Writer` is the interface
--- 3. specift receiver, struct, and interface
--- there's no need to put your coursor on the struct if you specify all arguments
--- `:GoImpl r RequestReader io.Reader`
--- where `r` is the receiver, `RequestReader` is the struct and `io.Reader` is the interface
---
--- simple example:
--- >go
--- type BytesReader struct{}
--- // ^ put your cursor here
--- // run `:GoImpl b io.Reader`
---
--- // this is what you will get
--- func (b *BytesReader) Read(p []byte) (n int, err error) {
--- panic("not implemented") // TODO: Implement
--- }
--- <
local c = require("gopher.config").commands local c = require("gopher.config").commands
local r = require "gopher._utils.runner" local r = require "gopher._utils.runner"
local ts_utils = require "gopher._utils.ts" local ts_utils = require "gopher._utils.ts"
@ -5,6 +34,7 @@ local u = require "gopher._utils"
local impl = {} local impl = {}
---@return string ---@return string
---@private
local function get_struct() local function get_struct()
local ns = ts_utils.get_struct_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0))) local ns = ts_utils.get_struct_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0)))
if ns == nil then if ns == nil then