Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.0.1 #1

Merged
merged 33 commits into from
Jun 17, 2022
Merged

v0.0.1 #1

merged 33 commits into from
Jun 17, 2022

Conversation

SilkyFowl
Copy link
Owner

No description provided.

@SilkyFowl SilkyFowl changed the title WIP: draft analysis logic. WIP: v0.0.1 Jun 3, 2022
@SilkyFowl SilkyFowl changed the title WIP: v0.0.1 v0.0.1 Jun 3, 2022
SilkyFowl added 15 commits June 4, 2022 19:29
- FSharp.Compiler.Service 41.0.3
- Changed to display previews when a function with a LivePreviewAttribute that satisfies the condition exists in editing file.
- This enables previewing of multiple variations.
- Change in LiveView expansion method
- Updated sample code
- EvalResult: change `IWritable<obj>` to   `IWritable<IView>`
- Enable AttachDevTools
- Change sample script to edge case
- Edit environment variable to control LivePreview startup
- Updated sample code
Fix to load required services
- Condition was changed to only "single argument of  `unit` function".
@SilkyFowl
Copy link
Owner Author

WHAT!?

image

dotnet/fsharp#8854

Unfortunately I think only @dsyme has familiarity with this, since the expression API is not a part of the compiler proper. Perhaps @ncave and @alfonsogarciacaro can weigh in here since Fable uses this API extensively.

We'd certainly welcome a pull request here and we're happy to review it. But I'm not sure this will be a high priority for us to implement right now since no supported F# editor tooling makes use of this.

oh...
Hopefully this tool will make implementation a bit more of a priority ......

@alfonsogarciacaro
Copy link

I think I saw that error once though I don't remember well. I will try to check. Is the Analyzers SDK used only to update the UI on the fly? Can the UI be updated when the file is saved? That's what Fable does.

- When there is a pattern that FSharp.Compiler.Service cannot analyze
  Warning message is output when there is a pattern that FSharp.Compiler.Service cannot analyze.
- WIP:Add test cases
@SilkyFowl
Copy link
Owner Author

@alfonsogarciacaro

I will try to check.

Thank you very much.

Can the UI be updated when the file is saved?

I can't do it at the moment, but I think it could be achieved by using FileSystemWatcher or by monitoring file update times. I hope to achieve this at some point.

@SilkyFowl
Copy link
Owner Author

image

I thought a case label with no value could be avoided, but perhaps it is even more troublesome...

@SilkyFowl
Copy link
Owner Author

Since this bug is related to code analysis, it should not be a problem if the DU is precompiled. In other words, if I don't write the DU in the code I want to Preview, I should be able to work around it.
I would like to add test code and sample code to verify this.

@dsyme
Copy link

dsyme commented Jun 11, 2022

What specific construct is being used that is triggering that error?

@SilkyFowl
Copy link
Owner Author

SilkyFowl commented Jun 11, 2022

@dsyme Thanks for your comments, I see great potential in Analyzer.SDK and the draft of Modernizing F# Analysis (dotnet/fsharp#11057) that would follow in its footsteps.

We have not fully verified this yet, so this is current result.
I was looking into it, and I got an unintended exception when I wrote a DU containing a label case with no value, except at the end of the code.

Work

// Some code...

type AnyDuHasNoValueLabelCase =
    | Foo
    | Bar of int

Not Work

// Some code...
// So far, I can analyze it correctly.

type AnyDuHasNoValueLabelCase =
    | Foo
    | Bar of int

// Other some code...
// Not work

Test Code is here.

let module_with_some_value_after_DU =
let baseCode =
sprintf """
open System
open Avalonia.FuncUI
open Avalonia.FuncUI.DSL
open Avalonia.Controls
open Avalonia.FuncUI.LiveView.Core.Types
%s
module Counter =
open Avalonia.FuncUI
open Avalonia.Controls
open Avalonia.Media
open Avalonia.FuncUI.DSL
open Avalonia.Layout
let view =
Component.create (
"Counter",
fun ctx ->
let state = ctx.useState 0
Grid.create [
Grid.rowDefinitions "test,Auto"
Grid.children [
TextBlock.create [
TextBlock.text "Foo!!"
]
]
]
)
[<LivePreview>]
let preview () =
view
[<LivePreview>]
let preview2 =
let n = 1
view
"""
anyNoValueCaseDUs
|> List.map ( fun du ->
[| (baseCode >> box) du |]
)
let nestedAnyNoValueCaseDUs =
[
"""
type Foo = Foo
"""
"""
type Bar =
| Hoge
| Fuga of string
"""
"""
type Bar<'t> =
| Hoge
| Fuga of string
| A of {|a:int; b:string; c: bool * string|}
| B of ('t -> unit)
"""
]
let module_after_DU_contain_module =
let baseCode =
sprintf """
open System
open Avalonia.FuncUI
open Avalonia.FuncUI.DSL
open Avalonia.Controls
open Avalonia.FuncUI.LiveView.Core.Types
module DUs =
%s
module Counter =
open Avalonia.FuncUI
open Avalonia.Controls
open Avalonia.Media
open Avalonia.FuncUI.DSL
open Avalonia.Layout
let view =
Component.create (
"Counter",
fun ctx ->
let state = ctx.useState 0
Grid.create [
Grid.rowDefinitions "test,Auto"
Grid.children [
TextBlock.create [
TextBlock.text "Foo!!"
]
]
]
)
[<LivePreview>]
let preview () =
view
[<LivePreview>]
let preview2 =
let n = 1
view
"""
nestedAnyNoValueCaseDUs
|> List.map ( fun du ->
[| (baseCode >> box) du |]
)
[<Theory>]
[<MemberData(nameof module_with_some_value_after_DU)>]
[<MemberData(nameof module_after_DU_contain_module)>]
let ``wont work If module with some value after DU`` code =
let ex =
Assert.Throws<Sdk.EmptyException>(fun _ ->
createTestCode code
|> Helper.runFuncUIAnalysis
|> ignore
)
ex.Message |> shouldContainText "typecheck error Duplicate definition of type, exception or module 'Counter'"

- Since adding more cases by hand is the source of bugs like this one,
  I would like to change to an implementation using reflection at
  some point.
- change to an implementation using reflection.
- add FUNCUI_LIVEPREVIEW on linux.
@SilkyFowl
Copy link
Owner Author

If it''s considered v0.0.1, it looks good?

livepreview.mp4

@SilkyFowl
Copy link
Owner Author

How to use(memo)

{
    "FSharp.enableAnalyzers": true,
    "FSharp.analyzersPath": [
-        "packages/Analyzers",
+        "packages/analyzers",
        "analyzers"
    ]
}
source https://api.nuget.org/v3/index.json

storage: symlink
framework: net6.0
nuget Avalonia.Desktop >= 0.10.12
nuget Avalonia.Diagnostics >= 0.10.12
nuget FSharp.Core content: none
nuget JaggerJo.Avalonia.FuncUI >= 0.5.0
nuget JaggerJo.Avalonia.FuncUI.DSL >= 0.5.0
nuget JaggerJo.Avalonia.FuncUI.Elmish >= 0.5.0
nuget Avalonia.Angle.Windows.Natives <= 2.1.0.2020091801
nuget SilkyFowl.Avalonia.FuncUI.LiveView

// [ Analyzers Group ]
group Analyzers
    framework: net6.0
    source https://api.nuget.org/v3/index.json
    nuget SilkyFowl.Avalonia.FuncUI.LiveView.Analyzer

--- a/./src/LivePreviewApp/Counter.fs
+++ b/./src/LivePreviewApp/Counter.fs
@@ -1,14 +1,18 @@
-namespace LivePreviewApp
+namespace LivePreviewApp
 
 module Counter =
     open Avalonia.Controls
     open Avalonia.FuncUI
     open Avalonia.FuncUI.DSL
+    open Avalonia.FuncUI.LiveView.Core.Types
     open Avalonia.Layout
 
-    let view =
-        Component(fun ctx ->
-            let state = ctx.useState 0
+    let counter name num =
+        Component.create(
+            name,
+            fun ctx ->
+            let state = ctx.usePassed num
+
             DockPanel.create [
                 DockPanel.verticalAlignment VerticalAlignment.Center
                 DockPanel.horizontalAlignment HorizontalAlignment.Center
@@ -46,3 +50,16 @@ module Counter =
                 ]
             ]
         )
+
+    [<LivePreview>]
+    let preview()=
+        let state = new State<_> 0
+        counter "counter" state
+
+    let view =
+        Component(fun ctx ->
+            let state = ctx.useState 0
+            counter "counter" state
+        )
+
+    

@SilkyFowl
Copy link
Owner Author

@alfonsogarciacaro @dsyme
DU issues are inconvenient but there is a workaround, so I'm going to merge it for now.
I will follow up with a new issue in the future.

@SilkyFowl SilkyFowl merged commit c67e6e7 into master Jun 17, 2022
@SilkyFowl SilkyFowl deleted the v0.0.1 branch June 17, 2022 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants