From 76733f0cd456005295e60da8c45d74c8c48f177c Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Wed, 29 Apr 2020 13:52:55 +0200 Subject: Add unwrap block assist #4156 Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- docs/user/assists.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index 6c6943622..02323772c 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -695,3 +695,21 @@ use std::┃collections::HashMap; // AFTER use std::{collections::HashMap}; ``` + +## `unwrap_block` + +Removes the `mut` keyword. + +```rust +// BEFORE +fn foo() { + if true {┃ + println!("foo"); + } +} + +// AFTER +fn foo() { + ┃println!("foo"); +} +``` -- cgit v1.2.3 From bbe22640b8d52354c3de3e126c9fcda5b1b174fd Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Wed, 29 Apr 2020 14:53:47 +0200 Subject: Add unwrap block assist #4156 Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- docs/user/assists.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index 02323772c..a421aa0c3 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -698,7 +698,7 @@ use std::{collections::HashMap}; ## `unwrap_block` -Removes the `mut` keyword. +This assist removes if...else, for, while and loop control statements to just keep the body. ```rust // BEFORE @@ -710,6 +710,6 @@ fn foo() { // AFTER fn foo() { - ┃println!("foo"); + println!("foo"); } ``` -- cgit v1.2.3 From b73dbbfbf2cad646eb3f8e3342a1c390a874dc53 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 May 2020 11:50:43 +0200 Subject: Add missing members generates indented blocks --- docs/user/assists.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index 6c6943622..5a83c4a98 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -175,7 +175,9 @@ trait Trait { } impl Trait for () { - fn foo(&self) -> u32 { todo!() } + fn foo(&self) -> u32 { + todo!() + } } ``` -- cgit v1.2.3 From 9914f7fbb2f901c9293a1463707ceffcfdd51ceb Mon Sep 17 00:00:00 2001 From: KENTARO OKUDA Date: Sat, 2 May 2020 17:45:46 -0400 Subject: Fix Typos --- docs/dev/syntax.md | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'docs') diff --git a/docs/dev/syntax.md b/docs/dev/syntax.md index 33973ffec..9f3c689b2 100644 --- a/docs/dev/syntax.md +++ b/docs/dev/syntax.md @@ -64,7 +64,7 @@ struct Token { } ``` -All the difference bettwen the above sketch and the real implementation are strictly due to optimizations. +All the difference between the above sketch and the real implementation are strictly due to optimizations. Points of note: * The tree is untyped. Each node has a "type tag", `SyntaxKind`. @@ -72,7 +72,7 @@ Points of note: * Trivia and non-trivia tokens are not distinguished on the type level. * Each token carries its full text. * The original text can be recovered by concatenating the texts of all tokens in order. -* Accessing a child of particular type (for example, parameter list of a function) generarly involves linerary traversing the children, looking for a specific `kind`. +* Accessing a child of particular type (for example, parameter list of a function) generally involves linerary traversing the children, looking for a specific `kind`. * Modifying the tree is roughly `O(depth)`. We don't make special efforts to guarantree that the depth is not liner, but, in practice, syntax trees are branchy and shallow. * If mandatory (grammar wise) node is missing from the input, it's just missing from the tree. @@ -123,7 +123,7 @@ To more compactly store the children, we box *both* interior nodes and tokens, a `Either, Arc>` as a single pointer with a tag in the last bit. To avoid allocating EVERY SINGLE TOKEN on the heap, syntax trees use interning. -Because the tree is fully imutable, it's valid to structuraly share subtrees. +Because the tree is fully immutable, it's valid to structurally share subtrees. For example, in `1 + 1`, there will be a *single* token for `1` with ref count 2; the same goes for the ` ` whitespace token. Interior nodes are shared as well (for example in `(1 + 1) * (1 + 1)`). @@ -134,8 +134,8 @@ Currently, the interner is created per-file, but it will be easy to use a per-th We use a `TextSize`, a newtyped `u32`, to store the length of the text. -We currently use `SmolStr`, an small object optimized string to store text. -This was mostly relevant *before* we implmented tree interning, to avoid allocating common keywords and identifiers. We should switch to storing text data alongside the interned tokens. +We currently use `SmolStr`, a small object optimized string to store text. +This was mostly relevant *before* we implemented tree interning, to avoid allocating common keywords and identifiers. We should switch to storing text data alongside the interned tokens. #### Alternative designs @@ -162,12 +162,12 @@ Explicit trivia nodes, like in `rowan`, are used by IntelliJ. ##### Accessing Children -As noted before, accesing a specific child in the node requires a linear traversal of the children (though we can skip tokens, beacuse the tag is encoded in the pointer itself). +As noted before, accessing a specific child in the node requires a linear traversal of the children (though we can skip tokens, because the tag is encoded in the pointer itself). It is possible to recover O(1) access with another representation. We explicitly store optional and missing (required by the grammar, but not present) nodes. That is, we use `Option` for children. We also remove trivia tokens from the tree. -This way, each child kind genrerally occupies a fixed position in a parent, and we can use index access to fetch it. +This way, each child kind generally occupies a fixed position in a parent, and we can use index access to fetch it. The cost is that we now need to allocate space for all not-present optional nodes. So, `fn foo() {}` will have slots for visibility, unsafeness, attributes, abi and return type. @@ -193,7 +193,7 @@ Modeling this with immutable trees is possible, but annoying. ### Syntax Nodes A function green tree is not super-convenient to use. -The biggest problem is acessing parents (there are no parent pointers!). +The biggest problem is accessing parents (there are no parent pointers!). But there are also "identify" issues. Let's say you want to write a code which builds a list of expressions in a file: `fn collect_exrepssions(file: GreenNode) -> HashSet`. For the input like @@ -207,7 +207,7 @@ fn main() { } ``` -both copies of the `x + 2` expression are representing by equal (and, with interning in mind, actualy the same) green nodes. +both copies of the `x + 2` expression are representing by equal (and, with interning in mind, actually the same) green nodes. Green trees just can't differentiate between the two. `SyntaxNode` adds parent pointers and identify semantics to green nodes. @@ -285,9 +285,9 @@ They also point to the parent (and, consequently, to the root) with an owning `R In other words, one needs *one* arc bump when initiating a traversal. To get rid of allocations, `rowan` takes advantage of `SyntaxNode: !Sync` and uses a thread-local free list of `SyntaxNode`s. -In a typical traversal, you only directly hold a few `SyntaxNode`s at a time (and their ancesstors indirectly), so a free list proportional to the depth of the tree removes all allocations in a typical case. +In a typical traversal, you only directly hold a few `SyntaxNode`s at a time (and their ancestors indirectly), so a free list proportional to the depth of the tree removes all allocations in a typical case. -So, while traversal is not exactly incrementing a pointer, it's still prety cheep: tls + rc bump! +So, while traversal is not exactly incrementing a pointer, it's still pretty cheep: tls + rc bump! Traversal also yields (cheap) owned nodes, which improves ergonomics quite a bit. @@ -308,15 +308,15 @@ struct SyntaxData { } ``` -This allows using true pointer equality for comparision of identities of `SyntaxNodes`. +This allows using true pointer equality for comparison of identities of `SyntaxNodes`. rust-analyzer used to have this design as well, but since we've switch to cursors. -The main problem with memoizing the red nodes is that it more than doubles the memory requirenments for fully realized syntax trees. +The main problem with memoizing the red nodes is that it more than doubles the memory requirements for fully realized syntax trees. In contrast, cursors generally retain only a path to the root. C# combats increased memory usage by using weak references. ### AST -`GreenTree`s are untyped and homogeneous, because it makes accomodating error nodes, arbitrary whitespace and comments natural, and because it makes possible to write generic tree traversals. +`GreenTree`s are untyped and homogeneous, because it makes accommodating error nodes, arbitrary whitespace and comments natural, and because it makes possible to write generic tree traversals. However, when working with a specific node, like a function definition, one would want a strongly typed API. This is what is provided by the AST layer. AST nodes are transparent wrappers over untyped syntax nodes: @@ -397,7 +397,7 @@ impl HasVisbility for FnDef { Points of note: * Like `SyntaxNode`s, AST nodes are cheap to clone pointer-sized owned values. -* All "fields" are optional, to accomodate incomplete and/or erroneous source code. +* All "fields" are optional, to accommodate incomplete and/or erroneous source code. * It's always possible to go from an ast node to an untyped `SyntaxNode`. * It's possible to go in the opposite direction with a checked cast. * `enum`s allow modeling of arbitrary intersecting subsets of AST types. @@ -437,13 +437,13 @@ impl GreenNodeBuilder { } ``` -The parser, ultimatelly, needs to invoke the `GreenNodeBuilder`. +The parser, ultimately, needs to invoke the `GreenNodeBuilder`. There are two principal sources of inputs for the parser: * source text, which contains trivia tokens (whitespace and comments) * token trees from macros, which lack trivia -Additionaly, input tokens do not correspond 1-to-1 with output tokens. -For example, two consequtive `>` tokens might be glued, by the parser, into a single `>>`. +Additionally, input tokens do not correspond 1-to-1 with output tokens. +For example, two consecutive `>` tokens might be glued, by the parser, into a single `>>`. For these reasons, the parser crate defines a callback interfaces for both input tokens and output trees. The explicit glue layer then bridges various gaps. @@ -491,7 +491,7 @@ Syntax errors are not stored directly in the tree. The primary motivation for this is that syntax tree is not necessary produced by the parser, it may also be assembled manually from pieces (which happens all the time in refactorings). Instead, parser reports errors to an error sink, which stores them in a `Vec`. If possible, errors are not reported during parsing and are postponed for a separate validation step. -For example, parser accepts visibility modifiers on trait methods, but then a separate tree traversal flags all such visibilites as erroneous. +For example, parser accepts visibility modifiers on trait methods, but then a separate tree traversal flags all such visibilities as erroneous. ### Macros @@ -501,7 +501,7 @@ Specifically, `TreeSink` constructs the tree in lockstep with draining the origi In the process, it records which tokens of the tree correspond to which tokens of the input, by using text ranges to identify syntax tokens. The end result is that parsing an expanded code yields a syntax tree and a mapping of text-ranges of the tree to original tokens. -To deal with precedence in cases like `$expr * 1`, we use special invisible parenthesis, which are explicitelly handled by the parser +To deal with precedence in cases like `$expr * 1`, we use special invisible parenthesis, which are explicitly handled by the parser ### Whitespace & Comments -- cgit v1.2.3 From 4f4d0fd9ac2e1d4929bc749cbba0b67406302b6a Mon Sep 17 00:00:00 2001 From: KENTARO OKUDA Date: Sat, 2 May 2020 18:55:04 -0400 Subject: Update syntax.md --- docs/dev/syntax.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/dev/syntax.md b/docs/dev/syntax.md index 9f3c689b2..c2864bbbc 100644 --- a/docs/dev/syntax.md +++ b/docs/dev/syntax.md @@ -287,7 +287,7 @@ In other words, one needs *one* arc bump when initiating a traversal. To get rid of allocations, `rowan` takes advantage of `SyntaxNode: !Sync` and uses a thread-local free list of `SyntaxNode`s. In a typical traversal, you only directly hold a few `SyntaxNode`s at a time (and their ancestors indirectly), so a free list proportional to the depth of the tree removes all allocations in a typical case. -So, while traversal is not exactly incrementing a pointer, it's still pretty cheep: tls + rc bump! +So, while traversal is not exactly incrementing a pointer, it's still pretty cheap: TLS + rc bump! Traversal also yields (cheap) owned nodes, which improves ergonomics quite a bit. @@ -309,7 +309,7 @@ struct SyntaxData { ``` This allows using true pointer equality for comparison of identities of `SyntaxNodes`. -rust-analyzer used to have this design as well, but since we've switch to cursors. +rust-analyzer used to have this design as well, but we've since switched to cursors. The main problem with memoizing the red nodes is that it more than doubles the memory requirements for fully realized syntax trees. In contrast, cursors generally retain only a path to the root. C# combats increased memory usage by using weak references. -- cgit v1.2.3 From 42e2eca921db19d4c39f4d3ea281a624f8f8a166 Mon Sep 17 00:00:00 2001 From: KENTARO OKUDA Date: Sun, 3 May 2020 15:14:56 -0400 Subject: Update debugging.md --- docs/dev/debugging.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs') diff --git a/docs/dev/debugging.md b/docs/dev/debugging.md index bece6a572..1aa392935 100644 --- a/docs/dev/debugging.md +++ b/docs/dev/debugging.md @@ -26,7 +26,7 @@ where **only** the `rust-analyzer` extension being debugged is enabled. - `Run Extension (Dev Server)` - runs extension with the locally built LSP server (`target/debug/rust-analyzer`). TypeScript debugging is configured to watch your source edits and recompile. -To apply changes to an already running debug process press Ctrl+Shift+P and run the following command in your `[Extension Development Host]` +To apply changes to an already running debug process, press Ctrl+Shift+P and run the following command in your `[Extension Development Host]` ``` > Developer: Reload Window @@ -76,11 +76,11 @@ Make sure you open a rust file in the `[Extension Development Host]` and try aga Make sure you have run `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope`. -By default this should reset back to 1 everytime you log in. +By default this should reset back to 1 every time you log in. ### Breakpoints are never being hit -Check your version of `lldb` if it's version 6 and lower use the `classic` adapter type. +Check your version of `lldb`. If it's version 6 and lower, use the `classic` adapter type. It's `lldb.adapterType` in settings file. -If you're running `lldb` version 7 change the lldb adapter type to `bundled` or `native`. +If you're running `lldb` version 7, change the lldb adapter type to `bundled` or `native`. -- cgit v1.2.3 From 18ba86b1c5e9b3d6288dd612ecd054f6386d529e Mon Sep 17 00:00:00 2001 From: Francisco Lopes Date: Mon, 4 May 2020 14:12:32 -0300 Subject: [manual] Improve requirements and editor wording --- docs/user/readme.adoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs') diff --git a/docs/user/readme.adoc b/docs/user/readme.adoc index b1af72ce6..2c0a96a05 100644 --- a/docs/user/readme.adoc +++ b/docs/user/readme.adoc @@ -159,11 +159,11 @@ Emacs support is maintained as part of the https://github.com/emacs-lsp/lsp-mode 3. Run `lsp` in a Rust buffer. 4. (Optionally) bind commands like `lsp-rust-analyzer-join-lines`, `lsp-extend-selection` and `lsp-rust-analyzer-expand-macro` to keys. -=== Vim +=== Vim/NeoVim -Prerequisites: You have installed the <>. +Prerequisites: You have installed the <>. Not needed if the extension can install/update it on its own, coc-rust-analyzer is one example. -The are several LSP client implementations for vim: +The are several LSP client implementations for vim or neovim: ==== coc-rust-analyzer -- cgit v1.2.3 From bcc171737889038061ebf5714f71618f1a913bd3 Mon Sep 17 00:00:00 2001 From: Jacob Greenfield Date: Mon, 4 May 2020 13:16:29 -0400 Subject: Update server binary paths Fixed macOS path and converted to a list --- docs/user/readme.adoc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/user/readme.adoc b/docs/user/readme.adoc index b1af72ce6..29959ca72 100644 --- a/docs/user/readme.adoc +++ b/docs/user/readme.adoc @@ -57,7 +57,11 @@ To disable this notification put the following to `settings.json` ---- ==== -The server binary is stored in `~/.config/Code/User/globalStorage/matklad.rust-analyzer` (Linux) or in `~/.Library/Application Support/Code/User/globalStorage/matklad.rust-analyzer` (macOS) or in `%APPDATA%\Code\User\globalStorage` (Windows). +The server binary is stored in: + +* Linux: `~/.config/Code/User/globalStorage/matklad.rust-analyzer` +* macOS: `~/Library/Application Support/Code/User/globalStorage/matklad.rust-analyzer` +* Windows: `%APPDATA%\Code\User\globalStorage` Note that we only support the latest version of VS Code. -- cgit v1.2.3 From 2b06041692dcdbc1c49292fd64fdc67da312c1ca Mon Sep 17 00:00:00 2001 From: "Daniel M. Capella" Date: Tue, 5 May 2020 18:23:32 -0400 Subject: Update Arch Linux and ALE install instructions Package has been added to the Arch repos: https://www.archlinux.org/packages/community/x86_64/rust-analyzer/ ALE merged rust-analyzer support: https://github.com/dense-analysis/ale/commit/70005134e5b2d40d176ee5b851ac64a296b22201 --- docs/user/readme.adoc | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'docs') diff --git a/docs/user/readme.adoc b/docs/user/readme.adoc index 69f5b13d6..2f2b1d37a 100644 --- a/docs/user/readme.adoc +++ b/docs/user/readme.adoc @@ -139,17 +139,16 @@ If your editor can't find the binary even though the binary is on your `$PATH`, ==== Arch Linux -The `rust-analyzer` binary can be installed from AUR (Arch User Repository): +The `rust-analyzer` binary can be installed from the repos or AUR (Arch User Repository): -- https://aur.archlinux.org/packages/rust-analyzer-bin[`rust-analyzer-bin`] (binary from GitHub releases) -- https://aur.archlinux.org/packages/rust-analyzer[`rust-analyzer`] (built from latest tagged source) -- https://aur.archlinux.org/packages/rust-analyzer-git[`rust-analyzer-git`] (latest git version) +- https://www.archlinux.org/packages/community/x86_64/rust-analyzer/[`rust-analyzer`] (built from latest tagged source) +- https://aur.archlinux.org/packages/rust-analyzer-git[`rust-analyzer-git`] (latest Git version) -Install it with AUR helper of your choice, for example: +Install it with pacman, for example: [source,bash] ---- -$ yay -S rust-analyzer-bin +$ pacman -S rust-analyzer ---- === Emacs @@ -187,7 +186,7 @@ The are several LSP client implementations for vim or neovim: 1. Install LanguageClient-neovim by following the instructions https://github.com/autozimu/LanguageClient-neovim[here] - * The github project wiki has extra tips on configuration + * The GitHub project wiki has extra tips on configuration 2. Configure by adding this to your vim/neovim config file (replacing the existing Rust-specific line if it exists): + @@ -220,17 +219,11 @@ let g:ycm_language_server = ==== ALE -To add the LSP server to https://github.com/dense-analysis/ale[ale]: +To use the LSP server in https://github.com/dense-analysis/ale[ale]: [source,vim] ---- -call ale#linter#Define('rust', { -\ 'name': 'rust-analyzer', -\ 'lsp': 'stdio', -\ 'executable': 'rust-analyzer', -\ 'command': '%e', -\ 'project_root': '.', -\}) +let g:ale_linters = {'rust': ['analyzer']} ---- ==== nvim-lsp -- cgit v1.2.3 From 51c02ab84f6b88ba39e2d0a3ed22bea51114b05a Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Tue, 5 May 2020 19:02:45 +0200 Subject: add Ok wrapping Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- docs/user/assists.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index ee515949e..692fd4f52 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -241,6 +241,18 @@ fn main() { } ``` +## `change_return_type_to_result` + +Change the function's return type to Result. + +```rust +// BEFORE +fn foo() -> i32┃ { 42i32 } + +// AFTER +fn foo() -> Result { Ok(42i32) } +``` + ## `change_visibility` Adds or changes existing visibility specifier. -- cgit v1.2.3 From e0b63855b1874ccc71a49c933f73c62c95a92d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Wed, 6 May 2020 19:53:14 +0300 Subject: Fix Windows server path CC @Coder-256. --- docs/user/readme.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/user/readme.adoc b/docs/user/readme.adoc index 69f5b13d6..301e9a49c 100644 --- a/docs/user/readme.adoc +++ b/docs/user/readme.adoc @@ -61,7 +61,7 @@ The server binary is stored in: * Linux: `~/.config/Code/User/globalStorage/matklad.rust-analyzer` * macOS: `~/Library/Application Support/Code/User/globalStorage/matklad.rust-analyzer` -* Windows: `%APPDATA%\Code\User\globalStorage` +* Windows: `%APPDATA%\Code\User\globalStorage\matklad.rust-analyzer` Note that we only support the latest version of VS Code. -- cgit v1.2.3 From 72e229fcb35f6056183f681e0d16c4fff8e5e381 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 11 May 2020 19:14:12 +0200 Subject: Use RA_LOG instead of RUST_LOG for logging RUST_LOG might be set up for debugging the user's problem, slowing down rust-analyzer considerably. That's the same reason why rustc uses RUSTC_LOG. --- docs/dev/README.md | 2 +- docs/user/readme.adoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/dev/README.md b/docs/dev/README.md index f230dc1db..a20ead0b6 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md @@ -134,7 +134,7 @@ To log all communication between the server and the client, there are two choice * you can log on the server side, by running something like ``` - env RUST_LOG=gen_lsp_server=trace code . + env RA_LOG=gen_lsp_server=trace code . ``` * you can log on the client side, by enabling `"rust-analyzer.trace.server": diff --git a/docs/user/readme.adoc b/docs/user/readme.adoc index f6ce0accf..d750c7705 100644 --- a/docs/user/readme.adoc +++ b/docs/user/readme.adoc @@ -108,7 +108,7 @@ Here are some useful self-diagnostic commands: * **Rust Analyzer: Show RA Version** shows the version of `rust-analyzer` binary * **Rust Analyzer: Status** prints some statistics about the server, like the few latest LSP requests -* To enable server-side logging, run with `env RUST_LOG=info` and see `Output > Rust Analyzer Language Server` in VS Code's panel. +* To enable server-side logging, run with `env RA_LOG=info` and see `Output > Rust Analyzer Language Server` in VS Code's panel. * To log all LSP requests, add `"rust-analyzer.trace.server": "verbose"` to the settings and look for `Server Trace` in the panel. * To enable client-side logging, add `"rust-analyzer.trace.extension": true` to the settings and open the `Console` tab of VS Code developer tools. -- cgit v1.2.3 From 76af4a18db701820e28cf6c939a266e2f09fd58f Mon Sep 17 00:00:00 2001 From: Coenen Benjamin Date: Tue, 12 May 2020 09:46:28 +0200 Subject: Update features.md --- docs/user/features.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/user/features.md b/docs/user/features.md index b9a365fc1..340bce835 100644 --- a/docs/user/features.md +++ b/docs/user/features.md @@ -143,9 +143,9 @@ takes arguments, the cursor is positioned inside the parenthesis. There are postfix completions, which can be triggered by typing something like `foo().if`. The word after `.` determines postfix completion. Possible variants are: -- `expr.if` -> `if expr {}` +- `expr.if` -> `if expr {}` or `if let ... {}` for `Option` or `Result` - `expr.match` -> `match expr {}` -- `expr.while` -> `while expr {}` +- `expr.while` -> `while expr {}` or `while let ... {}` for `Option` or `Result` - `expr.ref` -> `&expr` - `expr.refm` -> `&mut expr` - `expr.not` -> `!expr` @@ -161,6 +161,16 @@ There also snippet completions: #### Inside Modules - `tfn` -> `#[test] fn f(){}` +- `tmod` -> +```rust +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_fn() {} +} +``` ### Code Highlighting -- cgit v1.2.3 From 19a8c1450c1fd7263b49e2e176f8fef0d93d923b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 17 May 2020 15:57:30 +0200 Subject: Relax VS Code version requirement --- docs/user/readme.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/user/readme.adoc b/docs/user/readme.adoc index d750c7705..03836e6e2 100644 --- a/docs/user/readme.adoc +++ b/docs/user/readme.adoc @@ -63,7 +63,7 @@ The server binary is stored in: * macOS: `~/Library/Application Support/Code/User/globalStorage/matklad.rust-analyzer` * Windows: `%APPDATA%\Code\User\globalStorage\matklad.rust-analyzer` -Note that we only support the latest version of VS Code. +Note that we only support two most recent versions of VS Code. ==== Updates -- cgit v1.2.3 From fa2e5299c3332b99fcd09fd54e8d812a6c34b0cc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 17 May 2020 14:21:24 +0200 Subject: Add snippet support for some assists --- docs/user/assists.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index 692fd4f52..41c5df528 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -17,7 +17,7 @@ struct S; struct S; impl Debug for S { - + $0 } ``` @@ -33,7 +33,7 @@ struct Point { } // AFTER -#[derive()] +#[derive($0)] struct Point { x: u32, y: u32, @@ -105,16 +105,16 @@ Adds a new inherent impl for a type. ```rust // BEFORE struct Ctx { - data: T,┃ + data: T,┃ } // AFTER struct Ctx { - data: T, + data: T, } impl Ctx { - + $0 } ``` -- cgit v1.2.3 From a752853350639a915178ea900a51f3c45443795e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 17 May 2020 21:24:33 +0200 Subject: Add snippetTextEdit protocol extension --- docs/dev/lsp-extensions.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 docs/dev/lsp-extensions.md (limited to 'docs') diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md new file mode 100644 index 000000000..d2ec6c021 --- /dev/null +++ b/docs/dev/lsp-extensions.md @@ -0,0 +1,34 @@ +# LSP Extensions + +This document describes LSP extensions used by rust-analyzer. +It's a best effort document, when in doubt, consult the source (and send a PR with clarification ;-) ). +We aim to upstream all non Rust-specific extensions to the protocol, but this is not a top priority. +All capabilities are enabled via `experimental` field of `ClientCapabilities`. + +## `SnippetTextEdit` + +**Capability** + +```typescript +{ + "snippetTextEdit": boolean +} +``` + +If this capability is set, `WorkspaceEdit`s returned from `codeAction` requests might contain `SnippetTextEdit`s instead of usual `TextEdit`s: + +```typescript +interface SnippetTextEdit extends TextEdit { + insertTextFormat?: InsertTextFormat; +} +``` + +```typescript +export interface TextDocumentEdit { + textDocument: VersionedTextDocumentIdentifier; + edits: (TextEdit | SnippetTextEdit)[]; +} +``` + +When applying such code action, the editor should insert snippet, with tab stops and placeholder. +At the moment, rust-analyzer guarantees that only a single edit will have `InsertTextFormat.Snippet`. -- cgit v1.2.3 From 80545e5d3a72ef05a77ff9584234f030c69bfe9f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 00:07:00 +0200 Subject: New assist: add turbo fish --- docs/user/assists.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index 41c5df528..c72b50a4d 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -203,6 +203,24 @@ impl Ctx { ``` +## `add_turbo_fish` + +Adds `::<_>` to a call of a generic method or function. + +```rust +// BEFORE +fn make() -> T { todo!() } +fn main() { + let x = make┃(); +} + +// AFTER +fn make() -> T { todo!() } +fn main() { + let x = make::<${0:_}>(); +} +``` + ## `apply_demorgan` Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). -- cgit v1.2.3 From 8eb3272ad6f774bccb967ee640b72a9a17273e7b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 19 May 2020 22:25:07 +0200 Subject: Use snippets in add function --- docs/user/assists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index c72b50a4d..10ab67b2e 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -77,7 +77,7 @@ fn foo() { } fn bar(arg: &str, baz: Baz) { - todo!() + ${0:todo!()} } ``` -- cgit v1.2.3 From a04cababaa144d7a6db7b1dd114494b33d281ab9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 01:53:21 +0200 Subject: Use snippets in add_missing_members --- docs/user/assists.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index 10ab67b2e..b687330f3 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -146,7 +146,7 @@ trait Trait { impl Trait for () { Type X = (); fn foo(&self) {} - fn bar(&self) {} + $0fn bar(&self) {} } ``` @@ -175,7 +175,7 @@ trait Trait { } impl Trait for () { - fn foo(&self) -> u32 { + $0fn foo(&self) -> u32 { todo!() } -- cgit v1.2.3 From 767d169a2ae543f28544e85e15bac1b6aa1cab23 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 02:07:21 +0200 Subject: Better cursor placement when adding impl members --- docs/user/assists.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index b687330f3..f329fcc10 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -175,8 +175,8 @@ trait Trait { } impl Trait for () { - $0fn foo(&self) -> u32 { - todo!() + fn foo(&self) -> u32 { + ${0:todo!()} } } -- cgit v1.2.3 From 9b2bd022dc6fbe13356622ada5b6499f012cb5ae Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 10:17:46 +0200 Subject: Snippetify add_new --- docs/user/assists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index f329fcc10..03c01d6c0 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -198,7 +198,7 @@ struct Ctx { } impl Ctx { - fn new(data: T) -> Self { Self { data } } + fn $0new(data: T) -> Self { Self { data } } } ``` -- cgit v1.2.3 From 33e111483fbc80c017037e0b158ee652ed41b3e8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 11:10:15 +0200 Subject: Use snippets in change_return_type_to_result --- docs/user/assists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index 03c01d6c0..006ec4d54 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -268,7 +268,7 @@ Change the function's return type to Result. fn foo() -> i32┃ { 42i32 } // AFTER -fn foo() -> Result { Ok(42i32) } +fn foo() -> Result { Ok(42i32) } ``` ## `change_visibility` -- cgit v1.2.3 From cec773926f08e2d46b05d923165f8e73c420aa8c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 13:33:13 +0200 Subject: Split change_ and fix_ visibility assists --- docs/user/assists.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index 006ec4d54..0ae242389 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -331,6 +331,28 @@ fn handle(action: Action) { } ``` +## `fix_visibility` + +Makes inaccessible item public. + +```rust +// BEFORE +mod m { + fn frobnicate() {} +} +fn main() { + m::frobnicate┃() {} +} + +// AFTER +mod m { + pub(crate) fn frobnicate() {} +} +fn main() { + m::frobnicate() {} +} +``` + ## `flip_binexpr` Flips operands of a binary expression. -- cgit v1.2.3 From c446fd76a2a6191adce87b20707a37bd46cb85a9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 14:00:37 +0200 Subject: Snippetify fill_match_arms --- docs/user/assists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index 0ae242389..a33c490b8 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -325,7 +325,7 @@ enum Action { Move { distance: u32 }, Stop } fn handle(action: Action) { match action { - Action::Move { distance } => {} + $0Action::Move { distance } => {} Action::Stop => {} } } -- cgit v1.2.3 From ba3a58d1b2d76bae2ac84923d12918a32ad680f6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 14:13:17 +0200 Subject: Snippetify fix_visibility --- docs/user/assists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index a33c490b8..51807ffda 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -346,7 +346,7 @@ fn main() { // AFTER mod m { - pub(crate) fn frobnicate() {} + $0pub(crate) fn frobnicate() {} } fn main() { m::frobnicate() {} -- cgit v1.2.3 From d58d6412d837a9f6475e04c74709d78f52c9ff6a Mon Sep 17 00:00:00 2001 From: Yuki Kodama Date: Thu, 21 May 2020 03:01:37 +0900 Subject: Fix names of launch configuration in dev docs --- docs/dev/README.md | 4 ++-- docs/dev/debugging.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'docs') diff --git a/docs/dev/README.md b/docs/dev/README.md index a20ead0b6..65cc9fc12 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md @@ -74,7 +74,7 @@ relevant test and execute it (VS Code includes an action for running a single test). However, launching a VS Code instance with locally build language server is -possible. There's **"Run Extension (Dev Server)"** launch configuration for this. +possible. There's **"Run Extension (Debug Build)"** launch configuration for this. In general, I use one of the following workflows for fixing bugs and implementing features. @@ -86,7 +86,7 @@ then just do printf-driven development/debugging. As a sanity check after I'm done, I use `cargo xtask install --server` and **Reload Window** action in VS Code to sanity check that the thing works as I expect. -If the problem concerns only the VS Code extension, I use **Run Extension** +If the problem concerns only the VS Code extension, I use **Run Installed Extension** launch configuration from `launch.json`. Notably, this uses the usual `rust-analyzer` binary from `PATH`. For this it is important to have the following in `setting.json` file: diff --git a/docs/dev/debugging.md b/docs/dev/debugging.md index 1aa392935..59a83f7d7 100644 --- a/docs/dev/debugging.md +++ b/docs/dev/debugging.md @@ -22,8 +22,8 @@ where **only** the `rust-analyzer` extension being debugged is enabled. ## Debug TypeScript VSCode extension -- `Run Extension` - runs the extension with the globally installed `rust-analyzer` binary. -- `Run Extension (Dev Server)` - runs extension with the locally built LSP server (`target/debug/rust-analyzer`). +- `Run Installed Extension` - runs the extension with the globally installed `rust-analyzer` binary. +- `Run Extension (Debug Build)` - runs extension with the locally built LSP server (`target/debug/rust-analyzer`). TypeScript debugging is configured to watch your source edits and recompile. To apply changes to an already running debug process, press Ctrl+Shift+P and run the following command in your `[Extension Development Host]` @@ -47,7 +47,7 @@ To apply changes to an already running debug process, press Ctrl+Shift+P Date: Wed, 20 May 2020 20:11:14 +0200 Subject: Fix GNOME spelling GNOME is a trademark. :-) --- docs/user/readme.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/user/readme.adoc b/docs/user/readme.adoc index 03836e6e2..40ed54809 100644 --- a/docs/user/readme.adoc +++ b/docs/user/readme.adoc @@ -249,7 +249,7 @@ If it worked, you should see "rust-analyzer, Line X, Column Y" on the left side If you get an error saying `No such file or directory: 'rust-analyzer'`, see the <> section on installing the language server binary. -=== Gnome Builder +=== GNOME Builder Prerequisites: You have installed the <>. -- cgit v1.2.3 From fd771707187a505c826096fc62ced6ba9b65460e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 23:07:17 +0200 Subject: Snippetify introduce/inline var --- docs/user/assists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index 51807ffda..a6e27d67f 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -426,7 +426,7 @@ fn main() { // AFTER fn main() { - let var_name = (1 + 2); + let $0var_name = (1 + 2); var_name * 4; } ``` -- cgit v1.2.3 From 4ac0abd2960acf1b3a357c681e64b3cddba6fc8e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 May 2020 00:01:08 +0200 Subject: Snippetify unwrap -> match --- docs/user/assists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index a6e27d67f..4ad7ea59d 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -733,7 +733,7 @@ fn main() { let x: Result = Result::Ok(92); let y = match x { Ok(a) => a, - _ => unreachable!(), + $0_ => unreachable!(), }; } ``` -- cgit v1.2.3 From 5b5ebec440841ee98a0aa70b71a135d94f5ca077 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 May 2020 19:50:23 +0200 Subject: Formalize JoinLines protocol extension --- docs/dev/lsp-extensions.md | 66 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 7 deletions(-) (limited to 'docs') diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md index d2ec6c021..0e3a0af1c 100644 --- a/docs/dev/lsp-extensions.md +++ b/docs/dev/lsp-extensions.md @@ -7,13 +7,7 @@ All capabilities are enabled via `experimental` field of `ClientCapabilities`. ## `SnippetTextEdit` -**Capability** - -```typescript -{ - "snippetTextEdit": boolean -} -``` +**Client Capability:** `{ "snippetTextEdit": boolean }` If this capability is set, `WorkspaceEdit`s returned from `codeAction` requests might contain `SnippetTextEdit`s instead of usual `TextEdit`s: @@ -32,3 +26,61 @@ export interface TextDocumentEdit { When applying such code action, the editor should insert snippet, with tab stops and placeholder. At the moment, rust-analyzer guarantees that only a single edit will have `InsertTextFormat.Snippet`. + +### Example + +"Add `derive`" code action transforms `struct S;` into `#[derive($0)] struct S;` + +### Unresolved Questions + +* Where exactly are `SnippetTextEdit`s allowed (only in code actions at the moment)? +* Can snippets span multiple files (so far, no)? + +## `joinLines` + +**Server Capability:** `{ "joinLines": boolean }` + +This request is send from client to server to handle "Join Lines" editor action. + +**Method:** `experimental/JoinLines` + +**Request:** + +```typescript +interface JoinLinesParams { + textDocument: TextDocumentIdentifier, + /// Currently active selections/cursor offsets. + /// This is an array to support multiple cursors. + ranges: Range[], +} +``` + +**Response:** + +```typescript +TextEdit[] +``` + +### Example + +```rust +fn main() { + /*cursor here*/let x = { + 92 + }; +} +``` + +`experimental/joinLines` yields (curly braces are automagiacally removed) + +```rust +fn main() { + let x = 92; +} +``` + +### Unresolved Question + +* What is the position of the cursor after `joinLines`? + Currently this is left to editor's discretion, but it might be useful to specify on the server via snippets. + However, it then becomes unclear how it works with multi cursor. -- cgit v1.2.3