Skip to content

Commit d3d3a5b

Browse files
author
Yatao Li
committed
fvr error messages
1 parent 2261165 commit d3d3a5b

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

Properties/launchSettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"profiles": {
33
"fvim": {
4-
"commandName": "Project"
4+
"commandName": "Project",
5+
"commandLineArgs": "--daemon"
56
},
67
"norc": {
78
"commandName": "Project",

daemon.fs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,22 @@ type Session =
2727

2828
let private sessions = hashmap []
2929
let mutable private sessionId = 0
30-
let FVR_MAGIC = [| 0x46uy ; 0x56uy ; 0x49uy ; 0x4Duy |]
30+
let private FVR_MAGIC = [| 0x46uy ; 0x56uy ; 0x49uy ; 0x4Duy |]
31+
32+
[<Literal>]
33+
let private FVR_NO_FREE_SESSION = -1
34+
[<Literal>]
35+
let private FVR_SESSION_NOT_FOUND = -2
36+
[<Literal>]
37+
let private FVR_CLIENT_EXCEPTION = -10
38+
39+
let getErrorMsg =
40+
function
41+
| FVR_NO_FREE_SESSION -> "No attachable free session available."
42+
| FVR_SESSION_NOT_FOUND -> "The specified session is not found."
43+
| FVR_CLIENT_EXCEPTION -> "Could not connect to the session server."
44+
| _ -> "Unknown error."
45+
3146
let private jsonopts = JsonSerializerOptions()
3247
jsonopts.Converters.Add(JsonFSharpConverter())
3348
let inline private serialize x = JsonSerializer.Serialize(x, jsonopts)
@@ -51,7 +66,7 @@ let attachSession id svrpipe =
5166
let ns = {s with server = Some svrpipe}
5267
sessions.[id] <- ns
5368
Ok ns
54-
| _ -> Error -2
69+
| _ -> Error FVR_SESSION_NOT_FOUND
5570

5671
let newSession nvim stderrenc args svrpipe =
5772
let myid = sessionId
@@ -86,13 +101,14 @@ let attachFirstSession svrpipe =
86101
let ns = {kv.Value with server = Some svrpipe}
87102
sessions.[kv.Key] <- ns
88103
Some ns)
89-
|> function | Some ns -> Ok ns | None -> Error -1
104+
|> function | Some ns -> Ok ns | None -> Error FVR_NO_FREE_SESSION
90105

91106
let serveSession (session: Session) =
92107
async {
93108
let pname = pipename (string session.id)
94109
use client = new NamedPipeClientStream(".", pname, IO.Pipes.PipeDirection.InOut, IO.Pipes.PipeOptions.Asynchronous, TokenImpersonationLevel.Impersonation)
95110
do! Async.AwaitTask(client.ConnectAsync())
111+
trace "Connected to NeoVim server at %s" pname
96112
let fromNvim = client.CopyToAsync(session.server.Value)
97113
let toNvim = session.server.Value.CopyToAsync(client)
98114
let! _ = Async.AwaitTask(Task.WhenAny [| fromNvim; toNvim |])
@@ -181,4 +197,4 @@ let fvrConnect (stdin: Stream) (stdout: Stream) (verb: FVimRemoteVerb) =
181197
toInt32LE intbuf
182198
with ex ->
183199
trace "%O" ex
184-
-10
200+
FVR_CLIENT_EXCEPTION

neovim.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type Nvim() as nvim =
7676
let id = fvrConnect pipe pipe verb
7777
if id < 0 then
7878
pipe.Dispose()
79-
failwithf "Remote daemon closed the connection with error code %d" id
79+
getErrorMsg id |> failwith
8080
RemoteSession pipe
8181
| FVimRemote(pipe, Remote(prog, args), verb, _) ->
8282
let pname = Option.defaultValue defaultDaemonName pipe
@@ -87,7 +87,7 @@ type Nvim() as nvim =
8787
let id = fvrConnect proc.StandardInput.BaseStream proc.StandardOutput.BaseStream verb
8888
if id < 0 then
8989
proc.Kill()
90-
failwithf "Remote daemon closed the connection with error code %d" id
90+
getErrorMsg id |> failwith
9191
else
9292
trace "Connected to session %d" id
9393
TunneledSession proc

0 commit comments

Comments
 (0)