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

Document ra_syntax::ast API #3682

Closed
Veetaha opened this issue Mar 22, 2020 · 1 comment · Fixed by #4083
Closed

Document ra_syntax::ast API #3682

Veetaha opened this issue Mar 22, 2020 · 1 comment · Fixed by #4083
Labels
E-has-instructions Issue has some instructions and pointers to code to get started E-medium

Comments

@Veetaha
Copy link
Contributor

Veetaha commented Mar 22, 2020

I wish we had some docs on ast node types, at least an example source code that shows to which kind of symbols the node referes to.
E.g. the difference between Name and NameRef is not very evident, does ParenType pertain to unnamed tuples or tuple structs too and all these kinds of questions arise...

I suppose the ast api is quite stable already so we might want to better document it.
See the reference from matlkad

@matklad matklad added E-medium E-has-instructions Issue has some instructions and pointers to code to get started labels Mar 23, 2020
@matklad
Copy link
Member

matklad commented Mar 23, 2020

As the ast is generated, the docs should actually go to https://github.com/rust-analyzer/rust-analyzer/blob/master/xtask/src/ast_src.rs

bors bot added a commit that referenced this issue Mar 31, 2020
3780: Simplify r=matklad a=Veetaha

I absolutely love tha fact that removing `.clone()` simplifies the code comparing to other languages where it's actually the contrary (ahem ~~`std::move()`~~)

3787: vscode: add syntax tree inspection hovers and highlights r=matklad a=Veetaha

![inspect-tree](https://user-images.githubusercontent.com/36276403/78029767-c7426900-7369-11ea-9ed6-b8a0f8e05bac.gif)
I implemented the reverse mapping (when you hover in the rust editor), but it seems overcomplicated, so I removed it

Related #3682 

Co-authored-by: veetaha <veetaha2@gmail.com>
Co-authored-by: Veetaha <veetaha2@gmail.com>
bors bot added a commit that referenced this issue Apr 2, 2020
3817: vscode: highlight syntax tree ro editor r=matklad a=Veetaha

Small textmate grammar declaration to make rust-analyzer syntax tree more easily inspectable:
Btw, if we change the file extension of our `ra_syntax/test_data/**` files to `.rast` they should be highlighted in vscode too.

The colors of the tokens are actually going to be color-theme dependent, or you can customize them via:
```jsonc
{
    "editor.tokenColorCustomizations": {
        "textMateRules": [ { "scope": "name", "settings": { /* */ } } ] 
    }
}
```
![image](https://user-images.githubusercontent.com/36276403/78204947-99f9d600-74a3-11ea-8315-cb1c87810c7c.png)

Related: #3682

Co-authored-by: veetaha <veetaha2@gmail.com>
bors bot added a commit that referenced this issue Apr 2, 2020
3816: vscode: add goto ast node definition from rust source code r=Veetaha a=Veetaha

By holding the `Ctrl` key you can now goto-definition of the appropriate syntax token in the syntax tree read-only editor. But actually going to the definition is not very convenient, since it opens the new editor, you'd rather just hold the `Ctrl` and look at the syntax tree because it is automatically scrolled to the proper node and the node itself is enclosed with text selection.

Unfortunately, the algorithm is very simple (because we don't do any elaborate parsing of the syntax tree text received from the server), but it is enough to debug not very large source files.
I tested the performance and in a bad case (rust source file with 5K lines of code) it takes `1.3` seconds to build the `rust -> ast` mapping index (lazily once on the first goto definition request) and each lookup in this worst-case is approx `20-120` ms. I think this is good enough. In the simple case where the file is < 100 lines of code, it is instant.

One peculiarity that I've noticed is that vscode doesn't trigger the goto-definition provider when the user triggers it on some punctuation characters (i.e. it doesn't underline them and invoke te goto-definition provider), but if you explicitly click `Ctrl+LMB` it will only then invoke the provider and navigate to the definition in a new editor. I think this is fine ;D

![rust2ast](https://user-images.githubusercontent.com/36276403/78198718-24d1d500-7492-11ea-91f6-2687cedf26ee.gif)


Related: #3682 

Co-authored-by: veetaha <veetaha2@gmail.com>
@bors bors bot closed this as completed in 9594fe3 May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-has-instructions Issue has some instructions and pointers to code to get started E-medium
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants