Commit Graph

21958 Commits

Author SHA1 Message Date
harpsword
dfae0a12ef fix: calculate right range for Dos line ending in mapping rustc range to lsp range 2022-05-18 21:08:18 +08:00
bors
187bd7d48a Auto merge of #12130 - weirane:let-else-let-match, r=weirane
Turn let-else statements into let and match

Fixes #11906.
2022-05-17 19:01:18 +00:00
bors
1a5925dc84 Auto merge of #12294 - listochkin:prettier, r=Veykril
Switch to Prettier for TypeScript Code formatting

## Summary of changes:

 1. Added [`.editorconfig` file](https://editorconfig.org) to dictate general hygienic stuff like character encoding, no trailing whitespace, new line symbols etc. for all files (e.g. Markdown). Install an editor plugin to get this rudimentary formatting assistance automatically. Prettier can read this file and, for example, use it for indentation style and size.
 2. Added a minimal prettier config file. All options are default except line width, which per [Veykril](https://github.com/Veykril) suggestion is set to 100 instead of 80, because [that's what `Rustfmt` uses](https://rust-lang.github.io/rustfmt/?version=v1.4.38&search=#max_width).
 3. Change `package.json` to use Prettier instead of `tsfmt` for code formatting.
 4. Performed initial formatting in a separate commit, per [bjorn3](https://github.com/bjorn3) suggestion added its hash to a `.git-blame-ignore-revs` file. For it to work you need to add a configuration to your git installation:
    ```Shell
    git config --global blame.ignoreRevsFile .git-blame-ignore-revs
    ```
 5. Finally, removed `typescript-formatter` from the list of dependencies.

----
What follows below is summary of the discussion we had on Zulip about the formatter switch:

## Background

For the context, there are three reasons why we went with `tsfmt` originally:
* stick to vscode default/built-in
* don't add extra deps to package.json.lock
* follow upstream (language server node I think still uses `tsfmt`)

And the meta reason here was that we didn't have anyone familiar with frontend, so went for the simplest option, at the expense of features and convenience.

Meanwhile, [**Prettier**](https://prettier.io) became a formatter project that JS community consolidated on a few years ago. It's similar to `go fmt` / `cargo fmt` in spirit: minimal to no configuration to promote general uniformity in the ecosystem. There are some options, that were needed early on to make sure the project gained momentum, but by no means it's a customizable formatter that is easy to adjust to reduce the number of changes for adoption.

## Overview of changes performed by Prettier

Some of the changes are acceptable. Prettier dictates a unified string quoting style, and as a result half of our imports at the top are changed. No one would mind that. Some one-line changes are due to string quotes, too, and although these a re numerous, the surrounding lines aren't changed, and git blame / GitLens will still show relevant context.

Some are toss ups. `trailingComma` option - set it to `none`, and get a bunch of meaningless changes in half of the code. set it to `all` and get a bunch of changes in the other half of the code. Same with using parentheses around single parameters in arrow functions: `x => x + 1` vs `(x) => x + 1`. Perrier forces one style or the other, but we use both in our code.

Like I said, the changes above are Ok - they take a single line, don't disrupt GitLens / git blame much. **The big one is line width**. Prettier wants you to choose one and stick to it. The default is 80 and it forces some reformatting to squish deeply nested code or long function type declarations. If I set it to 100-120, then Prettier finds other parts of code where a multi-line expression can be smashed into a single long line. The problem is that in both cases some of the lines that get changed are interesting, they contain somewhat non-trivial logic, and if I were to work on them in future I would love to see the commit annotations that tell me something relevant. Alas, we use some of that.

## Project impact

Though Prettier is a mainstream JS project it has no dependencies. We add another package so that it and ESLint work together nicely, and that's it.
2022-05-17 18:50:00 +00:00
weirane
4a0821f332 Simplify const reference check
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-05-17 11:43:53 -07:00
bors
52b69fae6d Auto merge of #12296 - jonas-schievink:add-attribute-assist, r=jonas-schievink
feat: add a "Add attribute" assist

This generalizes the "Add `#[derive]`" assist and supports adding `#[must_use]` and `#[inline]`.

Removes `#[must_use]` from the "Generate getter/setter" assist, addressing the last point in https://github.com/rust-lang/rust-analyzer/issues/12273. Closes https://github.com/rust-lang/rust-analyzer/issues/12273.
2022-05-17 18:30:26 +00:00
Jonas Schievink
cb135ae71b Add a "Add attribute" assist 2022-05-17 20:28:25 +02:00
Andrei Listochkin
00a97272f2 automate braceless return substitution for long lines
Per [bjorn3][https://github.com/bjorn3] suggestion resolves cases where
an early return is moved to a separate line due to line width formatting.

This setting changes
```
if (a very long condition) return;
```
to
```
if (a very long
    condition) {
  return;
}
```
while keeping
```
if (short) return;
```
as is.

In pathological cases this may cause `npm run fix` not to fix formatting
in one go and may require running it twice.
2022-05-17 18:31:51 +01:00
Andrei Listochkin
e0df2c9bee remove tsfmt from dependencies 2022-05-17 18:16:04 +01:00
Andrei Listochkin
1add3e6395 add prettier format commit to ignored revisions 2022-05-17 18:15:51 +01:00
Andrei Listochkin
f247090558 prettier run 2022-05-17 18:15:06 +01:00
Andrei Listochkin
8e9f54f238 use prettier to format the code 2022-05-17 18:14:28 +01:00
Andrei Listochkin
4fcdb0fea0 prettier config
[Prettier][1] is an up-to date code formatter for JavaScript ecosystem.

For settings we rely on [EditorConfig][2] for things like tab style and
size (with added bonus that the code editor with an EditorConfig plugin
does some automated code formatting on file save for you). Unfortunately,
Prettier's Glob handling isn't great:
 1. `*.{ts,js,json}` has no effect
 2. Similarly, in a list of globs `*.ts,*.js,*.json` only the first glob
has an effect, the rest are ignored.
That's why the file looks the way it does.

The only other setting we change is line width. [Lukas][3] suggested we
use 100 instead of 80, because that's what Rustfmt is using.

[1]: https://prettier.io
[2]: https://editorconfig.org
[3]: https://github.com/Veykril
2022-05-17 18:12:49 +01:00
bors
7e95c14ea7 Auto merge of #12292 - jonas-schievink:bump-extension-version, r=jonas-schievink
internal: Bump extension version
2022-05-17 14:03:08 +00:00
Jonas Schievink
21b6ce8b8e Bump extension version 2022-05-17 16:02:07 +02:00
bors
c5c442eee1 Auto merge of #12285 - Veykril:inlay-hints, r=Veykril
feat: Implement inlay hint tooltips

Currently this just delegates to hover request for some things, and otherwise fallsback to the label.
![image](https://user-images.githubusercontent.com/3757771/168816520-e015726f-53e1-4dac-a76e-8f1312f145d7.png)
![image](https://user-images.githubusercontent.com/3757771/168802753-43749b75-866c-40db-b106-aeaa542b87a3.png)
![image](https://user-images.githubusercontent.com/3757771/168816579-da2050f0-f198-4b3a-a9a1-53199fcaab61.png)
![image](https://user-images.githubusercontent.com/3757771/168818804-d4400ffe-0e6c-48a0-a872-f054e5f550fa.png)
2022-05-17 13:11:40 +00:00
Lukas Wirth
58a241134c Update test output 2022-05-17 14:58:26 +02:00
bors
f8fc0ea528 Auto merge of #12289 - rust-lang:Veykril-patch-1, r=Veykril
fix: Fix incorrect config key in client config update

Closes https://github.com/rust-lang/rust-analyzer/issues/12288
2022-05-17 12:56:25 +00:00
Lukas Wirth
d43b9dae56
Fix incorrect config key in client config update
Closes https://github.com/rust-lang/rust-analyzer/issues/12288
2022-05-17 14:56:08 +02:00
Lukas Wirth
0c488fa215 Update lsp-extensions hash 2022-05-17 14:48:28 +02:00
Lukas Wirth
21f37a6d9e Allow inlay hint tooltips to trigger hovers 2022-05-17 14:46:43 +02:00
Lukas Wirth
a2ec010185 Trigger hover requests on closing brace hints 2022-05-17 13:39:45 +02:00
Lukas Wirth
0756719a30 Replace some SmolStr usages with String as the conversion happens anyways 2022-05-17 12:56:14 +02:00
Lukas Wirth
91833f1974 feat: Implement inlay hint tooltips 2022-05-17 12:49:51 +02:00
bors
3bbdb0dbb6 Auto merge of #12284 - Veykril:inlay-hints, r=Veykril
internal: Cleanup lifetime elision hints
2022-05-17 10:19:14 +00:00
Lukas Wirth
12d5343993 internal: Cleanup lifetime elision hints 2022-05-17 12:18:07 +02:00
bors
ce9b174f8a Auto merge of #12276 - jonas-schievink:improve-generate-deref-impl, r=jonas-schievink
feat: Improve "Generate `Deref` impl" assist

Fixes https://github.com/rust-lang/rust-analyzer/issues/12265
Fixes https://github.com/rust-lang/rust-analyzer/issues/12266

The assist will now generate a `DerefMut` impl if a `Deref` impl is already present.
2022-05-16 18:12:53 +00:00
Jonas Schievink
1df6560fd8 Improve "Generate Deref impl" assist 2022-05-16 20:10:46 +02:00
bors
8bc6a8fe6d Auto merge of #12275 - jonas-schievink:remove-setter-doc-gen, r=jonas-schievink
fix: Don't generate documentation in `generate_setter`

Followup to https://github.com/rust-lang/rust-analyzer/pull/12274
2022-05-16 17:28:01 +00:00
Jonas Schievink
54c8c39da0 Don't generate documentation in generate_setter 2022-05-16 19:27:27 +02:00
bors
da503b6a13 Auto merge of #12274 - jonas-schievink:move-getter-docs-generation, r=jonas-schievink
feat: Handle getters and setters in documentation template assist

The assist can now turn this:

```rust
pub struct S;
impl S {
    pub fn data_mut$0(&mut self) -> &mut [u8] { &mut [] }
}
```

into

```rust
pub struct S;
impl S {
    /// Returns a mutable reference to the data.
    ///
    /// # Examples
    ///
    /// ```
    /// use test::S;
    ///
    /// let mut s = ;
    /// assert_eq!(s.data_mut(), );
    /// assert_eq!(s, );
    /// ```
    pub fn data_mut(&mut self) -> &mut [u8] { &mut [] }
}
```

And similarly for by-value or immutable getters, and for setters. Previously the intro line would be empty.

This PR also removes the documentation generation function from the "Generate getter/setter" assist, since that is better handled by applying the 2 assists in sequence. cc https://github.com/rust-lang/rust-analyzer/issues/12273
2022-05-16 17:14:16 +00:00
Jonas Schievink
f1b6e45fba Handle getters and setters in documentation template assist 2022-05-16 19:10:38 +02:00
bors
825ce48180 Auto merge of #12271 - bitgaoshu:box_with_expec, r=flodiebold
fix #12227 Type mismatch error shown

add box expectation hint
2022-05-16 15:00:36 +00:00
bors
795930717b Auto merge of #12272 - jonas-schievink:fix-signature-help-offsets, r=jonas-schievink
fix: Fix signature help LSP offset conversion

Fixes https://github.com/rust-lang/rust-analyzer/issues/12270

I don't think we really handle this correctly anywhere (eg. surrogates probably aren't counted right), but this at least fixes the immediately visible bug.
2022-05-16 13:50:00 +00:00
Jonas Schievink
5ee028bbb8 Fix signature help LSP offset conversion 2022-05-16 15:48:38 +02:00
bors
ee2cbe0ae8 Auto merge of #12244 - jonas-schievink:closing-brace-hints, r=jonas-schievink
feat: Show inlay hints after a `}` to indicate the closed item

Closes https://github.com/rust-lang/rust-analyzer/issues/7315

![screenshot-2022-05-13-19:42:00](https://user-images.githubusercontent.com/1786438/168338713-4cedef50-3611-4667-aa6a-49e154ec16a7.png)
2022-05-16 13:25:04 +00:00
Jonas Schievink
fccc12982e Add closing brace hints for macros 2022-05-16 15:23:25 +02:00
bitgaoshu
e362929fa1 add box expection hint 2022-05-16 21:17:00 +08:00
Jonas Schievink
867a7dc7a0 Show inlay hints after a } to indicate the closed item 2022-05-16 14:55:47 +02:00
bors
58234c64da Auto merge of #12256 - matklad:m, r=matklad
minor: rename
2022-05-16 11:44:00 +00:00
Aleksey Kladov
2f3453994a minor: rename 2022-05-16 12:42:48 +01:00
bors
1dc25e51a0 Auto merge of #12253 - Veykril:bm, r=Veykril
feat: Add binding mode inlay hints

![image](https://user-images.githubusercontent.com/3757771/168427387-2f299438-a0cc-496b-a9a5-d689ef6a2b55.png)
2022-05-16 11:16:22 +00:00
bors
ac4ce4259b Auto merge of #12242 - flodiebold:extension-description, r=flodiebold
Improve extension description and README
2022-05-15 18:11:32 +00:00
bors
5ae9847dea Auto merge of #12262 - jhgg:fix-whitespace-between-mut-self-in-macro-expansion, r=lnicola
ide: insert whitespace between 'mut' and 'self' in macro expansion

fixes #12260
2022-05-15 12:47:38 +00:00
bors
fa133d065b Auto merge of #12190 - harpsword:fix_diagostics_map_incorrectly, r=harpsword
fix cargo check diagnostics are mapped incorrectly with non-BMP codepoints

fix #11945
2022-05-15 09:48:51 +00:00
Jake Heinz
4efc2a9df2 ide: insert whitespace between 'mut' and 'self' in macro expansion 2022-05-15 07:55:13 +00:00
bors
1ff5b2cab4 Auto merge of #12251 - matklad:lsp-server, r=matklad
internal: vendor lsp-server
2022-05-14 20:20:01 +00:00
Aleksey Kladov
57cb65bb7a internal: vendor lsp-server 2022-05-14 21:15:43 +01:00
Lukas Wirth
977f0ba968 Update package.json 2022-05-14 15:18:18 +02:00
Lukas Wirth
7cbde1b3a5 Enable reborrow hints in attribute calls 2022-05-14 15:00:14 +02:00
Lukas Wirth
6b696fced8 feat: Add binding mode inlay hints 2022-05-14 14:58:35 +02:00