From 06d3db7cc3655e800de3f27ce56be3d9ad1b388d Mon Sep 17 00:00:00 2001 From: Gary Burd Date: Mon, 13 May 2024 10:43:10 -0700 Subject: [PATCH] Prepare to deprecate support for remote plugins Neovim plans to deprecate remote plugins as described at https://github.com/neovim/neovim/issues/27949. This commit removes references to remote plugins from all directories except nvim/plugin. We will wait for the completion of https://github.com/neovim/neovim/issues/27949 before marking the `github.com/go-client/nvim/plugin` package as deprecated. --- README.md | 65 +------------------------------------ nvim/doc.go | 5 +-- nvim/nvim.go | 5 --- nvim/plugin/README.md | 74 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 73 deletions(-) create mode 100644 nvim/plugin/README.md diff --git a/README.md b/README.md index 0fd23d95..86f2101a 100644 --- a/README.md +++ b/README.md @@ -4,70 +4,7 @@ [![Github Actions][Github Actions Badge]][Github Actions] [![codecov.io][codecov-badge]][codecov] -Neovim/go-client is a [Neovim](https://neovim.io/) client and plugin host for [Go](https://golang.org/). - -This example plugin adds the Hello command to Nvim. - -```go -package main - -import ( - "strings" - "github.com/neovim/go-client/nvim/plugin" -) - -func hello(args []string) (string, error) { - return "Hello " + strings.Join(args, " "), nil -} - -func main() { - plugin.Main(func(p *plugin.Plugin) error { - p.HandleFunction(&plugin.FunctionOptions{Name: "Hello"}, hello) - return nil - }) -} -``` - -Build the program with the [go tool](https://golang.org/cmd/go/) to an -executable named `hello`. Ensure that the executable is in a directory in -the `PATH` environment variable. - -```go -// Use the `go build` command to generate an executable. -// To ensure this "hello" executable is on your path, -// you can move "hello" to your $GOPATH/bin directory -// or add the current directory to the `PATH` environment variable. -go build -o hello -``` - -Add the following plugin to Nvim: - -```vim -if exists('g:loaded_hello') - finish -endif -let g:loaded_hello = 1 - -function! s:Requirehello(host) abort - " 'hello' is the binary created by compiling the program above. - return jobstart(['hello'], {'rpc': v:true}) -endfunction - -call remote#host#Register('hello', 'x', function('s:Requirehello')) -" The following lines are generated by running the program -" command line flag --manifest hello -call remote#host#RegisterPlugin('hello', '0', [ - \ {'type': 'function', 'name': 'Hello', 'sync': 1, 'opts': {}}, - \ ]) - -" vim:ts=4:sw=4:et -``` - -Start Nvim and run the following command: - -```vim -:echo Hello('world') -``` +Neovim/go-client is a [Neovim](https://neovim.io/) client for [Go](https://golang.org/). Release ------- diff --git a/nvim/doc.go b/nvim/doc.go index 81dcfb01..95f8c8e2 100644 --- a/nvim/doc.go +++ b/nvim/doc.go @@ -1,10 +1,7 @@ // Package nvim implements a Nvim client. // -// See the ./plugin package for additional functionality required for writing -// Nvim plugins. -// // The Nvim type implements the client. To connect to a running instance of -// Nvim, create a *Nvim value using the Dial or NewChildProcess functions. +// Nvim, create a *Nvim value using the New, Dial or NewChildProcess functions. // Call the Close() method to release the resources used by the client. // // Use the Batch type to execute a sequence of Nvim API calls atomically. The diff --git a/nvim/nvim.go b/nvim/nvim.go index 25e5f23a..b827390e 100644 --- a/nvim/nvim.go +++ b/nvim/nvim.go @@ -103,9 +103,6 @@ func (v *Nvim) ExitCode() int { // // The application must call Serve() to handle RPC requests and responses. // -// New is a low-level function. Most applications should use NewChildProcess, -// Dial or the ./plugin package. -// // :help rpc-connecting func New(r io.Reader, w io.Writer, c io.Closer, logf func(string, ...interface{})) (*Nvim, error) { ep, err := rpc.NewEndpoint(r, w, c, rpc.WithLogf(logf), withExtensions()) @@ -354,8 +351,6 @@ func Dial(address string, options ...DialOption) (*Nvim, error) { // :help rpcrequest() // :help rpcnotify() // -// Plugin applications should use the Handler* methods in the ./plugin package -// to register handlers instead of this method. func (v *Nvim) RegisterHandler(method string, fn interface{}) error { var args []interface{} t := reflect.TypeOf(fn) diff --git a/nvim/plugin/README.md b/nvim/plugin/README.md new file mode 100644 index 00000000..397ea6ac --- /dev/null +++ b/nvim/plugin/README.md @@ -0,0 +1,74 @@ +Status +------ + +This package will be deprecated when Neovim [removes the concept of +remote plugins](https://github.com/neovim/neovim/issues/27949). + + +Example +------- + +This example plugin adds the Hello command to Nvim. + +```go +package main + +import ( + "strings" + "github.com/neovim/go-client/nvim/plugin" +) + +func hello(args []string) (string, error) { + return "Hello " + strings.Join(args, " "), nil +} + +func main() { + plugin.Main(func(p *plugin.Plugin) error { + p.HandleFunction(&plugin.FunctionOptions{Name: "Hello"}, hello) + return nil + }) +} +``` + +Build the program with the [go tool](https://golang.org/cmd/go/) to an +executable named `hello`. Ensure that the executable is in a directory in +the `PATH` environment variable. + +```bash +// Use the `go build` command to generate an executable. +// To ensure this "hello" executable is on your path, +// you can move "hello" to your $GOPATH/bin directory +// or add the current directory to the `PATH` environment variable. +go build -o hello +``` + +Add the following plugin to Nvim: + +```vim +if exists('g:loaded_hello') + finish +endif +let g:loaded_hello = 1 + +function! s:Requirehello(host) abort + " 'hello' is the binary created by compiling the program above. + return jobstart(['hello'], {'rpc': v:true}) +endfunction + +call remote#host#Register('hello', 'x', function('s:Requirehello')) +" The following lines are generated by running the program +" command line flag --manifest hello +call remote#host#RegisterPlugin('hello', '0', [ + \ {'type': 'function', 'name': 'Hello', 'sync': 1, 'opts': {}}, + \ ]) + +" vim:ts=4:sw=4:et +``` + +Start Nvim and run the following command: + +```vim +:echo Hello('world') +``` + +