Commit Graph

2596 Commits

Author SHA1 Message Date
bors[bot]
e1ea2500fc Merge #1238
1238: Macro queries r=edwin0cheng a=matklad

In https://github.com/rust-analyzer/rust-analyzer/pull/1231, I've added aggressive clean up of `ast_id_to_node` query. 

The result of this query is a `SyntaxTree`, and we don't want to retain syntax trees in memory unless absolutely necessary.

Moreover, `SyntaxTree` has identity equality semantics, meaning that we'll get a diffferent syntax tree for a file after every reparse. That means that `ast_id_to_node` query should not genereally be used in HIR, unless it is behind some kind of salsa firewall, like the `raw` module of name resoulution.

However, that PR resulted in the abysmal performance: turns out we were using  ast_id_to_node quite heavily in hir when expanding macros! 

So this PR  installs the more incremental-friendly query structure:

* converting source to token tree is now a query; changing source without affecting token-trees will now preserve macro expansions
* expand macro (tt -> tt) is now a query as well, so we cache macro expansions *before* parsing them into item lists or expressions, which is nice: we can cache expansion without knowing the calling context!

r? @edwin0cheng 

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-05-04 15:54:04 +00:00
Aleksey Kladov
bcf45371ff make macro expansion into a proper query 2019-05-04 18:01:43 +03:00
Aleksey Kladov
87a1e276d5 minor, move 2019-05-04 17:42:24 +03:00
Aleksey Kladov
5dc384132f introduce macro_arg intermediate query
Currently, when expanding macros, we look at the source code
directly (we invoke ast_id_to_node query via to_node method).

This is less then ideal, because it make us re-expand macros after
every source change.

This commit establishes a salsa-firewall: a query to get macro call's
token tree. Unlike the syntax tree, token tree changes only if we
actually modify the macro itself.
2019-05-04 17:38:09 +03:00
Edwin Cheng
50f288db92 Add test 2019-05-04 22:32:48 +08:00
Edwin Cheng
0c4efbb2b6 Error out when parse_subtree is not a subtree 2019-05-04 21:57:20 +08:00
Aleksey Kladov
8876f44054 Revert "eagarly clean astd maps"
This reverts commit 6c63a59425.

This causes massive slowdowns: looks like we accidentally have some source-depndent
2019-05-04 16:04:34 +03:00
bors[bot]
b1febf2e6d Merge #1235
1235: revert eagarly clean astd maps r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-05-04 12:30:13 +00:00
Aleksey Kladov
ca5aedc9bf revert eagarly clean astd maps
This causes massive slowdown :-(
2019-05-04 15:29:35 +03:00
bors[bot]
dc666c8101 Merge #1230
1230: Desugar doc comments to `#[doc = "...."]` attributes in `syntax node` to tt conversion r=matklad a=edwin0cheng

As discussed in [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/MBE.20discussion/near/164446835), this PR desugar doc comments to  `#[doc = "...."]` in `syntax node` to tt conversion. 

Note that after this PR, all obvious mbe bugs in dogfooding are fixed. (i.e. No parsing or expanding mbe error in `env RUST_LOG=ra_hir=WARN target\release\ra_cli.exe analysis-stats`) 🎉

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-05-04 12:17:13 +00:00
Edwin Cheng
036141663b Quote the quoted comment 2019-05-04 19:34:02 +08:00
Edwin Cheng
048f12d9f0 Use explict escape_default instead of dbg print 2019-05-04 17:03:22 +08:00
Aleksey Kladov
6c63a59425 eagarly clean astd maps 2019-05-04 11:53:44 +03:00
Edwin Cheng
e7e896170a Convert doc comment to attr 2019-05-04 15:00:16 +08:00
Edwin Cheng
4ba4747578 Mark unused mbe variable as Binding::Empty 2019-05-04 01:14:25 +08:00
Edwin Cheng
31909cc7d7 By pass unbind $var while mbe expanding 2019-05-03 23:23:21 +08:00
Edwin Cheng
e8e46100d6 Refactor out tests module and remove empty subtree 2019-05-03 21:38:00 +08:00
bors[bot]
b29f442c8b Merge #1227
1227: Add `default_type` method in `TypeParam` Node r=matklad a=edwin0cheng

This PR add a `default_type` method in `TypeParam` Node which allow future PR to handle #1099 case.

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-05-03 13:06:55 +00:00
Edwin Cheng
9e4fee8b41 Add default type param in TypeParam Node 2019-05-03 12:18:35 +08:00
Edwin Cheng
11d6a1449d Fixed old incorrect test 2019-05-03 00:20:27 +08:00
Edwin Cheng
ab91050d49 Fix typo 2019-05-03 00:01:48 +08:00
Edwin Cheng
91745c62f8 Compare text instead 2019-05-02 23:59:13 +08:00
Edwin Cheng
1446d620c5 Add empty bindings and some refactoring 2019-05-02 23:23:14 +08:00
Edwin Cheng
35c4633150 Make vis matcher optional and fix typo 2019-05-02 21:24:51 +08:00
Edwin Cheng
779676f782 Remove unused code in subtree_source 2019-05-02 10:19:12 +08:00
Edwin Cheng
a7ef9bac4e Formating 2019-05-02 10:08:11 +08:00
Edwin Cheng
6b2985ebc7 Remove unused code and add space bewteen tt 2019-05-02 10:02:17 +08:00
bors[bot]
12629d5e4f Merge #1222
1222: Skip Dollars when bump raw  token r=matklad a=edwin0cheng

This PR fixed a bug while parsing token_tree, it should skip all L_DOLLAR AND R_DOLLAR.

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-05-01 17:45:56 +00:00
bors[bot]
817a38538f Merge #1223
1223: Move guard to arm body assist r=matklad a=unrealhoang

This is my attempt at #1206 

Co-authored-by: Unreal Hoang <unrealhoang@gmail.com>
2019-05-01 17:28:07 +00:00
Unreal Hoang
d1c21b85cf
add complex match case and documentation 2019-05-02 01:41:02 +09:00
Unreal Hoang
f83e452b1e
move guard to arm body assist. 2019-05-02 00:42:00 +09:00
Edwin Cheng
a42f26502d Skip Dollars when bump raw token 2019-05-01 22:39:47 +08:00
bors[bot]
71c13528cd Merge #1220
1220: Add macro pat parsing r=matklad a=edwin0cheng

This PR add support to parsing macro call in pattern , e.g :
```
let m!(x) = 0;
```

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-05-01 14:09:44 +00:00
Aleksey Kladov
594aac059e Use correct FileId when expanding macros in expressions 2019-05-01 15:53:13 +03:00
Edwin Cheng
b454eb5a60 Add macro pat parsing 2019-04-30 23:22:48 +08:00
Felix S. Klock II
d694b0174a Sidestep two-phase borrow violation signaled by mutable_borrow_reservation_conflict.
See rust-lang/rust#59159 for further information/discussion.
2019-04-29 14:03:51 +02:00
bors[bot]
6618d1edc3 Merge #1213
1213: Make lexer produce only single character puncts r=matklad a=edwin0cheng

As discussed in Zulip, this PR change `lexer` to produce only single char punct.

* Remove producing `DOTDOTDOT, DOTDOTEQ, DOTDOT, COLONCOLON, EQEQ, FAT_ARROW, NEQ, THIN_ARROW` in lexer.
* Add required code in parser to make sure everythings works fine.
* Change some tests (Mainly because the `ast::token_tree` is different)

Note: i think the use of `COLON` in rust is too overloaded :)


Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-04-28 16:51:02 +00:00
Edwin Cheng
d436ab0581 Refactor parser handle mult-char punct internally 2019-04-28 23:46:03 +08:00
Florian Diebold
85633656df Fix hover on the beginning of a nested expression
E.g. in
```
let foo = 1u32;
if true {
   <|>foo;
}
```
the hover shows `()`, the type of the whole if expression, instead of the more
sensible `u32`. The reason for this was that the search for an expression was
slightly left-biased: When on the edge between two tokens, it first looked at
all ancestors of the left token and then of the right token. Instead merge the
ancestors in ascending order, so that we get the smaller of the two possible
expressions.
2019-04-28 16:03:49 +02:00
kjeremy
d8649c1af8 Simplify 2019-04-26 11:42:56 -04:00
kjeremy
4251f083b5 Add is_empty to Arena 2019-04-26 11:42:10 -04:00
kjeremy
47f10fce8a Pass in char instead of single-char string 2019-04-26 11:41:58 -04:00
kjeremy
70dc33e00c Elide lifetime 2019-04-26 11:41:14 -04:00
Edwin Cheng
1908819bf6 Use panic instead of unwrap 2019-04-26 02:56:44 +08:00
Edwin Cheng
c55a2dbc1d Fix more bugs 2019-04-26 02:03:56 +08:00
Edwin Cheng
299d97b6d9 Add handling token seperator in mbe 2019-04-26 02:03:55 +08:00
Edwin Cheng
dfab545d5d Add more information on macro rules fail to parse 2019-04-26 02:03:55 +08:00
Edwin Cheng
e4e2338f97 Fix incorrect repeat sep eating 2019-04-26 02:03:55 +08:00
Aleksey Kladov
848cb16a01 drop empty file 2019-04-25 10:07:23 +03:00
kjeremy
558bdf73c8 simplify match 2019-04-24 14:45:02 -04:00
kjeremy
f69bf6a12b See through references 2019-04-24 12:09:29 -04:00
bors[bot]
6009af9b7c Merge #1200
1200: Allows searching for case-equivalent symbols (fixes #1151) r=matklad a=jrvidal

I couldn't find a nice, functional way of calculating the ranges in one pass so I resorted to a plain old `for` loop.

Co-authored-by: Roberto Vidal <vidal.roberto.j@gmail.com>
2019-04-23 21:25:37 +00:00
Roberto Vidal
dd8c3840cb CR corrections 2019-04-23 22:19:45 +02:00
kjeremy
a5bf0cdb97 Simplify 2019-04-23 15:44:37 -04:00
kjeremy
7125192c1e Basic resolution for ADT 2019-04-23 14:32:47 -04:00
Roberto Vidal
b56f010201 Allows searching for case-equivalent symbols (fixes #1151) 2019-04-23 20:11:45 +02:00
bors[bot]
a094d5c621 Merge #1147
1147: Handle macros in type checking / HIR r=matklad a=Lapz

An other attempt at  #1102. I will need to flatten the nested if statements and im also not sure if the way that i get the resolver and module will always work

Co-authored-by: Lenard Pratt <l3np27@gmail.com>
2019-04-23 12:49:31 +00:00
Lenard Pratt
1ab7066e32 Introduced resolve_macro_call on resolver
changed to manual expansion

fix for nested macros
2019-04-23 10:17:31 +01:00
Edwin Cheng
6c913d8fa7 Add ... parsing for fn pointer type 2019-04-23 11:10:41 +08:00
Lenard Pratt
ce211434a6 Added macro resolution and expansion 2019-04-22 21:35:44 +01:00
Lenard Pratt
afaeb18910 Addeded resolver and db 2019-04-22 21:33:48 +01:00
Edwin Cheng
fccd045229 Add cached for SubtreeSource 2019-04-22 22:46:39 +08:00
bors[bot]
c416caeda2 Merge #1194
1194: Pr 1190 r=matklad a=matklad



Co-authored-by: Andrea Pretto <eulerdisk@gmail.com>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-04-22 13:19:47 +00:00
Aleksey Kladov
aa1ef6ae9a unused import 2019-04-22 16:18:14 +03:00
Aleksey Kladov
c27a3da5e8 remove path_ident from CompletionContext
We really shouldn't be looking at the identifier at point. Instead,
all filtering and sorting should be implemented at the layer above.

This layer should probably be home for auto-import completions as
well, but, since that is not yet implemented, let's just stick this
into complete_scope.
2019-04-22 16:04:56 +03:00
Aleksey Kladov
e01052d1f0 move auto-imoprter into IDE
auto-import is purely an IDE concern, so it should be done outside of
HIR
2019-04-22 15:56:28 +03:00
bors[bot]
6162278075 Merge #1193
1193: Add a test for #1178 case r=edwin0cheng a=edwin0cheng

A little PR to add a test case for #1178

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-04-22 12:22:08 +00:00
Edwin Cheng
bb84fce1a4 Remove unused print out 2019-04-22 20:21:14 +08:00
Edwin Cheng
1cdfc38066 Add a test for #1178 case 2019-04-22 20:14:46 +08:00
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
Andrea Pretto
200032852b complete_import: prevent panic when the anchor is the completion source range
(fix rebase mess)

 Please enter the commit message for your changes. Lines starting
2019-04-22 00:48:43 +02:00
Andrea Pretto
9144214958 complete_import: add new import resolver infrastructure with some hardcoded importable name.
Changes complete_scope to support that.
2019-04-22 00:14:58 +02:00
Andrea Pretto
cf0eff2e33 auto_import: better no anchor management 2019-04-22 00:13:00 +02:00
Andrea Pretto
766813898f auto_import: make auto import working with target as a list of SmolStr instead of ast::Path 2019-04-22 00:13:00 +02:00
Andrea Pretto
0e0ae47b47 auto_import: use TextEditBuilder instead of AssistBuilder to make it more reusable 2019-04-22 00:13:00 +02: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