Skip to content

Commit

Permalink
Merge branch 'master' into windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Mar 10, 2021
2 parents 218583a + 70730b5 commit afc4df6
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 57 deletions.
14 changes: 14 additions & 0 deletions .vimspector.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"configurations": {
"launch - netcoredbg": {
"adapter": "netcoredbg",
"configuration": {
"request": "launch",
"program": "${workspaceRoot}/bin/Debug/netcoreapp3.1/FVim.dll",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceRoot}"
}
}
}
}
47 changes: 33 additions & 14 deletions Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ open common
open shell
open daemon
open MessagePack.Formatters
open FVim.ui

let inline trace x = FVim.log.trace "main" x

// Avalonia configuration, don't remove; also used by visual designer.
[<CompiledName "BuildAvaloniaApp">]
Expand All @@ -24,7 +27,7 @@ let buildAvaloniaApp() =
.Configure<App>()
.UsePlatformDetect()
.UseReactiveUI()
.With(new Win32PlatformOptions(UseDeferredRendering=false))
.With(new Win32PlatformOptions(UseDeferredRendering=false, UseWgl=true))
.With(new AvaloniaNativePlatformOptions(UseDeferredRendering=false))
.With(new X11PlatformOptions(UseDeferredRendering=false))
.With(new MacOSPlatformOptions(ShowInDock=true))
Expand Down Expand Up @@ -65,23 +68,39 @@ let startMainWindow app serveropts =
>>= fun comp -> states.background_composition <- comp; None
|> ignore

let mainwin = new MainWindowViewModel(workspace)
app <| MainWindow(DataContext = mainwin)
let x, y, w, h =
let x, y, w, h = (int mainwin.X), (int mainwin.Y), (int mainwin.Width), (int mainwin.Height)
// sometimes the metrics will just go off...
// see #136
let x, y = (max x 0), (max y 0)
if x + w < 0 || y + h < 0
then 0, 0, 800, 600
else x, y, w, h
config.save cfg x y w h (mainwin.WindowState.ToString()) (states.backgroundCompositionToString states.background_composition) mainwin.CustomTitleBar
let mainwinVM = new MainWindowViewModel(workspace)
let mainwin = MainWindow(DataContext = mainwinVM)
// sometimes the metrics will just go off...
// see #136
let screenBounds =
mainwin.Screens.All
|> Seq.fold (fun r (s: Platform.Screen) -> s.Bounds.Union r) (PixelRect())
let boundcheck() =
let mutable winBounds =
PixelRect(max (int mainwinVM.X) screenBounds.X,
max (int mainwinVM.Y) screenBounds.Y,
min (int mainwinVM.Width) screenBounds.Width,
min (int mainwinVM.Height) screenBounds.Height)
if winBounds.Right > screenBounds.Right then
winBounds <- winBounds.WithX(screenBounds.Right - winBounds.Width)
if winBounds.Bottom > screenBounds.Bottom then
winBounds <- winBounds.WithY(screenBounds.Bottom - winBounds.Height)
trace "mainwin bound adjusted to %O" winBounds
mainwinVM.X <- float winBounds.X
mainwinVM.Y <- float winBounds.Y
mainwinVM.Width <- float winBounds.Width
mainwinVM.Height <- float winBounds.Height
boundcheck()
app <| mainwin
boundcheck()
let x, y, w, h = (int mainwinVM.X), (int mainwinVM.Y), (int mainwinVM.Width), (int mainwinVM.Height)
config.save cfg x y w h (mainwinVM.WindowState.ToString()) (states.backgroundCompositionToString states.background_composition) mainwinVM.CustomTitleBar
0

let startCrashReportWindow app ex =
let app = app()
FVim.log.trace "main" "displaying crash dialog"
FVim.log.trace "main" "exception: %O" ex
trace "displaying crash dialog"
trace "exception: %O" ex
let code, msgs = states.get_crash_info()
let crash = new CrashReportViewModel(ex, code, msgs)
let win = new CrashReport(DataContext = crash)
Expand Down
3 changes: 3 additions & 0 deletions Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"profiles": {
"fvim": {
"commandName": "Project"
},
"multigrid": {
"commandName": "Project",
"commandLineArgs": "--debug-multigrid"
},
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ Cross platform Neovim front-end UI, built with [F#](https://fsharp.org/) + [Aval
### Installation
[Download](https://github.com/yatli/fvim/releases) the latest release package for your system, extract and run `FVim`!

- For Windows 7, use the `win7-x64` package.
- Make sure you have [KB2533623](https://www.microsoft.com/en-us/download/details.aspx?id=26764) installed.
- For Windows 7 / Vista / 8.1 / Server 2008 R2 / Server 2012 R2, use the `win7-x64` package.
- Follow [these additional steps to install compatibility patches](https://docs.microsoft.com/en-us/dotnet/core/install/windows?tabs=netcore31&pivots=os-windows#additional-deps).
- The link to the KB update is no longer functioning. [The issue is tracked here](https://github.com/dotnet/docs/issues/20459).
- For Windows 10, use the `win-x64` package -- this version has faster startup.
- For macOS, it's packaged as an app bundle -- unzip and drag it to your applications folder.
- For Linux:
- Debian based distributions: `dpkg -i fvim_package_name.deb`
- Arch Linux: [Install via AUR](https://aur.archlinux.org/packages/fvim/)
- RPM-based distributions: `rpm -ivh fvim_package_name.rpm`
- Fedora: `dnf install fvim_package_name.rpm`
- Compile from Source (having dotnet-sdk-3.1+ installed):
- Compile from Source (having dotnet-sdk-3.1.404+ installed):
```
git clone https://github.com/yatli/fvim && cd fvim && dotnet publish -f netcoreapp3.1 -c Release -r linux-x64 --self-contained
```
Expand Down
5 changes: 3 additions & 2 deletions ViewModels/CrashReportViewModel.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace FVim

open ui
open log
open common
open Avalonia.Media

type CrashReportViewModel(ex: exn, code: int, msgs: ResizeArray<string>) =
inherit ViewModelBase()
Expand All @@ -25,3 +24,5 @@ type CrashReportViewModel(ex: exn, code: int, msgs: ResizeArray<string>) =
"Feel free to create new issues, and I'll help to triage and fix the problem."
tip + generic_message

member __.Font =
FontFamily(ui.DefaultFont)
6 changes: 3 additions & 3 deletions Views/CrashReport.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120" />
<ColumnDefinition Width="400" />
<ColumnDefinition Width="600" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="FVim exited unexpectedly." Grid.Row="0" Grid.Column="1" Margin="0,10,0,0" FontWeight="Bold"/>
<TextBlock Text="Close this window to exit FVim." Grid.Row="3" Grid.Column="1" Margin="0,10,0,0" FontWeight="Bold"/>
<Image Source="/Assets/error.png" Grid.Row="0" Grid.RowSpan="4" Grid.Column="0" Height="64" Margin="0,0,0,50" />
<TextBox Text="{Binding MainMessage}" Grid.Row="1" Grid.Column="1" Margin="0,20,0,0"
AcceptsReturn="True" TextWrapping="Wrap" />
AcceptsReturn="True" FontFamily="{Binding Font}" />
<TextBlock Text="{Binding TipMessage}" Grid.Row="2" Grid.Column="1" Margin="0,20,0,0" />
<TextBlock Text="Stack trace:" Grid.Row="0" Grid.Column="2" Margin="0,10,0,0"/>
<TextBox Text="{Binding StackTrace}" Grid.Row="1" Grid.RowSpan="2" Grid.Column="2" Margin="10,10,10,10"
AcceptsReturn="True" TextWrapping="Wrap" />
AcceptsReturn="True" FontFamily="{Binding Font}" />
</Grid>
</Window>
1 change: 1 addition & 0 deletions Views/CrashReport.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ type CrashReport() as this =

do
AvaloniaXamlLoader.Load(this)

26 changes: 26 additions & 0 deletions def.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,35 @@ open common

open Avalonia.Media
open System
open System.Threading.Tasks

let inline private trace fmt = trace "def" fmt

[<Struct>]
type Request =
{
method: string
parameters: obj[]
}

[<Struct>]
type Response =
{
result: Result<obj, obj>
}

[<Struct>]
type Event =
| Request of reqId: int32 * req: Request * handler: (int32 -> Response -> unit Task)
| Response of rspId: int32 * rsp: Response
| Notification of nreq: Request
| Error of emsg: string
| Crash of ccode: int32
| ByteMessage of bmsg: byte
| UnhandledException of ex: exn
| Exit


[<Struct>]
type CursorShape =
| Block
Expand Down
1 change: 1 addition & 0 deletions input.fs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ let (|Mouse|Special|Normal|ImeEvent|TextInput|Unrecognized|) (x: InputEvent) =
(Key.NumPad0 | Key.NumPad1 | Key.NumPad2 | Key.NumPad3
| Key.NumPad4 | Key.NumPad5 | Key.NumPad6 | Key.NumPad7
| Key.NumPad8 | Key.NumPad9)) -> Special("k" + string(x.ToString() |> Seq.last))
| Key(_, Key.Decimal) -> Normal "."
| Key(NoFlag(KeyModifiers.Shift), Key.OemComma) -> Normal ","
| Key(NoFlag(KeyModifiers.Shift), Key.OemPeriod) -> Normal "."
| Key(HasFlag(KeyModifiers.Shift), Key.OemPeriod) -> Normal ">"
Expand Down
28 changes: 16 additions & 12 deletions neovim.fs
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,22 @@ type Nvim() as nvim =

let pending = ConcurrentDictionary<int, TaskCompletionSource<Response>>()
let parse (data: obj) : Event =
match data :?> obj[] with
// request
| [| (Integer32 0); (Integer32 msg_id) ; (String method); :? (obj[]) as parameters |]
-> Request(msg_id, { method = method; parameters = parameters }, reply)
// response
| [| (Integer32 1); (Integer32 msg_id) ; err; result |]
-> Response(msg_id, { result = if err = null then Ok result else Result.Error err })
// notification
| [| (Integer32 2); (String method); :? (obj[]) as parameters |]
-> Notification { method = method; parameters = parameters }
// event forwarding
| [| :? Event as e |] -> e
match data with
| :? (obj[]) as data ->
match data with
// request
| [| (Integer32 0); (Integer32 msg_id) ; (String method); :? (obj[]) as parameters |]
-> Request(msg_id, { method = method; parameters = parameters }, reply)
// response
| [| (Integer32 1); (Integer32 msg_id) ; err; result |]
-> Response(msg_id, { result = if err = null then Ok result else Result.Error err })
// notification
| [| (Integer32 2); (String method); :? (obj[]) as parameters |]
-> Notification { method = method; parameters = parameters }
// event forwarding
| [| :? Event as e |] -> e
| _ -> raise <| EventParseException(data)
| :? byte as b -> ByteMessage b
| _ -> raise <| EventParseException(data)

let intercept (ev: Event) =
Expand Down
29 changes: 6 additions & 23 deletions states.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,11 @@ open Avalonia.Layout
open System.Threading.Tasks
open FSharp.Control.Tasks.V2

[<Struct>]
type Request =
{
method: string
parameters: obj[]
}

[<Struct>]
type Response =
{
result: Result<obj, obj>
}

[<Struct>]
type Event =
| Request of reqId: int32 * req: Request * handler: (int32 -> Response -> unit Task)
| Response of rspId: int32 * rsp: Response
| Notification of nreq: Request
| Error of emsg: string
| Crash of ccode: int32
| UnhandledException of ex: exn
| Exit

let private _stateChangeEvent = Event<string>()
let private _appLifetime = lazy(Avalonia.Application.Current.ApplicationLifetime :?> Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime)
let mutable private _crashcode = 0
let private _errormsgs = ResizeArray<string>()
let private _bytemsg = ResizeArray<byte>()

// request handlers are explicitly registered, 1:1, with no broadcast.
let requestHandlers = hashmap[]
Expand Down Expand Up @@ -269,7 +247,12 @@ let msg_dispatch =
| Error err ->
error "rpc" "neovim: %s" err
_errormsgs.Add err
| ByteMessage bmsg ->
_bytemsg.Add bmsg
| Exit ->
if _bytemsg.Count <> 0 then
let _bytemsg = System.Text.Encoding.UTF8.GetString(_bytemsg.ToArray())
failwithf "neovim says:\n%s" _bytemsg
trace "rpc" "shutting down application lifetime"
Shutdown 0
| Crash code ->
Expand Down

0 comments on commit afc4df6

Please sign in to comment.