diff options
author | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
---|---|---|
committer | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
commit | f05d7b41a719d848844b054a16477b29d0f063c6 (patch) | |
tree | 0a8a0946e8aef2ce64d4c13d0035ba41cce2daf3 /docs/user/manual.adoc | |
parent | 73ff610e41959e3e7c78a2b4b25b086883132956 (diff) | |
parent | 6b7cb8b5ab539fc4333ce34bc29bf77c976f232a (diff) |
Merge remote-tracking branch 'upstream/master' into 503-hover-doc-links
Hasn't fixed tests yet.
Diffstat (limited to 'docs/user/manual.adoc')
-rw-r--r-- | docs/user/manual.adoc | 120 |
1 files changed, 99 insertions, 21 deletions
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index b763958fe..cfc0ad81c 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc | |||
@@ -13,8 +13,12 @@ This manual focuses on a specific usage of the library -- running it as part of | |||
13 | https://microsoft.github.io/language-server-protocol/[Language Server Protocol] (LSP). | 13 | https://microsoft.github.io/language-server-protocol/[Language Server Protocol] (LSP). |
14 | The LSP allows various code editors, like VS Code, Emacs or Vim, to implement semantic features like completion or goto definition by talking to an external language server process. | 14 | The LSP allows various code editors, like VS Code, Emacs or Vim, to implement semantic features like completion or goto definition by talking to an external language server process. |
15 | 15 | ||
16 | To improve this document, send a pull request against | 16 | [TIP] |
17 | https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/manual.adoc[this file]. | 17 | ==== |
18 | [.lead] | ||
19 | To improve this document, send a pull request: + | ||
20 | https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/manual.adoc[https://github.com/rust-analyzer/.../manual.adoc] | ||
21 | ==== | ||
18 | 22 | ||
19 | If you have questions about using rust-analyzer, please ask them in the https://users.rust-lang.org/c/ide/14["`IDEs and Editors`"] topic of Rust users forum. | 23 | If you have questions about using rust-analyzer, please ask them in the https://users.rust-lang.org/c/ide/14["`IDEs and Editors`"] topic of Rust users forum. |
20 | 24 | ||
@@ -106,20 +110,8 @@ Here are some useful self-diagnostic commands: | |||
106 | * **Rust Analyzer: Show RA Version** shows the version of `rust-analyzer` binary | 110 | * **Rust Analyzer: Show RA Version** shows the version of `rust-analyzer` binary |
107 | * **Rust Analyzer: Status** prints some statistics about the server, like the few latest LSP requests | 111 | * **Rust Analyzer: Status** prints some statistics about the server, like the few latest LSP requests |
108 | * To enable server-side logging, run with `env RA_LOG=info` and see `Output > Rust Analyzer Language Server` in VS Code's panel. | 112 | * To enable server-side logging, run with `env RA_LOG=info` and see `Output > Rust Analyzer Language Server` in VS Code's panel. |
109 | * To log all LSP requests, add `"rust-analyzer.trace.server": "verbose"` to the settings and look for `Server Trace` in the panel. | 113 | * To log all LSP requests, add `"rust-analyzer.trace.server": "verbose"` to the settings and look for `Rust Analyzer Language Server Trace` in the panel. |
110 | * To enable client-side logging, add `"rust-analyzer.trace.extension": true` to the settings and open the `Console` tab of VS Code developer tools. | 114 | * To enable client-side logging, add `"rust-analyzer.trace.extension": true` to the settings and open `Output > Rust Analyzer Client` in the panel. |
111 | |||
112 | ==== Special `when` clause context for keybindings. | ||
113 | You may use `inRustProject` context to configure keybindings for rust projects only. For example: | ||
114 | [source,json] | ||
115 | ---- | ||
116 | { | ||
117 | "key": "ctrl+i", | ||
118 | "command": "rust-analyzer.toggleInlayHints", | ||
119 | "when": "inRustProject" | ||
120 | } | ||
121 | ---- | ||
122 | More about `when` clause contexts https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts[here]. | ||
123 | 115 | ||
124 | === rust-analyzer Language Server Binary | 116 | === rust-analyzer Language Server Binary |
125 | 117 | ||
@@ -281,9 +273,6 @@ However, if you use some other build system, you'll have to describe the structu | |||
281 | [source,TypeScript] | 273 | [source,TypeScript] |
282 | ---- | 274 | ---- |
283 | interface JsonProject { | 275 | interface JsonProject { |
284 | /// The set of paths containing the crates for this project. | ||
285 | /// Any `Crate` must be nested inside some `root`. | ||
286 | roots: string[]; | ||
287 | /// The set of crates comprising the current project. | 276 | /// The set of crates comprising the current project. |
288 | /// Must include all transitive dependencies as well as sysroot crate (libstd, libcore and such). | 277 | /// Must include all transitive dependencies as well as sysroot crate (libstd, libcore and such). |
289 | crates: Crate[]; | 278 | crates: Crate[]; |
@@ -296,11 +285,37 @@ interface Crate { | |||
296 | edition: "2015" | "2018"; | 285 | edition: "2015" | "2018"; |
297 | /// Dependencies | 286 | /// Dependencies |
298 | deps: Dep[]; | 287 | deps: Dep[]; |
288 | /// Should this crate be treated as a member of current "workspace". | ||
289 | /// | ||
290 | /// By default, inferred from the `root_module` (members are the crates which reside | ||
291 | /// inside the directory opened in the editor). | ||
292 | /// | ||
293 | /// Set this to `false` for things like standard library and 3rd party crates to | ||
294 | /// enable performance optimizations (rust-analyzer assumes that non-member crates | ||
295 | /// don't change). | ||
296 | is_workspace_member?: boolean; | ||
297 | /// Optionally specify the (super)set of `.rs` files comprising this crate. | ||
298 | /// | ||
299 | /// By default, rust-analyzer assumes that only files under `root_module.parent` can belong to a crate. | ||
300 | /// `include_dirs` are included recursively, unless a subdirectory is in `exclude_dirs`. | ||
301 | /// | ||
302 | /// Different crates can share the same `source`. | ||
303 | /// | ||
304 | /// If two crates share an `.rs` file in common, they *must* have the same `source`. | ||
305 | /// rust-analyzer assumes that files from one source can't refer to files in another source. | ||
306 | source?: { | ||
307 | include_dirs: string[], | ||
308 | exclude_dirs: string[], | ||
309 | }, | ||
299 | /// The set of cfgs activated for a given crate, like `["unix", "feature=foo", "feature=bar"]`. | 310 | /// The set of cfgs activated for a given crate, like `["unix", "feature=foo", "feature=bar"]`. |
300 | cfg: string[]; | 311 | cfg: string[]; |
312 | /// Target triple for this Crate. | ||
313 | /// | ||
314 | /// Used when running `rustc --print cfg` to get target-specific cfgs. | ||
315 | target?: string; | ||
316 | /// Environment variables, used for the `env!` macro | ||
317 | env: : { [key: string]: string; }, | ||
301 | 318 | ||
302 | /// value of the OUT_DIR env variable. | ||
303 | out_dir?: string; | ||
304 | /// For proc-macro crates, path to compiles proc-macro (.so file). | 319 | /// For proc-macro crates, path to compiles proc-macro (.so file). |
305 | proc_macro_dylib_path?: string; | 320 | proc_macro_dylib_path?: string; |
306 | } | 321 | } |
@@ -337,3 +352,66 @@ They are usually triggered by a shortcut or by clicking a light bulb icon in the | |||
337 | Cursor position or selection is signified by `┃` character. | 352 | Cursor position or selection is signified by `┃` character. |
338 | 353 | ||
339 | include::./generated_assists.adoc[] | 354 | include::./generated_assists.adoc[] |
355 | |||
356 | == Editor Features | ||
357 | === VS Code | ||
358 | ==== Special `when` clause context for keybindings. | ||
359 | You may use `inRustProject` context to configure keybindings for rust projects only. For example: | ||
360 | [source,json] | ||
361 | ---- | ||
362 | { | ||
363 | "key": "ctrl+i", | ||
364 | "command": "rust-analyzer.toggleInlayHints", | ||
365 | "when": "inRustProject" | ||
366 | } | ||
367 | ---- | ||
368 | More about `when` clause contexts https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts[here]. | ||
369 | |||
370 | ==== Setting runnable environment variables | ||
371 | You can use "rust-analyzer.runnableEnv" setting to define runnable environment-specific substitution variables. | ||
372 | The simplest way for all runnables in a bunch: | ||
373 | ```jsonc | ||
374 | "rust-analyzer.runnableEnv": { | ||
375 | "RUN_SLOW_TESTS": "1" | ||
376 | } | ||
377 | ``` | ||
378 | |||
379 | Or it is possible to specify vars more granularly: | ||
380 | ```jsonc | ||
381 | "rust-analyzer.runnableEnv": [ | ||
382 | { | ||
383 | // "mask": null, // null mask means that this rule will be applied for all runnables | ||
384 | env: { | ||
385 | "APP_ID": "1", | ||
386 | "APP_DATA": "asdf" | ||
387 | } | ||
388 | }, | ||
389 | { | ||
390 | "mask": "test_name", | ||
391 | "env": { | ||
392 | "APP_ID": "2", // overwrites only APP_ID | ||
393 | } | ||
394 | } | ||
395 | ] | ||
396 | ``` | ||
397 | |||
398 | You can use any valid RegExp as a mask. Also note that a full runnable name is something like *run bin_or_example_name*, *test some::mod::test_name* or *test-mod some::mod*, so it is possible to distinguish binaries, single tests, and test modules with this masks: `"^run"`, `"^test "` (the trailing space matters!), and `"^test-mod"` respectively. | ||
399 | |||
400 | ==== Compiler feedback from external commands | ||
401 | |||
402 | Instead of relying on the built-in `cargo check`, you can configure Code to run a command in the background and use the `$rustc-watch` problem matcher to generate inline error markers from its output. | ||
403 | |||
404 | To do this you need to create a new https://code.visualstudio.com/docs/editor/tasks[VS Code Task] and set `rust-analyzer.checkOnSave.enable: false` in preferences. | ||
405 | |||
406 | For example, if you want to run https://crates.io/crates/cargo-watch[`cargo watch`] instead, you might add the following to `.vscode/tasks.json`: | ||
407 | |||
408 | ```json | ||
409 | { | ||
410 | "label": "Watch", | ||
411 | "group": "build", | ||
412 | "type": "shell", | ||
413 | "command": "cargo watch", | ||
414 | "problemMatcher": "$rustc-watch", | ||
415 | "isBackground": true | ||
416 | } | ||
417 | ``` | ||