Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
dotnet-version: 10.0.x

- name: Install CSharpier
run: dotnet tool install --tool-path ./.tools CSharpier --version 1.2.6
run: dotnet tool install --tool-path ./.tools CSharpier --version 1.3.0

- name: Check formatting
run: |
mapfile -t files < <(git ls-files '*.cs' '*.csx' '*.csproj' '*.props' '*.targets' '*.xml' '*.slnx')
./.tools/csharpier check "${files[@]}"
./.tools/csharpier check --include-generated "${files[@]}"
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

env:
CONFIGURATION: Release
PACKAGE_PROJECT: src/NvimClient.API/NvimClient.API.csproj
PACKAGE_PROJECT: src/Nvim.Client/Nvim.Client.csproj
PACKAGE_OUTPUT: artifacts/packages
GITHUB_PACKAGE_SOURCE: https://nuget.pkg.github.com/neovim/index.json
NUGET_ORG_SOURCE: https://api.nuget.org/v3/index.json
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

env:
CONFIGURATION: Release
TEST_PROJECT: test/NvimClient.Test/NvimClient.Test.csproj
TEST_PROJECT: test/Nvim.Client.Test/Nvim.Client.Test.csproj

steps:
- name: Checkout
Expand Down
27 changes: 24 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Contributing

## Build and test

```sh
dotnet restore Nvim.Client.slnx
dotnet build Nvim.Client.slnx --no-restore
dotnet test Nvim.Client.slnx --no-restore
```

## Updating the generated API

The tracked generated API is built normally; generation is only needed when
updating that output. Use the Neovim `v0.12.4` source at commit
`68ea43cd0c28af25cd47731308c94fedfcfd1b0b`:

```sh
git -C /path/to/neovim checkout v0.12.4
git -C /path/to/neovim rev-parse HEAD
dotnet run --project src/Nvim.Client.Generator.Cli -- \
/path/to/neovim
```

## Formatting

Format C# files, XML project/configuration files, and `.slnx` files with
Expand All @@ -8,19 +29,19 @@ CSharpier before opening a pull request.
Install CSharpier as a local .NET tool:

```sh
dotnet tool install --global CSharpier
dotnet tool install --global CSharpier --version 1.3.0
```

Format the checked files locally:

```sh
dotnet csharpier format $(git ls-files '*.cs' '*.csx' '*.csproj' '*.props' '*.targets' '*.xml' '*.slnx')
csharpier format $(git ls-files '*.cs' '*.csx' '*.csproj' '*.props' '*.targets' '*.xml' '*.slnx')
```

Check formatting without writing changes:

```sh
dotnet csharpier check $(git ls-files '*.cs' '*.csx' '*.csproj' '*.props' '*.targets' '*.xml' '*.slnx')
csharpier check $(git ls-files '*.cs' '*.csx' '*.csproj' '*.props' '*.targets' '*.xml' '*.slnx')
```

See the official CSharpier docs for
Expand Down
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<TargetFrameworks>net10.0</TargetFrameworks>
</PropertyGroup>
</Project>
9 changes: 7 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="CSharpier.Core" Version="1.2.6" />
<PackageVersion Include="MsgPack.Cli" Version="0.9.2" />
<PackageVersion Include="CSharpier.Core" Version="1.3.0" />
<PackageVersion Include="MessagePack" Version="3.1.8" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.6.0" />
<PackageVersion
Include="Microsoft.CodeAnalysis.CSharp.Workspaces"
Version="5.6.0"
/>
<PackageVersion Include="xunit.v3.mtp-v2" Version="3.2.2" />
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions Nvim.Client.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Solution>
<Project Path="src/Nvim.Client.Generator/Nvim.Client.Generator.csproj" />
<Project Path="src/Nvim.Client.Generator.Cli/Nvim.Client.Generator.Cli.csproj" />
<Project Path="test/Nvim.Client.Test/Nvim.Client.Test.csproj" />
<Project Path="test/Nvim.Client.Test.Module/Nvim.Client.Test.Module.csproj" />
<Project Path="src/Nvim.Client/Nvim.Client.csproj" />
</Solution>
6 changes: 0 additions & 6 deletions NvimClient.slnx

This file was deleted.

158 changes: 45 additions & 113 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,116 +1,48 @@
Nvim.NET
========
<div align="center">

[![Test Workflow Status](https://github.com/neovim/nvim.net/actions/workflows/test.yml/badge.svg)](https://github.com/neovim/nvim.net/actions/workflows/test.yml)

.NET client for [Neovim](https://github.com/neovim/neovim)

Quickstart for Linux
--------------------

1. [Install dotnet](https://www.microsoft.com/net/download/linux-package-manager/ubuntu16-04/sdk-current)
2. Clone the Nvim .NET client (this repo):
```
git clone https://github.com/neovim/nvim.net
```
3. Run the tests, to check that everything is working:
```
dotnet test --solution NvimClient.slnx
```

Plugin Example
--------------

The following is a complete, working RPC module. It adds an `:ExampleAdd`
command that prints `3`.

1. From the repository root, create a console project and reference
`NvimClient.API`:
```sh
dotnet new console --output NvimNetExample
dotnet add NvimNetExample/NvimNetExample.csproj reference src/NvimClient.API/NvimClient.API.csproj
cd NvimNetExample
```
2. Replace `Program.cs` with:
```csharp
using System;
using NvimClient.API;

var nvim = NvimAPI.CreateFromStandardIO();
nvim.RegisterHandler(
"example.add",
args => (long)args[0] + (long)args[1]
);
Console.Error.WriteLine("ready");
nvim.WaitForDisconnect();
```
Standard output is the MessagePack RPC stream. Write diagnostics only to
standard error.
3. Publish the module:
```sh
dotnet publish --output publish
```
4. Create `example.lua` in the project directory:
```lua
local module_path = vim.fn.getcwd() .. "/publish/NvimNetExample.dll"
local ready = false
local channel = vim.fn.jobstart(
{ "dotnet", module_path },
{
rpc = true,
on_stderr = function(_, data)
if vim.tbl_contains(data, "ready") then
ready = true
end
end,
}
)
assert(channel > 0, "failed to start the .NET module")
assert(vim.wait(5000, function()
return ready
end), "timed out waiting for the .NET module")

vim.api.nvim_create_user_command("ExampleAdd", function()
print(vim.fn.rpcrequest(channel, "example.add", 1, 2))
end, {})
```
5. Start Neovim from the project directory and run `:ExampleAdd`:
```sh
nvim --clean -u example.lua
```
# Nvim.Client

Build
-----
**A lifecycle-safe .NET client for embedding, controlling, and extending
[Neovim](https://neovim.io/) over MessagePack-RPC.**

dotnet build

Generate API
-----

The API generator takes two arguments: the output path of the generated C# class
file and the path to the Neovim source directory. `nvim` and `doxygen` must be
in the `PATH`.

dotnet run --project src/NvimClient.APIGenerator/NvimClient.APIGenerator.csproj
src/NvimClient.API/NvimAPI.generated.cs
/usr/local/src/neovim/

Test
----

Run all tests (`nvim` must be in the `PATH`):

dotnet test --solution NvimClient.slnx

Release
-----

1. Update version as necessary in `src/NvimClient.API/NvimClient.API.csproj`.
2. Ensure the repository secret `NUGET_API_KEY` is set to a nuget.org API key
with package push permission. No extra GitHub Packages secret is required;
the workflow uses the built-in `GITHUB_TOKEN`.
3. Run the [publish workflow](https://github.com/neovim/nvim.net/actions/workflows/publish.yml)
from the branch or tag to release. Leave `package-version` empty to use the
project version, or set it to override `PackageVersion` for that run.
4. The workflow builds, packs, uploads the `.nupkg` and `.snupkg` artifacts,
then pushes the `.nupkg` packages to GitHub Packages and nuget.org.

[![Test Workflow Status](https://github.com/neovim/nvim.net/actions/workflows/test.yml/badge.svg)](https://github.com/neovim/nvim.net/actions/workflows/test.yml)
[![NuGet](https://img.shields.io/nuget/v/Nvim.Client.svg?logo=nuget)](https://www.nuget.org/packages/Nvim.Client)
[![.NET 10](https://img.shields.io/badge/.NET-10.0-512BD4?logo=dotnet)](https://dotnet.microsoft.com/)
[![License](https://img.shields.io/github/license/neovim/nvim.net)](LICENSE)

</div>

## Install

```sh
dotnet add package Nvim.Client
```

Start an owned embedded Neovim instance, or attach to streams supplied by your
host:

```csharp
using Nvim.Client;

using var nvim = NvimClient.Start();
var result = await nvim.RequestAsync("nvim_eval", [new NvimString("2 + 2")]);
```

For a stdio RPC module, use `NvimClient.BorrowStandardIO()`, register
asynchronous handlers, and write diagnostics only to standard error. Attached
streams and processes are borrowed; stopping the client never closes or kills
them. `Start` and `ConnectAsync` own their transport resources.

```csharp
using var nvim = NvimClient.AttachToStandardIO();
using var registration = nvim.RegisterRequestHandler(
"example.add",
(arguments, cancellationToken) => Task.FromResult<NvimValue>(
new NvimInteger(((NvimInteger)arguments[0]).Value + ((NvimInteger)arguments[1]).Value)
)
);
await nvim.Completion;
```

See [CONTRIBUTING.md](CONTRIBUTING.md) for development instructions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Nvim.Client.Generator\Nvim.Client.Generator.csproj" />
</ItemGroup>
</Project>
Loading