Commit Graph

2209 Commits

Author SHA1 Message Date
Lukas Wirth
b5e0452c71 Lazy progress reporting 2023-06-17 10:34:44 +02:00
Lukas Wirth
64a8887a94 Add body lowering step, track time of each step separtely 2023-06-17 09:55:48 +02:00
bors
fdba1b6a5c Auto merge of #15066 - Veykril:analysis-stats, r=Veykril
internal: Analyze all bodies in analysis-stats, not just functions
2023-06-17 07:09:50 +00:00
Lukas Wirth
bd762e62df internal: Add more context to overly long loop turn message 2023-06-16 19:31:07 +02:00
Lukas Wirth
76acf3b992 internal: Analyze all bodies in analysis-stats, not just functions 2023-06-16 19:14:46 +02:00
hkalbasi
e55a1f1916 Map our diagnostics to rustc and clippy's ones 2023-06-15 01:47:22 +03:30
bors
9c967d3809 Auto merge of #15053 - Veykril:crate-root-module-id, r=Veykril
internal: Add a CrateRootModuleId that encodes a module id that is always a crate root
2023-06-14 14:41:06 +00:00
Lukas Wirth
cf178cba8f internal: Add a CrateRootModuleId that encodes a module id that is always a crate root 2023-06-14 15:41:06 +02:00
Lukas Wirth
b322805918 internal: Record file dependencies in crate graph construction 2023-06-13 12:29:24 +02:00
bors
dcd31550e2 Auto merge of #14932 - HKalbasi:dev, r=HKalbasi
Lower const params with a bad id

cc #7434

This PR adds an `InTypeConstId` which is a `DefWithBodyId` and lower const generic parameters into bodies using it, and evaluate them with the mir interpreter. I think this is the last unimplemented const generic feature relative to rustc stable.

But there is a problem: The id used in the `InTypeConstId` is the raw `FileAstId`, which changes frequently. So these ids and their bodies will be invalidated very frequently, which is bad for incremental analysis.

Due this problem, I disabled lowering for local crates (in library crate the id is stable since files won't be changed). This might be overreacting (const generic expressions are usually small, maybe it would be better enabled with bad performance than disabled) but it makes motivation for doing it in the correct way, and it splits the potential panic and breakages that usually comes with const generic PRs in two steps.

Other than the id, I think (at least I hope) other parts are in the right direction.
2023-06-12 08:49:02 +00:00
Lukas Wirth
179b8d7efc
Formatting
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2023-06-11 20:11:26 +02:00
Lukas Wirth
52bb94d697 internal: Give rustfmt jobs a separate thread 2023-06-11 19:56:24 +02:00
hkalbasi
a481e004b0 Lower const params with a bad id 2023-06-11 00:39:28 +03:30
bors
68bdf609f3 Auto merge of #14974 - max-heller:issue-14958, r=lowr
Properly format documentation for `SignatureHelpRequest`s

Properly formats function documentation instead of returning it raw when responding to `SignatureHelpRequest`s.

I added a test in `crates/rust-analyzer/tests/slow-tests/main.rs` -- not sure if this is the best location given the relevant code is in `crates/rust-analyzer` or if it's possible to test in a less heavyweight manner.

Closes #14958
2023-06-10 14:15:37 +00:00
max-heller
78fab7d5d5 format documentation for SignatureHelpRequests 2023-06-10 09:54:34 -04:00
bors
489eeab978 Auto merge of #14960 - jneem:group-delim-span, r=Veykril
Add span to group.

This appears to fix #14959, but I've never contributed to rust-analyzer before and there were some things that confused me:

- I had to add the `fn byte_range` method to get it to build. This was added to rust in [April](https://github.com/rust-lang/rust/pull/109002), so I don't understand why it wasn't needed until now
- When testing, I ran into the fact that rust recently updated its `METADATA_VERSION`, so I had to test this with nightly-2023-05-20. But then I noticed that rust has its own copy of `rust-analyzer`, and the metadata version bump has already been [handled there](60e95e76d0). So I guess I don't really understand the relationship between the code there and the code here.
2023-06-10 11:15:16 +00:00
Lukas Wirth
ccce893577 Count query entries in memory usage command 2023-06-10 01:49:32 +02:00
bors
9c03aa1ac2 Auto merge of #14997 - lnicola:fix-warning, r=Veykril
internal: Fix dependency warning

Hope this doesn't break #14984 again.
2023-06-08 15:48:58 +00:00
beyarkay
dac660dc1d Fix typo in reload.rs 2023-06-07 20:57:27 +02:00
Joe Neeman
ad2a0d1093 Add configurable proc-macro-srv path for diagnostics 2023-06-07 08:48:19 -05:00
Laurențiu Nicola
08ef169435 Fix dependency warning 2023-06-07 12:34:38 +03:00
Lukas Wirth
a6bef7808f fix: Fix proc-macro slow test 2023-06-07 07:03:27 +02:00
Laurențiu Nicola
768a6c5931 Add back sysroot-abi feature gate to rust-analyzer 2023-06-05 14:43:31 +03:00
Lukas Wirth
f9a9e40c0a Update builtin attribute list 2023-06-04 10:02:11 +02:00
Lukas Wirth
a1af9eb1f8
Revert "Add mandatory panic contexts to all threadpool tasks" 2023-06-04 09:30:21 +02:00
Lukas Wirth
2d0510e226 Add mandatory panic contexts to all threadpool tasks 2023-06-04 09:09:25 +02:00
bors
526507fe22 Auto merge of #14888 - lunacookies:multi-qos, r=Veykril
Prioritize threads affected by user typing

To this end I’ve introduced a new custom thread pool type which can spawn threads using each QoS class. This way we can run latency-sensitive requests under one QoS class and everything else under another QoS class. The implementation is very similar to that of the `threadpool` crate (which is currently used by rust-analyzer) but with unused functionality stripped out.

I’ll have to rebase on master once #14859 is merged but I think everything else is alright :D
2023-05-31 10:23:19 +00:00
Lukas Wirth
3c862507b9 Add render configs for memory layout hovers 2023-05-30 18:36:06 +02:00
bors
76d86502f7 Auto merge of #14912 - Veykril:cargo-alltargets, r=Veykril
Don't add --all-targets to runnables for no-std crates

Fixes https://github.com/rust-lang/rust-analyzer/issues/14155
2023-05-30 12:34:28 +00:00
bors
e8dbb8e2e0 Auto merge of #14911 - Veykril:config-cfg, r=Veykril
Allow setting cfgs

Fixes https://github.com/rust-lang/rust-analyzer/issues/14365
2023-05-30 12:00:14 +00:00
Lukas Wirth
bbd9e41606 Don't add --all-targets to runnables for no-std crates 2023-05-28 14:18:44 +02:00
Luna Razzaghipour
6b46095980
Make formatting a latency-sensitive request 2023-05-28 22:10:24 +10:00
Lukas Wirth
cea84427e0 Allow setting cfgs 2023-05-28 13:43:21 +02:00
Luna Razzaghipour
74bc2a47e0
Wrap platform-specific QoS in r-a-specific “thread intent” 2023-05-28 20:37:38 +10:00
Luna Razzaghipour
d0b001eed2
Use appropriate QoS classes throughout the codebase 2023-05-28 20:37:37 +10:00
Luna Razzaghipour
2924fd2213
Implement custom QoS-aware thread pool
This code replaces the thread pool implementation we were using
previously (from the `threadpool` crate). By making the thread pool
aware of QoS, each job spawned on the thread pool can have a different
QoS class.

This commit also replaces every QoS class used previously with Default
as a temporary measure so that each usage can be chosen deliberately.
2023-05-28 20:37:35 +10:00
Lukas Wirth
35b208aaa7 Filter out unused cargo features from config 2023-05-26 22:16:34 +02:00
Lukas Wirth
ee8c18cb6e Fix out_dirs_check test on stable 2023-05-26 20:54:58 +02:00
bors
6bca9f2aac Auto merge of #14859 - lunacookies:qos, r=lunacookies
Specify thread types using Quality of Service API

<details>
<summary>Some background (in case you haven’t heard of QoS before)</summary>

Heterogenous multi-core CPUs are increasingly found in laptops and desktops (e.g. Alder Lake, Snapdragon 8cx Gen 3, M1). To maximize efficiency on this kind of hardware, it is important to provide the operating system with more information so threads can be scheduled on different core types appropriately.

The approach that XNU (the kernel of macOS, iOS, etc) and Windows have taken is to provide a high-level semantic API – quality of service, or QoS – which informs the OS of the program’s intent. For instance, you might specify that a thread is running a render loop for a game. This makes the OS provide this thread with as large a share of the system’s resources as possible. Specifying a thread is running an unimportant background task, on the other hand, is cause for it to be scheduled exclusively on high-efficiency cores instead of high-performance cores.

QoS APIs allows for easy configuration of many different parameters at once; for instance, setting QoS on XNU affects scheduling, timer latency, I/O priorities, and of course what core type the thread in question should run on. I don’t know any details on how QoS works on Windows, but I would guess it’s similar.

Hypothetically, taking advantage of these APIs would improve power consumption, thermals, battery life if applicable, etc.

</details>

# Relevance to rust-analyzer

From what I can tell the philosophy behind both the XNU and Windows QoS APIs is that _user interfaces should never stutter under any circumstances._ You can see this in the array of QoS classes which are available: the highest QoS class in both APIs is one intended explicitly for UI render loops.

Imagine rust-analyzer is performing CPU-intensive background work – maybe you just invoked Find Usages on `usize` or opened a large project – in this scenario the editor’s render loop should absolutely get higher priority than rust-analyzer, no matter what. You could view it in terms of “realtime-ness”: flight control software is hard realtime, audio software is soft realtime, GUIs are softer realtime, and rust-analyzer is not realtime at all. Of course, maximizing responsiveness is important, but respecting the rest of the system is more important.

# Implementation

I’ve tried my best to unify thread creation in `stdx`, where the new API I’ve introduced _requires_ specifying a QoS class. Different points along the performance/efficiency curve can make a great difference; the M1’s e-cores use around three times less power than the p-cores, so putting in this effort is worthwhile IMO.

It’s worth mentioning that Linux does not [yet](https://youtu.be/RfgPWpTwTQo) have a QoS API. Maybe translating QoS into regular thread priorities would be acceptable? From what I can tell the only scheduling-related code in rust-analyzer is Windows-specific, so ignoring QoS entirely on Linux shouldn’t cause any new issues. Also, I haven’t implemented support for the Windows QoS APIs because I don’t have a Windows machine to test on, and because I’m completely unfamiliar with Windows APIs :)

I noticed that rust-analyzer handles some requests on the main thread (using `.on_sync()`) and others on a threadpool (using `.on()`). I think it would make sense to run the main thread at the User Initiated QoS and the threadpool at Utility, but only if all requests that are caused by typing use `.on_sync()` and all that don’t use `.on()`. I don’t understand how the `.on_sync()`/`.on()` split that’s currently present was chosen, so I’ve let this code be for the moment. Let me know if changing this to what I proposed makes any sense.

To avoid having to change everything back in case I’ve misunderstood something, I’ve left all threads at the Utility QoS for now. Of course, this isn’t what I hope the code will look like in the end, but I figured I have to start somewhere :P

# References

<ul>

<li><a href="https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/PrioritizeWorkAtTheTaskLevel.html">Apple documentation related to QoS</a></li>
<li><a href="67e155c940/include/pthread/qos.h">pthread API for setting QoS on XNU</a></li>
<li><a href="https://learn.microsoft.com/en-us/windows/win32/procthread/quality-of-service">Windows’s QoS classes</a></li>
<li>
<details>
<summary>Full documentation of XNU QoS classes. This documentation is only available as a huge not-very-readable comment in a header file, so I’ve reformatted it and put it here for reference.</summary>
<ul>
<li><p><strong><code>QOS_CLASS_USER_INTERACTIVE</code>: A QOS class which indicates work performed by this thread is interactive with the user.</strong></p><p>Such work is requested to run at high priority relative to other work on the system. Specifying this QOS class is a request to run with nearly all available system CPU and I/O bandwidth even under contention. This is not an energy-efficient QOS class to use for large tasks. The use of this QOS class should be limited to critical interaction with the user such as handling events on the main event loop, view drawing, animation, etc.</p></li>
<li><p><strong><code>QOS_CLASS_USER_INITIATED</code>: A QOS class which indicates work performed by this thread was initiated by the user and that the user is likely waiting for the results.</strong></p><p>Such work is requested to run at a priority below critical user-interactive work, but relatively higher than other work on the system. This is not an energy-efficient QOS class to use for large tasks. Its use should be limited to operations of short enough duration that the user is unlikely to switch tasks while waiting for the results. Typical user-initiated work will have progress indicated by the display of placeholder content or modal user interface.</p></li>
<li><p><strong><code>QOS_CLASS_DEFAULT</code>: A default QOS class used by the system in cases where more specific QOS class information is not available.</strong></p><p>Such work is requested to run at a priority below critical user-interactive and user-initiated work, but relatively higher than utility and background tasks. Threads created by <code>pthread_create()</code> without an attribute specifying a QOS class will default to <code>QOS_CLASS_DEFAULT</code>. This QOS class value is not intended to be used as a work classification, it should only be set when propagating or restoring QOS class values provided by the system.</p></li>
<li><p><strong><code>QOS_CLASS_UTILITY</code>: A QOS class which indicates work performed by this thread may or may not be initiated by the user and that the user is unlikely to be immediately waiting for the results.</strong></p><p>Such work is requested to run at a priority below critical user-interactive and user-initiated work, but relatively higher than low-level system maintenance tasks. The use of this QOS class indicates the work should be run in an energy and thermally-efficient manner. The progress of utility work may or may not be indicated to the user, but the effect of such work is user-visible.</p></li>
<li><p><strong><code>QOS_CLASS_BACKGROUND</code>: A QOS class which indicates work performed by this thread was not initiated by the user and that the user may be unaware of the results.</strong></p><p>Such work is requested to run at a priority below other work. The use of this QOS class indicates the work should be run in the most energy and thermally-efficient manner.</p></li>
<li><p><strong><code>QOS_CLASS_UNSPECIFIED</code>: A QOS class value which indicates the absence or removal of QOS class information.</strong></p><p>As an API return value, may indicate that threads or pthread attributes were configured with legacy API incompatible or in conflict with the QOS class system.</p></li>
</ul>
</details>
</li>

</ul>
2023-05-26 15:48:22 +00:00
Lukas Wirth
f876adf617 Report flycheck errors via status 2023-05-26 15:37:41 +02:00
Lukas Wirth
a2b59b110f Report config errors via status 2023-05-26 15:26:03 +02:00
Lukas Wirth
79fe11ced3 Shuffle some things around 2023-05-26 15:09:19 +02:00
bors
8589a2d843 Auto merge of #14849 - alibektas:14557n, r=Veykril
enhancement : using doc aliases to search workspace symbols  ( fixes #14557 )

Doc aliases are now visible among symbols and can be used for searching.
2023-05-26 11:30:40 +00:00
Ali Bektas
d49924dc6e Choose & over ref, make nav target's name more intuitive. 2023-05-26 13:24:44 +02:00
Wilfred Hughes
5b0e170683 Allow users to override the .scip output file path
Previously, rust-analyzer would write to the file index.scip
unconditionally.
2023-05-25 16:54:31 -07:00
Lukas Wirth
e3dfcf2eb2 Add context to overly long loop message 2023-05-25 16:20:28 +02:00
alibektas
1222869b3e Fix #14557. Docs aliases can now be detected and used in searching for workspace symbols 2023-05-24 23:57:24 +02:00
Lukas Wirth
c7ef6c25b7 internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
Luna Razzaghipour
430bdd3509
Run the main thread under the User Interactive QoS class 2023-05-25 00:22:14 +10:00
Luna Razzaghipour
578d99477a
Move on-type formatting request handler onto the main thread 2023-05-25 00:16:52 +10:00
Luna Razzaghipour
ca6461c143
Add proof-of-concept QoS implementation 2023-05-20 22:29:32 +10:00
hkalbasi
261047d019 Fix layout for hir_ty::Ty and friends 2023-05-18 11:29:03 +03:30
bors
c7b03491cd Auto merge of #14834 - Veykril:ty-diag-unit, r=Veykril
internal: Less file parsing for symbol index generation
2023-05-18 06:25:40 +00:00
Lukas Wirth
d6dcfa5744 internal: Less file parsing for symbol index generation 2023-05-18 08:25:06 +02:00
bors
c06f088968 Auto merge of #14823 - Veykril:discriminant-inlays, r=Veykril
fix: Discriminant hints only render for datacarrying enums with primitive repr
2023-05-18 05:50:41 +00:00
Lukas Wirth
c12ede8c34 fix: Discriminant hints only render for datacarrying enums with primitive repr 2023-05-16 22:15:39 +02:00
Weihang Lo
77be56b691
fix(analysis-stats): divided by zero error 2023-05-16 13:57:36 +01:00
bors
2f8cd66fb4 Auto merge of #14810 - Veykril:inline-module, r=Veykril
internal: Inline handlers module
2023-05-15 10:19:21 +00:00
Lukas Wirth
9e80c8571d internal: Inline handlers module 2023-05-15 11:59:09 +02:00
bors
1e6bd6cb0d Auto merge of #14794 - Veykril:inlay-kind-refac, r=Veykril
Restructure InlayHint, no longer derive properties from its kind

Closes https://github.com/rust-lang/rust-analyzer/issues/14595
2023-05-15 09:49:17 +00:00
bors
b198815e7f Auto merge of #14775 - hecatia-elegua:doc-alias-methods, r=Veykril
feat: add #[doc(alias(..))]-based method completions

![Screenshot showing a completion when you type a doc alias instead of a real name](https://github.com/rust-lang/rust-analyzer/assets/108802164/e7c69bb9-3da6-4d8f-a09b-fece1bdd1c0e)
2023-05-15 09:32:10 +00:00
hkalbasi
206a0b5bc6 Add timer for new items 2023-05-14 22:34:58 +03:30
hkalbasi
51e8b8ff14 Add metrics for unevaluated constants, failed mir bodies, and failed data layouts 2023-05-14 17:12:28 +03:30
Lukas Wirth
cace5bb35d fix: Fix process-changes duplicating change events 2023-05-13 21:21:03 +02:00
mataha
9fff960636
Remove root from patched UNC windows path drives 2023-05-13 18:38:12 +02:00
Lukas Wirth
8e116855f5 Add macro modifier for highlighting tokens in macro calls 2023-05-13 11:43:39 +02:00
Lukas Wirth
730286b523 Restructure InlayHint, no longer derive properties from its kind 2023-05-13 10:42:26 +02:00
Lukas Wirth
91d5a689c7 Add config for disabling non standard lsp highlight tokens 2023-05-11 10:01:38 +02:00
Lukas Wirth
4b42acf617 Add basic support for augmentsSyntaxTokens 2023-05-10 20:48:51 +02:00
hecatia-elegua
d4b668a3bb Prepare tidy.rs 2023-05-10 12:47:05 +02:00
bors
d3ce333ec8 Auto merge of #14742 - Veykril:closure-capture-inlays, r=Veykril
feat: Closure capture inlay hints

I opted for a fictional `move(foo, &bar, &mut qux)` syntax here, disabled by default as these are not correct rust syntax and hence could cause confusion.
![image](https://user-images.githubusercontent.com/3757771/236447484-649a4ea6-ad61-496e-bad8-765a5236150e.png)
2023-05-08 09:52:29 +00:00
bors
833d5301d1 Auto merge of #14758 - lumenian:hover-layout-config, r=HKalbasi
Add config for disabling hover memory layout data

Requested in https://github.com/rust-lang/rust-analyzer/pull/14748#issuecomment-1537190252
2023-05-07 16:22:57 +00:00
Yury Ivanou
98a4c5049f Rename hover memory layout config key 2023-05-07 18:37:56 +03:00
Yury Ivanou
4ed0fa8414 Add config for disabling hover memory layout data 2023-05-07 18:21:07 +03:00
Ariel Davis
02e8bb0c6e Return Option 2023-05-06 00:57:57 -07:00
Ariel Davis
fcbe73ec1c Refactor position 2023-05-06 00:52:32 -07:00
Ariel Davis
1ad0779a00 Make WideEncoding non-exhaustive 2023-05-06 00:49:23 -07:00
Ariel Davis
4a1922fd1a Depend on nohash-hasher individually 2023-05-06 00:49:23 -07:00
Lukas Wirth
8081a654da feat: Closure capture inlay hints 2023-05-05 13:38:22 +02:00
Laurențiu Nicola
7197a27028 Use triomphe Arc 2023-05-02 20:02:43 +03:00
Ddystopia
2025f17ac3
Workspace without sysroot could be possible 2023-05-02 17:24:00 +02:00
Ddystopia
7e19d99d4f
Add a localDocs capability 2023-05-02 17:13:21 +02:00
Ddystopia
4ac39f0c98
Propagating sysroot down + Refactoring 2023-05-02 17:08:56 +02:00
Ddystopia
396934860c
Getting cargo workspace from file_id and refactoring 2023-05-02 17:08:56 +02:00
Ddystopia
c47a34fddc
Add target_dir path argument for external_docs and other methods 2023-05-02 17:06:38 +02:00
Ddystopia
f2d933ecaf
Add support for local documentation links alongside web documentation links, pending for target_dir path and tests 2023-05-02 17:06:38 +02:00
Bruno Ortiz
ecfe7c0488 last fixes after rebase 2023-05-02 11:24:08 -03:00
Bruno Ortiz
bcb21311ea Accepting review suggestions 2023-05-02 11:06:25 -03:00
Bruno Ortiz
800b3b6323 adding doc and simplifying function 2023-05-02 11:03:32 -03:00
Bruno Ortiz
66fe84d936 accepting review suggestions 2023-05-02 11:01:41 -03:00
Bruno Ortiz
1b8288ff96 Fixing naming from graph to list 2023-05-02 10:59:29 -03:00
Bruno Ortiz
e2535926e9 Fixing tests 2023-05-02 10:56:50 -03:00
Bruno Ortiz
440889edec fixing main_loop.rs 2023-05-02 10:56:13 -03:00
Lukas Wirth
299382dacd WIP: Add lsp-ext scaffold 2023-05-02 10:56:13 -03:00
Bruno Ortiz
09e0a00d36 fetching dependencies from the server 2023-05-02 10:56:09 -03:00
Lukas Wirth
1201b156d8 WIP: Add lsp-ext scaffold 2023-05-02 10:52:33 -03:00
bors
1ad58a42aa Auto merge of #14711 - Veykril:highlight-captures, r=Veykril
feat: Highlight closure captures when cursor is on pipe or move keyword

This runs into the same issue on vscode as exit points for `->`, where highlights are only triggered on identifiers, https://github.com/rust-lang/rust-analyzer/issues/9395

Though putting the cursor on `move` should at least work.
2023-05-02 07:22:43 +00:00
Lukas Wirth
a64626d99e Highlight closure captures when cursor is on pipe 2023-05-02 08:59:40 +02:00
Jake Heinz
b9007a26a0 add module docs 2023-05-02 06:48:29 +00:00
Jake Heinz
f4d2044528 rust-analyzer: refactor notification handlers 2023-05-02 06:28:26 +00:00