Commit graph

890 commits

Author SHA1 Message Date
Edwin Cheng
bb22a4e386 Add support for macro in symbo_index 2020-03-22 15:00:44 +08:00
Edwin Cheng
e1a9461806 Add identity expansion checking 2020-03-21 22:43:48 +08:00
Aleksey Kladov
89694ec8f6 Support arbitrary discriminants
Closes #3661
2020-03-20 08:50:34 +01:00
Aleksey Kladov
ef3bf906c4 Generalize 2020-03-19 11:38:26 +01:00
Aleksey Kladov
0bf903411c Use match_ast 2020-03-18 20:51:47 +01:00
Aleksey Kladov
3f6dc20d3c Merge imports assist
Work towards #2220
2020-03-18 19:34:47 +01:00
Aleksey Kladov
4e50efcfc5 Strongly-typed generic methods for editing nodes 2020-03-18 19:34:47 +01:00
bors[bot]
a99cac671c
Merge #3540
3540: Swtches to rust SSR query check r=matklad a=mikhail-m1

related to #3186 

Co-authored-by: Mikhail Modin <mikhailm1@gmail.com>
2020-03-16 09:48:09 +00:00
Mikhail Modin
b150965ed7 Swtches to rust SSR query check 2020-03-15 21:23:18 +00:00
Aleksey Kladov
bee5cdb359 Parse variadics correctly
closes #3571
2020-03-13 13:54:14 +01:00
Aleksey Kladov
1e19847af3 Move verbose tests out of line 2020-03-13 12:20:42 +01:00
CAD97
88c944f96b Remove some TextUnit->usize escapees 2020-03-12 22:33:27 -04:00
Aleksey Kladov
afd64ef4f7
Merge pull request #3562 from FireofGods/display_for_node
Add `std::fmt::Display` as a supertrait for `AstNode`
2020-03-12 15:40:53 +01:00
Fireassember
31eec5e80c implementing Display for enums too. 2020-03-11 22:54:24 +02:00
Aleksey Kladov
4a745cc8cf Fix parsing of stement-ish binary expressions
closes #3512
2020-03-11 14:28:18 +01:00
Edwin Cheng
e7206467d5 Add parse_to_token_tree 2020-03-09 00:13:04 +08:00
Fireassember
787043496a added fmt::Display as a supertrait for AstNode and changed generation. 2020-03-06 19:29:30 +02:00
Aleksey Kladov
1f84c3b18f make::use_item 2020-03-06 15:56:25 +01:00
Aleksey Kladov
85e2346b74 Simplify creation of T[,] 2020-03-06 15:38:48 +01:00
Aleksey Kladov
ea0c124219 Rerail split_import API onto AST
The code is more verbose and less efficient now, but should be
reusable in add_import context as well
2020-03-06 14:08:43 +01:00
Aleksey Kladov
381ace587e Add with_use_tree 2020-03-05 18:38:52 +01:00
Edwin Cheng
1465cc0c4f Implement concat macro 2020-03-04 01:21:14 +08:00
Aleksey Kladov
584c8d9875 Slightly refactor inlay hints 2020-02-29 23:24:50 +01:00
Aleksey Kladov
a1e1869554 Rename ast::ImplBlock -> ast::ImplDef 2020-02-29 21:33:15 +01:00
Aleksey Kladov
9abcab1669 Fix typo 2020-02-29 13:51:23 +01:00
Aleksey Kladov
5f8b37563e Cleanup editing API 2020-02-29 13:51:23 +01:00
Aleksey Kladov
ca713e462b More orthogonal API for building paths 2020-02-29 11:55:36 +01:00
Edwin Cheng
f4e48ad3e4 Parse attr in rhs of let stmts 2020-02-28 13:08:47 +08:00
Aleksey Kladov
e74484e133 Refactor string literals 2020-02-27 17:19:53 +01:00
Aleksey Kladov
c6247f74c7 Basic injections 2020-02-27 16:16:13 +01:00
Edwin Cheng
553254973e Skip trival token in original_range 2020-02-27 00:12:26 +08:00
Aleksey Kladov
c3a4c4429d Refactor primary IDE API
This introduces the new type -- Semantics.
Semantics maps SyntaxNodes to various semantic info, such as type,
name resolution or macro expansions.

To do so, Semantics maintains a HashMap which maps every node it saw
to the file from which the node originated. This is enough to get all
the necessary hir bits just from syntax.
2020-02-26 12:55:50 +01:00
Aleksey Kladov
469011169b ⬆️ rowan 2020-02-25 14:44:51 +01:00
Shotaro Yamada
dd0c3c41b9 Fix a crash with non-ascii whitespace in doc-comments 2020-02-19 13:13:29 +09:00
Kirill Bulatov
f6816c253b Update versions 2020-02-18 16:12:40 +02:00
Kirill Bulatov
b8ddcb0652 Run cargo +nightly fix --clippy -Z unstable-options 2020-02-18 16:03:08 +02:00
Veetaha
583b1e155a
Remove dat FIXME 2020-02-18 15:19:49 +02:00
bors[bot]
c447fe9bc0
Merge #3026
3026: ra_syntax: reshape SyntaxError for the sake of removing redundancy r=matklad a=Veetaha

Followup of #2911, also puts some crosses to the todo list of #223.

**AHTUNG!** A big part of the diff of this PR are test data files changes.

Simplified `SyntaxError` that was `SyntaxError { kind: { /* big enum */  }, location: Location }` to `SyntaxError(String, TextRange)`. I am not sure whether the tuple struct here is best fit, I am inclined to add names to the fields, because I already provide getters `SyntaxError::message()`, `SyntaxError::range()`.
I also removed `Location` altogether ...

This is currently WIP, because the following is not done:
- [ ] ~~Add tests to `test_data` dir for unescape errors *// I don't know where to put these errors in particular, because they are out of the scope of the lexer and parser. However, I have an idea in mind that we move all validators we have right now to parsing stage, but this is up to discussion...*~~ **[UPD]** I came to a conclusion that tree validation logic, which unescape errors are a part of, should be rethought of, we currently have no tests and no place to put tests for tree validations. So I'd like to extract potential redesign (maybe move of tree validation to ra_parser) and adding tests for this into a separate task.

Co-authored-by: Veetaha <gerzoh1@gmail.com>
Co-authored-by: Veetaha <veetaha2@gmail.com>
2020-02-18 12:57:26 +00:00
Aleksey Kladov
c0fa5e2246 Rename the binary to rust-analyzer 2020-02-18 12:33:16 +01:00
Veetaha
053ccf4121 ra_syntax: fix reparsing merging errors, also now reparse_token() reports errors 2020-02-18 02:11:16 +02:00
Veetaha
fc5e7b8807 ra_syntax: migrate test data to 0-length text-range of SyntaxError when constructed from TextUnit 2020-02-17 23:14:31 +02:00
Veetaha
cd8e56c580 ra_syntax: remove message() method and use only Display trait in SyntaxError as per matklad 2020-02-17 23:13:38 +02:00
Veetaha
e05eb631d4 ra_syntax: change module-level documentation for syntax_error to "see X" as per matklad 2020-02-17 22:50:58 +02:00
Veetaha
b510e77fbe ra_syntax: followup fix for making SyntaxError::range() to return by value 2020-02-17 22:24:38 +02:00
Veetaha
e00922d113 ra_syntax: SyntaxError::range() now returns by value 2020-02-17 22:24:38 +02:00
Veetaha
acdab6f0f2 ra_syntax: moved reexport declaration after imports as per matklad 2020-02-17 22:24:38 +02:00
Veetaha
6ae4850c89 ra_syntax: Apply Aleksei Kladov suggestion about TextRange of TextUnit
Co-Authored-By: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-02-17 22:24:33 +02:00
Veetaha
c58276673a Change semmantical analyzis to tree validation as per @matklad
Co-Authored-By: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-02-17 22:24:33 +02:00
Veetaha
9fdf984958 ra_syntax: reshape SyntaxError for the sake of removing redundancy 2020-02-17 22:24:33 +02:00
Mikhail Modin
f8f454ab5c Init implementation of structural search replace 2020-02-14 21:45:42 +00:00
Han Mertens
bed9c083de Run cargo test 2020-02-12 23:15:48 +01:00
Han Mertens
537da096fe Run cargo xtask codegen 2020-02-12 23:09:13 +01:00
Kirill Bulatov
2a7d97d829 Fix the trailing whitespace test 2020-02-12 17:04:16 +02:00
Kirill Bulatov
848c576266 Introduce AttrKind 2020-02-12 16:44:52 +02:00
Kirill Bulatov
1596b31698 Do not add imports before inner attributes 2020-02-12 16:21:55 +02:00
bors[bot]
759100fb0d
Merge #3062
3062: Implement slice pattern AST > HIR lowering r=jplatte a=jplatte

WIP. The necessary changes for parsing are implemented, but actual inference is not yet. Just wanted to upload what I've got so far so it doesn't get duplicated :)

Will fix #3043

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2020-02-11 21:46:36 +00:00
Jonas Platte
a3b104aa6d
Implement slice pattern AST > HIR lowering 2020-02-11 22:33:11 +01:00
Matthew Jasper
49b53cd7a0 Address review comments 2020-02-10 20:11:44 +00:00
Matthew Jasper
504e2a46bd Update tests for or-patterns 2020-02-09 22:06:28 +00:00
Matthew Jasper
8c8d0bb34f Add or- and parenthesized-patterns 2020-02-09 22:06:15 +00:00
Florian Diebold
9bb699b28d Some README fixes/cleanups
Make capitalization more consistent and fix some typos.
2020-02-09 13:35:54 +01:00
Kirill Bulatov
740a26b7d2 Rename add import assist 2020-02-07 23:53:08 +02:00
bors[bot]
8337dcd9e2
Merge #3047
3047: Update async unsafe fn ordering in parser r=matklad a=kiljacken

As of rust-lang/rust#61319 the correct order for functions that are both unsafe and async is: `async unsafe fn` and not `unsafe async fn`.

This commit updates the parser tests to reflect this, and corrects parsing behavior to accept the correct ordering.

Fixes #3025

Co-authored-by: Emil Lauridsen <mine809@gmail.com>
2020-02-07 13:21:02 +00:00
bors[bot]
6d6a995e09
Merge #3040
3040: Rework value parameter parsing r=matklad a=tobz1000

Fixes #2847.

- `Fn__(...)` parameters with idents/patterns no longer parse
- Trait function parameters with arbitrary patterns parse
- Trait function parameters without idents/patterns no longer parse
- `fn(...)` parameters no longer parse with patterns other than a single ident

__Question__: The pre-existing test `param_list_opt_patterns` has been kept as-is, although the name no longer makes sense (it's testing `Fn__(...)` params, which aren't allowed patterns any more). What would be best to do about this?

Co-authored-by: Toby Dimmick <tobydimmick@pm.me>
2020-02-07 13:13:36 +00:00
Emil Lauridsen
73ec2ab184 Update async unsafe fn ordering.
As of rust-lang/rust#61319 the correct order for functions that are both
unsafe and async is: `async unsafe fn` and not `unsafe async fn`.

This commit updates the parser tests to reflect this, and corrects
parsing behavior to accept the correct ordering.

Fixes #3025
2020-02-07 13:51:51 +01:00
Aleksey Kladov
36ee9ecb67 Cleanup early return assist 2020-02-07 12:30:39 +01:00
Aleksey Kladov
aa1234e02b Generalize invert_if to just always work 2020-02-07 12:14:33 +01:00
Aleksey Kladov
56e3fbe588 A tiny bit more consistent API 2020-02-06 23:59:27 +01:00
Toby Dimmick
0183952d2e Closure params test 2020-02-06 20:39:27 +00:00
Toby Dimmick
7e66785859 Rework value parameter parsing
- `Fn__(...)` parameters with idents/patterns no longer parse
- Trait function parameters with arbitrary patterns parse
- Trait function parameters without idents/patterns no longer parse
- `fn(...)` parameters no longer parse with patterns other than a single ident
2020-02-06 19:45:51 +00:00
Aleksey Kladov
a4c6e8c4e2 Refactor if-let -> match assist to use ast::make 2020-02-05 14:08:16 +01:00
Aleksey Kladov
4ea0c12cf1 Make sure that newly created nodes are the root of the tree 2020-02-04 13:22:32 +01:00
Veetaha
a3e5663ae0 ra_syntax: added tests for tokenization errors 2020-02-04 00:00:55 +02:00
Veetaha
9367b9a292 ra_syntax: add backticks around tokens specimen 2020-02-04 00:00:55 +02:00
Veetaha
c3117eea31 ra_syntax: removed unnecessary init statement from reparsing tests 2020-02-04 00:00:55 +02:00
Veetaha
58e01d8754 ra_syntax: rename first_token() -> lex_first_token() 2020-02-04 00:00:55 +02:00
Veetaha
b1764d85fc ra_syntax: fixed a typo in doc comment 2020-02-04 00:00:55 +02:00
Veetaha
9e7eaa959f ra_syntax: refactored the lexer design as per @matklad and @kiljacken PR review 2020-02-04 00:00:55 +02:00
Veetaha
bf60661aa3 ra_syntax: remove backticks from TokenizeError message since that is not Markdown ;( 2020-02-04 00:00:55 +02:00
Veetaha
c6d0881382 add better docs for tokenize errors 2020-02-04 00:00:55 +02:00
Veetaha
ffe00631d5 ra_syntax: moved ParsedToken derive attribute under the doc comment 2020-02-04 00:00:55 +02:00
Veetaha
a2bc4c2a74 ra_syntax: fixed doc comment 2020-02-04 00:00:55 +02:00
Veetaha
ac37a11f04 Reimplemented lexer with vectors instead of iterators 2020-02-04 00:00:55 +02:00
Veetaha
ad24976da3 ra_syntax: changed added diagnostics information returned from tokenize() (implemented with iterators) 2020-02-04 00:00:55 +02:00
Veetaha
fa31841f1f Fixed a typo 2020-01-22 13:02:21 +02:00
Veetaha
1ac105056a Fixed a typo 2020-01-22 13:02:21 +02:00
Veetaha
b6be1b6f61 Preserved a comment on the bug previously present in ast::Literal::kind() 2020-01-22 13:02:21 +02:00
Veetaha
3ec781d4f2 ra_syntax: remove code duplication and token reevaluation from ast::Literal::kind() 2020-01-22 13:02:21 +02:00
TomasKralCZ
72792f6bc5 changed 'descendants()' to 'children()' 2020-01-20 10:19:33 +01:00
TomasKralCZ
f67ee69777 added eq_token() method to LetStmt 2020-01-19 18:55:56 +01:00
Aleksey Kladov
3a859e587f Nest attrs into exprs in function args 2020-01-17 11:47:07 +01:00
Aleksey Kladov
b7c45fba57 Extract expr_with_attrs 2020-01-17 11:44:40 +01:00
Aleksey Kladov
90b8a31b83
Merge pull request #2813 from jyn514/arg_attributes
Allow attributes before function arguments
2020-01-17 11:15:07 +01:00
Joshua Nelson
f077d5c303
move inline function closer to relevant code
also updates generated inline tests
2020-01-16 22:20:17 -05:00
Aleksey Kladov
5398b9eeba Minimize test 2020-01-16 18:39:29 +01:00
Aleksey Kladov
ab0a11b1de Simplify array parsing 2020-01-16 18:35:03 +01:00
bors[bot]
e614356de1
Merge #2827
2827: Fix array element attribute position r=matklad a=edwin0cheng

This PR fixed a bug which an ATTR node insert in the wrong place in array element. ~~And introduce `precede_next` for allow outer attributes to insert into a parsed `expr`.~~  

related #2783

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-01-16 15:49:23 +00:00
Edwin Cheng
ed8d5c86e3 Fix array element attribute position 2020-01-16 23:37:43 +08:00
bors[bot]
c78d269b66
Merge #2837
2837: Accidentally quadratic r=matklad a=matklad

Our syntax highlighting is accdentally quadratic. Current state of the PR fixes it in a pretty crude way, looks like for the proper fix we need to redo how source-analyzer works. 

**NB:** don't be scared by diff stats, that's mostly a test-data file

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-01-15 19:38:10 +00:00
Aleksey Kladov
ef1326ee19 More orthogonal path editing 2020-01-15 18:48:28 +01:00
Aleksey Kladov
7d2d3ac3db More fluent API 2020-01-15 18:30:23 +01:00
Aleksey Kladov
c84010e246 Slightly more fluent API 2020-01-15 18:14:49 +01:00
Aleksey Kladov
8296d3208d Simplify 2020-01-15 18:01:05 +01:00
Aleksey Kladov
448575aa4a Simplify 2020-01-15 18:01:05 +01:00
Aleksey Kladov
35bfeaf4af Add a test 2020-01-15 16:52:28 +01:00
Veetaha
60251da204 refactor(ra_syntax.validation): removed code duplication from validate_literal() function 2020-01-14 04:09:03 +02:00
kjeremy
a82c679c97 Some clippy lints 2020-01-13 11:27:06 -05:00
Joshua Nelson
c3ac2c93fb
Allow attributes before function arguments
This adds support for function calls of the form:

```rust
  (
    #[attr(...)] 1.2,
    #[attr_one(...)]
    #[attr_two(...)]
    1.5,
    ... etc ...
  )
```

Closes https://github.com/rust-analyzer/rust-analyzer/issues/2801
2020-01-12 10:25:41 -05:00
Florian Diebold
2c11a9b42d Qualify paths in 'fill match arms' assist 2020-01-12 11:34:52 +01:00
Florian Diebold
15fc643e05 Fix ordering problem between qualifying paths and substituting params 2020-01-11 23:33:04 +01:00
Florian Diebold
4545f289a9 Handle type args 2020-01-11 23:33:04 +01:00
Jeremy Kolb
d993f329a0 Basic DocumentHighlightKind support for assignments 2020-01-10 15:14:19 -05:00
Emil Lauridsen
aa433c67d8 Parse trait aliases 2020-01-09 18:40:01 +01:00
Aleksey Kladov
47785b0cd4 ⬆️ rowan 2020-01-09 16:33:02 +01:00
Michael Chesser
ce1b34fd59 Improve const generics parsing
- Handle const generics type args
- Fix issue with const generic as first parameter in trait impl
2020-01-07 09:29:03 +10:30
Jeremy Kolb
5afb22e2b3 BinOp helper to detect assignment 2020-01-04 15:54:31 -05:00
Aleksey Kladov
b5e7186265 remove unused file 2020-01-04 10:58:10 +01:00
Aleksey Kladov
084bd304f3 Switch ast declaration from ron to a macro 2020-01-03 21:54:10 +01:00
Florian Diebold
79c90b5641 Collect visibility of items during nameres 2019-12-26 16:23:40 +01:00
Florian Diebold
069bf55cca Add infrastructure for visibility on syntax and hir_def level 2019-12-26 16:23:40 +01:00
Edwin Cheng
208ad97fdc Remove AsyncOwner 2019-12-25 00:25:18 +08:00
Edwin Cheng
0edb5b4a50 Implement infer await from async func 2019-12-24 19:45:28 +08:00
bors[bot]
436df298ba
Merge #2642
2642: Use name instead of ident in parser for macro 2.0 syntax r=matklad a=edwin0cheng



Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-12-22 08:05:02 +00:00
bors[bot]
d33493d779
Merge #2641
2641: Parse const generics r=matklad a=roblabla

Adds very primitive support for parsing const generics (`const IDENT: TY`) so that rust-analyzer stops complaining about the syntax being invalid.

Fixes #1574
Fixes #2281 

Co-authored-by: roblabla <unfiltered@roblab.la>
2019-12-22 07:56:33 +00:00
Edwin Cheng
737045c1ea Use name instead of ident for macro 2.0 sytnax 2019-12-22 11:11:10 +08:00
roblabla
b04d4a88d1 Parse const generics
Fixes #1574
Fixes #2281
2019-12-22 01:32:08 +00:00
bors[bot]
90ef070db3
Merge #2628
2628: Add macro 2.0 support in parser r=matklad a=edwin0cheng

This PR added a new syntax kind : `MACRO_DEF` and a keyword `MACRO_KW`

there are two syntax for declarative macro 2.0 :
1. Normal : `macro m { ($i:ident) => {} }` , which handle similar to legacy one. 
2. Call like: `macro m($i:ident) {}`, it produces a single token tree which have two child token trees : `($i:ident)` and `{}`

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-12-21 10:47:47 +00:00
Edwin Cheng
bea8f58118 Add macro 2.0 support in parser 2019-12-21 18:29:14 +08:00
kjeremy
0d5d63a80e Clippy lints 2019-12-20 15:14:30 -05:00
Florian Diebold
2a8c9100bf Handle closure return types
Fixes #2547.
2019-12-20 18:16:11 +01:00
Edwin Cheng
4a7e19946a Fix parser for macro call in pattern position 2019-12-20 23:26:04 +08:00
kjeremy
f22aabc136 Use unwrap_or_default 2019-12-20 09:43:30 -05:00
Aleksey Kladov
3e2f4e4293 Improve recovery for incomplete lambdas 2019-12-17 12:11:01 +01:00
Aleksey Kladov
b0739d5a26 Avoid recompiling serde 2019-12-12 14:11:06 +01:00
Aleksey Kladov
8c86963d47 DynMap
This might, or might not help us to reduce boilerplate associated with
plumbing values from analysis to the IDE layer
2019-12-06 21:28:05 +01:00
Aleksey Kladov
193b1a7437 ⬆️ rowan 2019-12-04 17:15:55 +01:00
ice1000
379482068d Add ModuleItemsOwner to Block 2019-12-03 12:07:39 -05:00
Aleksey Kladov
5fd68b5929 Fix hir for ast::UnionDef 2019-11-25 17:50:49 +03:00
Aleksey Kladov
e1c0bdaf75 Introduce dedicated AST node for union
Although structs and unions have the same syntax and differ only in
the keyword, re-using the single syntax node for both of them leads to
confusion in practice, and propagates further down the hir in an
upleasent way.

Moreover, static and consts also share syntax, but we use different
nodes for them.
2019-11-25 17:50:49 +03:00
bors[bot]
7b6aa7c34e
Merge #2343
2343: implement assist invert_if r=matklad a=bravomikekilo

fix [issue 2219 invert if condition](https://github.com/rust-analyzer/rust-analyzer/issues/2219)
I put the assist cursor range to `if` of the if expression, because both condition and body will be replaced. Is there any way to replace them without cover the cursor position?
@matklad 

Co-authored-by: bravomikekilo <bmk1221@126.com>
2019-11-24 08:32:07 +00:00
bravomikekilo
adac4fc2f2 do refact and fix some issue 2019-11-24 13:14:57 +08:00
Aleksey Kladov
d8caf56dfc Uniformalize naming 2019-11-22 21:52:06 +03:00
Aleksey Kladov
cebeedc66f Next gen IDs for functions
The current system with AstIds has two primaraly drawbacks:

* It is possible to manufacture IDs out of thin air.
  For example, it's possible to create IDs for items which are not
  considered in CrateDefMap due to cfg. Or it is possible to mixup
  structs and unions, because they share ID space.

* Getting the ID of a parent requires a secondary index.

Instead, the plan is to pursue the more traditional approach, where
each items stores the id of the parent declaration. This makes
`FromSource` more awkward, but also more correct: now, to get from an
AST to HIR, we first do this recursively for the parent item, and the
just search the children of the parent for the matching def
2019-11-20 16:22:58 +03:00
Aleksey Kladov
0e771915fa Allow non-path default type parameters 2019-11-20 11:46:44 +03:00
Aleksey Kladov
83a8430e0a ⬆️ rowan 2019-11-19 21:13:36 +03:00
DJMcNab
27ce1e822b Remove the custom impl of AttrsOwner for ImplItem
The default impl should have the same behaviour, and it can be generated
by codegen.
See also `ModuleItem` and `NominalDef`
2019-11-18 18:13:56 +00:00
Aleksey Kladov
7e2f4b30db Disable doctests 2019-11-17 18:35:05 +03:00
Aleksey Kladov
5b54a93fe7 Add ast for plain and raw string literals 2019-11-16 22:50:41 +03:00
Aleksey Kladov
d898ecb8f2 Force passing Source when creating a SourceAnalyzer 2019-11-16 02:12:35 +03:00
Geoffry Song
5645c153e0 Attempt to implement typed accessors 2019-11-15 12:05:29 -08:00