Skip to content

Commit

Permalink
enjoy some FS1001
Browse files Browse the repository at this point in the history
  • Loading branch information
yatli committed Mar 14, 2022
1 parent 06ef298 commit 67faad2
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 29 deletions.
7 changes: 4 additions & 3 deletions Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ let main(args: string[]) =
let _ = Thread.CurrentThread.TrySetApartmentState(ApartmentState.STA)

AppDomain.CurrentDomain.UnhandledException.Add(fun exArgs ->
let filename = Path.Combine(config.configdir, sprintf "fvim-crash-%s.txt" (DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")))
let datetime = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")
let filename = Path.Combine(config.configdir, $"fvim-crash-{datetime}.txt")
use dumpfile = new StreamWriter(filename)
dumpfile.WriteLine(sprintf "Unhandled exception: (terminating:%A)" exArgs.IsTerminating)
dumpfile.WriteLine(exArgs.ExceptionObject.ToString())
dumpfile.WriteLine($"Unhandled exception: (terminating:%A{exArgs.IsTerminating})")
dumpfile.WriteLine($"{exArgs.ExceptionObject}")
)
System.Console.OutputEncoding <- System.Text.Encoding.Unicode

Expand Down
2 changes: 1 addition & 1 deletion ViewModels/CompletionItemViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module CompletionItemHelper =
Map.map (fun k name ->
if name = "Unknown" then null
else
let fname = sprintf "avares://FVim/Assets/intellisense/%s_16x.png" name
let fname = $"avares://FVim/Assets/intellisense/{name}_16x.png"
(*trace "CompleteItem" "loading intellisense icon %s" fname*)
new Bitmap(assets.Open(new System.Uri(fname))))

Expand Down
6 changes: 3 additions & 3 deletions ViewModels/CrashReportViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ open Avalonia.Media
type CrashReportViewModel(ex: exn, code: int, msgs: ResizeArray<string>) =
inherit ViewModelBase()
member __.MainMessage =
sprintf "Exit code: %d\n" code +
sprintf "Exception message: %s\n" ex.Message +
join msgs
$"""Exit code: {code}
Exception message: {ex.Message}
{join msgs}"""
member __.StackTrace =
ex.StackTrace
member __.TipMessage =
Expand Down
4 changes: 2 additions & 2 deletions ViewModels/FrameViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type FrameViewModel(cfg: config.ConfigObject.Workspace option, ?_maingrid: GridV
let toggleFullScreen() =
if mainGrid.IsFocused then
this.Fullscreen <- not this.Fullscreen
trace (sprintf "FrameVM #%d" mainGrid.GridId) "ToggleFullScreen %A" this.Fullscreen
trace $"FrameVM #{mainGrid.GridId}" "ToggleFullScreen %A" this.Fullscreen

let updateBackgroundImage() =
try
Expand All @@ -69,7 +69,7 @@ type FrameViewModel(cfg: config.ConfigObject.Workspace option, ?_maingrid: GridV
path.[2..])
else
path
trace (sprintf "FrameVM #%d" mainGrid.GridId) "%s" path
trace $"FrameVM #{mainGrid.GridId}" "%s" path
let new_img = new Bitmap(path)
ignore <| this.RaiseAndSetIfChanged(&m_bgimg_src, new_img, "BackgroundImage")
ignore <| this.RaiseAndSetIfChanged(&m_bgimg_w, m_bgimg_src.Size.Width, "BackgroundImageW")
Expand Down
2 changes: 1 addition & 1 deletion ViewModels/GridViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ open Avalonia.Interactivity

module private GridViewModelHelper =
let inline trace id fmt =
FVim.log.trace (sprintf "editorvm #%d" id) fmt
FVim.log.trace $"editorvm #{id}" fmt

open GridViewModelHelper

Expand Down
2 changes: 1 addition & 1 deletion Views/Grid.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ type Grid() as this =

let drawDebug(dc: IDrawingContextImpl) =
let txt = Media.FormattedText()
txt.Text <- sprintf "Grid #%d, Z=%d" grid_vm.GridId this.ZIndex
txt.Text <- $"Grid #{grid_vm.GridId}, Z={this.ZIndex}"
txt.Typeface <- Media.Typeface("Iosevka Slab")

dc.DrawText(Media.Brushes.Tan, Point(10.0, 10.0), txt.PlatformImpl)
Expand Down
6 changes: 3 additions & 3 deletions daemon.fs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ let pipeaddr x =
then @"\\.\pipe\" + x
else pipeaddrUnix x

let pipename = sprintf "fvr_%s"
let pipename (x:'a) = $"fvr_{x}"

let defaultDaemonName = pipename "main"

Expand All @@ -71,7 +71,7 @@ let attachSession id svrpipe =
let newSession nvim stderrenc args svrpipe =
let myid = sessionId

let pname = pipename (string myid)
let pname = pipename myid
let paddr = pipeaddr pname
let args = "--headless" :: "--listen" :: paddr :: args
let proc = newProcess nvim args stderrenc
Expand Down Expand Up @@ -105,7 +105,7 @@ let attachFirstSession svrpipe =

let serveSession (session: Session) =
task {
let pname = pipename (string session.id)
let pname = pipename session.id
use client = new NamedPipeClientStream(".", pname, IO.Pipes.PipeDirection.InOut, IO.Pipes.PipeOptions.Asynchronous, TokenImpersonationLevel.Impersonation)
do! client.ConnectAsync()
trace "Connected to NeoVim server at %s" pname
Expand Down
4 changes: 2 additions & 2 deletions def.fs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ type Rune =
override x.ToString() =
match x with
| SingleChar c -> c.ToString()
| SurrogatePair(c1, c2) -> sprintf "%c%c" c1 c2
| SurrogatePair(c1, c2) -> $"{c1}{c2}"
| Composed str -> String.Join("", str)
override x.GetHashCode() =
match x with
Expand Down Expand Up @@ -432,7 +432,7 @@ type RedrawCommand =
type EventParseException(data: obj) =
inherit exn()
member __.Input = data
override __.Message = sprintf "Could not parse the neovim message: %A" data
override __.Message = $"Could not parse the neovim message: %A{data}"

/// Matches ObjArray against the [|string; p1; p2; ... |] form
let (|C|_|) (x:obj) =
Expand Down
2 changes: 1 addition & 1 deletion getopt.fs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ let parseOptions (args: string[]) =
| None, None ->
let prog, args, r =
if wsl then
"wsl", ["bash"; "-l"; "-c"; sprintf "nvim --embed %s" (args |> escapeArgs |> join)], true
"wsl", ["bash"; "-l"; "-c"; $"nvim --embed {args |> escapeArgs |> join}"], true
elif ssh.IsSome then
"ssh", [ssh.Value; nvim; "--embed"] @ argsL, true
else
Expand Down
8 changes: 4 additions & 4 deletions input.fs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ let rec ModifiersPrefix (x: InputEvent) =
let a = if m.HasFlag(KeyModifiers.Alt) then "A-" else ""
let d = if m.HasFlag(KeyModifiers.Meta) then "D-" else ""
let s = if m.HasFlag(KeyModifiers.Shift) then "S-" else ""
(sprintf "%s%s%s%s" c a d s).TrimEnd('-')
$"{c}{a}{d}{s}".TrimEnd('-')
| TextInput _ -> ""
| _ -> ""

Expand All @@ -401,10 +401,10 @@ let onInput (nvim: Nvim) (input: IObservable<int*InputEvent*RoutedEventArgs>) =
ev.Handled <- true
let pref = ModifiersPrefix x
match x,pref with
| (Special sp), "" -> Some(sprintf "<%s>" sp)
| (Special sp), pref -> Some(sprintf "<%s-%s>" pref sp)
| (Special sp), "" -> Some($"<{sp}>")
| (Special sp), pref -> Some($"<{pref}-{sp}>")
| (Normal n), "" -> Some n
| (Normal n), pref -> Some(sprintf "<%s-%s>" pref n)
| (Normal n), pref -> Some($"<{pref}-{n}>")
| x ->
#if DEBUG
trace "rejected: %A" x
Expand Down
6 changes: 3 additions & 3 deletions log.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ open System.Collections.Generic
let mutable private _filter = fun _ -> true

let private _logsSource = Event<string*string>()
let private _logsPub = _logsSource.Publish |> Observable.map (fun (a,b) -> sprintf "%s: %s" a b)
let private _logsPub = _logsSource.Publish |> Observable.map (fun (a,b) -> $"{a}: {b}")

let private _logsESource = Event<string*string>()
let private _logsEPub = _logsESource.Publish |> Observable.map (fun (a,b) -> sprintf "error: %s: %s" a b)
let private _logsEPub = _logsESource.Publish |> Observable.map (fun (a,b) -> $"error: {a}: {b}")

let private _logsSink = Observable.merge _logsPub _logsEPub
|> Observable.filter(fun x -> _filter x)
Expand Down Expand Up @@ -45,7 +45,7 @@ let init { logToStdout = logToStdout; logToFile = logToFile; logPatterns = logPa
| _ -> "fvim"
if logToFile then
_n_logsSink <- _n_logsSink + 1
let logname = sprintf "%s-%s.log" fprefix ftime
let logname = $"{fprefix}-{ftime}.log"
let logToFile = System.IO.Path.Combine(config.configdir, logname)
try System.IO.File.Delete logToFile
with _ -> ()
Expand Down
2 changes: 1 addition & 1 deletion model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ let Detach() =
let private UpdateUICapabilities() =
let opts = hashmap[]
states.PopulateUIOptions opts
trace "UpdateUICapabilities: %A" <| String.Join(", ", Seq.map (fun (KeyValue(k, v)) -> sprintf "%s=%b" k v) opts)
trace "UpdateUICapabilities: %A" <| String.Join(", ", Seq.map (fun (KeyValue(k, v)) -> $"{k}={v}") opts)
backgroundTask {
do! init.Task
for KeyValue(k, v) in opts do
Expand Down
2 changes: 1 addition & 1 deletion neovim.fs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ type Nvim() as nvim =
| 1 -> "1"
| _ -> "+"

nvim.command(sprintf "command! -nargs=%s %s %s" nargs name cmd)
nvim.command $"command! -nargs={nargs} {name} {cmd}"

member __.exec (src: string) (output: bool) =
nvim.call { method = "nvim_exec"; parameters = mkparams2 src output }
Expand Down
4 changes: 2 additions & 2 deletions shell.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let private win32RegisterFileAssociation() =
let HKCR = Registry.ClassesRoot
let HKLM = Registry.LocalMachine
let exe = Path.Combine(FVimDir, "FVim.exe")
let fvicon = sprintf "%s,0" exe
let fvicon = $"{exe},0"

let setupShell(key: RegistryKey) (ico: string) =

Expand All @@ -81,7 +81,7 @@ let private win32RegisterFileAssociation() =
_edit.SetValue("", "Open with FVim")
_edit.SetValue("Icon", fvicon)
use command = _edit.CreateSubKey("command")
command.SetValue("", sprintf "\"%s\" \"%%1\"" exe)
command.SetValue("", $"\{exe}\" \"%%1\"")

// https://docs.microsoft.com/en-us/windows/desktop/shell/app-registration
do
Expand Down
2 changes: 1 addition & 1 deletion ui.fs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ let DefaultFontEmoji =
let private nerd_typeface =
let name = if RuntimeInformation.IsOSPlatform(OSPlatform.OSX) then "Iosevka Nerd Font"
else "Iosevka"
Typeface(sprintf "resm:fvim.Fonts.nerd.ttf?assembly=FVim#%s" name)
Typeface($"resm:fvim.Fonts.nerd.ttf?assembly=FVim#{name}")
let private emoji_typeface = Typeface(DefaultFontEmoji)
let private fontcache = System.Collections.Generic.Dictionary<string*bool*bool, Typeface>()

Expand Down

0 comments on commit 67faad2

Please sign in to comment.