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>
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>
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>
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>
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.
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.
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.
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>
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.
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>
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>
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.
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.
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>
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.
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.
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>
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>
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>
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>
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>
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.
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.
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>
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>
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
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>
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.
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.
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>
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.
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>