Commit Graph

2472 Commits

Author SHA1 Message Date
bors[bot]
38c0a1e333 Merge #1184
1184: Start structured editing API r=matklad a=matklad

I think I finally understand how to provide nice, mutable structured editing API on top of red-green trees.

The problem I am trying to solve is that any modification to a particular `SyntaxNode` returns an independent new file. So, if you are editing a struct literal, and add a field, you get back a SourceFile, and you have to find the struct literal inside it yourself! This happens because our trees are immutable, but have parent pointers. 

The main idea here is to introduce `AstEditor<T>` type, which abstracts away that API. So, you create an `AstEditor` for node you want to edit and call various `&mut` taking methods on it. Internally, `AstEditor` stores both the original node and the current node. All edits are applied to the current node, which is replaced by the corresponding node in the new file. In the end, `AstEditor` computes a text edit between old and new nodes.

Note that this also should sole a problem when you create an anchor pointing to a subnode and mutate the parent node, invalidating anchor. Because mutation needs `&mut`, all anchors must be killed before modification. 

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-04-22 10:08:18 +00:00
Aleksey Kladov
b73a978b95 drop useless test 2019-04-22 13:05:01 +03:00
Aleksey Kladov
268e739c94 move add_missing_members to structured editing API
Currently, this is more code, and we also loose auto-indenting of
bodies, but, long-term, this is the right approach
2019-04-22 13:01:33 +03:00
Edwin Cheng
ad1c3b5bd6 Use map, sum in Subtree::coount instead of fold 2019-04-22 17:37:27 +08:00
Edwin Cheng
d6d9aa2003 Change macro stack monitor test to func ptr based 2019-04-22 17:15:22 +08:00
Aleksey Kladov
b811922a53 fix postfix match indent 2019-04-22 10:38:39 +03:00
Edwin Cheng
b177813f3b Add mbe expand limit and poision macro set 2019-04-22 15:33:55 +08:00
Aleksey Kladov
5b2fd86d25 more type safety 2019-04-22 10:11:06 +03:00
Aleksey Kladov
97f41d7343 test short structs 2019-04-22 00:52:21 +03:00
Edwin Cheng
120bfde3c2 Add tests 2019-04-22 05:04:37 +08:00
Edwin Cheng
3d1cdc834d Fix offset bug in SourceWalker 2019-04-22 05:04:37 +08:00
Edwin Cheng
49c9686c3c Handle *+ case and single token case 2019-04-22 05:04:37 +08:00
Edwin Cheng
bcf5cf8ac6 fix mbe_parser rhs colon parsing 2019-04-22 05:04:37 +08:00
Edwin Cheng
9a5b9638c1 Add more information on parse_macro fail 2019-04-22 05:04:37 +08:00
Edwin Cheng
da05bbcfb1 Fix lifetime in tt to syntax node conversion 2019-04-22 05:04:36 +08:00
Aleksey Kladov
f313ac45af use structured editing API for fill struct assist 2019-04-21 22:13:52 +03:00
Aleksey Kladov
7cc845e88d start structured editing API 2019-04-21 20:51:20 +03:00
Florian Diebold
787fb3e5ec Add HIR for where clauses & ignore impls with where clauses in trait resolution
This prevents any `impl<T> Trait for T where ...` from being treated as a
blanket impl while we don't handle where clauses yet.
2019-04-21 15:01:17 +02:00
Aleksey Kladov
47672726d8 ⬆️ lsp 2019-04-21 15:17:22 +03:00
bors[bot]
fa15c4d75e Merge #1175
1175: Fix bugs and add error log about macro expansion r=matklad a=edwin0cheng

This PR fixed / add following things:

* Add a fused count which stop recursion of macro expansion in name resolution.
* Add some logs when macro expansion fails
* Add `$crate` meta variable support in mbe, which create a `$crate` ident token in token tree.
* Fixed matching a `$REPEAT` pattern inside a subtree, e.g. `(fn $name:ident {$($i:ident)*} ) => {...}`
* Remove composite-able punct token in syntax node to token conversion. 

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-04-21 10:34:07 +00:00
Aleksey Kladov
fa12ed2b8f switch to official extend selection API 2019-04-21 12:13:48 +03:00
Florian Diebold
82751f8a4a Add a simple test for str method completion 2019-04-20 18:26:53 +02:00
bors[bot]
4ad2e4ce4e Merge #1154
1154: Initial support for lang items (and str completion) r=flodiebold a=marcogroppo

This PR adds partial support for lang items.
For now, the only supported lang items are the ones that target an impl block.

Lang items are now resolved during type inference - this means that `str` completion now works.

Fixes #1139.

(thanks Florian Diebold for the help!)


Co-authored-by: Marco Groppo <marco.groppo@gmail.com>
2019-04-20 16:13:50 +00:00
Edwin Cheng
9e35bf91b8 Fix bugs 2019-04-20 23:53:39 +08:00
Marco Groppo
8ac3d1f9aa lang_item_lookup is now a salsa query. 2019-04-20 00:29:16 +02:00
Marco Groppo
8ebb20edce New krate() method in Resolver.
Renamed Impl to ImplBlock.
2019-04-20 00:20:26 +02:00
Marco Groppo
e85ee60c42 Initial support for lang items. 2019-04-20 00:10:19 +02:00
Edwin Cheng
210c762fe6 Disable test_tt_xx 2019-04-20 02:41:13 +08:00
Edwin Cheng
41c1a639c3 Disable tt matcher 2019-04-20 02:19:46 +08:00
Edwin Cheng
1afde29adb Add back missing assert 2019-04-19 21:52:54 +08:00
Edwin Cheng
763569017a Fix bug for ident to lifetime 2019-04-19 21:43:41 +08:00
Edwin Cheng
87ff908135 Add vis matcher 2019-04-19 21:38:26 +08:00
Edwin Cheng
c5983b85fc Add literal matcher 2019-04-19 21:21:47 +08:00
Edwin Cheng
313854c728 Add lifetime matcher 2019-04-19 21:15:19 +08:00
Edwin Cheng
59b6cc780b add tt matcher 2019-04-19 19:41:59 +08:00
Edwin Cheng
762819864f add block matcher 2019-04-19 19:33:29 +08:00
Edwin Cheng
8092b6487f Add block matcher 2019-04-19 18:30:43 +08:00
bors[bot]
ab0a96586f Merge #1148
1148: Add token_tree_to_xxx functions r=matklad a=edwin0cheng

<del>As discus in  PR #1147 , this PR added a `mbe::MacroKind` .
Currently only 2 kind of macro are supported, `SourceFile` and `Block`.</del>

Added following functions for `tt::TokenTree` and `ast::Node` conversion:

* token_tree_to_expr
* token_tree_to_pat
* token_tree_to_ty
* token_tree_to_macro_stmts
* token_tree_to_macro_items

And added two new syntax kind:

* MACRO_ITEMS
* MACRO_STMTS

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-04-19 08:56:39 +00:00
Edwin Cheng
a6d51e0961 Return Result for token_tree_to_xx functions 2019-04-19 04:03:22 +08:00
Edwin Cheng
c0f19d7005 Add expr, pat, ty and macro_stmts 2019-04-19 03:49:56 +08:00
Edwin Cheng
3ff5440a50 Add MacroItems and MacroStmts in grammer.ron 2019-04-19 02:47:29 +08:00
Edwin Cheng
e8ddeb869d Fix missing last token in mbe $repeat parsing 2019-04-18 23:33:54 +08:00
Edwin Cheng
e944fd059d Add item matcher in mbe 2019-04-18 10:21:36 +08:00
bors[bot]
112fd0ec7d Merge #1160
1160: better formatting when adding trait members r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-04-17 11:11:31 +00:00
Aleksey Kladov
a27fc96aa1 better formatting when adding trait members
* it's conventional not to use one-liners
* new placement is more predictable, b/c it does not depend on
  header's length
2019-04-17 14:05:02 +03:00
bors[bot]
4c8e6e89aa Merge #1145
1145: Fix #1099, plug self type type parameters in infer_path_expr r=flodiebold a=edwin0cheng

As discussed in #1099, this PR try to "plug" a `self type` type parameters in `infer_path_expr`.
All the cases in 1099 was fixed and tested.
And luckily, this PR fixed bug #1030 again and make the test output correct.





Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-04-17 11:03:34 +00:00
Aleksey Kladov
f75feb6724 cleanup cancellation
Now that we explicitelly exit the reading loop on exit notification,
we can assume that the sender is always alive
2019-04-17 11:47:38 +03:00
bors[bot]
d3afb1b378 Merge #1153
1153: "Restart server" command r=jrvidal a=jrvidal

The only tricky aspect is that fact that once the `exit` command has been received, we no longer need to join on the reader thread. 

Also, I think `terminateProcesses.sh` was not working properly. In fact, the very same script from the vscode language server implementation is not working either! It's because of that I noticed the reader thread issue 😮 

Co-authored-by: Roberto Vidal <vidal.roberto.j@gmail.com>
2019-04-17 05:51:12 +00:00
Edwin Cheng
57e4122b89 Add mbe stmt matcher 2019-04-17 12:34:43 +08:00
Edwin Cheng
8747c903a2 Refactoring 2019-04-17 09:35:03 +08:00