diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-02 09:34:03 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-02 09:34:03 +0100 |
commit | 9ee96dcf4a2b47a6df0e3ea379d36aec2e6e1784 (patch) | |
tree | 672f5ebda7447c06ff28556515e41b13cef261e1 /docs | |
parent | 98f7842e408587fdaca3d15d8eda677b689a035a (diff) | |
parent | dd5e4d4870b4e59bc82d285c481bb6971d016912 (diff) |
Merge #3816
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 <[email protected]>
Diffstat (limited to 'docs')
-rw-r--r-- | docs/dev/README.md | 10 | ||||
-rw-r--r-- | docs/user/features.md | 6 |
2 files changed, 10 insertions, 6 deletions
diff --git a/docs/dev/README.md b/docs/dev/README.md index 8d7e18010..f230dc1db 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md | |||
@@ -155,6 +155,16 @@ There's also two VS Code commands which might be of interest: | |||
155 | 155 | ||
156 | * `Rust Analyzer: Syntax Tree` shows syntax tree of the current file/selection. | 156 | * `Rust Analyzer: Syntax Tree` shows syntax tree of the current file/selection. |
157 | 157 | ||
158 | You can hover over syntax nodes in the opened text file to see the appropriate | ||
159 | rust code that it refers to and the rust editor will also highlight the proper | ||
160 | text range. | ||
161 | |||
162 | If you press <kbd>Ctrl</kbd> (i.e. trigger goto definition) in the inspected | ||
163 | Rust source file the syntax tree read-only editor should scroll to and select the | ||
164 | appropriate syntax node token. | ||
165 | |||
166 | ![demo](https://user-images.githubusercontent.com/36276403/78225773-6636a480-74d3-11ea-9d9f-1c9d42da03b0.png) | ||
167 | |||
158 | # Profiling | 168 | # Profiling |
159 | 169 | ||
160 | We have a built-in hierarchical profiler, you can enable it by using `RA_PROFILE` env-var: | 170 | We have a built-in hierarchical profiler, you can enable it by using `RA_PROFILE` env-var: |
diff --git a/docs/user/features.md b/docs/user/features.md index 8aeec2e81..56d2969fd 100644 --- a/docs/user/features.md +++ b/docs/user/features.md | |||
@@ -81,12 +81,6 @@ Join selected lines into one, smartly fixing up whitespace and trailing commas. | |||
81 | Shows the parse tree of the current file. It exists mostly for debugging | 81 | Shows the parse tree of the current file. It exists mostly for debugging |
82 | rust-analyzer itself. | 82 | rust-analyzer itself. |
83 | 83 | ||
84 | You can hover over syntax nodes in the opened text file to see the appropriate | ||
85 | rust code that it refers to and the rust editor will also highlight the proper | ||
86 | text range. | ||
87 | |||
88 | <img src="https://user-images.githubusercontent.com/36276403/78043783-7425e180-737c-11ea-8653-b02b773c5aa1.png" alt="demo" height="200px" > | ||
89 | |||
90 | #### Expand Macro Recursively | 84 | #### Expand Macro Recursively |
91 | 85 | ||
92 | Shows the full macro expansion of the macro at current cursor. | 86 | Shows the full macro expansion of the macro at current cursor. |