rust/crates/rust-analyzer/src
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
..
bin Inline all format arguments where possible 2022-12-24 14:36:10 -05:00
cli remove needless borrows 2023-01-02 14:52:32 +00:00
config Fix wrong config patching logic for addCallParenthesis 2022-12-13 16:39:00 +01:00
diagnostics Auto merge of #13860 - danieleades:clippy, r=lnicola 2023-01-08 17:29:57 +00:00
caps.rs remove needless borrows 2023-01-02 14:52:32 +00:00
cargo_target_spec.rs ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
cli.rs Inline all format arguments where possible 2022-12-24 14:36:10 -05:00
config.rs Auto merge of #13744 - vtta:numthreads, r=Veykril 2023-01-09 11:53:23 +00:00
diagnostics.rs remove useless conversions 2023-01-02 15:02:54 +00:00
diff.rs Fix last few warnings manually 2022-07-20 15:05:02 +02:00
dispatch.rs Inline all format arguments where possible 2022-12-24 14:36:10 -05:00
from_proto.rs remove useless casts 2023-01-02 15:02:54 +00:00
global_state.rs Auto merge of #13744 - vtta:numthreads, r=Veykril 2023-01-09 11:53:23 +00:00
handlers.rs remove useless conversions 2023-01-02 15:02:54 +00:00
integrated_benchmarks.rs Inline all format arguments where possible 2022-12-24 14:36:10 -05:00
lib.rs Inline all format arguments where possible 2022-12-24 14:36:10 -05:00
line_index.rs ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
lsp_ext.rs Add a command to clear flycheck diagnostics 2022-12-17 23:43:26 +01:00
lsp_utils.rs Inline all format arguments where possible 2022-12-24 14:36:10 -05:00
main_loop.rs remove needless borrows 2023-01-02 14:52:32 +00:00
markdown.rs Code blocks with tilde also works like code block 2022-04-01 20:29:32 +09:00
mem_docs.rs ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
op_queue.rs internal: more visibility into why things happen 2022-04-16 13:17:27 +01:00
reload.rs Remove non-needed clones 2022-12-23 02:20:03 -05:00
semantic_tokens.rs remove useless casts 2023-01-02 15:02:54 +00:00
task_pool.rs Add numThreads in config to avoid spawning lots of threads every time 2022-12-09 21:35:06 +08:00
to_proto.rs remove unnecessary lazy evaluations 2023-01-02 15:02:54 +00:00
version.rs Bring the version command output in line with other rust tools 2022-06-02 18:36:02 +02:00