ast-explorer icon indicating copy to clipboard operation
ast-explorer copied to clipboard

autofocus not working with Rust / syn

Open blueglyph opened this issue 1 year ago • 5 comments

Describe the bug

The standard library to parse Rust is now syn 2.0, so it's great that it's supported by this AST explorer. Unfortunately, the autofocus doesn't work, neither with the tree or JSON representation.

I'm not sure whether it's a bug or a feature request, but the option is there and not working, so I reported it as a bug.

With other languages, the feature is working (I only checked Javascript and HTML): when I move the cursor in the left panel, the right panel is expanding the AST to show and focus on the corresponding elements. Without that, it's almost impossible to use the tool.

How to reproduce

  • https://ast-explorer.dev/
  • select Rust and syn
  • move the cursor or select any part of the sample code => no focus on the right panel (either with tree or JSON representation)

Reproduction

100 %

System Info

Website version at https://ast-explorer.dev/ with AST Explorer version 0.27.1
Brave v1.77.95 or Firefox 137.0
(Windows 10 x64 22H2)

Used Package Manager

n/a

Validations

  • [x] Follow our Code of Conduct
  • [x] Read the Contributing Guide.
  • [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • [x] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • [x] The provided reproduction is a minimal reproducible of the bug.

blueglyph avatar Apr 05 '25 13:04 blueglyph

This is because the AST generated by astexplorer-syn includes only line and column information, without an offset, which is currently not supported.

sxzz avatar Apr 13 '25 15:04 sxzz

It's odd, another ast explorer works. https://astexplorer.net/#/gist/fc7356a18684fd9d898a048034044263/3d8e01de427ca159edd904827886d9b6e6bb1b6e

taikulawo avatar Nov 13 '25 06:11 taikulawo

It's odd, another ast explorer works. https://astexplorer.net/#/gist/fc7356a18684fd9d898a048034044263/3d8e01de427ca159edd904827886d9b6e6bb1b6e

This one is the old version of syn (see at the top right: it's version 1). My issue is about version 2:

The standard library to parse Rust is now syn 2.0, so it's great that it's supported by this AST explorer.

blueglyph avatar Nov 13 '25 08:11 blueglyph

I don't found offset in syn1, only have span in there.

{
    "start": {
        "_type": "LineColumn",
        "line": 1,
        "column": 0
      },
      "end": {
        "_type": "LineColumn",
        "line": 1,
        "column": 2
      }
}

I think start and end is already enough for locate code.

Can we just copy https://github.com/fkling/astexplorer/blob/master/website/src/parsers/rust/syn.js#L20-L40?

taikulawo avatar Nov 13 '25 12:11 taikulawo

PR welcome if anyone wants to work on that!

sxzz avatar Nov 13 '25 14:11 sxzz