aboutsummaryrefslogtreecommitdiff
path: root/docs/dev/README.md
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-03-20 13:05:49 +0000
committerAleksey Kladov <[email protected]>2019-03-20 13:44:44 +0000
commitd56c2f24252d5d444267e33950825f0a7cb438ca (patch)
treea0e0b76567e4f9a5210c6545d089c722508c4a27 /docs/dev/README.md
parent1ad322236dbe54ada2c284bda4a2b72830b3ff3d (diff)
explain how to launch the thing
Diffstat (limited to 'docs/dev/README.md')
-rw-r--r--docs/dev/README.md81
1 files changed, 81 insertions, 0 deletions
diff --git a/docs/dev/README.md b/docs/dev/README.md
index 0c09dddfc..ac7f4fd71 100644
--- a/docs/dev/README.md
+++ b/docs/dev/README.md
@@ -41,3 +41,84 @@ We use Travis for CI. Most of the things, including formatting, are checked by
41`cargo test` so, if `cargo test` passes locally, that's a good sign that CI will 41`cargo test` so, if `cargo test` passes locally, that's a good sign that CI will
42be green as well. We use bors-ng to enforce the [not rocket 42be green as well. We use bors-ng to enforce the [not rocket
43science](https://graydon2.dreamwidth.org/1597.html) rule. 43science](https://graydon2.dreamwidth.org/1597.html) rule.
44
45You can run `cargo format-hook` to install git-hook to run rustfmt on commit.
46
47# Code organization
48
49All Rust code lives in the `crates` top-level directory, and is organized as a
50single Cargo workspace. The `editors` top-level directory contains code for
51integrating with editors. Currently, it contains plugins for VS Code (in
52typescript) and Emacs (in elisp). The `docs` top-level directory contains both
53developer and user documentation.
54
55We have some automation infra in Rust in the `crates/tool` package. It contains
56stuff like formatting checking, code generation and powers `cargo install-code`.
57The latter syntax is achieved with the help of cargo aliases (see `.cargo`
58directory).
59
60# Launching rust-analyzer
61
62Debugging language server can be tricky: LSP is rather chatty, so driving it
63from the command line is not really feasible, driving it via VS Code requires
64interacting with two processes.
65
66For this reason, the best way to see how rust-analyzer works is to find a
67relevant test and execute it (VS Code includes an action for running a single
68test).
69
70However, launching a VS Code instance with locally build language server is
71possible. There's even a VS Code task for this, so just <kbd>F5</kbd> should
72work (thanks, [@andrew-w-ross](https://github.com/andrew-w-ross)!).
73
74I often just install development version with `cargo jinstall-lsp` and
75restart the host VS Code.
76
77See [./debugging.md](./debugging.md) for how to attach to rust-analyzer with
78debugger, and don't forget that rust-analyzer has useful `pd` snippet and `dbg`
79postfix completion for printf debugging :-)
80
81# Working With VS Code Extension
82
83To work on the VS Code extension, launch code inside `editors/code` and use `F5`
84to launch/debug. To automatically apply formatter and linter suggestions, use
85`npm run fix`.
86
87# Logging
88
89Logging is done by both rust-analyzer and VS Code, so it might be tricky to
90figure out where logs go.
91
92Inside rust-analyzer, we use the standard `log` crate for logging, and
93`flexi_logger` for logging frotend. By default, log goes to stderr (the same as
94with `env_logger`), but the stderr itself is processed by VS Code. To mirror
95logs to a `./log` directory, set `RA_INTERNAL_MODE=1` environmental variable.
96
97To see stderr in the running VS Code instance, go to the "Output" tab of the
98panel and select `rust-analyzer`. This shows `eprintln!` as well. Note that
99`stdout` is used for the actual protocol, so `println!` will break things.
100
101To log all communication between the server and the client, there are two choices:
102
103* you can log on the server side, by running something like
104 ```
105 env RUST_LOG=gen_lsp_server=trace code .
106 ```
107
108* you can log on the client side, by enabling `"rust-analyzer.trace.server":
109 "verbose"` workspace setting. These logs are shown in a separate tab in the
110 output and could be used with LSP inspector. Kudos to
111 [@DJMcNab](https://github.com/DJMcNab) for setting this awesome infra up!
112
113
114There's also two VS Code commands which might be of interest:
115
116* `Rust Analyzer: Status` shows some memory-usage statistics. To take full
117 advantage of it, you need to compile rust-analyzer with jemalloc support:
118 ```
119 $ cargo install --path crates/ra_lsp_server --force --features jemalloc
120 ```
121
122 There's an alias for this: `cargo jinstall-lsp`.
123
124* `Rust Analyzer: Syntax Tree` shows syntax tree of the current file/selection.