]> git.lizzy.rs Git - rust.git/blob - README.md
a93dc87676a454ec7fffcd0a336da7ca075f5d0c
[rust.git] / README.md
1 # libsyntax2.0
2
3 [![Build Status](https://travis-ci.org/matklad/libsyntax2.svg?branch=master)](https://travis-ci.org/matklad/libsyntax2)
4 [![Build status](https://ci.appveyor.com/api/projects/status/j56x1hbje8rdg6xk/branch/master?svg=true)](https://ci.appveyor.com/project/matklad/libsyntax2/branch/master)
5
6
7 libsyntax2.0 is an **experimental** parser of the Rust language,
8 intended for the use in IDEs.
9 [RFC](https://github.com/rust-lang/rfcs/pull/2256).
10
11
12 ## Quick Start
13
14 ```
15 $ cargo test
16 $ cargo parse < crates/libsyntax2/src/lib.rs
17 ```
18
19
20 ## Trying It Out
21
22 This installs experimental VS Code plugin
23
24 ```
25 $ cargo install-code
26 ```
27
28 It's better to remove existing Rust plugins to avoid interference.
29 Warning: plugin is not intended for general use, has a lot of rough
30 edges and missing features (notably, no code completion). That said,
31 while originally libsyntax2 was developed in IntelliJ, @matklad now
32 uses this plugin (and thus, libsytax2) to develop libsyntax2, and it
33 doesn't hurt too much :-)
34
35
36 ### Features:
37
38 * syntax highlighting (LSP does not have API for it, so impl is hacky
39   and sometimes fall-backs to the horrible built-in highlighting)
40   
41 * commands (`ctrl+shift+p` or keybindings)
42   - **Show Rust Syntax Tree** (use it to verify that plugin works)
43   - **Rust Extend Selection** (works with multiple cursors)
44   - **Rust Matching Brace** (knows the difference between `<` and `<`)
45   - **Rust Parent Module**
46   - **Rust Join Lines** (deals with trailing commas)
47   
48 * **Go to symbol in file**
49
50 * **Go to symbol in workspace** (no support for Cargo deps yet)
51
52 * code actions:
53   - Flip `,` in comma separated lists
54   - Add `#[derive]` to struct/enum
55   - Add `impl` block to struct/enum
56   - Run tests at caret
57   
58 * **Go to definition** ("correct" for `mod foo;` decls, index-based for functions).
59
60
61 ## Code Walk-Through
62
63 ### `crates/libsyntax2`
64
65 - `yellow`, red/green syntax tree, heavily inspired [by this](https://github.com/apple/swift/tree/ab68f0d4cbf99cdfa672f8ffe18e433fddc8b371/lib/Syntax)
66 - `grammar`, the actual parser
67 - `parser_api/parser_impl` bridges the tree-agnostic parser from `grammar` with `yellow` trees
68 - `grammar.ron` RON description of the grammar, which is used to
69   generate `syntax_kinds` and `ast` modules.
70 - `algo`: generic tree algorithms, including `walk` for O(1) stack
71   space tree traversal (this is cool) and `visit` for type-driven
72   visiting the nodes (this is double plus cool, if you understand how
73   `Visitor` works, you understand libsyntax2).
74   
75
76 ### `crates/libeditor`
77
78 Most of IDE features leave here, unlike `libanalysis`, `libeditor` is
79 single-file and is basically a bunch of pure functions.
80
81
82 ### `crates/libanalysis`
83
84 A stateful library for analyzing many Rust files as they change.
85 `WorldState` is a mutable entity (clojure's atom) which holds current
86 state, incorporates changes and handles out `World`s --- immutable
87 consistent snapshots of `WorldState`, which actually power analysis. 
88
89
90 ### `crates/server`
91
92 An LSP implementation which uses `libanalysis` for managing state and
93 `libeditor` for actually doing useful stuff.
94
95
96 ### `crates/cli`
97
98 A CLI interface to libsyntax
99
100 ### `crate/tools`
101
102 Code-gen tasks, used to develop libsyntax2:
103
104 - `cargo gen-kinds` -- generate `ast` and `syntax_kinds`
105 - `cargo gen-tests` -- collect inline tests from grammar
106 - `cargo install-code` -- build and install VS Code extension and server
107
108 ### `code`
109
110 VS Code plugin
111
112
113 ## Getting in touch
114
115 @matklad can be found at Rust
116 [discord](https://discordapp.com/invite/rust-lang), in
117 #ides-and-editors.
118
119
120 ## License
121
122 libsyntax2 is primarily distributed under the terms of both the MIT license
123 and the Apache License (Version 2.0).
124
125 See LICENSE-APACHE and LICENSE-MIT for details.