Commit graph

2516 commits

Author SHA1 Message Date
Lukas Wirth
21a3d01875 Remove inline rust_2018_idioms, unused_lifetimes lint warn, Cargo.toml already enforces this 2024-06-30 15:23:54 +02:00
Lukas Wirth
bfb187aacd Fix expression scope calculation when within macro expansions 2024-06-30 13:26:17 +02:00
Lukas Wirth
3168ab5b99 Enum variants are not generic def ids 2024-06-24 10:07:31 +02:00
bors
6738f81b12 Auto merge of #17419 - ishanjain28:filter_builtin_macro_expansion, r=Veykril
Filter builtin macro expansion

This PR adds a filter on the types of built in macros that are allowed to be expanded.

Currently, This list of allowed macros contains, `stringify, cfg, core_panic, std_panic, concat, concat_bytes, include, include_str, include_bytes, env` and `option_env`.

Fixes #14177
2024-06-20 08:39:17 +00:00
Lukas Wirth
bf9a7264d1 Invert matching on builtin macros in expand_allowed_builtins 2024-06-20 10:31:20 +02:00
Ishan Jain
5465979b7a
updated tests 2024-06-19 16:11:50 +05:30
bors
a150d422cf Auto merge of #17426 - roife:fix-issue-17420, r=Veykril
fix: handle character boundaries for wide chars in extend_selection

fix #17420.

When calling 'extend_selection' within a string, r-a attempts to locate the current word at the cursor. This is done by finding the first char before the cursor which is not a letter, digit, or underscore.

The position of this character is referred to as `start_idx`, and the word is considered to start from `start_idx + 1`. However, for wide characters, `start_idx + 1` is not character boundaries, which leading to panic. We should use `ceil_char_boundary` to ensure that the idx is always on character boundaries.
2024-06-19 08:13:18 +00:00
Lunaphied
e1ffec2b4c docs: document omission heuristics for parameter inlay hints
These are not currently documented and could cause users to think
that their rust-analyzer configuration is broken.

Partially addresses #17433.
2024-06-16 15:15:36 -06:00
roife
bf356e0eec fix: handle character boundaries for wide chars in extend_selection 2024-06-15 23:35:29 +08:00
Ishan Jain
020537cd06
Created expand_allowed_builtins, updated expand_macro to call this function 2024-06-15 15:20:46 +05:30
Ishan Jain
7c37e57426
added tests 2024-06-14 09:17:56 +05:30
bors
c07076b35c Auto merge of #17394 - Veykril:recurse-fix, r=Veykril
fix: Fix `HirDisplay` stackoverflow for parameter Self defaults

Fixes https://github.com/rust-lang/rust-analyzer/issues/10932
2024-06-11 15:05:26 +00:00
Lukas Wirth
1ecf230792 fix: Fix HirDisplay stackoverflow for parameter Self defaults 2024-06-11 17:04:07 +02:00
roife
78118f98f6 feat: add hover config for showing container bounds 2024-06-11 21:02:13 +08:00
bors
ba1c56c83a Auto merge of #17374 - Veykril:configs, r=Veykril
Allow choosing logical cores for num threads config
2024-06-11 08:49:19 +00:00
Lukas Wirth
1dcb11be5d Simplify some config serialization stuff 2024-06-11 10:45:17 +02:00
Lukas Wirth
8520a0c585 Thread more HasSource::source calls through Semantics for caching 2024-06-10 10:33:07 +02:00
Lukas Wirth
e972dd2385 Allow choosing logical cores for num threads config 2024-06-09 12:04:28 +02:00
Lukas Wirth
379f885373 fix: Fix renaming imports of foreign items touching foreign sources 2024-06-07 14:36:37 +02:00
bors
7c5d496ef8 Auto merge of #17058 - alibektas:13529/ratoml, r=Veykril
feat: TOML based config for rust-analyzer

> Important
>
> We don't promise _**any**_ stability with this feature yet, any configs exposed may be removed again, the grouping may change etc.

# TOML Based Config for RA

This PR ( addresses #13529 and this is a follow-up PR on #16639 ) makes rust-analyzer configurable by configuration files called `rust-analyzer.toml`. Files **must** be named `rust-analyzer.toml`. There is not a strict rule regarding where the files should be placed, but it is recommended to put them near a file that triggers server to start (i.e., `Cargo.{toml,lock}`, `rust-project.json`).

## Configuration Types

Previous configuration keys are now split into three different classes.

1. Client keys: These keys only make sense when set by the client (e.g., by setting them in `settings.json` in VSCode). They are but a small portion of this list. One such example is `rust_analyzer.files_watcher`, based on which either the client or the server will be responsible for watching for changes made to project files.
2. Global keys: These keys apply to the entire workspace and can only be set on the very top layers of the hierarchy. The next section gives instructions on which layers these are.
3. Local keys: Keys that can be changed for each crate if desired.

### How Am I Supposed To Know If A Config Is Gl/Loc/Cl ?

#17101

## Configuration Hierarchy

There are 5 levels in the configuration hierarchy. When a key is searched for, it is searched in a bottom-up depth-first fashion.

### Default Configuration

**Scope**: Global, Local, and Client

This is a hard-coded set of configurations. When a configuration key could not be found, then its default value applies.

### User configuration

**Scope**: Global, Local

If you want your configurations to apply to **every** project you have, you can do so by setting them in your `$CONFIG_DIR/rust-analyzer/rust-analyzer.toml` file, where `$CONFIG_DIR` is :

| Platform | Value                                 | Example                                  |
| ------- | ------------------------------------- | ---------------------------------------- |
| Linux   | `$XDG_CONFIG_HOME` or `$HOME`/.config | /home/alice/.config                      |
| macOS   | `$HOME`/Library/Application Support   | /Users/Alice/Library/Application Support |
| Windows | `{FOLDERID_RoamingAppData}`           | C:\Users\Alice\AppData\Roaming           |

### Client configuration

**Scope**: Global, Local, and Client

Previously, the only way to configure rust-analyzer was to configure it from the settings of the Client you are using. This level corresponds to that.

> With this PR, you don't need to port anything to benefit from new features. You can continue to use your old settings as they are.

### Workspace Root Configuration

**Scope**: Global, Local

Rust-analyzer already used the path of the workspace you opened in your Client. We used this information to create a configuration file that won't affect your other projects and define global level configurations at the same time.

### Local Configuration

**Scope**: Local

You can also configure rust-analyzer on a crate level. Although it is not an error to define global ( or client ) level keys in such files, they won't be taken into consideration by the server. Defined local keys will affect the crate in which they are defined and crate's descendants. Internally, a Rust project is split into what we call `SourceRoot`s. This, although with exceptions, is equal to splitting a project into crates.

> You may choose to have more than one `rust-analyzer.toml` files within a `SourceRoot`, but among them, the one closer to the project root will be
2024-06-07 10:49:02 +00:00
Wilfred Hughes
27182bb96b chore: Prefer tracing span shorthand macros 2024-06-06 16:52:25 -07:00
roife
4a4b13cbda fix: incorrect formatting of hover actions 2024-06-06 21:07:59 +08:00
bors
af488c971f Auto merge of #17352 - roife:fix-issue-17338, r=Veykril
fix: do not resolve prelude within block modules

fix #17338 (continuing from #17251).

In #17251, we injected preludes into non-top-level modules, which leading to r-a to directly resolve names in preludes in block modules. This PR fix it by checking whether the module is a pseudo-module introduced by blocks. (similar to what we do for extern preludes)
2024-06-06 09:40:39 +00:00
roife
22e82c72ac test: add regression test for prelude shadowing in block modules 2024-06-06 17:03:40 +08:00
Ali Bektas
23a5f31ff4 Apply suggested changes 2024-06-05 10:45:19 +02:00
Lukas Wirth
9349045e09 Use dyn cache for Semantics macro resolution 2024-06-04 16:25:38 +02:00
bors
6bae8e333b Auto merge of #17282 - jkelleyrtp:jk/filter-by-underscorte, r=Veykril
Feat: hide double underscored symbols from symbol search

Fixes #17272 by changing the default behavior of query to skip results that start with `__` (two underscores).

Not sure if this has any far reaching implications - a review would help to understand if this is the right place to do the filtering, and if it's fine to do it by default on the query.

If you type `__` as your search, then we'll show the matching double unders, just in case you actually need the symbol.
2024-06-04 08:37:56 +00:00
Lukas Wirth
0110cfcae0 Recognize __ prefixes for symbol search query 2024-06-04 10:36:04 +02:00
bors
cb6b808185 Auto merge of #17315 - hamirmahal:style/simplify-string-interpolation, r=Veykril
style: simplify string interpolation
2024-06-03 12:29:27 +00:00
Luke Franceschini
8c5ef9c15f
docs: Missing word typo 2024-05-31 11:24:26 -04:00
Hamir Mahal
7c34eb3880
style: simplify string interpolation 2024-05-30 16:18:49 -07:00
Mathew Horner
333bedd70f
Avoid clone when constructing runnable label. 2024-05-25 15:00:15 -05:00
bors
f372a8a117 Auto merge of #17284 - Veykril:doc-links, r=Veykril
fix: Use correct toolchain channel when generating builtin type doc links
2024-05-23 08:55:08 +00:00
Lukas Wirth
5717622c95 Use correct toolchain channel when generating builtin type doc links 2024-05-23 10:42:15 +02:00
bors
dec43b6cb3 Auto merge of #17174 - Kohei316:fix-infer-async-block-with-tail-return-expr, r=Veykril
Fix: infer type of async block with tail return expr

Fixes #17106
The `infer_async_block` method calls the `infer_block` method internally, which returns the never type without coercion when `tail_expr` is `None` and `ctx.diverges` is `Diverges::Always`.This is the reason for the bug in this issue.
cfce2bb46d/crates/hir-ty/src/infer/expr.rs (L1411-L1413)

This PR solves the bug by adding a process to coerce after calling `infer_block` method.

This code passes all the tests, including tests I added for this isuue, however, I am not sure if this solution is right. I think that this solution is an ad hoc solution. So, I would appreciate to have your review.
I apologize if I'm off the mark, but `infer_async_block` method should be rewritten to share code with the process of infering type of `expr::Closure` instead of the `infer_block` method. That way it will be closer to the infer process of rustc.
2024-05-23 08:42:09 +00:00
Jonathan Kelley
28ddddd091
Feat: hide double underscored symbols from symbol search 2024-05-22 13:43:07 -07:00
Lukas Wirth
7bd343e085 Show fn traits in signature info for trait implementors 2024-05-18 16:22:59 +02:00
Lukas Wirth
0de904d539 Enable linked locations for closure param inlay hints 2024-05-18 15:06:46 +02:00
Lukas Wirth
ff79903cf6 Render closure fn trait kind in siganture help 2024-05-18 15:01:37 +02:00
Lukas Wirth
7c6f31a45b Allow hir::Param to refer to other entity params aside from functions 2024-05-18 12:35:55 +02:00
Lukas Wirth
aaa5426fec internal: Add StaticLifetime to hir API 2024-05-16 08:02:51 +02:00
Lukas Wirth
465ebbc102 internal: Sort computed runnables 2024-05-14 12:32:48 +02:00
bors
7afd8d8a1a Auto merge of #17225 - Veykril:expand-macro-interlocked, r=Veykril
Expand macro recursively expands both fp-like and attribute macros when intertwined
2024-05-14 09:22:04 +00:00
Lukas Wirth
580b8dab1a Expand macro recursively expands both fp-like and attribute macros intertwined 2024-05-14 10:58:18 +02:00
Lukas Wirth
5b696bac5c Don't render multi-line literal values 2024-05-13 12:56:02 +02:00
Lukas Wirth
a39c0493a1 Render literal escaping errors in hovers 2024-05-13 12:51:57 +02:00
Lukas Wirth
253929f6ae Fix literal hovers being confusing and wrong for floats 2024-05-13 12:26:45 +02:00
Lukas Wirth
e1aeed3aed Implement unsafe attribute parsing 2024-05-06 12:11:29 +02:00
Wilfred Hughes
c981ff0944 fix: Tracing span names should match function names
When viewing traces, it's slightly confusing when the span name doesn't
match the function name. Ensure the names are consistent.

(It might be worth moving most of these to use #[tracing::instrument]
so the name can never go stale. @davidbarsky suggested that is marginally
slower, so I've just done the simple change here.)
2024-04-30 11:22:47 -07:00
morine0122
da3fa2b7f0 Fix coercion of async block 2024-04-30 18:31:10 +09:00