Skip to content

Commit

Permalink
use FSharp.SystemTextJson
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Nov 19, 2020
1 parent 5111a73 commit 86fe5aa
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
30 changes: 17 additions & 13 deletions daemon.fs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module FVim.daemon

open System
open System.IO.Pipes
open System.Runtime.InteropServices
open System.Diagnostics
open System.Threading.Tasks

open FSharp.Span.Utils
open FSharp.Json

open log
open common
open getopt
open System.Security.Principal

open FSharp.Span.Utils
open System
open System.Diagnostics
open System.IO
open System.IO.Pipes
open System.Runtime.InteropServices
open System.Security.Principal
open System.Text.Json
open System.Text.Json.Serialization
open System.Threading.Tasks

type Session =
{
Expand All @@ -28,6 +28,10 @@ type Session =
let private sessions = hashmap []
let mutable private sessionId = 0
let FVR_MAGIC = [| 0x46uy ; 0x56uy ; 0x49uy ; 0x4Duy |]
let private jsonopts = JsonSerializerOptions()
jsonopts.Converters.Add(JsonFSharpConverter())
let inline private serialize x = JsonSerializer.Serialize(x, jsonopts)
let inline private deserialize<'a> (x: string) = JsonSerializer.Deserialize<'a>(x, jsonopts)

let inline private trace x = trace "daemon" x

Expand Down Expand Up @@ -121,13 +125,13 @@ let serve nvim stderrenc (pipe: NamedPipeServerStream) =
let request: FVimRemoteVerb =
(rbuf, 0, len)
|> Text.Encoding.UTF8.GetString
|> Json.deserialize
|> deserialize
trace "Payload=%A" request
let session =
match request with
| NewSession args -> newSession nvim stderrenc args pipe
| AttachTo id -> attachSession id pipe
| AttachFirst _ -> attachFirstSession pipe
| AttachFirst -> attachFirstSession pipe

match session with
| Error errno ->
Expand Down Expand Up @@ -165,7 +169,7 @@ let daemon (pname: string option) (nvim: string) (stderrenc: Text.Encoding) =
let fvrConnect (stdin: Stream) (stdout: Stream) (verb: FVimRemoteVerb) =
let payload =
verb
|> Json.serialize
|> serialize
|> Text.Encoding.UTF8.GetBytes
let intbuf = fromInt32LE payload.Length
try
Expand Down
2 changes: 1 addition & 1 deletion fvim.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
<PackageReference Include="FSharp.Control.Reactive" Version="4.4.2" />
<PackageReference Include="FSharp.Data" Version="3.3.3" />
<PackageReference Include="FSharp.Core" Version="5.0" />
<PackageReference Include="FSharp.Json" Version="0.4.0" />
<PackageReference Include="FSharp.Span.Utils" Version="1.1.3353.13900" />
<PackageReference Include="FSharp.SystemTextJson" Version="0.14.8" />
<PackageReference Include="MessagePack" Version="1.9.11" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Include="NSubsys" Version="1.0.0">
Expand Down
4 changes: 2 additions & 2 deletions getopt.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type NeovimRemoteEndpoint =
type FVimRemoteVerb =
| AttachTo of id: int
| NewSession of args: string list
| AttachFirst of args: int // FSharp.Json bug
| AttachFirst
// | Interactive

type FVimRemoteTransport =
Expand Down Expand Up @@ -125,7 +125,7 @@ let parseOptions (args: string[]) =
else Local
let verb =
match fvrVerb.ToLowerInvariant() with
| "attach" | "a" -> AttachFirst 0
| "attach" | "a" -> AttachFirst
| "new" | "n" -> NewSession(argsL)
| v -> AttachTo(int v)
let files =
Expand Down
8 changes: 3 additions & 5 deletions input.fs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ let rec (|ModifiersPrefix|_|) (x: InputEvent) =
| TextInput _ -> None
| _ -> None

let mutable _imeArmed = false
let mutable private _imeArmed = false

let onInput (nvim: Nvim) (input: IObservable<int*InputEvent>) =
let inputClassifier =
Expand Down Expand Up @@ -307,14 +307,12 @@ let onInput (nvim: Nvim) (input: IObservable<int*InputEvent>) =
let mouse = inputClassifier |> Observable.choose (function | Choice2Of3 x -> Some x | _ -> None)
Disposables.compose [
key |> Observable.subscribe(fun x ->
nvim.input x
|> ignore
nvim.input x |> ignore
)
mouse |> Observable.subscribe(fun (grid, (but, act, r, c, rep), mods) ->
let mods = match mods with Some mods -> mods | _ -> ""
for _ in 1..rep do
nvim.input_mouse but act mods grid r c
|> ignore
nvim.input_mouse but act mods grid r c |> ignore
)
]

4 changes: 3 additions & 1 deletion ui.fs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ let GetTypeface(txt, italic, bold, font, wfont) =
match w with
| CharType.Wide -> _get wfont
| CharType.Powerline
| CharType.Nerd when states.font_nonerd -> nerd_typeface
| CharType.Nerd when not states.font_nonerd -> nerd_typeface
| CharType.Emoji -> emoji_typeface
| _ -> _get font

Expand Down Expand Up @@ -229,7 +229,9 @@ let RenderText (ctx: IDrawingContextImpl, region: Rect, scale: float, fg: Color,

// emoji, nerd params calibration hack...
let isEmoji = emoji_typeface = font
let isNerd = nerd_typeface = font
let fontSize = if isEmoji then fontSize - 1.0 else fontSize
let clip = clip || isNerd

let glyphTypeface = font.GlyphTypeface
let px_per_unit = fontSize / float glyphTypeface.DesignEmHeight
Expand Down

0 comments on commit 86fe5aa

Please sign in to comment.