Skip to content

Commit 40df4bd

Browse files
committed
WIP determine server info
1 parent 92e4e92 commit 40df4bd

3 files changed

Lines changed: 110 additions & 5 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
-- https://github.com/neovim/neovim/blob/c12701d4e1404a67fef6da01a8a9d7e2d48d78d6/runtime/lua/uv/_meta.lua#L4297-L4301
2+
--- @class uv.os_uname.info
3+
--- @field sysname string
4+
--- @field release string
5+
--- @field version string
6+
--- @field machine string
7+
8+
-- https://github.com/neovim/neovim/blob/c12701d4e1404a67fef6da01a8a9d7e2d48d78d6/runtime/lua/uv/_meta.lua#L4367-L4372
9+
--- @class uv.os_get_passwd.passwd
10+
--- @field username string
11+
--- @field uid integer?
12+
--- @field gid integer?
13+
--- @field shell string?
14+
--- @field homedir string
15+
16+
---@type uv.os_uname.info
17+
local uname = vim.uv.os_uname()
18+
---@type uv.os_get_passwd.passwd
19+
local passwd = vim.uv.os_get_passwd()
20+
21+
local function get_os()
22+
local os = uname.sysname:lower()
23+
24+
if os == 'linux' then
25+
return 'linux'
26+
elseif os == 'darwin' then
27+
return 'macos'
28+
elseif os == 'windows_nt' then
29+
return 'windows'
30+
elseif os:match('^cygwin') or os:match('^mingw') or os:match('^msys') then
31+
return 'windows'
32+
else
33+
return 'unknown'
34+
end
35+
end
36+
37+
local function get_arch()
38+
local arch = uname.machine:lower()
39+
40+
if arch == 'x86_64' or arch == 'amd64' then
41+
return 'amd64'
42+
elseif arch == 'aarch64' or arch == 'arm64' then
43+
return 'arm64'
44+
elseif arch:match('^armv8') then
45+
return 'arm64'
46+
elseif arch:match('^armv7') or arch:match('^armv6') then
47+
return 'arm'
48+
elseif
49+
arch == 'i386'
50+
or arch == 'i486'
51+
or arch == 'i586'
52+
or arch == 'i686'
53+
or arch == 'i786'
54+
or arch == 'x86'
55+
then
56+
return '386'
57+
elseif arch == 'ppc64le' then
58+
return 'ppc64le'
59+
elseif arch == 's390x' then
60+
return 's390x'
61+
else
62+
return 'unknown'
63+
end
64+
end
65+
66+
local function get_shell_name()
67+
if vim.env.COMSPEC and vim.env.PROMPT then
68+
return 'cmd'
69+
end
70+
71+
if vim.env.PSMODULEPATH then
72+
return 'powershell'
73+
end
74+
75+
local shell = (vim.env.SHELL or passwd.shell or ''):lower()
76+
if shell:match('bash') then
77+
return 'bash'
78+
elseif shell:match('zsh') then
79+
return 'zsh'
80+
end
81+
82+
return 'unknown'
83+
end
84+
85+
local server_info = {
86+
os = get_os(),
87+
arch = get_arch(),
88+
username = passwd.username,
89+
homedir = passwd.homedir,
90+
tmpdir = vim.uv.os_tmpdir(),
91+
shell_name = get_shell_name(),
92+
}
93+
94+
return vim.json.encode(server_info)

src/client/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package client
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"log/slog"
78
"math/rand/v2"
@@ -510,6 +511,15 @@ func BuildClientNvimCmd(ctx context.Context, nvrhContext *nvrh_context.NvrhConte
510511
return editorCommand
511512
}
512513

514+
type NvrhServerInfo struct {
515+
Os string `json:"os"`
516+
Arch string `json:"arch"`
517+
Username string `json:"username"`
518+
Homedir string `json:"homedir"`
519+
Tmpdir string `json:"tmpdir"`
520+
ShellName string `json:"shell_name"`
521+
}
522+
513523
func prepareRemoteNvim(nvrhContext *nvrh_context.NvrhContext, nv *nvim.Nvim, version string) error {
514524
currentUser, _ := user.Current()
515525
hostname, _ := os.Hostname()
@@ -545,6 +555,12 @@ func prepareRemoteNvim(nvrhContext *nvrh_context.NvrhContext, nv *nvim.Nvim, ver
545555
},
546556
)
547557

558+
var wut string
559+
var nvrhInfo NvrhServerInfo
560+
nv.ExecLua(bridge_files.ReadFileWithoutError("lua/determine_server_info.lua"), &wut, nil)
561+
json.Unmarshal([]byte(wut), &nvrhInfo)
562+
fmt.Printf("nvrh: %+v\n", nvrhInfo)
563+
548564
nv.RegisterHandler("tunnel-port", func(v *nvim.Nvim, args []string) {
549565
if _, ok := nvrhContext.TunneledPorts[args[0]]; ok {
550566
return

src/manifest.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)