Commit Graph

2333 Commits

Author SHA1 Message Date
bors[bot]
1cd18f9237 Merge #991
991: Use Marker argument for item parsers r=matklad a=pcpthm

Before doing this for expressions, I found that the pattern (Marker argument) should be applied to the item parsers because visiblity and modifiers are parsed in a separate function.

Fixed some parser bugs:
- Fix pub_expr: `pub 42;` was allowed.
- Fix incorrect parsing of crate::path: incorrectly parsed as `crate` as a visibility.

Co-authored-by: pcpthm <pcpthm@gmail.com>
2019-03-18 09:32:28 +00:00
bors[bot]
7c117567ab Merge #989
989: Implement naive version of fill_struct_fields assist r=matklad a=yanchith

Fixes #964

This implements the `fill_struct_fields` assist. Currently only works for named struct fields, but not for tuple structs, because we seem to be missing a `TupleStructLit` (akin to `StructLit`, but for tuple structs). I am happy to implement `TupleStructLit` parsing given some guidance (provided it's really missing) and make the assist work for tuple structs as well. Could do so either in this PR, or another one 🙂 

Sorry if I missed something important, this is my first PR for Rust Analyzer.

Btw is there any way to run the assists in emacs?

UPDATE: I just realized that parsing `TupleStructLit` would be quite difficult as it it really similar, if not identical to a function call...

Co-authored-by: yanchith <yanchi.toth@gmail.com>
2019-03-18 08:24:18 +00:00
yanchith
ca262fbab8 Only replace NamedFieldList and add test for preserving Self 2019-03-18 09:03:10 +01:00
yanchith
8d47e004b8 Remove unachievable TODO 2019-03-18 08:19:51 +01:00
pcpthm
76075c7410 Use Marker argument for item parsers
- Fix pub_expr
- Fix incorrect parsing of crate::path
2019-03-18 14:34:08 +09:00
bors[bot]
4c1ea0b628 Merge #987
987: Refactor maybe_item to use Marker argument r=pcpthm a=pcpthm

As suggested at <https://github.com/rust-analyzer/rust-analyzer/pull/980#issuecomment-473659745>.
For expression paring functions, changing signature
- from `fn(&mut Parser) -> Option<CompletedMarker>` to `fn(&mut Parser, Marker) -> Result<CompletedMarker, Marker>`
- from `fn(&mut Parser) -> CompletedMarker` to `fn(&mut Parser, Marker) -> CompletedMarker`
is my plan.

Co-authored-by: pcpthm <pcpthm@gmail.com>
2019-03-18 04:16:20 +00:00
pcpthm
3d9c2beb8e Apply stylistic changes suggested 2019-03-18 13:14:47 +09:00
bors[bot]
40c6dd1f4c Merge #982
982: Implement BindingMode for pattern matching. r=flodiebold a=mjkillough

Implement `BindingMode` for pattern matching, so that types can be
correctly inferred using match ergonomics. The binding mode defaults to
`Move` (referred to as 'BindingMode::BindByValue` in rustc), and is
updated by automatic dereferencing of the value being matched.

Fixes #888.

 - [Binding modes in The Reference](https://doc.rust-lang.org/reference/patterns.html#binding-modes)
 - [`rustc` implementation](e17c48e2f2/src/librustc_typeck/check/_match.rs (L77)) (and [definition of `BindingMode`](e957ed9d10/src/librustc/ty/binding.rs))
 - [Match Ergonomics RFC](https://github.com/rust-lang/rfcs/blob/master/text/2005-match-ergonomics.md#binding-mode-rules)

Co-authored-by: Michael Killough <michaeljkillough@gmail.com>
2019-03-17 21:41:37 +00:00
Michael Killough
6299ccd350 Split test case and use tested_by!. 2019-03-17 19:08:51 +00:00
Michael Killough
33add0ee30 Simplify match statement. 2019-03-17 18:50:22 +00:00
yanchith
907f7307af Implement naive version of fill_struct_fields assist 2019-03-17 19:48:25 +01:00
Michael Killough
354134ffb4 impl Default for BindingMode.
This decouples callers from knowing what the default binding mode of
pattern matching is.
2019-03-17 18:46:01 +00:00
bors[bot]
91e7a3b6f2 Merge #983
983: support remainder assignment operator r=matklad a=JeanMertz

`%=` was returning errors for me, turns out it wasn't added as a valid assignment operation.

I'm not sure what the best location would be to add a test for this. Please let me know and I'll add one.

Co-authored-by: Jean Mertz <jean@mertz.fm>
2019-03-17 14:34:14 +00:00
Jean Mertz
a8ee994ae0
support remainder assignment operator 2019-03-17 14:11:24 +01:00
pcpthm
e570267515 Refactor maybe_item to use Marker argument 2019-03-17 22:04:25 +09:00
pcpthm
a67fe4ea7e Fix parse tree of attribute on match arm 2019-03-17 20:57:27 +09:00
bors[bot]
aea9c98f53 Merge #985
985: simplify parsing blocks a bit r=pcpthm a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-03-17 10:26:45 +00:00
Aleksey Kladov
a8271cb31f simplify parsing blocks a bit 2019-03-17 13:14:17 +03:00
pcpthm
a1d84f5fb0 Allow attribute on struct literal field 2019-03-17 19:08:35 +09:00
Aleksey Kladov
3a77023365 docs 2019-03-17 12:53:22 +03:00
Aleksey Kladov
4d7fa6d30b remove fixme 2019-03-17 12:53:22 +03:00
Aleksey Kladov
6955e392f8 remove old macro support 2019-03-17 12:53:22 +03:00
Aleksey Kladov
ee3cf6172b rename ModuleId -> CrateModuleId 2019-03-17 12:53:22 +03:00
Aleksey Kladov
c51a6a7bdd fix error on wrong path 2019-03-17 12:53:22 +03:00
Aleksey Kladov
0d6b8baa89 log time 2019-03-17 12:53:22 +03:00
Aleksey Kladov
967a4b64af Reorganize name resolution 2019-03-17 12:53:22 +03:00
Aleksey Kladov
d4449945a0 hack around non-terminating macro expansion 2019-03-17 12:52:52 +03:00
Aleksey Kladov
b2a6c17362 remove lower module 2019-03-17 12:52:52 +03:00
Aleksey Kladov
c7259a899c remove ItemMap 2019-03-17 12:52:05 +03:00
Aleksey Kladov
71e5adf694 move tests over to crate-def-map 2019-03-17 12:49:07 +03:00
Aleksey Kladov
2195d1db6d Replace module_tree with CrateDefMap 2019-03-17 12:49:07 +03:00
Aleksey Kladov
182c05a96c add name resolution from the old impl
unlike the old impl, this also handles macro imports across crates
2019-03-17 12:46:13 +03:00
Aleksey Kladov
0d8d918656 add skeleton for macro-aware name resolutions 2019-03-17 12:46:13 +03:00
Igor Matuszewski
30a226c725 Move the primary assist fn to the top of the file 2019-03-16 23:24:17 +01:00
Igor Matuszewski
5b0b87f8de Provide assist when cursor is immediately outside impl item block 2019-03-16 23:19:14 +01:00
Igor Matuszewski
2f36f47dab Do a cleanup/legibility pass 2019-03-16 22:41:13 +01:00
Igor Matuszewski
1df81f3d65 Take into account parent indent when filling trait members 2019-03-16 22:41:13 +01:00
Igor Matuszewski
b3742873d9 Simplify trait resolution fragment 2019-03-16 22:41:13 +01:00
Igor Matuszewski
0e47c371fd Ignore unnamed trait fns and add more tests 2019-03-16 22:41:13 +01:00
Igor Matuszewski
406343492c Simplify calculation of missing functions
Asymptotically computing a set difference is faster but in the average
case we won't have more than ~10 functions. Also prefer not using hash
sets as these may yield nondeterministic results.
2019-03-16 22:41:13 +01:00
Igor Matuszewski
713975b1c1 Properly support the case when the cursor is inside an empty block or outside 2019-03-16 22:41:13 +01:00
Igor Matuszewski
38eece97ec Redo indent calculation when adding missing impl members 2019-03-16 22:41:13 +01:00
Igor Matuszewski
2f616eea9c Implement a simple working assist 2019-03-16 22:41:13 +01:00
Igor Matuszewski
1c07c5ccf9 Calculate missing functions from impl body 2019-03-16 22:41:13 +01:00
Igor Matuszewski
fc060573f9 Add 'add_missing_impl_members' assist stub 2019-03-16 22:41:13 +01:00
Michael Killough
b42c5ced68 Implement BindingMode for pattern matching.
Implement `BindingMode` for pattern matching, so that types can be
correctly inferred using match ergonomics. The binding mode defaults to
`Move` (referred to as 'BindingMode::BindByValue` in rustc), and is
updated by automatic dereferencing of the value being matched.
2019-03-16 18:13:13 +00:00
Florian Diebold
7faae12311 Remove FnSig from FnDef type
It doesn't need to be in there since it's just information from the def. Another
step towards aligning Ty with Chalk's representation.
2019-03-16 17:29:55 +01:00
Florian Diebold
a9ddaba905 Refactor FnSig a bit 2019-03-16 17:21:32 +01:00
Florian Diebold
628b530e92 Some more Ty displaying cleanup 2019-03-16 16:50:31 +01:00
Florian Diebold
c5ee60e05b Replace Display by a pretty printing trait for Ty
This allows removing the names from Adt and FnDef (and more later), as a first
step towards aligning more with chalk's Ty :)
2019-03-16 16:36:59 +01:00
Aleksey Kladov
8774067a87 sort navigations to make tests stable 2019-03-14 13:28:45 +03:00
Michael Chesser
943d2fb781 Add test for minus in inner pattern 2019-03-14 19:24:12 +10:30
Michael Chesser
16418c35bc Allow MINUS at the start of a pattern. 2019-03-14 19:24:11 +10:30
pcpthm
adad641c52 derive Hash for ra_hir::ModuleDef 2019-03-14 17:25:51 +09:00
bors[bot]
65a9066115 Merge #958
958: LSP: Support EnumMember and Field r=matklad a=kjeremy



Co-authored-by: kjeremy <kjeremy@gmail.com>
2019-03-12 10:16:04 +00:00
Aleksey Kladov
e9e792f2d7 remove Def 2019-03-12 12:36:37 +03:00
kjeremy
31b69e685d LSP: Support EnumMember and Field 2019-03-11 13:58:38 -04:00
Caio
cc9721996c Add test for async block 2019-03-10 14:35:25 -03:00
Caio
ad72699553 Add async keyword 2019-03-09 20:40:22 -03:00
Florian Diebold
c30c5fb4dd Don't default publishDecorations to true on the server
If the client doesn't specify this explicitly, that very likely means it doesn't
know about it and so we shouldn't send decorations. In particular, the recent
change to this default caused decorations to be sent to emacs, resulting in a
lot of warning spam.
2019-03-09 12:55:15 +01:00
kjeremy
27fc99776f Remove superfluous semicolons
Doesn't change the result of the test but it does prevent the
syntax tree from rendering.
2019-03-08 16:45:26 -05:00
Ville Penttinen
b168104d95 Use ast::Name::text() instead of name().syntax().text() 2019-03-07 20:58:41 +02:00
Ville Penttinen
5c0556c2ca Fix EnumVariants not showing properly when hovering
This fixes documentation as well for EnumVariants
2019-03-07 20:33:33 +02:00
bors[bot]
4ce962f64e Merge #948
948: Fix test_missing_module_code_action_in_json_project on Windows r=matklad a=vipentti

The test would fail on Windows due to the paths not being properly escaped for
JSON.

In addition adds extra braces around the fn main to actually introduce braces in
the file.

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>
2019-03-07 17:35:57 +00:00
Ville Penttinen
84e1d50a2a Fix test_missing_module_code_action_in_json_project on Windows
The test would fail on Windows due to the paths not being properly escaped for
JSON.

In addition adds extra braces around the fn main to actually introduce braces in
the file.
2019-03-07 19:27:06 +02:00
pcpthm
d4108cdd60 Specify derive feature for serde 2019-03-08 01:58:29 +09:00
Ville Penttinen
4a0bb3d7c5 Add support for goto definition and hover on Self
This fixes #943
2019-03-07 17:34:44 +02:00
Aleksey Kladov
1aa11eb7e9 when loading workspace, say how many packages were loaded
this should help to debug configuration issues, when you see `0
packages loaded` or something like that.
2019-03-07 17:46:17 +03:00
bors[bot]
5232099977 Merge #939
939: Initial implementation of project-lock.json. r=davidtwco a=davidtwco

Fixes #792.

This PR adds a initial implementation of project-lock.json, a build
system agnostic method of specifying the crate graph and roots.

Co-authored-by: David Wood <david@davidtw.co>
2019-03-07 11:36:04 +00:00
David Wood
4cd757c1e3
Remove rust-project.json test w/ dependencies. 2019-03-07 12:28:19 +01:00
David Wood
3bc33ae712
Add test demonstrating logic for handling deps. 2019-03-07 01:06:46 +01:00
David Wood
614dd3c347
Rename and change add_roots to return a Vec. 2019-03-07 01:05:07 +01:00
David Wood
00d927a188
Initial implementation of project-lock.json.
This commit adds a initial implementation of project-lock.json, a build
system agnostic method of specifying the crate graph and roots.
2019-03-07 01:05:03 +01:00
kjeremy
064707c5a0 Use source map 2019-03-06 14:40:42 -05:00
kjeremy
aac421b135 Hover for associated items in patterns 2019-03-06 11:39:11 -05:00
bors[bot]
b1a1d20e06 Merge #933
933: Check installed extension r=matklad a=c410-f3r

Fixes #918.

Edit: Windows encoding for Unicode is UTF-16 so String::from_utf8 will probably fail unless `Vec<u8>` is already UTF-8 somehow, which I don't know for sure.

Co-authored-by: Caio <c410.f3r@gmail.com>
2019-03-06 12:21:55 +00:00
Ville Penttinen
0dcb1cb569 Add showWorkspaceLoadedNotification to vscode client
This allows users to control whether or not they want to see the "workspace
loaded" notification.

This is done on the server side using InitializationOptions which are provided
by the client. By default show_workspace_loaded is true, meaning the
notification is sent.
2019-03-06 11:34:38 +02:00
Caio
cb60416cb5 Check installed extension 2019-03-05 18:19:36 -03:00
Ville Penttinen
ce118da149 Rename feedback to show_message 2019-03-05 22:25:24 +02:00
Ville Penttinen
80347b8187 Remove InternalFeedback 2019-03-05 22:20:11 +02:00
Ville Penttinen
9063dabcca Send an actual ShowMessage instead of InternalFeedback in feedback()
This now allows us to send a notification that can be shown in the UI when the
workspace has been loaded.

Additionally this removes the need for internal_mode flag.
2019-03-05 21:59:01 +02:00
kjeremy
eb3ee7b8e5 Updates 2019-03-05 10:26:36 -05:00
Aleksey Kladov
d1c982d3c7 dont produce giant debug dumps 2019-03-05 17:09:48 +03:00
Aleksey Kladov
73b892aaa3 show message in client's UI if workspace fails to load 2019-03-05 16:33:05 +03:00
bors[bot]
e7241274ef Merge #930
930: Add support for parsing multiple if and while-let patterns r=matklad a=vipentti



Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>
2019-03-05 10:28:24 +00:00
Ville Penttinen
eb1ac43867 Introduce pattern_list to parse pipe separated patterns
pattern_list comes in two variants, one uses the default PAT_RECOVERY_SET as the
recovery set, while other allows the user to provide a recovery set.
2019-03-05 11:31:25 +02:00
bors[bot]
fe48f9f4d2 Merge #912
912: Make goto definition/hover work for associated items r=matklad a=kjeremy

Just functions so far. Looking for comments.

Fixes #911
Towards #832

Co-authored-by: kjeremy <kjeremy@gmail.com>
Co-authored-by: Jeremy Kolb <kjeremy@gmail.com>
2019-03-05 07:30:19 +00:00
Ville Penttinen
1f4468a8da Add support for parsing multiple if and while-let patterns 2019-03-04 19:10:14 +02:00
kjeremy
ac678473b8 Use impl_froms! 2019-03-04 09:52:48 -05:00
kjeremy
1578375b89 Make ExpOrPatId private 2019-03-04 09:49:18 -05:00
Aleksey Kladov
90122542b2 allow mut ident patterns in trait methods
closes #928
2019-03-04 17:47:02 +03:00
Aleksey Kladov
0a19f4f1b4 allow aliases in underscores
this helps with

    use foo::Trait as _;

syntax
2019-03-04 16:40:08 +03:00
Jeremy Kolb
79f61dcb0e Format 2019-03-04 08:34:41 -05:00
Jeremy Kolb
e1b59bfe0b Add NavigationTarget::from_impl_item 2019-03-04 08:27:08 -05:00
Jeremy Kolb
ad2da5b1da Remove commented out code 2019-03-04 08:27:08 -05:00
Jeremy Kolb
3d8d880c59 Use ImplItems instead of just Function 2019-03-04 08:27:08 -05:00
kjeremy
49da9a3e81 Make goto definition/hover resolve constructors 2019-03-04 08:27:08 -05:00
bors[bot]
dc8bcc1e42 Merge #926
926: allow vararg functions r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-03-04 12:49:37 +00:00
Aleksey Kladov
77f2381eea improve error recovery
parse the contents of error block as an expression
2019-03-04 15:31:18 +03:00
Aleksey Kladov
a99b1db49f allow vararg functions 2019-03-04 14:34:59 +03:00
Aleksey Kladov
3000b13df2 extract block contents into a function 2019-03-04 14:17:31 +03:00
bors[bot]
5197e16648 Merge #916
916: Error handling for macros r=matklad a=detrumi

Part of #720 

Co-authored-by: Wilco Kusee <wilcokusee@gmail.com>
2019-03-04 10:58:08 +00:00
Ville Penttinen
1ef2c06131 Allow syntax strings to contain test markers
We simply remove all the CUSTOM_MARKERS before attempting to parse the file.
This allows for the syntax selection to work with most of the test strings.
2019-03-04 09:19:46 +02:00
Ville Penttinen
16ecd276f0 Implement syntax tree support for syntax inside string
This allows us to select a string or portions of it and try parsing it as rust
syntax. This is mostly helpful when developing tests where the test
itself contains some rust syntax as a string.
2019-03-04 09:02:01 +02:00
Wilco Kusee
c9d6efc468 Add expander unit tests 2019-03-03 20:33:50 +01:00
Ville Penttinen
ac52d9a1f1 Add optional range parameter to SyntaxTreeParams
When range is provided, instead of showing the syntax for the whole file, we'll
show the syntax tree for the given range.
2019-03-03 19:49:50 +02:00
Wilco Kusee
d149bb885b Add parser unit tests 2019-03-03 12:45:30 +01:00
Florian Diebold
2e8f258845 Inline type inference test snapshots 2019-03-03 12:41:42 +01:00
Wilco Kusee
725805dc79 Split parse and expand errors 2019-03-03 10:40:03 +01:00
Florian Diebold
affaf7700a Represent unknown types as {unknown} instead of [unknown]
Since the latter could actually be a real type...
2019-03-03 03:00:17 +01:00
Wilco Kusee
dffe318701 Formatting 2019-03-02 20:49:13 +01:00
Wilco Kusee
d3a252b559 Replace option with result in mbe 2019-03-02 20:30:13 +01:00
Florian Diebold
b7fdad8448 Add a bunch of tests for type inference involving traits
None of them works correctly yet, of course.
2019-03-02 16:42:51 +01:00
bors[bot]
00b09bcd8c Merge #908
908: Enable markup for hover on expressions which resolve using type_of r=matklad a=vipentti

This adds highlighting when hovering over items which are resolved using
`type_of`.

This adds basic highlighting, discussed in #904.

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>
2019-03-02 14:21:44 +00:00
bors[bot]
fd7240837b Merge #915
915: Bring BodySyntaxMapping in line with other source-map instances r=flodiebold a=matklad

* rename to SourceMap
* don't store the actual body inline, just return a pair

r? @flodiebold 

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-03-02 14:09:46 +00:00
Aleksey Kladov
f0a9d026fc remove comment 2019-03-02 17:01:20 +03:00
Aleksey Kladov
8fc08d36e3 remove second way to get the body 2019-03-02 16:59:18 +03:00
Aleksey Kladov
03b2ab8e1f rename syntax_mapping as well 2019-03-02 16:56:09 +03:00
Florian Diebold
862b663501 A bit of cleanup in ty.rs 2019-03-02 14:53:12 +01:00
Aleksey Kladov
80bb7d86ec align lower module query names 2019-03-02 16:49:06 +03:00
Aleksey Kladov
fe5574b05a rename scopes 2019-03-02 16:38:28 +03:00
Aleksey Kladov
ca957edf96 rename to source_map 2019-03-02 16:36:25 +03:00
Aleksey Kladov
f4c5383103 dont store body inside source map 2019-03-02 16:18:40 +03:00
Aleksey Kladov
eaf1df26e9 rename syntax-mapping -> source-map 2019-03-02 15:40:40 +03:00
kjeremy
d0efa77e0e Update hover message since we do support globs 2019-02-28 14:48:21 -05:00
Ville Penttinen
da26820ebd Enable markup for hover on expressions which resolve using type_of
This adds highlighting when hovering over items which are resolved using
`type_of`.
2019-02-28 09:33:06 +02:00
bors[bot]
84e47113e0 Merge #906
906: Add support for goto definition and hover for struct fields r=matklad a=vipentti

This works partially towards fixing #512

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>
2019-02-27 15:59:56 +00:00
Ville Penttinen
c879f43186 Enable hover support for NamedFieldDefs
Additionally add type ascription for const and statics as well.
2019-02-27 17:52:37 +02:00
Ville Penttinen
bb4521be1c Allow goto-definition to work for named fields in struct initializer
Now goto definition should work when done on a named field in a struct
initializer.
2019-02-27 17:51:59 +02:00
kjeremy
7463f5debb Fix the build 2019-02-27 09:35:04 -05:00
bors[bot]
2e2a6dd2fb Merge #900
900: Add new trait ast::TypeAscriptionOwner r=vipentti a=vipentti

This trait should be implemented for nodes which have an ascribed type,
e.g. thing : Type. Such as let, const, static, param, named struct fields.

In addition, we update some places where previously we used node + node.type_ref() with `TypeAscriptionOwner` in the trait bounds.

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>
2019-02-27 12:18:55 +00:00
Ville Penttinen
d3ce69aee3 Remove TypeRef from item opts which implement TypeAscriptionOwner 2019-02-27 14:08:09 +02:00
bors[bot]
1927eb088a Merge #901
901: Add basic support for showing fn signature when hovering r=matklad a=vipentti

This adds basic support for displaying function signature when hovering over a usage of a function. 

Additionally refactored `hover` to return `HoverResult` to ease with testing and in general to be more robust.

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>
2019-02-27 11:50:38 +00:00
Ville Penttinen
6eb45c1c2b Remove RawResponse::empty() 2019-02-27 12:57:59 +02:00
Ville Penttinen
33cebe1724 Work around for issue in vscode reporting a failure in request
vscode would report "A request has failed" when it got "Content modified"
message and this would cause a pop-up to appear. This works around the issue by
returning an "empty" response that vscode can ignore.
2019-02-27 12:49:04 +02:00
Ville Penttinen
e3525527e3 Add support for hovering over the name of an item 2019-02-27 09:49:22 +02:00
Ville Penttinen
79114c67b1 Replace visit_fn with crate::completion::function_label 2019-02-26 21:30:46 +02:00
Dale Wijnand
ffca2c1fe4
Fix a typo 2019-02-26 17:59:32 +00:00
Ville Penttinen
6f5fd6c9de Add new type HoverResult to contain the results of hovering
This makes testing hovers easier as well as allows us to do more things with the
results if needed.
2019-02-26 19:30:17 +02:00
Ville Penttinen
3ec2584148 Add support for showing fn signature when hovering 2019-02-26 18:55:08 +02:00
Ville Penttinen
52054e1140 Use TypeAscriptionOwner
This replaces places where we would use node + node.type_ref() with things that
have an ascribed type, with using the TypeAscriptionOwner as the trait bound so
we can simply pass the node.
2019-02-26 11:47:13 +02:00
Ville Penttinen
6eb070d661 Add new trait TypeAscriptionOwner
This trait should be implemented for nodes which have an ascribed type,
e.g. thing : Type. Such as let, const, static, param, named struct fields.
2019-02-26 11:35:57 +02:00
bors[bot]
7c9acf2f83 Merge #897
897: Add basic const/static type inference r=flodiebold a=vipentti

This adds basic const/static type inference discussed in #887.

Currently the inference does not work for const/static declared inside a block. In addition the inference does not work inside the bodies of const/static.

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>
2019-02-25 12:03:57 +00:00
Aleksey Kladov
4f67df9042 kill accidently commited file 2019-02-25 15:02:12 +03:00
Aleksey Kladov
78f10fcdc4 rename type to type_alias in the AST as well 2019-02-25 13:49:32 +03:00
Ville Penttinen
cff9a7dfad Move ConstSignature creation to a single method 2019-02-25 10:55:39 +02:00
Ville Penttinen
29f93a7906 Add static type inference 2019-02-25 10:55:23 +02:00
Ville Penttinen
18b0bd9bff Add const type inference 2019-02-25 10:51:46 +02:00
Aleksey Kladov
330ce2e26b complete patterns 2019-02-24 23:50:02 +03:00
Florian Diebold
bd8ed644e4 Rename Type => TypeAlias 2019-02-24 21:36:49 +01:00
Florian Diebold
c3c0979561 Add test for recursive type aliases 2019-02-24 20:54:04 +01:00
Florian Diebold
5d72b96988 Implement support for type aliases 2019-02-24 20:54:04 +01:00
Aleksey Kladov
d5f6a5f5e2 move testing functions 2019-02-24 21:54:13 +03:00
Aleksey Kladov
98510ec5d3 move the rest of presentation to presentation 2019-02-24 21:46:04 +03:00
Aleksey Kladov
b7a7872910 move more code to presentation 2019-02-24 21:34:38 +03:00
Aleksey Kladov
a650a93bf5 move res completion to presentation 2019-02-24 21:21:31 +03:00
Aleksey Kladov
2369af8c82 simplify 2019-02-24 20:59:12 +03:00
Aleksey Kladov
5887c0e574 move enum-variants to presentation 2019-02-24 20:56:53 +03:00
Aleksey Kladov
9af525dbd6 simplify 2019-02-24 20:49:55 +03:00
Aleksey Kladov
3c7c5a7354 move presentaion completion to presentation 2019-02-24 19:37:22 +03:00
Aleksey Kladov
b04cadc02c move function rendering to presentation 2019-02-24 19:34:27 +03:00
Aleksey Kladov
d0a261468e introduce completion presentation
This module should remove completion rendering boilerplate from the
"brains" of completion engine.
2019-02-24 18:51:38 +03:00
bors[bot]
67528c4b39 Merge #891
891: Field completion r=matklad a=matklad

bors r+

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-02-24 14:39:38 +00:00
Aleksey Kladov
6285fcc39b complete fields in struct literals 2019-02-24 17:39:08 +03:00
Florian Diebold
c71740e956 Clean up imports a bit 2019-02-24 15:17:20 +01:00
Aleksey Kladov
65a2be4953 complete struct literals 2019-02-24 17:01:56 +03:00
Aleksey Kladov
666303faf3 support upcastig in AST enum 2019-02-24 16:57:05 +03:00
Aleksey Kladov
c110e72a11 add marks to assists 2019-02-24 15:46:06 +03:00
Aleksey Kladov
b3cc7c057d dont show introduce variable everywhere 2019-02-24 14:18:10 +03:00
Aleksey Kladov
ef442b8682 Assign IDs to assists 2019-02-24 14:00:00 +03:00
bors[bot]
f6f160391d Merge #885
885: Parse token trees directy r=matklad a=matklad

This takes advantage of the recent macro refactoring to directly parse token stream into a syntax tree.

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-02-24 10:15:43 +00:00
Aleksey Kladov
81bca78349 rename 2019-02-24 13:14:14 +03:00
Florian Diebold
82fe7b77a3 Refactor associated method resolution a bit and make it work with generics 2019-02-23 23:00:02 +01:00
Aleksey Kladov
8cf156d85b Add a test for macro parsing 2019-02-23 17:51:23 +03:00
Florian Diebold
dcfb4ee702 Split ty.rs into several modules
It was just getting too big. We now have:

 - ty: the `Ty` enum and helpers
 - ty::infer: actual type inference
 - ty::lower: lowering from HIR to `Ty`
 - ty::op: helpers for binary operations, currently
2019-02-23 15:36:38 +01:00
Aleksey Kladov
8eac450f41 implement tt -> ast 2019-02-23 17:21:56 +03:00
Aleksey Kladov
83d6be6cec keep-text 2019-02-23 16:55:18 +03:00
Aleksey Kladov
71b8a874e7 flatten tt 2019-02-23 16:55:18 +03:00
Aleksey Kladov
10deefd371 token source scaffold 2019-02-23 16:55:18 +03:00
Aleksey Kladov
e9cafafbc2 add dependency on the parser 2019-02-23 16:55:18 +03:00
Aleksey Kladov
60373aa504 add interface 2019-02-23 16:55:18 +03:00
Aleksey Kladov
f078f7adc8 introduce tree builder 2019-02-23 16:55:01 +03:00
Ville Penttinen
14cff98cb0 Simplify test_fill_match_arm_refs test cases 2019-02-23 15:13:17 +02:00
Aleksey Kladov
0c1cb98182 rename 2019-02-23 16:07:29 +03:00
Ville Penttinen
9dafad2402 Fix fill_match_arms not working with references 2019-02-23 15:05:26 +02:00
bors[bot]
e5fb33a946 Merge #879
879: Fixes to goto definition r=vipentti a=vipentti

Previously goto definition would fail when the cursor was over the name of the definition. Now we should properly resolve to a `NavigationTarget` when on top of the name of a definition.

In addition this adds `name_range` field to `FileSymbol`, this further fixes goto_definition and symbol based navigation by allowing the `NavigationTarget` to actually have a `focus_range`, meaning instead of focusing on the start of the `full_range`, we can have the cursor focus on the name.

e.g. goto definition
```rust
fn bar() {
    fn foo() { }
  
   foo<|>();
}
```

Previously this would put the cursor at the start of the FN_DEF:
```rust
fn bar() {
   <|>fn foo() { }
  
   foo();
}
```
Now when using the symbol based resolving, we'll have a proper focus range and instead put the cursor at the start of the name.

```rust
fn bar() {
   fn <|>foo() { }
  
   foo();
}
```

This fixes #877 but doesn't contain the refactoring of the return type for `goto_definition`

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>
2019-02-23 12:17:53 +00:00
Ville Penttinen
40e6cb196b Remove unnecessary to_nav_target 2019-02-23 14:08:57 +02:00
Florian Diebold
6a04d1f292 Fix resolution of associated method calls across crates
I think it'll be better to make the path resolution the number of unresolved
segments, not the first unresolved index; then this error could simply not have
happened. But I'll do that separately.
2019-02-23 12:37:29 +01:00
Ville Penttinen
c565ec2d6e Add name_range field to FileSymbol
This contains the syntax range of the name itself, allowing NavigationTarget to
properly set the focus_range. This should make it so that when using symbol
based navigation, we should always focus on the name, instead of the full range.
2019-02-23 13:05:45 +02:00
Ville Penttinen
7046b16275 Fix NavigationTarget debug_render container_name output 2019-02-23 12:53:53 +02:00
Ville Penttinen
2a3abe2ce3 Fix goto def not working when cursor was over the name of a def
We now allow goto_definition to return the named NavigationTarget if the cursor
is on the name of a definition.
2019-02-23 11:02:42 +02:00
bors[bot]
3d8a0982a1 Merge #866
866: Implement basic support for Associated Methods r=flodiebold a=vipentti

This is my attempt at learning to understand how the type inference works by adding basic support for associated methods. Currently it does not resolve associated types or constants. 

The basic idea is that `Resolver::resolve_path` returns a new `PathResult` type, which has two variants, `FullyResolved` and `PartiallyResolved`, fully resolved matches the previous behavior, where as `PartiallyResolved` contains the `PerNs<Resolution` in addition to a `segment_index` which contains the index of the segment which we failed to resolve. This index can then be used to continue inference in `infer_path_expr` using the `Type` we managed to resolve.

This changes some of the previous apis, so looking for feedback and suggestions.

This should enable fixing #832

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>
2019-02-22 19:58:22 +00:00
Ville Penttinen
247d1c17b3 Change resolve_path to return the fully resolved path or PerNs::none
This also adds new pub(crate) resolve_path_segments which returns the
PathResult, which may or may not be fully resolved. PathResult is also now
pub(crate) since it is an implementation detail.
2019-02-22 10:15:23 +02:00
Ville Penttinen
39679d499f Ignore failing test for now 2019-02-22 00:27:22 +02:00
Ville Penttinen
a34eb98a78 Make nameres::ResolvePathResult private and refactor 2019-02-22 00:11:21 +02:00
Ville Penttinen
2e7bc905be Remove Const inference for now, refactor PathResult 2019-02-21 23:57:07 +02:00
bors[bot]
bb665a7062 Merge #864
864: Fix handling of generics in tuple variants and refactor a bit r=matklad a=flodiebold

(The problem was that we created separate substitutions for the return value, so we lost the connection between the type arguments in the constructor call and the type arguments of the result.)

Also make them display a tiny bit nicer.

Fixes #860.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
2019-02-21 20:47:50 +00:00
Florian Diebold
db9a5a9ac0 Add an assert (and fix the other) 2019-02-21 21:25:27 +01:00
bors[bot]
5100aeac42 Merge #876
876: Fix join_lines not adding a comma after join_single_expr_block with match arm r=matklad a=vipentti

Fixes #868 

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>
2019-02-21 16:55:26 +00:00
Ville Penttinen
82173c8de4 Move non_trivia_sibling to ra_syntax::algo 2019-02-21 18:49:03 +02:00
Ville Penttinen
3c22c64725 Simplify adding a comma after match arm 2019-02-21 18:26:27 +02:00
Ville Penttinen
40add5de9a Fix join_lines not adding a comma after join_single_expr_block in match arm
We will also remove optional whitespace between the expression and the comma.

e.g.

```rust
fn foo() {
    let x = (<|>{
       4
    }   ,); // NOTE: whitespace
}
```

becomes

```rust
fn foo() {
    let x = (<|>4,);
}
```
2019-02-21 17:55:14 +02:00
kjeremy
56f48ac42a Update lsp-types and backtrace 2019-02-21 10:07:14 -05:00
Aleksey Kladov
4fe07a2b61 add API guide to ra_syntax 2019-02-21 17:35:45 +03:00
Aleksey Kladov
7060a39d5c simplify trait bounds 2019-02-21 16:12:15 +03:00
Aleksey Kladov
b51b71bf25 rearrange methods 2019-02-21 16:04:03 +03:00
Aleksey Kladov
f7f99af0a6 kill utils module 2019-02-21 15:57:40 +03:00
Aleksey Kladov
6225e1ab70 Ignore lockfile in fuzz
It's too much trouble maintaining it
2019-02-21 15:44:38 +03:00
Aleksey Kladov
412ac63ff5 docs 2019-02-21 15:24:42 +03:00
Aleksey Kladov
2fa2805887 add failing test 2019-02-21 14:06:21 +03:00
Aleksey Kladov
46179230a0 fix the test 2019-02-21 13:45:10 +03:00
Aleksey Kladov
c47f9e2d37 fix compilation 2019-02-21 13:37:32 +03:00
Aleksey Kladov
d334b5a1db move parser to a separate crate 2019-02-21 13:27:45 +03:00
Ville Penttinen
816971ebc9 Implement basic support for Associated Methods and Constants
This is done in `infer_path_expr`. When `Resolver::resolve_path` returns
`PartiallyResolved`, we use the returned `Resolution` together with the given
`segment_index` to check if we can find something matching the segment at
segment_index in the impls for that particular type.
2019-02-21 12:25:55 +02:00
Aleksey Kladov
cd0d2866fc make grammar independent of syntax tree 2019-02-21 12:12:04 +03:00
Aleksey Kladov
1b2e70df99 minor 2019-02-21 12:05:52 +03:00
Aleksey Kladov
79ce0fa8d7 move whitespace handling to tree builder 2019-02-21 12:03:42 +03:00
Florian Diebold
72712b8a42 Fix handling of generics in tuple variants and refactor a bit
Also make them display a tiny bit nicer.

Fixes #860.
2019-02-20 22:48:55 +01:00
Aleksey Kladov
882c47f187 move syntax error to parser 2019-02-20 23:17:07 +03:00
Aleksey Kladov
61992dc1cd simplify 2019-02-20 23:05:59 +03:00
Aleksey Kladov
4c1f9b8d4e remove TokenPos 2019-02-20 23:02:24 +03:00
Aleksey Kladov
cce23fddba flattern module structure 2019-02-20 22:52:32 +03:00
Aleksey Kladov
2acb21e8f7 merge parse_impl and parser_api 2019-02-20 22:44:06 +03:00
Aleksey Kladov
e72ad0a2fa fix off by one error 2019-02-20 22:27:49 +03:00
Aleksey Kladov
2b5e336ce7 move abstract traits to top 2019-02-20 22:19:12 +03:00
Aleksey Kladov
d2bce118ae switch to dynamic dispatch for TokenSource
Benchmarks show no difference. This is probably because we are
bottlenecked on memory allocations, and we should fix that, but we are
not optimizing for performance just yet.

changes. Lines starting # with '#' will be ignored, and an empty
message aborts the commit. # # On branch token-source # Changes to be
committed: # modified: crates/ra_syntax/src/parsing/parser_api.rs #
modified: crates/ra_syntax/src/parsing/parser_impl.rs #
2019-02-20 22:02:03 +03:00
Aleksey Kladov
0c81b9deee route parsing via TokenSource trait 2019-02-20 21:50:07 +03:00
Aleksey Kladov
3517c175ac rename Sink -> TreeSink 2019-02-20 21:08:59 +03:00
Aleksey Kladov
86a67dce25 fix tests 2019-02-20 16:48:06 +03:00
Aleksey Kladov
45fc91cc47 rearrange modules in a suggestd reading order 2019-02-20 16:24:39 +03:00
Aleksey Kladov
a4a1e08ab8 flatten modules 2019-02-20 16:16:14 +03:00
Aleksey Kladov
9f6883fbf1 move reparsers to grammar 2019-02-20 16:02:06 +03:00
Aleksey Kladov
5a6eda528c tighten visibility 2019-02-20 15:57:26 +03:00
Aleksey Kladov
5222b8aba3 move all parsing related bits to a separate module 2019-02-20 15:47:32 +03:00
Aleksey Kladov
9d0cda4bc8 slightly better name 2019-02-20 15:03:31 +03:00
Aleksey Kladov
df6efe62c5 make stuff private 2019-02-20 14:53:19 +03:00
Aleksey Kladov
9738fb48a6 remove ignored macro tests
we need to significantly reengineer macros, so the tests as they exist
are useless
2019-02-19 20:06:53 +03:00
Aleksey Kladov
a6897a837c remove local-vfs 2019-02-18 16:43:48 +03:00
Aleksey Kladov
1bdd935e91 switch to crates.io vfs 2019-02-18 16:43:16 +03:00
Aleksey Kladov
d93097a493 better comments 2019-02-18 16:20:12 +03:00
Aleksey Kladov
def7bc0ec5 drop dependency on thread_worker 2019-02-18 15:30:58 +03:00
Aleksey Kladov
9da3705191 drop unused extern crate 2019-02-18 14:39:18 +03:00
Aleksey Kladov
c5a65466e2 hide TaskResult from the public API 2019-02-18 14:29:54 +03:00
Aleksey Kladov
062aa97235 move public API to top of the file 2019-02-18 14:29:39 +03:00
Aleksey Kladov
74288ae272 remove depedency on ra_arena 2019-02-18 14:20:54 +03:00
Aleksey Kladov
4c154c289e remove arena from Roots
we want to move ra_vfs to a new repo, so having fewer deps is useful.
Arena is a thin layer of sugar on top of Vec anyway.
2019-02-18 14:13:13 +03:00
Aleksey Kladov
d151b2a655 remove useless Arc 2019-02-18 14:05:08 +03:00
Aleksey Kladov
5823d3d042 drop unused deps 2019-02-18 12:46:08 +03:00
bors[bot]
16c7ebbb27 Merge #854
854: more compact edits in insta r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-02-18 09:26:24 +00:00
Aleksey Kladov
a92db7c848 more compact edits in insta 2019-02-18 12:24:25 +03:00