Skip to content

Commit 56604a9

Browse files
author
Yatao Li
committed
move argument organization to getopt to allow custom processing for wsl
1 parent d108f3f commit 56604a9

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

getopt.fs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ type Options =
2323
args: string list
2424
program: string
2525
stderrenc: System.Text.Encoding
26-
preArgs: string list
2726
server: ServerOptions
2827
}
2928

@@ -61,15 +60,6 @@ let parseOptions (args: string[]) =
6160
if wsl && ssh.IsSome then
6261
failwith "--wsl and --ssh cannot be used together."
6362

64-
let prog = if wsl then "wsl" elif ssh.IsSome then "ssh" else nvim
65-
let preargs = if wsl then ["bash"; "-l"; "-c"; "nvim"] elif ssh.IsSome then [ssh.Value; nvim] else []
66-
let enc = if wsl then System.Text.Encoding.Unicode else System.Text.Encoding.UTF8
67-
68-
let intent =
69-
if setup then Setup
70-
elif runDaemon then Daemon(port, pipe)
71-
else Start
72-
7363
if terminal then
7464
let set x = "+\"set " + x + "\""
7565
// fvim --wsl -u NORC +terminal +"set noshowmode" +"set laststatus=0" +"set noruler" +"set noshowcmd"
@@ -85,6 +75,33 @@ let parseOptions (args: string[]) =
8575
| None -> "+terminal"
8676
|> args.Add
8777

78+
let prog =
79+
if wsl then
80+
"wsl"
81+
elif ssh.IsSome then
82+
"ssh"
83+
else
84+
nvim
85+
86+
let args =
87+
if wsl then
88+
["bash"; "-l"; "-c"; sprintf "nvim --embed %s" (args |> escapeArgs |> join)]
89+
elif ssh.IsSome then
90+
[ssh.Value; nvim; "--embed"] @ (List.ofSeq args)
91+
else
92+
["--embed"] @ (List.ofSeq args)
93+
94+
let enc =
95+
if wsl then
96+
System.Text.Encoding.Unicode
97+
else
98+
System.Text.Encoding.UTF8
99+
100+
let intent =
101+
if setup then Setup
102+
elif runDaemon then Daemon(port, pipe)
103+
else Start
104+
88105
let serveropts =
89106
if tryDaemon then
90107
TryDaemon
@@ -100,9 +117,8 @@ let parseOptions (args: string[]) =
100117
logToFile = trace_to_file
101118
logPatterns = trace_patterns
102119
program = prog
103-
args = List.ofSeq args
120+
args = args
104121
server = serveropts
105-
preArgs = preargs
106122
stderrenc = enc
107123
intent = intent
108124
}

neovim/neovim.process.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ type Nvim() =
4747
| Some events -> events
4848
| None -> failwith "events"
4949

50-
member private this.createIO ({ args = args; server = serveropts; program = prog; preArgs = preargs; stderrenc = enc } as opts) =
50+
member private this.createIO ({ args = args; server = serveropts; program = prog; stderrenc = enc } as opts) =
5151
match serveropts with
5252
| StartNew ->
53-
let args = "--embed" :: args
54-
let psi = ProcessStartInfo(prog, (join << escapeArgs) (preargs @ args))
53+
let args = args |> escapeArgs |> join
54+
let psi = ProcessStartInfo(prog, args)
5555
psi.CreateNoWindow <- true
5656
psi.ErrorDialog <- false
5757
psi.RedirectStandardError <- true
@@ -62,6 +62,7 @@ type Nvim() =
6262
psi.WindowStyle <- ProcessWindowStyle.Hidden
6363
psi.WorkingDirectory <- Environment.CurrentDirectory
6464

65+
trace "Starting process. Program: %s; Arguments: %s" prog args
6566
StartProcess <| Process.Start(psi)
6667
| Tcp ipe ->
6768
let sock = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp)

0 commit comments

Comments
 (0)