Commit graph

1645 commits

Author SHA1 Message Date
Laurențiu Nicola
c3864eb511 Add and use rust-analyzer.cargo.extraArgs setting 2023-03-12 13:04:24 +02:00
Lukas Wirth
2cb60343ed Add fancy buttons to the vscode status message 2023-03-10 10:13:30 +01:00
hkalbasi
ac04bfd7a7 Add View Mir command and fix some bugs 2023-03-06 21:09:09 +03:30
bors
a0be16b0b2 Auto merge of #14040 - HKalbasi:mir, r=HKalbasi
Beginning of MIR

This pull request introduces the initial implementation of MIR lowering and interpreting in Rust Analyzer.

The implementation of MIR has potential to bring several benefits:
- Executing a unit test without compiling it: This is my main goal. It can be useful for quickly testing code changes and print-debugging unit tests without the need for a full compilation (ideally in almost zero time, similar to languages like python and js). There is a probability that it goes nowhere, it might become slower than rustc, or it might need some unreasonable amount of memory, or we may fail to support a common pattern/function that make it unusable for most of the codes.
- Constant evaluation: MIR allows for easier and more correct constant evaluation, on par with rustc. If r-a wants to fully support the type system, it needs full const eval, which means arbitrary code execution, which needs MIR or something similar.
- Supporting more diagnostics: MIR can be used to detect errors, most famously borrow checker and lifetime errors,  but also mutability errors and uninitialized variables, which can be difficult/impossible to detect in HIR.
- Lowering closures: With MIR we can find out closure capture modes, which is useful in detecting if a closure implements the `FnMut` or `Fn` traits, and calculating its size and data layout.

But the current PR implements no diagnostics and doesn't support closures. About const eval, I removed the old const eval code and it now uses the mir interpreter. Everything that is supported in stable rustc is either implemented or is super easy to implement. About interpreting unit tests, I added an experimental config, disabled by default, that shows a `pass` or `fail` on hover of unit tests (ideally it should be a button similar to `Run test` button, but I didn't figured out how to add them). Currently, no real world test works, due to missing features including closures, heap allocation, `dyn Trait` and ... so at this point it is only useful for me selecting what to implement next.

The implementation of MIR is based on the design of rustc, the data structures are almost copy paste (so it should be easy to migrate it to a possible future stable-mir), but the lowering and interpreting code is from me.
2023-02-28 09:12:19 +00:00
hkalbasi
cd67589f63 beginning of MIR 2023-02-27 23:45:54 +03:30
Tomoki Nakagawa
e4b184a776 Respect $CARGO_HOME when looking up toolchains. 2023-02-26 15:37:04 +09:00
bors
f5401f6206 Auto merge of #14175 - jmviz:openDocs-context-menu, r=lnicola
add openDocs command to context menu in VS Code extension

This adds the `openDocs` command to the VS Code context menu. I believe there are probably many user who are unaware of this command existing in the rust analyzer extension, and that this should enhance the discoverability of the command. Additionally, even if people are aware of this capability, it's helpful to have this in the context menu anyway; for example, one might forget the name of the command, or the keybinding they have assigned to it. I think that opening docs is a common enough action to warrant the extra line added to the context menu.

This makes a few other small changes as well. There are two minor style changes to increase style consistency. First, it changes the titles of the two commands that the rust analyzer extension will contribute to the context menu to title case. All standard VS Code commands that appear in the context menu are in title case. Second, it shortens the title of the `openDocs` command from `Open docs under cursor` to `Open Docs`. The implicit assumption in the standard VS Code context menu command titles is that the action applies to the symbol under the cursor: `Go to Definition`, `Find All References`, etc. Note that since these are changes to the command titles, rather than the command names themselves, these changes will not break any users' existing keybindings for these commands.

Second, this adds further restrictions to the `where` clauses of the two commands that the rust analyzer extension will contribute to the context menu, so that the two commands will appear in the context menu only when in a Rust project **and** within a Rust file. Say you have a Python or bash script inside your Rust project. Having these commands appear in the context menu when you right click a symbol in such a non-Rust file is extraneous and potentially confusing.

![demonstration](https://user-images.githubusercontent.com/6609145/219976062-b46ab21b-5753-48f5-a1da-562566cae71c.gif)
2023-02-24 06:55:02 +00:00
Laurențiu Nicola
563bd9c24a Try to improve the rustfmt.overrideCommand docs 2023-02-21 12:43:22 +02:00
jmviz
2351875e6a change titles of commands in context menu to title case. shorten open docs command 2023-02-19 10:12:44 -05:00
jmviz
ed1f467aab add openDocs to context menu. add further restrictions to context menu when clauses to prevent irrelevant commands in non-rust files 2023-02-17 17:41:39 -05:00
Lukas Wirth
95fa278f30 Don't assume VSCode internal commands in the server 2023-02-14 14:45:48 +01:00
bors
8011029d3a Auto merge of #13975 - DropDemBits:on-enter-after-dot-chains, r=DropDemBits
fix: Suppress extra indent after the end of field and function chains

(spurred on by <https://github.com/rust-lang/rust-analyzer/issues/4182#issuecomment-671275652>)

Caveat that this doesn't work for after tail expressions, although there shouldn't be anything after those anyways.

This also complicates when to reload the language configuration by nature of now always having a language configuration applicable.

Examples of indentation fixes:

```rs
fn main() {
    println!("Hello!"); // < enter here!
    // ... indents down here

    fs::read_to_string("soup") // < enter here!
    // ... still indents down here :(
        .map(|_| ())
        .map(|_| ()) // < enter here!
        // ... still indents down here :D
        .map_err(|_| ())
        .unwrap(); // < enter here!
    // ... indents down here :D

    // ... and subsequent enters stay at the same indent

    0.0f64
        .to_radians()
        .to_radians()
        .to_radians() // force semi on a new line
        ; // < enter here!
    // ... indents down here :D
}

fn tail_end() -> i32 {
    0i32.wrapping_abs()
        .wrapping_abs()
        .wrapping_abs()
        .wrapping_abs() // < enter here!
        // ... still indents here 🤷
}
```
2023-02-10 20:10:54 +00:00
DropDemBits
c7bd3c682f
Always reload onEnter configuration
Configuration reload doesn't happen often anyway,
and there will always be a set of onEnter rules to load
2023-02-10 14:55:17 -05:00
bors
c468e39b5a Auto merge of #14112 - Veykril:vscode-untrusted, r=lnicola
minor: Explicitly disable the rust-analyzer extension in untrusted workspaces

This is the default, but its always better to be explicit here + we can add a small note as to why.
2023-02-09 18:46:11 +00:00
Lukas Wirth
7fc0f8985d Explicitly disable the rust-analyzer extension in unstrusted workspaces 2023-02-09 17:34:21 +01:00
bors
a05ce5a3e7 Auto merge of #13986 - MariaSolOs:limit-completions, r=Veykril
Add setting for limiting number of completions

For #13911.
2023-02-08 09:31:35 +00:00
bors
14ad6087c5 Auto merge of #14090 - MariaSolOs:regions, r=Veykril
Unify language configuration folding markers with server behaviour

Fixes #14089.
2023-02-06 14:37:39 +00:00
Lukas Wirth
cb9a5b9549 Support sysroot library source being defined inside the workspace 2023-02-06 12:07:33 +01:00
Maria José Solano
3674502a98 Unify language config markers with server 2023-02-04 17:46:11 -08:00
Jonas Schievink
5b1187a046 Remove some types ¯\_(ツ)_/¯ 2023-01-31 15:49:39 +01:00
Jonas Schievink
56f81ebc3e Lazily create the trace output channel 2023-01-31 15:43:47 +01:00
Lukas Wirth
e6ad8a2edc fix: config substitution failing extension activation 2023-01-25 09:17:49 +01:00
Lukas Wirth
ec9476015c Substitute VSCode variables more generally 2023-01-24 13:46:56 +01:00
Lukas Wirth
64110714f0 🧹 lsp_ext.ts 2023-01-23 16:58:35 +01:00
Lukas Wirth
544c581e5f Bump package-lock.json 2023-01-23 13:52:13 +01:00
Lukas Wirth
b9fe5afb30 Add a 'open server logs' button to the error notification 2023-01-23 13:24:42 +01:00
OmarTawfik
7198cd04ac allow using vscode variables in config.serverPath 2023-01-20 13:22:11 -08:00
Maria José Solano
2ea703c659 Update VS Code settings 2023-01-19 18:34:19 -08:00
DropDemBits
992bafa773
Fix change detection for relevant lang config opts 2023-01-17 16:41:33 -05:00
DropDemBits
1c454736a4
Suppress extra indent after the end of dot chains 2023-01-17 15:29:52 -05:00
Lukas Wirth
f932d39945 Regen config 2023-01-16 17:02:30 +01:00
Lukas Wirth
4267b11c40
Revert "Use ZWNJ to prevent VSCode from forming ligatures between hints and code" 2023-01-10 09:43:08 +01:00
Ian Chamberlain
65cf7abbe2
Use experimental capability to enable color codes 2023-01-09 11:50:35 -05:00
Ian Chamberlain
738ce83d85
Strip colors before matching preview diagnostics 2023-01-09 11:49:59 -05:00
Ian Chamberlain
c3e4bc3136
Update docs to include note about ANSI diagnostics 2023-01-09 11:49:58 -05:00
Ian Chamberlain
1b8141b54c
Parse + decorate rendered ANSI cargo output
Use ANSI control characters to display text decorations matching the
VScode terminal theme, and strip them out when providing text content
for rustc diagnostics.

This adds the small `anser` library to parse the control codes, and it
also supports HTML output so it should be fairly easy to switch to a
rendered HTML/webview implementation if desired.
2023-01-09 11:46:29 -05:00
bors
fd300eebc9 Auto merge of #13799 - Veykril:flycheck, r=Veykril
Rename `checkOnSave` settings to `check`

Now that flychecks can be triggered without saving the setting name doesn't make that much sense anymore. This PR renames it to just `check`, but keeps `checkOnSave` as the enabling setting.
2023-01-09 15:35:38 +00:00
Maybe Waffle
12b7f9f7bf Add an option to minimize parentheses for adjustment hints 2023-01-09 13:35:17 +00:00
Maybe Waffle
b89c4f0a05 Implement postfix adjustment hints
I'd say "First stab at implementing..." but I've been working on this
for a month already lol
2023-01-09 13:27:59 +00:00
Lukas Wirth
d2bb62b6a8 Rename checkOnSave settings to check 2023-01-09 14:17:13 +01:00
Lukas Wirth
87d57f51bc Rename checkOnSave settings to flycheck 2023-01-09 14:17:13 +01:00
bors
fe8ee9c43a Auto merge of #13744 - vtta:numthreads, r=Veykril
feat: add the ability to limit the number of threads launched by `main_loop`

## Motivation
`main_loop` defaults to launch as many threads as cpus in one machine. When developing on multi-core remote servers on multiple projects, this will lead to thousands of idle threads being created. This is very annoying when one wants check whether his program under developing is running correctly via `htop`.

<img width="756" alt="image" src="https://user-images.githubusercontent.com/41831480/206656419-fa3f0dd2-e554-4f36-be1b-29d54739930c.png">

## Contribution
This patch introduce the configuration option `rust-analyzer.numThreads` to set the desired thread number used by the main thread pool.
This should have no effects on the performance as not all threads are actually used.
<img width="1325" alt="image" src="https://user-images.githubusercontent.com/41831480/206656834-fe625c4c-b993-4771-8a82-7427c297fd41.png">

## Demonstration
The following is a snippet of `lunarvim` configuration using my own build.
```lua
vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "rust_analyzer" })
require("lvim.lsp.manager").setup("rust_analyzer", {
  cmd = { "env", "RA_LOG=debug", "RA_LOG_FILE=/tmp/ra-test.log",
    "/home/jlhu/Projects/rust-analyzer/target/debug/rust-analyzer",
  },
  init_options = {
    numThreads = 4,
  },
  settings = {
    cachePriming = {
      numThreads = 8,
    },
  },
})

```

## Limitations
The `numThreads` can only be modified via `initializationOptions` in early initialisation because everything has to wait until the thread pool starts including the dynamic settings modification support.
The `numThreads` also does not reflect the end results of how many threads is actually created, because I have not yet tracked down everything that spawns threads.
2023-01-09 11:53:23 +00:00
dependabot[bot]
41d290d671
Bump d3-color and d3-graphviz in /editors/code
Bumps [d3-color](https://github.com/d3/d3-color) to 3.1.0 and updates ancestor dependency [d3-graphviz](https://github.com/magjac/d3-graphviz). These dependencies need to be updated together.


Updates `d3-color` from 2.0.0 to 3.1.0
- [Release notes](https://github.com/d3/d3-color/releases)
- [Commits](https://github.com/d3/d3-color/compare/v2.0.0...v3.1.0)

Updates `d3-graphviz` from 4.1.1 to 5.0.2
- [Release notes](https://github.com/magjac/d3-graphviz/releases)
- [Changelog](https://github.com/magjac/d3-graphviz/blob/master/CHANGELOG.md)
- [Commits](https://github.com/magjac/d3-graphviz/compare/v4.1.1...v5.0.2)

---
updated-dependencies:
- dependency-name: d3-color
  dependency-type: indirect
- dependency-name: d3-graphviz
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-07 19:20:08 +00:00
Lukas Wirth
c4d8cf1dad Use ZWNJ to prevent VSCode from forming ligatures between hints and code 2023-01-03 12:32:38 +01:00
bors
50801b7d6a Auto merge of #13853 - veber-alex:diag_fix, r=Veykril
Use diagnostic code as link to full message

fixes #13823 by adding a vscode setting that will keeping the existing diagnostic code and use it as a link to the full compiler error message.
While I was there I also fixed `index` to fallback to `rendered.length` to make the previewRustcOutput feature work.
2023-01-03 09:40:20 +00:00
Alex Veber
ddc0147d53 Fix diagnostic code 2023-01-03 08:33:27 +02:00
Lukas Wirth
df8fc78ece Enum variant discriminants hints 2022-12-23 11:37:42 +01:00
bors
eb3963b22e Auto merge of #13817 - WaffleLapkin:hide_adjustment_hints_outside_of_unsafe, r=Veykril
feat: Add an option to hide adjustment hints outside of `unsafe` blocks and functions

As the title suggests: this PR adds an option (namely `rust-analyzer.inlayHints.expressionAdjustmentHints.hideOutsideUnsafe`) that allows to hide adjustment hints outside of `unsafe` blocks and functions:

![2022-12-21_23-11](https://user-images.githubusercontent.com/38225716/208986376-d607de62-8290-4e16-b7fe-15b762dc5f60.png)

Requested by `@BoxyUwU` <3
2022-12-22 09:37:00 +00:00
Maybe Waffle
3bfe7040e8 Add an option to hide adjustment hints outside of unsafe blocks 2022-12-21 19:20:42 +00:00
hkalbasi
e1aa73ef40 Disable inlay hint location links on vscode < 1.76 2022-12-21 18:54:49 +03:30