Commit Graph

2173 Commits

Author SHA1 Message Date
Lukas Wirth
91a8f34aee Deduplicate lsp locations 2024-02-19 12:23:59 +01:00
Johannes Altmanninger
30b992e95a Deduplicate references to macro argument
Commit 6a06f6f72 (Deduplicate reference search results, 2022-11-07) deduplicates references
within each definition.

There is an edge case when requesting references of a macro argument.  Apparently, our
descend_into_macros() stanza in references.rs produces a cartesian product of
- references inside the macro times
- times references outside the macro.

Since the above deduplication only applies to the references within a single definition, we
return them all, leading to many redundant references.

Work around this by deduplicating definitions as well.  Perhaps there is a better fix to not
produce this cartesian product in the first place; but I think at least for definitions the
problem would remain; a macro can contain multiple definitions of the same name, but since the
navigation target will be the unresolved location, it's the same for all of them.

We can't use unique() because we don't want to drop references that don't have a declaration
(though I dont' have an example for this case).

I discovered this working with the "bitflags" macro from the crate of the same name.

Fixes #16357
2024-02-19 12:23:59 +01:00
bors
ac998a74b3 Auto merge of #16579 - DropDemBits:structured-snippet-fix-with-escaped-bits-and-cr, r=Veykril
fix: Fix snippets being placed leftwards of where they should be

Snippet bits were being escaped before placing snippets, shifting snippets leftwards. Snippets were also being shifted leftwards on files with CRLF line endings since they were placed done after the Unix -> DOS line ending conversion.

Hoping this fixes all of the little bugs related to snippet rendering 😅
2024-02-16 18:45:43 +00:00
Lukas Wirth
ead369117a CrateOrigin::Local means local to the project workspace, not cargo workspace 2024-02-16 16:28:17 +01:00
Lukas Wirth
0ccb3b8731 Move dedup-dev-deps tests into rust-analyzer crate 2024-02-16 15:47:40 +01:00
Lukas Wirth
b1404d387a fix: Split toolchain and datalayout out of CrateData 2024-02-16 14:48:25 +01:00
DropDemBits
e8457bb78b
Escape { and } as well
These are used in placeholder snippets, which may occur elsewhere in the insert text.
2024-02-16 00:28:02 -05:00
DropDemBits
1d8ed3408e
Escape snippet bits in-between placing snippets
Done so that we don't shift the range that we insert the snippet at.
2024-02-16 00:28:02 -05:00
DropDemBits
1aeec93412
Only use snippet_text_edit to make snippet SnippetTextEdits
The eventual LSP representation looks like it will diverge from RA's representation of `SnippetTextEdit`s, so this'll make it easier to transition to the LSP representation later.
2024-02-16 00:28:02 -05:00
DropDemBits
e4a3cc34d5
Add better snippet bits test 2024-02-16 00:28:01 -05:00
DropDemBits
e9efb568f6
Add dos line ending test 2024-02-16 00:28:01 -05:00
bors
b30b77d373 Auto merge of #16573 - Veykril:salsa-doc-tests, r=Veykril
internal: Remove salsa doc compile tests

These don't play well with the github CI error annotations
2024-02-15 16:29:39 +00:00
Lukas Wirth
1443d49b72 Remove salsa doc compile tests 2024-02-15 17:28:24 +01:00
bors
db277c7bb3 Auto merge of #16569 - DropDemBits:structured-snippet-fix-adjust-snippet-ranges, r=Veykril
fix: Place snippets correctly in multi-edit assists

Fixes #16539
2024-02-15 15:54:23 +00:00
DropDemBits
7cf4a8a3bf
fix: Place snippets correctly in multi-edit assists 2024-02-14 21:35:17 -05:00
DropDemBits
0d6024c021
Add tests for snippet range adjustment
Uses actual source for tests to easily confirm the results.
2024-02-14 21:33:05 -05:00
Wilfred Hughes
dda641c62c Set documentation field in SCIP from doc comment
Previously, the documentation field was the same as the text shown to
users when they hover over that symbol. The documentation should
really just be the doc comment, and as of #16179 the signature is
already stored in the signatureDocumentation field.
2024-02-14 14:46:32 -08:00
bors
3bb8d3a32f Auto merge of #16247 - Veykril:opqueues, r=Veykril
fix: Fix build scripts not being rebuilt in some occasions

Also makes proc-macro changed flag setting async, we don't wanna block `process_changes` on the database as that is on the main thread!
2024-02-14 14:33:16 +00:00
Lukas Wirth
1e6cef94df fix: Fix build scripts not being rebuilt in some occasions 2024-02-14 15:20:45 +01:00
Lukas Wirth
465ddef7cc fix: Set RUSTUP_TOOLCHAIN and invoke the proxies instead of directly invoking sysroot binaries 2024-02-14 15:13:45 +01:00
Lukas Wirth
a981db53fa fix: Pass .cargo/config.toml env vars to proc-macro server 2024-02-13 19:42:03 +01:00
bors
1811210339 Auto merge of #15476 - Wilfred:implement-saved-file3, r=Veykril
Substitute $saved_file in custom check commands

If the custom command has a $saved_file placeholder, and we know the file being saved, replace the placeholder and run a check command.

If there's a placeholder and we don't know the saved file, do nothing.

This is a simplified version of #15381, which I hope is easier to review.
2024-02-12 14:59:37 +00:00
bors
818c30c311 Auto merge of #16092 - kilpkonn:term_search_1, r=Veykril
feat: Introduce term search to rust-analyzer

# Introduce term search to `rust-analyzer`
_I've marked this as draft as there might be some shortcomings, please point them out so I can fix them. Otherwise I think it is kind of ready as I think I'll rather introduce extra functionality in follow up PRs._

Term search (or I guess expression search for rust) is a technique to generate code by basically making the types match.
Consider the following program
```rust
fn wrap(arg: i32) -> Option<i32> {
    todo!();
}
```
From the types of values in scope and constructors of `Option`, we can produce the expected result of wrapping the argument in `Option`

Dependently typed languages such as `Idris2` and `Agda` have similar tools to help with proofs, but this can be also used in everyday development as a "auto-complete".

# Demo videos

https://github.com/rust-lang/rust-analyzer/assets/19900308/7b68a1b7-7dba-4e31-9221-6c7485e77d88

https://github.com/rust-lang/rust-analyzer/assets/19900308/0fae530a-aabb-4b28-af71-e19f8d3d64b2

# What does it currently do
- It works well with locals, free functions, type constructors and non-static impl methods that take items by value.
- Works with functions/methods that take shared references, but not with unique references (very conservative).
- Can handle projections to struct fields (eg. `foo.bar.baz`) but this might me more conservative than it has to be to avoid conflicting with borrow checker
- Should create only valid programs (no type / borrow checking errors). Tested with `rust-analyzer analysis-stats /path/to/ripgrep/Cargo.toml --run-term-search --validate-term-search` (basically running `cargo check` on all of the generated programs and only error seems to be due to type inference which is more of issue of testing method.

# Performace / fitness
```txt
ripgrep (latest)
Tail Expr syntactic hits: 130/1692 (7%)
Tail Exprs found: 523/1692 (30%)
Term search avg time: 9ms
Term search:         15.64s, 97ginstr, 8mb

rust-analyzer (on this branch)
Tail Expr syntactic hits: 804/13860 (5%)
Tail Exprs found: 6757/13860 (48%)
Term search avg time: 78ms
Term search:         1088.23s, 6765ginstr, 98mb
```
Highly generic code seems to blow up the search space so currently the amount of generics allowed is functions/methods is limited down to 0 (1 didn't give much improvement and 2 is already like 0.5+s search time)

# Plans for the future (not in this PR)
- ``~~Add impl methods that do not take `self` type (should be quite straight forward)~~ Done
- Be smarter (aka less restrictive) about borrow checking - this seems quite hard but since the current approach is rather naive I think some easy improvement is available.
- ``~~See if it works as a autocomplete while typing~~ Done

_Feel free to ask questions / point of shortcoming either here or on Zulip, I'll be happy to address them. I'm doing this as part of my MSc thesis so I'll be working on it till summer anyway 😄_
2024-02-12 14:47:12 +00:00
Wilfred Hughes
cdbf54f4bd flycheck: initial implementation of $saved_file
If the custom command has a $saved_file placeholder, and we know the
file being saved, replace the placeholder and then run a check command.

If there's a placeholder and we don't know the saved file, do nothing.
2024-02-12 15:45:48 +01:00
Lukas Wirth
e2a985e93f Encode disabled proc-macros via boolean flag, not special Expander 2024-02-12 13:39:38 +01:00
tamasfe
6d45afd8d8 feat: ignored and disabled macro expansion 2024-02-12 12:50:40 +01:00
Lukas Wirth
8f3209ba27 internal: tool discovery prefers sysroot tools 2024-02-12 12:08:18 +01:00
Tavo Annus
125791386d Cleanup term search related changes 2024-02-11 14:35:54 +02:00
Tavo Annus
88964c0b6a Optionally disable term search for autocompletion 2024-02-11 13:33:29 +02:00
Tavo Annus
0b838e3e23 Expand target for autocompletion 2024-02-11 13:33:29 +02:00
Tavo Annus
a946970e2d Add quantified trees to reduce autocomplete options 2024-02-11 13:33:29 +02:00
Tavo Annus
bdbdd83ec1 Initial version of term_search for autocomplete 2024-02-11 13:33:29 +02:00
Tavo Annus
627255dd5a Add static method tactic 2024-02-11 13:33:29 +02:00
Tavo Annus
bb3c7cff60 Introduce term search to rust-analyzer 2024-02-11 13:33:29 +02:00
Tetsuharu Ohzeki
395708d5e0 rust-analyzer: Fix warnings about clippy str_to_string rule 2024-02-10 01:00:40 +09:00
bors
13707845f7 Auto merge of #15863 - davidbarsky:davidbarsky/start-of-monorepo-mode, r=Veykril
feature: Create `UnindexedProject` notification to be sent to the client

(Note that this branch contains commits from https://github.com/rust-lang/rust-analyzer/pull/15830, which I'll rebase atop of as needed.)

Based on the discussion in https://github.com/rust-lang/rust-analyzer/issues/15837, I've added a notification and off-by-default toggle to send that notification from `handle_did_open_text_document`. I'm happy to rename/tweak this as needed.

I've been using this for a little bit, and it does seem to cause a little bit more indexing/work in rust-analyzer, but it's something that I'll profile as needed, I think.
2024-02-08 19:36:09 +00:00
David Barsky
6330b028b3 feature: Add a UnindexedProject notification and a corresponding setting. 2024-02-08 14:23:00 -05:00
Lukas Wirth
91dab4d720 Better error message for when proc-macros have not yet been built 2024-02-08 14:53:12 +01:00
Lukas Wirth
0258f60cfe feat: Allow cargo check to run on only the current package 2024-02-08 10:40:42 +01:00
Lukas Wirth
9e8a0fae0c Lint debug prints and disallowed types with clippy 2024-02-01 17:57:27 +01:00
bors
850ba2fb63 Auto merge of #16451 - Urhengulas:satisfy-clippy, r=Veykril
internal: Work through temporarily allowed clippy lints, part 2

Another follow-up to https://github.com/rust-lang/rust-analyzer/pull/16401.
2024-02-01 14:23:18 +00:00
bors
42cb1a2bd7 Auto merge of #16465 - Veykril:eprintln, r=Veykril
minor: Remove `stdx::eprintln` overwrite
2024-01-31 21:07:50 +00:00
Lukas Wirth
23f4b7f45f Remove stdx::eprintln overwrite 2024-01-31 22:06:05 +01:00
bors
039681112f Auto merge of #16456 - davidbarsky:david/tracing-followups, r=Veykril
internal: `tracing` improvements and followups

Hi folks! Building on https://github.com/rust-lang/rust-analyzer/pull/16394, I've got a few small tweaks:
- Removed the accidental `mod.rs` usage that I introduced.
- Removed a panic in `pat_analysis.rs`.
- Recorded the event kind in `handle_event` to better distinguish what _kind_ of event is being handled.
- Did a small refactor of `hprof` to have somewhat more linear control flow, and more importantly, write the recorded fields to the output.

The end result is the following:
<img width="1530" alt="A screenshot of Visual Studio Code on a Mac. `hprof.rs` is open, with " src="https://github.com/rust-lang/rust-analyzer/assets/2067774/bd11dde5-b2da-4774-bc38-bcb4772d1192">
2024-01-31 18:29:51 +00:00
David Barsky
44494e235a internal: teach hprof to record tracing fields 2024-01-31 13:15:47 -05:00
Johann Hemmann
771c6c9271 format_collect 2024-01-31 19:06:36 +01:00
Johann Hemmann
04ccef80cb field_reassign_with_default 2024-01-31 19:06:18 +01:00
Johann Hemmann
b73ee2f50d useless_conversion 2024-01-31 19:06:18 +01:00
Johann Hemmann
f15ee8a380 unnecessary_filter_map 2024-01-31 19:06:18 +01:00
David Barsky
579e98c4c5 internal: record Event kind in handle_event 2024-01-31 13:00:40 -05:00