Giter VIP home page Giter VIP logo

nvimhost-d's Introduction

pipeline status DUB Package

nvimhost-d

Neovim (nvim) host plugin provider and API client library in D.

nvimhostd-logo

Docs

The following snippets show how you can use this library, check out the examples for more information. This GIF shows the demo-plugin below in action:

screencast

Goals

  • Provide a library for high-performance plugins (it takes between 2-4ms on average via msgpack RPC to call a function).
  • Provide an API for other projects to integrate with nvim.

Plugin snippet demo

import nvimhost.plugin;
import nvimhost.api;

struct DemoPlugin {

    NvimAPI nvim;

    this(ref NvimAPI nvim) {
        this.nvim = nvim;
    }

    // sync function with one argument
    @NvimFunc("Greet")
    string greet(string name) {
        return "Hello " ~ name;
    }

    // sync function with multiple arguments
    @NvimFunc("SumBeginToEnd")
    int sumBeginToEnd(int begin, int end) {
        import std.range;
        import std.algorithm.iteration;
        import std.stdio;

        return cast(int) iota(begin, end).sum();
    }

    // sync function calling async (non blocking) nvim functions
    @NvimFunc("SetVarValueSync")
    int setVarValue(int i) {
        import std.conv;

        nvim.commandAsync("let g:test_var_value=" ~ i.to!string);
        return i;
    }

    // async function calling both async and sync nvim functions
    @NvimFunc("SetVarValueAsync", Async)
    void setVarValueAsync(int i) {
        import std.conv;

        nvim.commandAsync("let g:testasync_var_value=" ~ i.to!string);
        nvim.command("echomsg 'hello world sync!'");
    }

}

void main() {

    // make sure you source this .vim file in neovim, since this will bootstrap
    // the binary and register the plugin
    auto pluginDstFile = "~/.config/nvim/settings/demo-plugin.vim";
    // template instantiate DemoPlugin
    auto plugin = NvimPlugin!(DemoPlugin)("demo-plugin", pluginDstFile);
    // keep it running
    scope (exit) {
        plugin.keepRunning();
    }
}

API client snippet demo

void main() {
    import std.stdio;
    import nvimhost.api : NvimAPI;
    auto nvim = NvimAPI();
    nvim.enableLog();

    // Calling a simple command on Neovim
    nvim.command("echomsg 'hello world!'");

    // Iterating over loaded buffers
    auto buffers = nvim.vimGetBuffers();
    foreach (buffer; buffers) {
        writeln("buffer #", buffer);
    }
}

You can find the code documentation generated by the dub registry here.

How to install and build

  • Fetch it using dub, and use it as a library in your source code by importing the nvimhost package:
dub fetch nvimhost
dub build nvimhost --build=release

For more information about building binaries, check out the .gitlab-ci.yml file

How to ship plugin binaries

Either:

  • Your users compile the binary using ldc2/dmd or
  • You pre-compile dynamically linked binaries for the platforms you want to target.

Based on the current build settings, the dynamic linked binary will depend on common C libraries such as libc.so.6, libpthread.so.0, and a few others, which are expected to be present on most Unix distributions, so it should run without any issues.

Trying out linux x86_64 compiled binaries

If you want to try out the demo-plugin, I've pre-compiled the binary for linux x86_64:

  • curl -LO https://github.com/viniarck/nvimhost-d/releases/download/v1.1.1/demo-plugin
  • chmod +x demo-plugin
  • sudo mv demo-plugin /usr/local/bin (or somewhere else in your PATH)
  • demo-plugin (execute the plugin once in your shell to generate the manifest)
  • In your ~/.config/nvim/init.vim file, source ~/.config/nvim/settings/demo-plugin.vim

From this point forward, all plugin functions will be available to be called from nvim

  • Launch nvim and call native D functions from this plugin, for example, :call Greet("D")

Testing

Both unit tests and system tests (end-to-end) testing with nvim have been automated in the CI.

nvimhost-d's People

Contributors

viniarck avatar

Stargazers

ppeb avatar tomat avatar Alisa Lain avatar Laeeth Isharc avatar  avatar  avatar  avatar Siniša Šušnjar avatar Ezneh avatar John Lamb avatar Markus Lanner avatar  avatar Rajat Soni avatar Reinaldo Molina avatar Anton P avatar Shu Kakihana avatar Kodera A. avatar Joakim Brännström avatar Victor Smith avatar

Watchers

James Cloos avatar  avatar

Forkers

laeeth

nvimhost-d's Issues

Update D's version

In the next weeks, I'll update D's version as long as it's still compatible.

Investigate ldc mangled name warnings

when building with ldc 1.13.0 there are mangled name overlap warnings, these functions are not core functions, but are important:

source/nvimhost/api.d(718,10): Warning: skipping definition of function nvimhost.api.NvimAPI.tabpageIsValid due to previous definition for the same mangled name: _D8nvimhost3api7NvimAPI1
4tabpageIsValidMFiZb
source/nvimhost/api.d(724,10): Warning: skipping definition of function nvimhost.api.NvimAPI.uiDetach due to previous definition for the same mangled name: _D8nvimhost3api7NvimAPI8uiDeta
chMFZv
source/nvimhost/api.d(730,10): Warning: skipping definition of function nvimhost.api.NvimAPI.uiDetachAsync due to previous definition for the same mangled name: _D8nvimhost3api7NvimAPI13
uiDetachAsyncMFZv

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.