Skip to content

TextMateSharp with Wasm not working? #57

Open

Description

@hendrikmennen

I saw the package TextmateSharp.Wasm.
Is it possible to run with AvaloniaEdit?
For me AvaloniaEdit alone works in Wasm. As soon as I add some highlighting it breaks, with or without the TextMateSharp.Wasm package.
Maybe I am not doing it right, since I didn't see any demo project for this

Activity

  1. changed the title [-]TextMateSharp with Wasm[/-] [+]TextMateSharp with Wasm not working?[/+] on Oct 26, 2023
  2. danipen commented on Oct 26, 2023

    @danipen
    Owner

    TextMateSharp should support WASM but it's possible that the AvaloniaEdit TextMate integration may not be fully prepared to work with WASM yet.

  3. SKProCH commented on Mar 29, 2024

    @SKProCH

    Hello, @danipen

    Is there any progress on this problem? Seems like TextMate.Wasm package exists, but installing it doesn't change anything - app still hangs while applying coloring to AvaloniaEdit.

  4. danipen commented on Mar 29, 2024

    @danipen
    Owner

    It worked some time ago but I didn't try it recently. Any clue of what the issue is?

  5. SKProCH commented on Mar 29, 2024

    @SKProCH

    Actually I think this is something related to TextMate library calls or coloring the AvaloniaEdit (perhaps a multithreading or something like that). I've actually use your library for ShowMeTheXaml editor: https://github.com/AvaloniaUtils/ShowMeTheXaml.Avalonia/blob/master/ShowMeTheXaml.Avalonia.AvaloniaEdit/XamlDisplayAvaloniaEditThemeBehavior.cs

    And seems like initialization was completed successfully:

    https://github.com/AvaloniaUtils/ShowMeTheXaml.Avalonia/blob/53c1c0c7e3702072a2b77560a67d4cb1abab95cf/ShowMeTheXaml.Avalonia.AvaloniaEdit/XamlDisplayAvaloniaEditThemeBehavior.cs#L27-L34

    But after that apps hangs out.

    Actual issue is reproduceable in Material.Avalonia demo app for browser. Here is the link: https://avaloniacommunity.github.io/Material.Avalonia/ (aim on code icons on the bottom right side of controls on any page).

    Also, this issue only reproduceable in browser WASM, since NAOT app on desktop works fine.

    I'd be grateful for any help to diagnose this issue.

  6. Numpsy commented on Apr 4, 2024

    @Numpsy
    Contributor

    It worked some time ago but I didn't try it recently. Any clue of what the issue is?

    I was never able to get WasmEnableTheads to work properly in Avalonia 11.0 (various problems occuring before it even got to the TextMateSharp bit), but I just had another try with the Avalonia 11.1 nightly and it seems to have worked:

    image

    (that's both highlighting Json and doing folding at the same time)

  7. SKProCH commented on Apr 4, 2024

    @SKProCH

    Hmm, I should give it a try.

  8. SKProCH commented on Apr 7, 2024

    @SKProCH

    Seems like my case still doesn't work properly with nightly avalonia. @Numpsy, can you, please, share your project?

  9. Numpsy commented on Apr 8, 2024

    @Numpsy
    Contributor

    The screen shot I posted is from a project at work that I can't post all the code for, but I'll try to extract a sample out of it

  10. danipen commented on Aug 10, 2024

    @danipen
    Owner

    Guys, you should try v1.0.61. It ships #70, so TextMateSharp now supports WASM and includes native libs for each dotnet (6.0, 7.0, 8.0).

  11. Numpsy commented on Aug 11, 2024

    @Numpsy
    Contributor

    I had a go at a minimal test project using Avalonia.FuncUI at https://github.com/Numpsy/FuncUITextMateSharpWasmTest and the syntax highlighting for Json seems ok (tried on Edge and Firefox on Windows).

    My first go at using TextMateSharp 1.0.61 rather than TextMateSharp.Wasm didn't work. I haven't had time to investigate that in detail, though it might be that the condition at https://github.com/aikawayataro/Onigwrap/blob/a62e9cae00b8cc134f807f59c995ae14b9f969ed/src/Onigwrap/buildTransitive/Onigwrap.targets#L3 doesn't include the native assets when using Avalonia.Browser (with no Blazor)

  12. aikawayataro commented on Aug 12, 2024

    @aikawayataro
    Contributor

    @Numpsy thanks for the example! I'll have a look at it

  13. hendrikmennen commented on Aug 12, 2024

    @hendrikmennen
    Author

    Once I enable "WasmEnableThreads" my app won't start anymore with:

    MONO_WASM: Assert failed: Expect to have one js-module-threads asset in resources
    Error: Assert failed: Expect to have one js-module-threads asset in resources
    at Te (http://127.0.0.1:53299/_framework/dotnet.js:3:18520)
    at J (http://127.0.0.1:53299/_framework/dotnet.js:3:5850)
    at http://127.0.0.1:53299/_framework/dotnet.js:3:27682
    at http://127.0.0.1:53299/_framework/dotnet.js:3:28704
    at async Object.create (http://127.0.0.1:53299/_framework/dotnet.js:3:34625)
    at async http://127.0.0.1:53299/main.js:6:23

    Probably doesn't have anything to do with TextMateSharp though, but without it won't work aswell
    https://github.com/one-ware/OneWare/tree/main/studio/OneWare.Studio.Browser

  14. 2 remaining items

  15. Numpsy commented on Aug 12, 2024

    @Numpsy
    Contributor

    I was just doing some tests with the 1.0.5 onigwrap build, and had this odd situation on Firefox where the behavior varies depending if I have the browser dev tools are open:
    ehhhhh

    (I'm not yet clear if my sample app is doing something wrong, or if there is a timing issue somewhere)

    I also sometimes get this in the diagnostics:
    image

    Reading the linked article, it mentions setting PTHREAD_POOL_SIZE to help with this, and I see that the project linked by @hendrikmennen has _WasmPThreadPoolSize set in the project file, so maybe it could be a configuration thing?

    Why any of this is different to the previous TextMateSharp.Wasm package, I don't know :-(

  16. Numpsy commented on Aug 12, 2024

    @Numpsy
    Contributor

    I've noticed that when I start deleting text from your example, I get a deadlock.

    Additional note: The app I posted the screen shot from on April 4th is actually running AvaloniaEdit in read only mode, so I didn't previously test editing the json after display.

  17. aikawayataro commented on Aug 12, 2024

    @aikawayataro
    Contributor

    Reading the linked article, it mentions setting PTHREAD_POOL_SIZE to help with this, and I see that the project linked by @hendrikmennen has _WasmPThreadPoolSize set in the project file, so maybe it could be a configuration thing?

    I can see an idle worker in dev tools, probably not the reason... Worth trying though

    Why any of this is different to the previous TextMateSharp.Wasm package, I don't know :-(

    Maybe because it was built with older emsdk. I will try to swap the asset with freshly built to confirm.

    Judging by deadlock it should be a threading problem, dont know where to dig though

  18. aikawayataro commented on Aug 12, 2024

    @aikawayataro
    Contributor

    Maybe because it was built with older emsdk. I will try to swap the asset with freshly built to confirm.

    Not confirmed. It works but still hangs with the same deadlock after text is erased.

    I have a wild guess. The only behavior from original Onigwrap I changed was dropping IDisposable in favor of just finalizer. This was supposed to ease freeing of native resources (pattern I follow with small memory resources), but maybe mono's GC has some problems with this. I'll try to understand current state of mono threading in Wasm and see if I can do anything.

  19. aikawayataro commented on Aug 12, 2024

    @aikawayataro
    Contributor

    I have a wild guess. ...

    Not confirmed. Replaced Onigwrap with a dummy implementation and still hangs.

  20. hendrikmennen commented on Aug 12, 2024

    @hendrikmennen
    Author

    I guess we will need to wait a little bit for things to work
    dotnet/runtime#68162

  21. Numpsy commented on Aug 12, 2024

    @Numpsy
    Contributor

    The hang that sometimes happens when changing the highlighted text does appear to work better when running on .NET 9.0 - https://github.com/Numpsy/FuncUITextMateSharpWasmTest/tree/net9.0

  22. aikawayataro commented on Aug 13, 2024

    @aikawayataro
    Contributor

    The hang that sometimes happens when changing the highlighted text does appear to work better when running on .NET 9.0

    Your example with dotnet 9 works for me without any freeze. I've released a new version with a workaround that links the latest available version of the binding with dotnet 9 (at this moment the emsdk used in 8 and 9 is the same).

    Honestly, I would like to wait for dotnet 9 release, it looks very promising for Wasm support. I couldn't set up a debug environment to debug Wasm though, seems like documentation in veryyy early stages 😁

  23. danipen commented on Aug 13, 2024

    @danipen
    Owner

    I bumped the new onigwrap version in a new TextMateSharp v1.0.61. Thanks guys.

  24. Numpsy commented on Sep 30, 2024

    @Numpsy
    Contributor

    The hang that sometimes happens when changing the highlighted text does appear to work better when running on .NET 9.0

    Your example with dotnet 9 works for me without any freeze. I've released a new version with a workaround that links the latest available version of the binding with dotnet 9 (at this moment the emsdk used in 8 and 9 is the same).

    Honestly, I would like to wait for dotnet 9 release, it looks very promising for Wasm support. I couldn't set up a debug environment to debug Wasm though, seems like documentation in veryyy early stages 😁

    According to
    mono/SkiaSharp#3010
    dotnet/runtime#100334

    .NET 9.0 has moved to emscripten 3.1.56.
    Does that require any updates over here to match?

  25. aikawayataro commented on Sep 30, 2024

    @aikawayataro
    Contributor

    .NET 9.0 has moved to emscripten 3.1.56.
    Does that require any updates over here to match?

    Yes, it has to be. Could you please check the value of the EmscriptenVersion property on the latest dotnet 9 preview?

  26. Numpsy commented on Sep 30, 2024

    @Numpsy
    Contributor

    If I run dotnet build --getProperty:EmscriptenVersion with the .NET 9.0 RC-1 SDK then it says 3.1.34, but when I did a dotnet workload update it installed a set of 3.1.56 versions:

    image

  27. aikawayataro commented on Sep 30, 2024

    @aikawayataro
    Contributor

    I will add functionality to use the appropriate version when EmscriptenVersion is defined, thanks for your investigation

  28. Numpsy commented on Nov 15, 2024

    @Numpsy
    Contributor

    for the record:
    I've had the minimal sample working on .NET 9, using Avalonia 11.2.1 and SkiaSharp 2.88.9, though there still seems to be a few issues with all the new versions of things (e.g. dotnet/runtime#109289) and it only presently works for me in release builds.

    Also the shipping .NET 9 apparently has the wrong value for EmscriptenVersion - dotnet/runtime#108972

  29. danipen commented on Nov 15, 2024

    @danipen
    Owner

    There is a workaround for dotnet/runtime#109289 here: AvaloniaUI/Avalonia#17507

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions