Skip to content

Changelog #64 #86

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

Merged
merged 1 commit into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 87 additions & 4 deletions generated_assists.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ enum A { One(u32) }

impl From<u32> for A {
fn from(v: u32) -> Self {
A::One(v)
Self::One(v)
}
}
```
Expand Down Expand Up @@ -632,9 +632,65 @@ fn bar(arg: &str, baz: Baz) ${0:-> ()} {
```


[discrete]
=== `generate_getter`
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_getter.rs#L9[generate_getter.rs]

Generate a getter method.

.Before
```rust
struct Person {
nam┃e: String,
}
```

.After
```rust
struct Person {
name: String,
}

impl Person {
/// Get a reference to the person's name.
fn name(&self) -> &String {
&self.name
}
}
```


[discrete]
=== `generate_getter_mut`
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_getter_mut.rs#L9[generate_getter_mut.rs]

Generate a mut getter method.

.Before
```rust
struct Person {
nam┃e: String,
}
```

.After
```rust
struct Person {
name: String,
}

impl Person {
/// Get a mutable reference to the person's name.
fn name_mut(&mut self) -> &mut String {
&mut self.name
}
}
```


[discrete]
=== `generate_impl`
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_impl.rs#L10[generate_impl.rs]
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_impl.rs#L5[generate_impl.rs]

Adds a new inherent impl for a type.

Expand All @@ -659,7 +715,7 @@ impl<T: Clone> Ctx<T> {

[discrete]
=== `generate_new`
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_new.rs#L13[generate_new.rs]
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_new.rs#L11[generate_new.rs]

Adds a new inherent impl for a type.

Expand All @@ -679,7 +735,34 @@ struct Ctx<T: Clone> {
impl<T: Clone> Ctx<T> {
fn ┃new(data: T) -> Self { Self { data } }
}
```


[discrete]
=== `generate_setter`
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_setter.rs#L9[generate_setter.rs]

Generate a setter method.

.Before
```rust
struct Person {
nam┃e: String,
}
```

.After
```rust
struct Person {
name: String,
}

impl Person {
/// Set the person's name.
fn set_name(&mut self, name: String) {
self.name = name;
}
}
```


Expand Down Expand Up @@ -730,7 +813,7 @@ fn main() {

[discrete]
=== `inline_local_variable`
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/inline_local_variable.rs#L16[inline_local_variable.rs]
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/inline_local_variable.rs#L14[inline_local_variable.rs]

Inlines local variable.

Expand Down
2 changes: 1 addition & 1 deletion generated_config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
[[rust-analyzer.runnables.cargoExtraArgs]]rust-analyzer.runnables.cargoExtraArgs (default: `[]`)::
Additional arguments to be passed to cargo for runnables such as tests or binaries.\nFor example, it may be `--release`.
[[rust-analyzer.rustcSource]]rust-analyzer.rustcSource (default: `null`)::
Path to the rust compiler sources, for usage in rustc_private projects.
Path to the rust compiler sources, for usage in rustc_private projects, or "discover" to try to automatically find it.
[[rust-analyzer.rustfmt.extraArgs]]rust-analyzer.rustfmt.extraArgs (default: `[]`)::
Additional arguments to `rustfmt`.
[[rust-analyzer.rustfmt.overrideCommand]]rust-analyzer.rustfmt.overrideCommand (default: `null`)::
Expand Down
4 changes: 2 additions & 2 deletions generated_diagnostic.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This diagnostic is shown for code with inactive `#[cfg]` attributes.


=== incorrect-ident-case
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L348[diagnostics.rs]
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L379[diagnostics.rs]

This diagnostic is triggered if an item name doesn't follow https://doc.rust-lang.org/1.0.0/style/style/naming/README.html[Rust naming convention].

Expand Down Expand Up @@ -95,7 +95,7 @@ This diagnostic is triggered if created structure does not have field provided i


=== replace-filter-map-next-with-find-map
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L389[diagnostics.rs]
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L420[diagnostics.rs]

This diagnostic is triggered when `.filter_map(..).next()` is used, rather than the more concise `.find_map(..)`.

Expand Down
7 changes: 7 additions & 0 deletions generated_features.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
//Generated file, do not edit by hand, see `xtask/src/codegen`
=== Annotations
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide/src/annotations.rs#L17[annotations.rs]

Provides user with annotations above items for looking up references or impl blocks
and running/debugging binaries.


=== Auto Import
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/auto_import.rs#L10[auto_import.rs]

Expand Down
90 changes: 85 additions & 5 deletions manual.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ $ pacman -S rust-analyzer

=== Emacs

Note this excellent https://robert.kra.hn/posts/2021-02-07_rust-with-emacs/[guide] from https://github.com/rksm[@rksm].

Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>.

Emacs support is maintained as part of the https://github.com/emacs-lsp/lsp-mode[Emacs-LSP] package in https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-rust.el[lsp-rust.el].
Expand Down Expand Up @@ -307,6 +309,52 @@ EOF

See https://sharksforarms.dev/posts/neovim-rust/ for more tips on getting started.

==== vim-lsp

vim-lsp is installed by following https://github.com/prabirshrestha/vim-lsp[the plugin instructions].
It can be as simple as adding this line to your `.vimrc`:

[source,vim]
----
Plug 'prabirshrestha/vim-lsp'
----

Next you need to register the `rust-analyzer` binary.
If it is available in `$PATH`, you may want to add this to your `.vimrc`:

[source,vim]
----
if executable('rust-analyzer')
au User lsp_setup call lsp#register_server({
\ 'name': 'Rust Language Server',
\ 'cmd': {server_info->['rust-analyzer']},
\ 'whitelist': ['rust'],
\ })
endif
----

There is no dedicated UI for the server configuration, so you would need to send any options as a value of the `initialization_options` field, as described in the <<_configuration,Configuration>> section.
Here is an example of how to enable the proc-macro support:

[source,vim]
----
if executable('rust-analyzer')
au User lsp_setup call lsp#register_server({
\ 'name': 'Rust Language Server',
\ 'cmd': {server_info->['rust-analyzer']},
\ 'whitelist': ['rust'],
\ 'initialization_options': {
\ 'cargo': {
\ 'loadOutDirsFromCheck': v:true,
\ },
\ 'procMacro': {
\ 'enable': v:true,
\ },
\ },
\ })
endif
----

=== Sublime Text 3

Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>.
Expand All @@ -331,17 +379,49 @@ If you get an error saying `No such file or directory: 'rust-analyzer'`, see the
GNOME Builder 3.37.1 and newer has native `rust-analyzer` support.
If the LSP binary is not available, GNOME Builder can install it when opening a Rust file.


=== Eclipse IDE

Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>.

Support for Rust development in the Eclipse IDE is provided by link:https://github.com/eclipse/corrosion[Eclipse Corrosion].
While it currently uses RLS as default, you can successfully configure it so the IDE will use `rust-analyzer` instead.
To do so, with an Eclipse IDE where Corrosion is installed, just go to __Window > Preferences > Rust__ and edit the __Path to Rust Language Server__ entry to reference the path to `rust-analyzer`.
You'll need to close and reopen all .rs and Cargo files, or to restart the IDE, for this change to take effect.

== Configuration

**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/config.rs[config.rs]

rust-analyzer is configured via LSP messages, which means that it's up to the editor to decide on the exact format and location of configuration files.
Please consult your editor's documentation to learn how to configure LSP servers.
The <<_installation,Installation>> section contains details on configuration for some of the editors.
In general `rust-analyzer` is configured via LSP messages, which means that it's up to the editor to decide on the exact format and location of configuration files.

Some clients, such as <<vs-code,VS Code>> or <<coc-rust-analyzer,COC plugin in Vim>> provide `rust-analyzer` specific configuration UIs. Others may require you to know a bit more about the interaction with `rust-analyzer`.

For the later category, it might help to know that the initial configuration is specified as a value of the `intializationOptions` field of the https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize[`InitializeParams` message, in the LSP protocol].
The spec says that the field type is `any?`, but `rust-analyzer` is looking for a JSON object that is constructed using settings from the list below.
Name of the setting, ignoring the `rust-analyzer.` prefix, is used as a path, and value of the setting becomes the JSON property value.

For example, a very common configuration is to enable proc-macro support, can be achieved by sending this JSON:

[source,json]
----
{
"cargo": {
"loadOutDirsFromCheck": true,
},
"procMacro": {
"enable": true,
}
}
----

Please consult your editor's documentation to learn more about how to configure https://microsoft.github.io/language-server-protocol/[LSP servers].

To verify which configuration is actually used by rust-analyzer, set `RA_LOG` environment variable to `rust_analyzer=info` and look for config-related messages.
Logs should show both the JSON that rust-analyzer sees as well as the updated config.
To verify which configuration is actually used by `rust-analyzer`, set `RA_LOG` environment variable to `rust_analyzer=info` and look for config-related messages.
Logs should show both the JSON that `rust-analyzer` sees as well as the updated config.

This is the list of config options rust-analyzer supports:
This is the list of config options `rust-analyzer` supports:

include::./generated_config.adoc[]

Expand Down
75 changes: 75 additions & 0 deletions thisweek/_posts/2021-02-15-changelog-64.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
= Changelog #66
:sectanchors:
:page-layout: post

Commit: commit:7435b9e98c9280043605748c11a1f450669e04d6[] +
Release: release:2021-02-15[]

== Sponsors

**Become a sponsor:** On https://opencollective.com/rust-analyzer/[OpenCollective] or
https://github.com/sponsors/rust-analyzer[GitHub Sponsors].

== New Features

* pr:7614[], pr:7627[] unleash inner item resolution to users:
+
image::https://user-images.githubusercontent.com/1786438/107394800-8627f300-6afc-11eb-8662-ed07226bc58f.gif[]

* pr:7617[] add generate getter/setter assists:
+
image::https://user-images.githubusercontent.com/3757771/107858728-0b314600-6e36-11eb-9603-8a59f23808e4.gif[]

* pr:7616[] show `Self` pattern and `Self`-prefixed enum variant completions:
+
image::https://user-images.githubusercontent.com/3757771/107413514-1ff99b00-6b11-11eb-88b3-126cd106b514.gif[]
+
image::https://user-images.githubusercontent.com/3757771/107413519-212ac800-6b11-11eb-8282-51115468dccc.gif[]

* pr:7618[] show qualified enum variant pattern completions:
+
image::https://user-images.githubusercontent.com/3757771/107425157-e9c31800-6b1e-11eb-8963-96653115f8e0.gif[]

* pr:7656[] implement constructor usage search for almost all items:
+
image::https://user-images.githubusercontent.com/308347/107944340-9f1a2380-6f96-11eb-8dd9-811d2c7a2d95.gif[]

* pr:7625[] add **Copy Run Command Line** command for Code.
* pr:7644[] implement completion for primitive types.
* pr:7658[] release `x86_64-unknown-linux-musl` binaries.
* pr:7643[] automatically detect `rustc-src` crates.


== Fixes

* pr:7593[] include `for` keyword in completion.
* pr:7602[] check for `dyn` impls in method resolution.
* pr:7591[] fix floating promises in the Code extension.
* pr:7622[] resolve `TupleStructPat` in `SourceAnalyzer::resolve_path`.
* pr:7652[] fix "slow" tests sometimes failing.
* pr:7659[] improve "Generate From impl" assist.
* pr:7665[] fix attribute macro classification.
* pr:7667[] strip type parameter defaults when generating impl generics.
* pr:7663[] tolerate spaces when patching the server binary on NixOS.

== Internal Improvements

* pr:7549[] explain how initial configuration is sent over LSP and document `vim-lsp`.
* pr:7592[] add note about Eclipse IDE support.
* pr:7595[] add `config: &CargoConfig` parameter to `fn load_cargo(…)`.
* pr:7599[] add emacs guide.
* pr:7597[] set remote branch on `xtask promote`.
* pr:7613[], pr:7615[] add initial benchmarking infrastructure.
* pr:7619[], pr:7621[] use `#[track_caller]` in assist tests.
* pr:7648[] fix `legacy_derive_helpers` warning on nightly.
* pr:7653[] document "config" pattern.
* pr:7639[] bump Rust to `1.50`.
* pr:7650[] add `find_impl_block_end` assist helper.
* pr:7358[] refactor reference searching to work with on the `ast`.
* pr:7596[] move `code_lens` to the `ide` crate.
* pr:7655[] include a commit log summary in the changelog.
* pr:7664[] refactor impl generation in assists.
* pr:7668[] finalize rename infra rewrite.
* pr:7678[] simplify `find_crlf`.
* pr:7661[] start LSP 3.17 support.
* pr:7676[] make it clear which client-side commands we use.